更新提示

This commit is contained in:
Yeomai committed 2026-10-01 11:33:12 +08:00
1 parent 879e74ebda
commit a9552b3d1a
2 files changed
+36 -16

No files matched your search

+36
View File
@@ -10,6 +10,42 @@ App({
onLaunch() {
this.globalData.ready = this.bootstrap();
this.watchUpdates();
},
/**
* 版本更新监听。**只在这里注册一次**。
*
* 以前写在首页的 onShow 里,每切回首页就注册一遍;微信这个接口不去重,
* 回调会一层层叠加,同一次更新会连着弹好几个弹窗。放在 App 里天然只执行一次。
*
* 提示文案来自后台配置,所以要等启动流程把配置读回来再弹,避免弹出空白内容。
*/
watchUpdates() {
const updateManager = wx.getUpdateManager();
updateManager.onUpdateReady(() => {
void this.ready().then(() => {
wx.showModal({
title: store.cfg('app.update.title'),
showCancel: false,
content: store.cfg('app.update.content'),
success: (res) => {
if (res.confirm) updateManager.applyUpdate();
},
});
});
});
updateManager.onUpdateFailed(() => {
void this.ready().then(() => {
wx.showModal({
title: store.cfg('app.update.title'),
showCancel: false,
content: store.cfg('app.update.failed'),
});
});
});
},
/**
-16
View File
@@ -4,7 +4,6 @@ const store = require('../../utils/store');
const config = require('../../config/index');
const app = getApp();
const updateManager = wx.getUpdateManager();
const PAGE_SIZE = 10;
@@ -107,21 +106,6 @@ Page({
.catch((err) => console.error('[index] 文章加载失败', err));
},
onShow() {
updateManager.onCheckForUpdate(() => {});
updateManager.onUpdateReady(() => {
wx.showModal({
title: store.cfg('app.update.title'),
showCancel: false,
content: store.cfg('app.update.content'),
success: (res) => {
if (res.confirm) updateManager.applyUpdate();
},
});
});
updateManager.onUpdateFailed(() => {});
},
onPullDownRefresh() {
Promise.all([this.reload()]).then(() => wx.stopPullDownRefresh());
},