回退以及 右上角胶囊丸 是小程序原生程序
// 先在页面json文件里如下配置,去掉小程序默认导航栏
"navigationStyle": "custom",
去掉后,页面布局会整体靠上 需要 写一个全局共用组件去替代原标签栏
<view style="background:{{backColor}};height:{{autoheight}};position:relative;">
<text style="color:{{textColor}};font-size:32rpx;position:absolute;bottom:{{textBottom}};left:0;right:0;text-align:center;line-height:1;font-weight:500;">{{title}}</text>
</view>
// distribution/assembly/navigateBar/navigateBar.js
Component({
/**
* 组件的属性列表
*/
properties: {
// 导航背景颜色,默认 白色
backColor:{
type: String,
value: '#fff'
},
// 字体颜色默认黑色
textColor: {
type: String,
value: '#000'
},
// 导航栏名字 默认为空
title: {
type: String,
value: ''
},
},
/**
* 组件的初始数据
*/
data: {
autoheight: '47rpx'
},
/**
* 组件的方法列表
*/
methods: {
},
lifetimes: {
attached: function () {
// 因为不同手机 头部高度不同。要动态获取 高度 再赋予导航栏
setTimeout(()=>{
let obj = wx.getMenuButtonBoundingClientRect()
this.setData({
autoheight: (obj.bottom + 8) + "px",
textBottom: (obj.height / 2 + 8 - 6) + "px",
})
wx.setBackgroundColor({
backgroundColor: this.data.backColor,
})
wx.setBackgroundColor({
backgroundColorTop: this.data.backColor, // 顶部窗口的背景色为导航色
backgroundColorBottom: '#f7f7f7', // 底部窗口的背景色为灰色
})
},100)
},
},
})