diff --git a/wechat-miniprogram/app.js b/wechat-miniprogram/app.js index 0b1295d..e3ea52f 100644 --- a/wechat-miniprogram/app.js +++ b/wechat-miniprogram/app.js @@ -16,6 +16,8 @@ App({ onLaunch(options) { // 小程序启动时执行 console.log('App launched', options); + // 检查版本更新 + this.checkUpdate(); // 检查登录状态 this.checkLoginStatus(); // 验证当前用户是否在数据库中存在 @@ -63,6 +65,31 @@ App({ // 小程序隐藏时执行 }, + // 检查小程序版本更新 + checkUpdate() { + if (!wx.getUpdateManager) return; + const updateManager = wx.getUpdateManager(); + updateManager.onCheckForUpdate((res) => { + if (res.hasUpdate) console.log('检测到新版本'); + }); + updateManager.onUpdateReady(() => { + wx.showModal({ + title: '更新提示', + content: '新版本已经准备好,是否重启应用?', + success: (res) => { + if (res.confirm) updateManager.applyUpdate(); + }, + }); + }); + updateManager.onUpdateFailed(() => { + wx.showModal({ + title: '更新提示', + content: '新版本下载失败,请删除当前小程序后重新搜索打开', + showCancel: false, + }); + }); + }, + // 检查登录状态 checkLoginStatus() { const token = wx.getStorageSync('token');