组件
<template>
<view class="bar-sticky">
<view class="status-line" :style="{height: lineHeight, background: navigationBarStyle.background || normal.background}">
</view>
<view class="bar-line" :style="{background: navigationBarStyle.background || normal.background}">
<view class="bar-line container-in" :style="{background: navigationBarStyle.background || normal.background}">
<view class="bar-font bar-content" v-if="!custom">
<view class="icon-fanhui bar-back" :style="{color: navigationBarStyle.iconColor || normal.iconColor}" @click="$turnPage('1', 'navigateBack')"
v-if="showBack">
<uni-icons type="back" size="30" color="#f9f8f8" ></uni-icons>
</view>
<view class="bar-title" :style="{color: navigationBarStyle.fontColor || normal.fontColor}">
{{navigationBarStyle.iconText}}
</view>
</view>
<view class="bar-font container-in" v-else>
<slot></slot>
</view>
</view>
</view>
</view>
</template>
<script>
import uniIcons from '../../components/uni-icons/uni-icons.vue'
export default {
props: {
custom: {
type: Boolean,
default: false
},
navigationBarStyle: {
type: Object,
default: function() {
return {
background: '#1d1515',
fontColor: '#f5efef',
iconColor: '#f5efef',
iconText: '好运牛'
}
}
},
showBack: {
type: Boolean,
default: true
},
},
data() {
return {
normal: {
background: '#FFFFFF',
fontColor: '#000000',
iconColor: '#000000',
},
lineHeight: ''
};
},
components: {
uniIcons:uniIcons
},
mounted() {
let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
console.log("menuButtonInfo",menuButtonInfo)
const systemInfo = uni.getSystemInfoSync();
let pxToRpxScale = 750 / systemInfo.windowWidth;
let systems = {
ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale,
navigationHeight: 44 * pxToRpxScale,
ktxWindowWidth: systemInfo.windowWidth * pxToRpxScale,
ktxWindowHeight: systemInfo.windowHeight * pxToRpxScale,
ktxScreentHeight: systemInfo.screenHeight * pxToRpxScale,
}
systems.tabBarHeight = systems.ktxScreentHeight - systems.ktxStatusHeight - systems.navigationHeight - systems.ktxWindowHeight
this.lineHeight = systems.ktxStatusHeight + 'rpx';
this.$emit('getHeight', systems)
}
}
</script>
<style lang="less">
.bar-content {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
//导航栏吸顶效果
.bar-sticky {
position: sticky;
position: -webkit-sticky;
top: 0;
z-index: 101;
}
.container-in {
display: flex;
-webkit-align-items: center;
align-items: center;
width: 100%;
height: 44px;
}
.bar-line {
height: 44px; //导航栏高度
.bar-back {
font-size: 52rpx !important;
position: absolute;
left: 30rpx;
}
.bar-title {
font-size: 32rpx;
}
}
</style>
pages.json配置
在tabBar或者pages配置
"navigationStyle":"custom"