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

189 lines
5.0 KiB

2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years 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="flyToService"
  39. >
  40. <image src="https://wechat.hnthee.com/ceres-local-file/image/service.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="flyToService"
  52. >
  53. <image src="https://wechat.hnthee.com/ceres-local-file/image/service.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. import { Services } from '../../../../utils/services'
  71. export default {
  72. name: "FixedHead",
  73. components: {
  74. DefaultHead
  75. },
  76. props: {
  77. componentContent: {
  78. type: Object,
  79. },
  80. },
  81. data() {
  82. return {
  83. // 头部对象
  84. headerObj: {
  85. height: 0, // 容器总体高度
  86. systemInfo: {}, // 系统此乃西
  87. menuPadding: 0, // 胶囊距离statusBar的高度(胶囊top - statusBarHeight)
  88. // 胶囊配置信息
  89. menuButtonTogetherNavInfo: {
  90. height: 36, // 跟胶囊齐平的nav高度(和CSS的nav高度一致)
  91. transformTop: 0 // nav要相对于menuPadding以后向上位移高度
  92. }
  93. },
  94. }
  95. },
  96. methods: {
  97. // 查询产品
  98. handleSearch() {
  99. uni.navigateTo({
  100. url: `/pages_category_page1/search/index/index`
  101. })
  102. },
  103. async flyToService() {
  104. (await Services()).flyToService();
  105. },
  106. /**
  107. * 获取系统信息
  108. * 由DefaultHead回调
  109. */
  110. handleGetSystemInfoData(data) {
  111. this.headerObj.systemInfo = data
  112. // #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
  113. this.headerObj.menuPadding = data.menuButtonInfo.top - data.systemInfo.statusBarHeight
  114. const {menuButtonTogetherNavInfo} = this.headerObj
  115. // 如果胶囊高度小于齐平的nav高度
  116. const menuButtonHeight = data.menuButtonInfo.height
  117. const menuButtonTogetherNavHeight = menuButtonTogetherNavInfo.height
  118. if (menuButtonHeight < menuButtonTogetherNavHeight) {
  119. // 胶囊始终在nav高度中心位置
  120. menuButtonTogetherNavInfo.transformTop = (menuButtonTogetherNavHeight - menuButtonHeight) / 2
  121. }
  122. // #endif
  123. this.$nextTick(()=>{
  124. let query = uni.createSelectorQuery().in(this);
  125. // 处理撑高逻辑
  126. query.select('#header_box').boundingClientRect(boxData => {
  127. this.headerObj.height = boxData.height
  128. if(boxData.height<data.menuButtonInfo.bottom){
  129. this.headerObj.height = data.menuButtonInfo.bottom+10
  130. }
  131. }).exec()
  132. })
  133. },
  134. }
  135. }
  136. </script>
  137. <style
  138. lang="scss"
  139. scoped
  140. >
  141. .header_content {
  142. position: relative;
  143. // 头部
  144. .header_box {
  145. width: 100%;
  146. height: auto;
  147. position: fixed;
  148. background-color: #FAFAFA;
  149. z-index: 9999;
  150. padding-right: 40rpx;
  151. padding-left: 25rpx;
  152. image {
  153. width: 100%;
  154. height: 100%;
  155. display: inline-block;
  156. }
  157. .logo_row {
  158. position: relative;
  159. display: flex;
  160. justify-content: space-between;
  161. align-items: center;
  162. box-sizing: border-box;
  163. height: 100rpx;
  164. .logo_box {
  165. width: 265rpx;
  166. height: 50rpx;
  167. margin-left: 24rpx;
  168. }
  169. .search_box {
  170. width: 60rpx;
  171. height: 60rpx;
  172. }
  173. }
  174. }
  175. .empty_box {
  176. width: 100%;
  177. position: relative;
  178. }
  179. }
  180. </style>