nav.js
const app = getApp();
Component({
properties: {
cityName: {
type: String,
value: ""
},
},
data: {
haveBack: true,
statusBarHeight: 0,
navbarHeight: 0,
navbarBtn: {
height: 0,
width: 0,
top: 0,
bottom: 0,
right: 0
},
cusnavH: 0,
},
attached: function () {
if (!app.globalData.systeminfo) {
app.globalData.systeminfo = wx.getSystemInfoSync();
}
if (!app.globalData.headerBtnPosi) app.globalData.headerBtnPosi = wx.getMenuButtonBoundingClientRect();
let statusBarHeight = app.globalData.systeminfo.statusBarHeight
let headerPosi = app.globalData.headerBtnPosi
let btnPosi = {
height: headerPosi.height,
width: headerPosi.width,
top: headerPosi.top - statusBarHeight,
bottom: headerPosi.bottom - headerPosi.height - statusBarHeight,
right: app.globalData.systeminfo.windowWidth - headerPosi.right
}
let haveBack;
if (getCurrentPages().length != 1) {
haveBack = false;
} else {
haveBack = true;
}
var cusnavH = btnPosi.height + btnPosi.top + btnPosi.bottom
this.setData({
haveBack: haveBack,
statusBarHeight: statusBarHeight,
navbarHeight: headerPosi.bottom + btnPosi.bottom,
navbarBtn: btnPosi,
cusnavH: cusnavH
});
this.triggerEvent('commonNavAttr',{
height: headerPosi.bottom + btnPosi.bottom
});
},
methods: {
selectCity: function () {
this.triggerEvent('selectCity');
}
}
})
nav.json
{
"component": true,
"usingComponents": {}
}
nav.wxml
<view class="custom_nav" style="height:{{navbarHeight}}px;">
<view class="custom_nav_box" style="height:{{navbarHeight}}px;">
<view class="custom_nav_bar" style="top:{{statusBarHeight}}px; height:{{cusnavH}}px;">
<view class="city_layout" style="height:{{cusnavH}}px;" bindtap="selectCity">
<image class="city_layout_image" src="../../images/icon_poi.png"/>
<view class="city_layout_text">{{cityName}}</view>
<image class="city_layout_image" src="../../images/icon_lower_triangle.png"/>
</view>
</view>
</view>
</view>
nav.wxss
.custom_nav {
width: 100%;
background: white;
position: relative;
z-index: 99999;
}
.custom_nav_box {
position: fixed;
width: 100%;
background: white;
z-index: 99999;
border-bottom: 1rpx solid rgba(255, 255, 255, 0.3);
}
.custom_nav_bar {
position: relative;
z-index: 9;
}
.city_layout {
display: flex;
flex-direction: row;
align-items: center;
padding-left: 15rpx;
font-size: 34rpx;
font-weight: 400;
color: #000000;
}
.city_layout_image {
width: 32rpx;
height: 32rpx;
}
.city_layout_text {
margin: 0rpx 4rpx;
}