// app.js App({ onLaunch: function (options) { const { statusBarHeight, platform, windowHeight }=wx.getSystemInfoSync() const { top, height } = wx.getMenuButtonBoundingClientRect() // 状态栏高度 wx.setStorageSync('statusBarHeight', statusBarHeight) // 屏幕高度 wx.setStorageSync('windowHeight', windowHeight) // 胶囊按钮高度 一般是32 如果获取不到就使用32 wx.setStorageSync('menuButtonHeight', height ? height : 32) // 判断胶囊按钮信息是否成功获取 if (top && top !== 0 && height && height !== 0) { const navigationBarHeight = (top - statusBarHeight) * 2 + height // 导航栏高度 wx.setStorageSync('navigationBarHeight', navigationBarHeight) } else { wx.setStorageSync('navigationBarHeight', platform === 'android' ? 48 : 40) } //获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度) //这个最初我是在组件中获取,但是出现了一个问题,当第一次进入小程序时导航栏会把 //页面内容盖住一部分,当打开调试重新进入时就没有问题,这个问题弄得我是莫名其妙 //虽然最后解决了,但是花费了不少时间 let code = [1011, 1017, 1025, 1047, 1124, 1001, 1038, 1041, 1089, 1090, 1104, 1131, 1187]; if (code.includes(options.scene)) { this.globalData.share = true } else { this.globalData.share = false } const menuButtonInfo = wx.getMenuButtonBoundingClientRect() wx.getSystemInfo({ success: (res) => { this.globalData.height = res.statusBarHeight this.globalData.deviceInfo.statusHeight = res.statusBarHeight this.globalData.deviceInfo.navigationHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2 } }) wx.hideTabBar() }, globalData: { userInfo: null, deviceInfo: { statusHeight: 19, navigationHeight: 40 }, selected: 0 }, })