chore: UniApp OTA静默更新 + 项目分析报告

1. UniApp OTA更新优化
   - 移除进度条和下载中Toast(静默后台下载)
   - 安装成功后3秒自动重启,无用户感知
   - 失败时仅console.error,不弹窗打扰用户

2. 项目分析报告
   - 新增PROJECT_ANALYSIS_REPORT.md
   - 涵盖技术栈、数据模型、核心业务流程、潜在痛点和架构建议
This commit is contained in:
2026-08-12 12:04:51 +08:00
parent d59f732a0e
commit d32a3dce49
2 changed files with 401 additions and 36 deletions

View File

@ -96,7 +96,6 @@ export default {
return;
}
// 弹窗询问用户是否更新
const content = description
? `发现新版本 ${newVersion}\n\n${description}\n\n是否立即更新`
: `发现新版本 ${newVersion},是否立即更新?`;
@ -109,63 +108,33 @@ export default {
success: (modalRes) => {
if (!modalRes.confirm) return;
// 初始反馈:告知用户已转入后台
uni.showToast({ title: '已转入后台下载...', icon: 'none', position: 'top' });
const downloadTask = uni.downloadFile({
// 🚀 静默更新:无进度条、无 toast、不监听 onProgressUpdate
uni.downloadFile({
url: wgtUrl,
success: (downloadRes) => {
if (downloadRes.statusCode !== 200) {
uni.showToast({ title: "下载失败", icon: "none" });
console.error("[OTA] 下载失败, statusCode:", downloadRes.statusCode);
return;
}
// 安装阶段 — toast 轻提示
uni.showToast({ title: "正在安装...", icon: "none", position: "top" });
plus.runtime.install(
downloadRes.tempFilePath,
{ force: true },
() => {
console.log("[OTA] WGT 安装成功");
// 🚀 静默重启toast 提示后自动重启
plus.nativeUI.toast("新版本已就绪,即将重启...");
console.log("[OTA] 安装成功3秒后自动重启");
setTimeout(() => {
plus.runtime.restart();
}, 2000);
}, 3000);
},
(err) => {
console.error("[OTA] 安装失败:", err.message);
uni.showToast({
title: "更新失败: " + (err.message || "未知错误"),
icon: "none",
duration: 4000,
});
}
);
},
fail: (err) => {
console.error("[OTA] 下载失败:", err.errMsg);
uni.showToast({ title: "下载失败,请检查网络", icon: "none" });
},
});
// 🚀 核心性能优化:节流阀 — 每跨越 20% 才触发一次轻提示
let lastProgress = 0;
if (downloadTask && downloadTask.onProgressUpdate) {
downloadTask.onProgressUpdate((res) => {
const pct = res.progress;
if (pct - lastProgress >= 20 && pct < 100) {
lastProgress = pct;
uni.showToast({
title: `新版本下载中 ${pct}%`,
icon: "none",
position: "top",
duration: 1200,
});
}
});
}
},
});
},