多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
4.4 KiB

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