多租户商城-商户小程序端
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.

183 lines
4.8 KiB

2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year 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. <image v-if="componentContent.logoType === 1" class="logo"
  28. :src="componentContent.imageUrl"
  29. mode="heightFix"></image>
  30. <view v-else class="h3"
  31. :style="{fontSize:componentContent.fontSizeNum+'px',fontWeight:componentContent.textFontW,color:componentContent.titColor}">{{componentContent.title}}</view>
  32. </view>
  33. <!-- 右侧搜索 -->
  34. <template>
  35. <!-- #ifndef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ -->
  36. <view
  37. class="search_box"
  38. @click="handleSearch"
  39. >
  40. <image src="https://ceres.zkthink.com/static/img/search.png" />
  41. </view>
  42. <!-- #endif -->
  43. <!-- #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ -->
  44. <view
  45. class="search_box"
  46. :style="{
  47. 'position':'absolute',
  48. 'left':`${headerObj.systemInfo.menuButtonInfo.left}px`,
  49. 'transform':`translateX(-110%)`
  50. }"
  51. @click="handleSearch"
  52. >
  53. <image src="https://ceres.zkthink.com/static/img/search.png" />
  54. </view>
  55. <!-- #endif -->
  56. </template>
  57. </view>
  58. <!-- 其他内容 -->
  59. <slot />
  60. </view>
  61. <!-- 空盒子撑高 -->
  62. <view
  63. class="empty_box"
  64. :style="{height:headerObj.height+'px'}"
  65. />
  66. </view>
  67. </template>
  68. <script>
  69. import DefaultHead from "@/components/DefaultHead";
  70. export default {
  71. name: "FixedHead",
  72. components: {
  73. DefaultHead
  74. },
  75. props: {
  76. componentContent: {
  77. type: Object,
  78. },
  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: `/pages_category_page1/search/index/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. let 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. }).exec()
  128. })
  129. },
  130. }
  131. }
  132. </script>
  133. <style
  134. lang="scss"
  135. scoped
  136. >
  137. .header_content {
  138. position: relative;
  139. // 头部
  140. .header_box {
  141. width: 100%;
  142. height: auto;
  143. position: fixed;
  144. background-color: #fff;
  145. z-index: 9999;
  146. image {
  147. width: 100%;
  148. height: 100%;
  149. display: inline-block;
  150. }
  151. .logo_row {
  152. position: relative;
  153. display: flex;
  154. justify-content: space-between;
  155. align-items: center;
  156. box-sizing: border-box;
  157. height: 100rpx;
  158. .logo_box {
  159. width: 265rpx;
  160. height: 50rpx;
  161. margin-left: 24rpx;
  162. }
  163. .search_box {
  164. width: 60rpx;
  165. height: 60rpx;
  166. }
  167. }
  168. }
  169. .empty_box {
  170. width: 100%;
  171. position: relative;
  172. }
  173. }
  174. </style>