FixedHead.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="header_content">
  3. <!-- 头部 -->
  4. <view id="header_box" class="header_box">
  5. <DefaultHead @getInfoData="handleGetSystemInfoData" />
  6. <!-- 和胶囊齐平nav条 -->
  7. <view
  8. :style="{
  9. 'padding-top': `${headerObj.menuPadding}px`,
  10. 'transform': `translateY(-${headerObj.menuButtonTogetherNavInfo.transformTop}px)`
  11. }" class="logo_row"
  12. >
  13. <!-- logo -->
  14. <!-- <view class="logo_box">
  15. <image src="../../../../static/images/logo/jf-name.png" />
  16. </view> -->
  17. <!-- 右侧搜索 -->
  18. <template>
  19. <!-- #ifndef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ -->
  20. <!-- <view class="search_box" @click="handleSearch">
  21. <image src="../../../../static/images/origin/search.png" />
  22. </view> -->
  23. <!-- #endif -->
  24. <!-- #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ -->
  25. <!-- <view
  26. class="search_box" :style="{
  27. 'position': 'absolute',
  28. 'left': `${headerObj.systemInfo.menuButtonInfo.left}px`,
  29. 'transform': `translateX(-110%)`
  30. }" @click="handleSearch"
  31. >
  32. <image src="../../../../static/images/origin/search.png" />
  33. </view> -->
  34. <!-- #endif -->
  35. <view style="display: flex;justify-content: center;align-items: center;width: 100%;padding: 10upx 22.5upx 0 22.5upx;">
  36. <TuanLocation
  37. free style="display: flex;align-items: center;padding-left: 18upx;line-height: 1;"
  38. >
  39. <text
  40. style="max-width: 130upx;font-size:28upx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"
  41. >
  42. {{ $store.getters.currentShopCity || '定位失败' }}
  43. </text>
  44. <BeeIcon :size="26" name="turningdown" color="#222229"></BeeIcon>
  45. </TuanLocation>
  46. <view style="width: 4upx;height: 28upx;background-color: #f6f6f8;"></view>
  47. <tui-input
  48. label="" placeholder="商城" disabled clearable
  49. :border-bottom="false"
  50. padding="6upx 10upx 6upx 2upx" placeholder-style="color: #292930;font-size: 28upx;"
  51. background-color="transparent" style="flex: 1;margin-left: 14upx;" @click="go(`/another-tf/another-serve/search/index`)"
  52. >
  53. <template #right>
  54. <tui-button
  55. type="warning" width="120rpx" height="50rpx" shape="circle"
  56. style="background: #ee692f!important;"
  57. @click="go(`/another-tf/another-serve/search/index`)"
  58. >
  59. 搜索
  60. </tui-button>
  61. </template>
  62. </tui-input>
  63. </view>
  64. </template>
  65. </view>
  66. <!-- 其他内容 -->
  67. <!-- <slot /> -->
  68. </view>
  69. <!-- 空盒子撑高 -->
  70. <view class="empty_box" :style="{ height: headerObj.height + 'px' }" />
  71. </view>
  72. </template>
  73. <script>
  74. import DefaultHead from './DefaultHead'
  75. export default {
  76. name: 'FixedHead',
  77. components: {
  78. DefaultHead
  79. },
  80. data() {
  81. return {
  82. // 头部对象
  83. headerObj: {
  84. height: 0, // 容器总体高度
  85. systemInfo: {}, // 系统此乃西
  86. menuPadding: 0, // 胶囊距离statusBar的高度(胶囊top - statusBarHeight)
  87. // 胶囊配置信息
  88. menuButtonTogetherNavInfo: {
  89. height: 36, // 跟胶囊齐平的nav高度(和CSS的nav高度一致)
  90. transformTop: 0 // nav要相对于menuPadding以后向上位移高度
  91. }
  92. }
  93. }
  94. },
  95. methods: {
  96. // 查询产品
  97. handleSearch() {
  98. uni.navigateTo({
  99. url: `/another-tf/another-serve/search/index`
  100. })
  101. },
  102. /**
  103. * 获取系统信息
  104. * 由DefaultHead回调
  105. */
  106. handleGetSystemInfoData(data) {
  107. this.headerObj.systemInfo = data
  108. // #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
  109. this.headerObj.menuPadding = data.menuButtonInfo.top - data.systemInfo.statusBarHeight
  110. const { menuButtonTogetherNavInfo } = this.headerObj
  111. // 如果胶囊高度小于齐平的nav高度
  112. const menuButtonHeight = data.menuButtonInfo.height
  113. const menuButtonTogetherNavHeight = menuButtonTogetherNavInfo.height
  114. if (menuButtonHeight < menuButtonTogetherNavHeight) {
  115. // 胶囊始终在nav高度中心位置
  116. menuButtonTogetherNavInfo.transformTop = (menuButtonTogetherNavHeight - menuButtonHeight) / 2
  117. }
  118. // #endif
  119. this.$nextTick(() => {
  120. const query = uni.createSelectorQuery().in(this)
  121. // 处理撑高逻辑
  122. query.select('#header_box').boundingClientRect((boxData) => {
  123. this.headerObj.height = boxData.height
  124. if (boxData.height < data.menuButtonInfo.bottom) {
  125. this.headerObj.height = data.menuButtonInfo.bottom + 10
  126. }
  127. })
  128. .exec()
  129. })
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .header_content {
  136. position: relative;
  137. /* // 头部 */
  138. .header_box {
  139. width: 100%;
  140. height: auto;
  141. position: fixed;
  142. background-color: #fff;
  143. z-index: 9999;
  144. image {
  145. width: 100%;
  146. height: 100%;
  147. display: inline-block;
  148. }
  149. .logo_row {
  150. position: relative;
  151. display: flex;
  152. justify-content: space-between;
  153. align-items: center;
  154. box-sizing: border-box;
  155. .logo_box {
  156. width: 286rpx;
  157. height: 72rpx;
  158. }
  159. .search_box {
  160. width: 60rpx;
  161. height: 60rpx;
  162. }
  163. }
  164. }
  165. .empty_box {
  166. width: 100%;
  167. position: relative;
  168. }
  169. }
  170. </style>