diff --git a/track-uniapp/src/App.vue b/track-uniapp/src/App.vue index fe57745..2336f41 100644 --- a/track-uniapp/src/App.vue +++ b/track-uniapp/src/App.vue @@ -97,41 +97,35 @@ export default { success: (modalRes) => { if (!modalRes.confirm) return; - // 显示下载进度 - uni.showLoading({ title: "下载中 0%", mask: true }); + // 🚀 使用原生等待框,原地更新文字,杜绝闪烁 + plus.nativeUI.showWaiting("正在下载 0%"); const downloadTask = uni.downloadFile({ url: wgtUrl, success: (downloadRes) => { if (downloadRes.statusCode !== 200) { - uni.hideLoading(); + plus.nativeUI.closeWaiting(); uni.showToast({ title: "下载失败", icon: "none" }); return; } - uni.showLoading({ title: "安装中...", mask: true }); + // 安装阶段 — 原生等待框直接更新文字,无闪烁 + plus.nativeUI.showWaiting("正在安装..."); - // 调用 plus.runtime.install 安装 WGT plus.runtime.install( downloadRes.tempFilePath, { force: true }, () => { - uni.hideLoading(); + plus.nativeUI.closeWaiting(); console.log("[OTA] WGT 安装成功"); - uni.showModal({ - title: "更新完成", - content: "新版本已安装,重启后生效。是否立即重启?", - confirmText: "立即重启", - cancelText: "稍后", - success: (restartRes) => { - if (restartRes.confirm) { - plus.runtime.restart(); - } - }, - }); + // 🚀 静默重启:toast 提示后自动重启,无需用户杀后台 + plus.nativeUI.toast("新版本已就绪,即将重启..."); + setTimeout(() => { + plus.runtime.restart(); + }, 2000); }, (err) => { - uni.hideLoading(); + plus.nativeUI.closeWaiting(); console.error("[OTA] 安装失败:", err.message); uni.showToast({ title: "更新失败: " + (err.message || "未知错误"), @@ -142,19 +136,18 @@ export default { ); }, fail: (err) => { - uni.hideLoading(); + plus.nativeUI.closeWaiting(); console.error("[OTA] 下载失败:", err.errMsg); uni.showToast({ title: "下载失败,请检查网络", icon: "none" }); }, }); - // 下载进度回调 + // 下载进度 — 稳定更新原生等待框文字,不会闪烁 if (downloadTask && downloadTask.onProgressUpdate) { downloadTask.onProgressUpdate((res) => { const pct = res.progress; - uni.showLoading({ title: `下载中 ${pct}%`, mask: true }); - if (pct >= 100) { - uni.showLoading({ title: "安装中...", mask: true }); + if (pct < 100) { + plus.nativeUI.showWaiting(`正在下载 ${pct}%`); } }); }