index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="tab" :style="{
  3. '--barheight': barHeight + 'px',
  4. '--color': color,
  5. '--bgcolor': bg,
  6. height: fixedHeight
  7. }">
  8. <view class="heads">
  9. <image class="bgImg" v-if="bgImg" :src="bgImg" mode=""></image>
  10. <slot name="left">
  11. <up-icon name="photo" color="#2979ff" size="28" v-if="show_back" :color="color" @click="back"></up-icon>
  12. <!-- <uni-icons v-if="show_back" type="left" size="30" :color="color" @click="back"></uni-icons> -->
  13. </slot>
  14. <slot name="title">
  15. <text class="title" :style="{'--size': titlesize}">{{ title }}</text>
  16. </slot>
  17. <slot name="right">
  18. <!-- <uni-icons type="left" size="30" color="transparent"></uni-icons> -->
  19. </slot>
  20. </view>
  21. <slot name="bottom"></slot>
  22. </view>
  23. </template>
  24. <script setup>
  25. import {
  26. ref,
  27. computed,
  28. onMounted,
  29. defineProps,
  30. defineEmits
  31. } from 'vue';
  32. const props = defineProps({
  33. title: { //标题
  34. type: String,
  35. default: ""
  36. },
  37. show_back: { //显示返回按钮
  38. type: Boolean,
  39. default: true
  40. },
  41. back_type: { //是否使用组件的返回
  42. type: Boolean,
  43. default: false
  44. },
  45. bg: { //背景
  46. type: String,
  47. default: '#fff'
  48. },
  49. color: { //标题的字体颜色
  50. type: String,
  51. default: 'white'
  52. },
  53. //背景图片
  54. bgImg: {
  55. default: ""
  56. },
  57. // 文字大小
  58. titlesize: {
  59. type: String,
  60. default: "36rpx"
  61. },
  62. bottomHeight: {
  63. type: String,
  64. default: "80rpx"
  65. },
  66. fixed: {
  67. type: Boolean,
  68. default: true
  69. }
  70. });
  71. const emit = defineEmits(['right']);
  72. // 状态栏高度
  73. const barHeight = ref(0);
  74. const rpxToPx = (rpx) => {
  75. const systemInfo = uni.getSystemInfoSync();
  76. return (rpx / 750) * systemInfo.windowWidth;
  77. };
  78. const fixedHeight = computed(() => {
  79. if (!props.fixed) return '0';
  80. // 将80rpx转换为px
  81. const navHeightPx = rpxToPx(80);
  82. return `${barHeight.value + navHeightPx}px`;
  83. });
  84. onMounted(() => {
  85. // 获取状态栏高度
  86. const systemInfo = uni.getSystemInfoSync();
  87. barHeight.value = systemInfo.statusBarHeight || 0;
  88. });
  89. // 返回按钮图片
  90. const back_image = computed(() => {
  91. return props.color == 'white' ? require('./down.png') : require('./back.png');
  92. });
  93. const back = () => {
  94. if (!props.show_back) return;
  95. uni.navigateBack({
  96. fail: () => {
  97. uni.reLaunch({
  98. url: uni.getStorageSync('userType') == 4 ?
  99. '/pages/index/dispose/index' : '/pages/index/index'
  100. });
  101. }
  102. });
  103. };
  104. const right = () => {
  105. emit('right');
  106. };
  107. </script>
  108. <style lang="scss" scoped>
  109. .tab {
  110. position: sticky;
  111. top: 0;
  112. left: 0;
  113. width: 100%;
  114. z-index: 999;
  115. }
  116. .heads {
  117. z-index: 100;
  118. width: 100%;
  119. height: calc(var(--barheight) + 80rpx);
  120. justify-content: space-between;
  121. display: flex;
  122. align-items: center;
  123. padding-top: var(--barheight);
  124. padding-left: 20rpx;
  125. padding-right: 20rpx;
  126. padding-bottom: 10rpx;
  127. background: var(--bgcolor);
  128. box-sizing: border-box;
  129. .bgImg {
  130. width: 100%;
  131. height: 100%;
  132. position: absolute;
  133. top: 0;
  134. left: 0;
  135. z-index: -1;
  136. }
  137. .title {
  138. width: 100%;
  139. text-align: center;
  140. font-size: var(--size);
  141. font-family: PingFang SC;
  142. font-weight: bold;
  143. color: var(--color);
  144. position: absolute;
  145. left: 0;
  146. pointer-events: none;
  147. }
  148. }
  149. </style>