2026-01-09 09:35:44 +08:00
|
|
|
// app.ts
|
|
|
|
|
App<IAppOption>({
|
2026-01-16 10:43:34 +08:00
|
|
|
globalData: {
|
|
|
|
|
navBarHeight: 0, // 导航栏总高度
|
|
|
|
|
navBarContentHeight: 0, // 胶囊那一栏的高度(不含状态栏)
|
|
|
|
|
statusBarHeight: 0, // 状态栏高度
|
|
|
|
|
menuRight: 0, // 胶囊右边距
|
|
|
|
|
menuTop: 0, // 胶囊顶部距离
|
|
|
|
|
menuHeight: 0, // 胶囊高度
|
|
|
|
|
tabbarHeight: 0, // 底部导航栏高度
|
|
|
|
|
safeAreaBottom: 0, // 底部安全区域坐标
|
|
|
|
|
safeAreaInsetBottom: 0, // 中间区域内容的底边坐标
|
|
|
|
|
system: '', // 系统信息
|
|
|
|
|
token: '',
|
|
|
|
|
},
|
|
|
|
|
onLaunch() {
|
|
|
|
|
// 1. 获取胶囊按钮位置信息
|
|
|
|
|
const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
|
|
|
|
|
|
|
|
|
|
// 2. 获取系统窗口信息
|
|
|
|
|
const windowInfo = wx.getWindowInfo()
|
|
|
|
|
const deviceInfo = wx.getDeviceInfo()
|
|
|
|
|
|
|
|
|
|
// 赋值基础信息
|
|
|
|
|
this.globalData.system = deviceInfo.system
|
|
|
|
|
this.globalData.menuRight = windowInfo.screenWidth - menuButtonInfo.right
|
|
|
|
|
this.globalData.menuTop = menuButtonInfo.top
|
|
|
|
|
this.globalData.menuHeight = menuButtonInfo.height
|
|
|
|
|
this.globalData.statusBarHeight = windowInfo.statusBarHeight
|
|
|
|
|
this.globalData.safeAreaBottom = windowInfo.safeArea.bottom
|
|
|
|
|
|
|
|
|
|
// 计算导航栏内容区域高度(不含状态栏)
|
|
|
|
|
// 解释:(胶囊上边距 - 状态栏高度) 是胶囊距离状态栏的间隙,上下各有一个间隙,所以 * 2
|
|
|
|
|
const gap = menuButtonInfo.top - windowInfo.statusBarHeight
|
|
|
|
|
const navContentHeight = menuButtonInfo.height + gap * 2
|
|
|
|
|
this.globalData.navBarContentHeight = navContentHeight
|
|
|
|
|
|
|
|
|
|
// 计算导航栏+手机状态栏高度
|
|
|
|
|
// 计算公式:导航栏高度 = 状态栏高度 + (胶囊上边距 - 状态栏高度) * 2 + 胶囊高度
|
|
|
|
|
this.globalData.navBarHeight = windowInfo.statusBarHeight + navContentHeight
|
|
|
|
|
|
|
|
|
|
// 计算底部小黑条高度 (屏幕高度 - 安全区域底部坐标)
|
|
|
|
|
const safeAreaInsetBottom = windowInfo.screenHeight - windowInfo.safeArea.bottom
|
|
|
|
|
this.globalData.safeAreaInsetBottom = safeAreaInsetBottom
|
|
|
|
|
},
|
2026-01-09 09:35:44 +08:00
|
|
|
})
|