From 80e346f2007a0ce2a4f3de54a5c873f6689a5813 Mon Sep 17 00:00:00 2001 From: chenyuwu <526249806@qq.com> Date: Mon, 17 Aug 2026 09:59:32 +0800 Subject: [PATCH] fix --- miniprogram/app.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/miniprogram/app.ts b/miniprogram/app.ts index b80000e..86b4dce 100644 --- a/miniprogram/app.ts +++ b/miniprogram/app.ts @@ -2,9 +2,40 @@ App({ globalData: {}, onLaunch() { + const updateManager = wx.getUpdateManager() + + updateManager.onCheckForUpdate(function (res) { + // 请求完新版本信息的回调 + console.log('是否有新版本', res.hasUpdate) + }) + + updateManager.onUpdateReady(function () { + // 新版本下载完毕,强制重启应用 + wx.showModal({ + title: '更新提示', + content: '新版本已就绪,即将重启应用', + showCancel: false, + success: function (res) { + if (res.confirm) { + // 强制重启,应用新版本 + updateManager.applyUpdate() + } + } + }) + }) + + updateManager.onUpdateFailed(function () { + // 新版本下载失败 + wx.showModal({ + title: '更新提示', + content: '新版本下载失败,请检查网络后重试', + showCancel: false + }) + }) const envVersion = wx.getAccountInfoSync().miniProgram.envVersion if (envVersion !== 'release') { wx.reLaunch({ url: '/pages/tools/index' }) } + }, })