From 01b8601dcd795d11104d4625ff9c2f3cc3d6a1bf Mon Sep 17 00:00:00 2001 From: duxingchen Date: Tue, 11 Aug 2026 16:53:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(app):=20OTA=E6=9B=B4=E6=96=B0=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E9=87=8D=E6=9E=84=20=E2=80=94=20=E5=BA=9F=E9=99=A4?= =?UTF-8?q?=E9=97=AA=E7=83=81=E5=BC=B9=E7=AA=97=20+=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: 1. uni.showLoading 每次调用都是关→开,进度回调中连续调用导致疯狂闪烁 2. 安装完成后弹窗询问重启,用户选「稍后」则必须手动杀后台 修复: 1. 替换 uni.showLoading → plus.nativeUI.showWaiting 原生等待框支持原地更新文字,下载进度平滑过渡,零闪烁 2. 安装成功后移除重启询问弹窗,改为: plus.nativeUI.toast('新版本已就绪,即将重启...') → 2秒后 setTimeout → plus.runtime.restart() 用户无需任何操作,2秒后自动生效 --- track-uniapp/src/App.vue | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) 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}%`); } }); }