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.
 
 
 
 

84 lines
2.3 KiB

function navParams() {
let params = {
// 是否支持自定义导航栏(小程序 pc版 false)
supportCustomBar: true,
// 胶囊
menuButton: {
width: 0,
height: 0
},
// 导航栏
// 可自定义,wx小程序会强制更改
navBar: {
height: 0,
// 导航栏字体大小 wx小程序 ios:13,Android:17
fontSize: 0,
// 导航栏样式 wx小程序时:ios:center,Android:left
style: '',
// 导航栏可用宽度 wx小程序时 ios,Android:屏幕宽-胶囊
enableWidth: 0,
// 导航栏不可用宽度 wx小程序时 ios,Android:胶囊+胶囊距离屏幕右侧边界的距离
disableWidth: 0
},
window: {
width: 0,
height: 0
},
os: {
osName: ''
},
// 导航栏+状态栏高度
navStatusHeight: '0px',
// 状态栏高度
statusBarHeight: 0,
unit: 'px'
}
// 同步获取信息
let info = uni.getSystemInfoSync();
// 状态栏高度
params.statusBarHeight = info.statusBarHeight;
params.window.width = info.screenWidth
params.window.height = info.screenHeight
params.os.osName = info.osName
// 获取胶囊相关内容
// #ifdef MP-WEIXIN
let menuButton = uni.getMenuButtonBoundingClientRect();
params.menuButton.width = menuButton.width;
params.menuButton.height = menuButton.height;
let paddingTop = menuButton.top - params.statusBarHeight;
let paddingBottom = 0;
if (params.os.osName === 'ios') {
paddingBottom = paddingTop * 2;
params.navBar.fontSize = 13;
params.navBar.style = 'center';
} else if (params.os.osName === 'android') {
paddingBottom = paddingTop;
params.navBar.fontSize = 17;
params.navBar.style = 'left';
} else if (params.os.osName === 'windows' || params.os.osName === 'mac') {
params.supportCustomBar = false;
} else {
// 未知系统按照Android处理
paddingBottom = paddingTop;
params.navBar.fontSize = 17;
params.navBar.style = 'left';
}
params.navBar.height = params.menuButton.height + paddingTop + paddingBottom;
// 导航栏可用宽度 屏幕左边界到胶囊左边界
params.navBar.enableWidth = menuButton.left;
params.navBar.disableWidth = params.window.width - params.navBar.enableWidth;
// #endif
params.navStatusHeight = params.statusBarHeight + params.navBar.height
console.log(params);
return params
}
export {
navParams
}