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

<!--
* @FileDescription: index
* @Author: kahu
* @Date: 2023/3/7
* @LastEditors: kahu
* @LastEditTime: 2023/3/7
-->
<template>
<view class="header_content">
<!-- 头部 -->
<view
class="header_box"
id="header_box"
>
<DefaultHead @getInfoData="handleGetSystemInfoData" />
<!-- 和胶囊齐平nav条 -->
<view
:style="{
'padding-top':`${headerObj.menuPadding}px`,
'transform':`translateY(-${headerObj.menuButtonTogetherNavInfo.transformTop}px)`
}"
class="logo_row"
>
<!-- logo -->
<view class="logo_box">
<!-- <image src="http://36.138.125.206:8081/ceres-local-file/image/logo_http://36.138.125.206:8081/ceres-local-filepng" /> -->
<image v-if="componentContent.logoType === 1" class="logo"
:src="componentContent.imageUrl"
mode="heightFix"></image>
<view v-else class="h3"
:style="{fontSize:componentContent.fontSizeNum+'px',fontWeight:componentContent.textFontW,color:componentContent.titColor}">{{componentContent.title}}</view>
</view>
<!-- 右侧搜索 -->
<template>
<!-- #ifndef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ -->
<view
class="search_box"
@click="flyToService"
>
<image src="http://36.138.125.206:8081/ceres-local-file/image/service.png" />
</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ -->
<view
class="search_box"
:style="{
'position':'absolute',
'left':`${headerObj.systemInfo.menuButtonInfo.left}px`,
'transform':`translateX(-110%)`
}"
@click="flyToService"
>
<image src="http://36.138.125.206:8081/ceres-local-file/image/service.png" />
</view>
<!-- #endif -->
</template>
</view>
<!-- 其他内容 -->
<slot />
</view>
<!-- 空盒子撑高 -->
<view
class="empty_box"
:style="{height:headerObj.height+'px'}"
/>
</view>
</template>
<script>
import DefaultHead from "@/components/DefaultHead";
import { Services } from '../../../../utils/services'
export default {
name: "FixedHead",
components: {
DefaultHead
},
props: {
componentContent: {
type: Object,
},
},
data() {
return {
// 头部对象
headerObj: {
height: 0, // 容器总体高度
systemInfo: {}, // 系统此乃西
menuPadding: 0, // 胶囊距离statusBar的高度(胶囊top - statusBarHeight)
// 胶囊配置信息
menuButtonTogetherNavInfo: {
height: 36, // 跟胶囊齐平的nav高度(和CSS的nav高度一致)
transformTop: 0 // nav要相对于menuPadding以后向上位移高度
}
},
}
},
methods: {
// 查询产品
handleSearch() {
uni.navigateTo({
url: `/pages_category_page1/search/index/index`
})
},
async flyToService() {
(await Services()).flyToService();
},
/**
* 获取系统信息
* 由DefaultHead回调
*/
handleGetSystemInfoData(data) {
this.headerObj.systemInfo = data
// #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
this.headerObj.menuPadding = data.menuButtonInfo.top - data.systemInfo.statusBarHeight
const {menuButtonTogetherNavInfo} = this.headerObj
// 如果胶囊高度小于齐平的nav高度
const menuButtonHeight = data.menuButtonInfo.height
const menuButtonTogetherNavHeight = menuButtonTogetherNavInfo.height
if (menuButtonHeight < menuButtonTogetherNavHeight) {
// 胶囊始终在nav高度中心位置
menuButtonTogetherNavInfo.transformTop = (menuButtonTogetherNavHeight - menuButtonHeight) / 2
}
// #endif
this.$nextTick(()=>{
let query = uni.createSelectorQuery().in(this);
// 处理撑高逻辑
query.select('#header_box').boundingClientRect(boxData => {
this.headerObj.height = boxData.height
if(boxData.height<data.menuButtonInfo.bottom){
this.headerObj.height = data.menuButtonInfo.bottom+10
}
}).exec()
})
},
}
}
</script>
<style
lang="scss"
scoped
>
.header_content {
position: relative;
// 头部
.header_box {
width: 100%;
height: auto;
position: fixed;
background-color: #FAFAFA;
z-index: 9999;
padding-right: 40rpx;
padding-left: 25rpx;
image {
width: 100%;
height: 100%;
display: inline-block;
}
.logo_row {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: border-box;
height: 100rpx;
.logo_box {
width: 265rpx;
height: 50rpx;
margin-left: 24rpx;
}
.search_box {
width: 60rpx;
height: 60rpx;
}
}
}
.empty_box {
width: 100%;
position: relative;
}
}
</style>