en-nav.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view :class="is_fixed?getBg(type):''">
  3. <view class="header" style="z-index: 3;" :style="[{color},{height},{paddingTop},{justifyContent:justify}]">
  4. <view class="left" :style="[{color},{paddingTop}]" v-if="back" @click="onBack">
  5. <image class="back" src="/static/img/tabBar/nav-back.png"></image>
  6. </view>
  7. <view class="title" :style="[{marginLeft:justify == 'left'?'30rpx':0},{fontSize}]">
  8. <uni-icons class="m-r10" type="calendar" size="22" color="#fff" v-if="is_icons"></uni-icons>
  9. <text>{{title}}</text>
  10. </view>
  11. </view>
  12. <view :style="[{height:is_fixed? `${$tools.topHeight()+bgHeight}px`:`${$tools.topHeight()+fixedHeight}px`}]">
  13. </view>
  14. <!-- 带背景插槽 start-->
  15. <slot></slot>
  16. <!-- 带背景插槽 end-->
  17. <image class="header" style="width: 100%;z-index: 2;"
  18. :style="[{height:is_fixed?`${$tools.topHeight()+navsHeight}px` :`${$tools.topHeight()+fixedHeight}px`},{opacity:is_fixed?navOpacity:1},]"
  19. :src="genre == 0?'/static/img/index/top-nav.png':'/static/img/enNav/tab.png'" mode="">
  20. </image>
  21. </view>
  22. </template>
  23. <script>
  24. // 获取系统状态栏的高度
  25. let systemInfo = uni.getSystemInfoSync();
  26. let menuButtonInfo = {};
  27. // #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
  28. menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  29. // #endif
  30. export default {
  31. data() {
  32. return {
  33. height: 0,
  34. paddingTop: 0,
  35. navOpacity: 0,
  36. navHeight: 0,
  37. }
  38. },
  39. props: {
  40. genre: {
  41. type: Number,
  42. default: 0
  43. },
  44. type: {
  45. type: Number,
  46. default: 0
  47. },
  48. fontSize: {
  49. type: String,
  50. default: '32rpx'
  51. },
  52. title: {
  53. type: String,
  54. default: ''
  55. },
  56. justify: {
  57. type: String,
  58. default: 'center'
  59. },
  60. color: {
  61. type: String,
  62. default: '#333'
  63. },
  64. opacity: {
  65. type: Number,
  66. default: 0
  67. },
  68. back: {
  69. type: Boolean,
  70. default: true
  71. },
  72. is_fixed: {
  73. type: Boolean,
  74. default: false
  75. },
  76. is_filter: {
  77. type: Boolean,
  78. default: false
  79. },
  80. is_icons: {
  81. type: Boolean,
  82. default: false
  83. },
  84. fixedHeight: {
  85. type: Number,
  86. default: 0
  87. },
  88. bgHeight: {
  89. type: Number,
  90. default: 0
  91. },
  92. navsHeight: {
  93. type: Number,
  94. default: 0
  95. },
  96. },
  97. created() {
  98. const navTop = uni.getMenuButtonBoundingClientRect()
  99. this.height = navTop.height + 'px'
  100. this.paddingTop = navTop.top + 'px'
  101. this.navHeight = `${navTop.height+navTop.top}px`
  102. },
  103. watch: {
  104. opacity(newValue, oldValue) {
  105. this.navOpacity = newValue;
  106. }
  107. },
  108. methods: {
  109. // 左侧返回按钮调用
  110. onBack() {
  111. uni.navigateBack()
  112. this.$emit('onBack')
  113. },
  114. getBg(type) {
  115. switch (type) {
  116. case 0:
  117. return 'nav-bg1'
  118. case 0:
  119. return 'nav-bg1'
  120. case 0:
  121. return 'nav-bg1'
  122. default:
  123. break;
  124. }
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .header {
  131. position: fixed;
  132. width: 100%;
  133. display: flex;
  134. align-items: center;
  135. font-size: 26rpx;
  136. z-index: 1;
  137. padding-bottom: 10rpx;
  138. top: 0;
  139. .left {
  140. float: left;
  141. position: absolute;
  142. width: 100rpx;
  143. height: 42rpx;
  144. top: 0;
  145. bottom: 0;
  146. left: 30rpx;
  147. color: #fff;
  148. margin: auto;
  149. .back {
  150. width: 25rpx;
  151. height: 35rpx;
  152. }
  153. }
  154. .title {
  155. font-size: 32rpx;
  156. font-weight: bold;
  157. font-family: Source Han Sans CN;
  158. }
  159. }
  160. .nav-bg1 {
  161. background-image: url("https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/new-xcx/index/index-bg.png?imageMogr2/quality/20");
  162. background-repeat: no-repeat;
  163. background-size: 100% auto;
  164. }
  165. </style>