拆约:启动时检查小程序版本更新并提示重启

This commit is contained in:
2026-11-12 02:15:20 +08:00
parent 0f7d804d05
commit 02b1075bcf
+27
View File
@@ -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');