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.
94 lines
2.7 KiB
94 lines
2.7 KiB
function navParams() {
|
|
|
|
let params = {
|
|
// 胶囊
|
|
menuButton: {
|
|
width: 0,
|
|
height: 0,
|
|
describe: ''
|
|
},
|
|
// 导航栏
|
|
// 可自定义,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
|
|
|
|
// 获取胶囊相关内容
|
|
// 以下示例数据都 来自 iPhoneX 7nWidth
|
|
|
|
// 获取胶囊相关内容
|
|
// 以下示例数据都 来自 iPhoneX 75%大小的微信模拟器
|
|
// #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';
|
|
params.menuButton.describe = '原生导航栏可去掉,胶囊不可去掉';
|
|
} else if (params.os.osName === 'android') {
|
|
paddingBottom = paddingTop;
|
|
params.navBar.fontSize = 17;
|
|
params.navBar.style = 'left';
|
|
params.menuButton.describe = '原生导航栏可去掉,胶囊不可去掉';
|
|
} else if (params.os.osName === 'windows') {
|
|
paddingBottom = paddingTop;
|
|
params.navBar.fontSize = 17;
|
|
params.navBar.style = 'center';
|
|
params.menuButton.describe = '原生导航栏胶囊都不可去掉';
|
|
} else {
|
|
// Harmony,Android
|
|
paddingBottom = paddingTop;
|
|
params.navBar.fontSize = 17;
|
|
params.navBar.style = 'left';
|
|
// windows、macos 未测试
|
|
}
|
|
// params.navBar.paddingRight = params.window.width - menuButton.right;
|
|
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
|
|
}
|