en-nav.vue 3.1 KB

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