fix(app): onShow 中增加更新检查 — 用户无需杀后台即可感知新版本

问题: checkUpdate 仅在 onLaunch 执行,App 常驻内存时永不复用。
      用户部署更新后,不杀后台就永远感知不到新版本。

修复:
1. onShow 中追加 checkUpdate(),每次回到前台自动检测
2. checkUpdate 顶部加 5分钟节流,避免频繁切后台时重复弹窗
This commit is contained in:
2026-08-11 16:56:22 +08:00
parent 01b8601dcd
commit 9064973a3f

View File

@ -22,6 +22,10 @@ export default {
onShow() {
console.log("App 显示");
this.updateTabBarBadge();
// 🚀 每次回到前台也检查更新,用户无需杀后台就能感知新版本
// #ifdef APP-PLUS
this.checkUpdate();
// #endif
},
onHide() {
console.log("App 隐藏");
@ -31,6 +35,14 @@ export default {
// OTA 热更新雷达 — 版本检测 + WGT 下载 + 静默安装
// ==========================================================
checkUpdate() {
// 🚀 节流5分钟内不重复检查避免 onShow 频繁触发弹窗骚扰
const now = Date.now();
if (this._lastUpdateCheck && now - this._lastUpdateCheck < 5 * 60 * 1000) {
console.log("[OTA] 距上次检查不足5分钟跳过");
return;
}
this._lastUpdateCheck = now;
// 🔧 appWgtVersion 跟随 WGT 更新,解析算法: major*100 + lastNum
// "T1.0.1"→101, "T1.0.10"→110, "T1.0.99"→199
const sysInfo = uni.getSystemInfoSync();