// app.js // 应用入口文件 App({ onLaunch() { this.checkVersion() this.initApp() }, globalData: { userInfo: null, token: null, systemInfo: null, statusBarHeight: 0, navBarHeight: 44 }, // 检查版本更新 checkVersion() { const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(res => { if (res.hasUpdate) { updateManager.onUpdateReady(() => { wx.showModal({ title: '更新提示', content: '新版本已准备好,是否重启应用?', success: res => { if (res.confirm) { updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(() => { wx.showModal({ title: '更新失败', content: '新版本下载失败,请检查网络后重试', showCancel: false }) }) } }) }, // 初始化应用 initApp() { const token = wx.getStorageSync('token') const userInfo = wx.getStorageSync('userInfo') this.globalData.token = token this.globalData.userInfo = userInfo wx.getSystemInfo({ success: res => { this.globalData.systemInfo = res this.globalData.statusBarHeight = res.statusBarHeight } }) this.requestNotificationSetting() }, // 检查登录状态 checkLogin() { const token = wx.getStorageSync('token') if (!token) { wx.showModal({ title: '提示', content: '请先登录', success: res => { if (res.confirm) { wx.navigateTo({ url: '/pages/login/login' }) } } }) return false } return true }, // 请求通知权限 requestNotificationSetting() { wx.getSetting({ success: res => { if (!res.authSetting['scope.notify']) { wx.authorize({ scope: 'scope.notify', success: () => { console.log('通知权限获取成功') } }) } } }) }, // 获取用户信息 getUserInfo() { return this.globalData.userInfo || wx.getStorageSync('userInfo') }, // 设置用户信息 setUserInfo(userInfo) { this.globalData.userInfo = userInfo wx.setStorageSync('userInfo', userInfo) }, // 清除用户信息 clearUserInfo() { this.globalData.userInfo = null this.globalData.token = null wx.removeStorageSync('userInfo') wx.removeStorageSync('token') } }) /** * @联系作者:16768118056 * @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。 * @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。 */