export function getNavigationBarHeight() {
// 获取系统信息
const systemInfo = getItem(GLOBAL_SYSTEM_INFO);
//获取胶囊信息
const menuBtnInfo = uni.getMenuButtonBoundingClientRect()
//状态栏高度
const statusBarHeight = systemInfo.statusBarHeight
//胶囊高度
const menuHeight = menuBtnInfo.height
//胶囊与顶部的距离
const menuTop = menuBtnInfo.top
//导航栏高度= (胶囊顶部距离-状态栏高度) x 2 + 胶囊的高度
const navigatorHeight = (menuTop - statusBarHeight) * 2 + menuHeight
//总高度 = 状态栏的高度 + 导航栏高度
return (statusBarHeight + navigatorHeight) * 2
}
onLaunch: function () {
var that = this;
//获取设备信息
let systemInfo = wx.getSystemInfoSync()
that.globalData.systemInfo = systemInfo
//1rpx 像素值
let pixelRatio1 = 750 / systemInfo.windowWidth;
that.globalData.pixelRatio1 = pixelRatio1
//胶囊信息
let menu = wx.getMenuButtonBoundingClientRect()
that.globalData.menuInfo = menu
//状态栏高度
let statusHeight = systemInfo.statusBarHeight
that.globalData.statusHeight = statusHeight * pixelRatio1
//导航栏高度
let naviHeight = (menu.top - statusHeight) * 2 + menu.height
that.globalData.naviHeight = naviHeight * pixelRatio1
//顶部高度 = 状态栏高度 + 导航栏高度
that.globalData.topHeight = (statusHeight + naviHeight) * pixelRatio1
//屏幕高度
let screenHeight = systemInfo.screenHeight
that.globalData.screenHeight = screenHeight * pixelRatio1
//底部高度 = 屏幕高度 - 安全区域bottom
let bottom = systemInfo.safeArea.bottom
that.globalData.bottomHeight = (screenHeight - bottom) * pixelRatio1
}
标签:pixelRatio1,const,程序,高度,globalData,获取,let,头部,systemInfo
From: https://blog.51cto.com/u_16492874/9087095