如题,今天在敲代码的时候遇到了这个问题,记录一下,一般小程序进入首页,我都会通过uniapp的api获得登录系统的信息,uni.getSystemInfo(),通过参数确定有底部导航栏和没有底部导航栏的高度,原本在安卓和ios都是完美运行的程序,到了客户端不显示还不报错,后来发现,osName这个字段为windows时状态栏高度为0,结果我对高度的设置没有成功,也为0,导致没有显示。
解决办法
加上对windows的判断,当然还有macos 和linux 一共五种情况。每一个平台的感觉有点误差,所以进行相应的调整。
总结
不要想着是平台的错,先看看自己代码有没有问题,debug是天。
代码段(自己看的,我觉得这个px适配大部分的手机了,微调后直接用)
if (res.statusBarHeight || res.statusBarHeight == 0) {
if (res.osName == 'ios') {
store.commit('uploadWindowHeight', res.windowHeight)
store.commit(
'bottomWindowHeight',
res.screenHeight - res.statusBarHeight - 44
)
windowHeight.value = res.windowHeight
} else if (res.osName == 'android') {
store.commit('uploadWindowHeight', res.windowHeight)
store.commit(
'bottomWindowHeight',
res.screenHeight - res.statusBarHeight - 49
)
windowHeight.value = res.windowHeight
} else if (
res.osName == 'windows' ||
res.osName == 'macos' ||
res.osName == 'linux'
) {
store.commit('uploadWindowHeight', res.windowHeight - 58)
store.commit('bottomWindowHeight', res.screenHeight - res.statusBarHeight)
windowHeight.value = res.windowHeight - 58
}
}