From 016a988962e82393e41db3617df2ffe9387bbe94 Mon Sep 17 00:00:00 2001 From: duxingchen Date: Mon, 10 Aug 2026 14:22:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20parseVersionCode=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E2=80=94major*100+lastNum,=20T1.0.10=E2=86=92110=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E6=9C=8D=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- track-uniapp/src/App.vue | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/track-uniapp/src/App.vue b/track-uniapp/src/App.vue index 8bcfa86..fe57745 100644 --- a/track-uniapp/src/App.vue +++ b/track-uniapp/src/App.vue @@ -31,11 +31,14 @@ export default { // OTA 热更新雷达 — 版本检测 + WGT 下载 + 静默安装 // ========================================================== checkUpdate() { - // 🔧 直接用 manifest.json 的 versionCode 与服务器对比(避免 parseVersionCode 精度丢失) - const currentVersionCode = plus.runtime.versionCode || 0; + // 🔧 appWgtVersion 跟随 WGT 更新,解析算法: major*100 + lastNum + // "T1.0.1"→101, "T1.0.10"→110, "T1.0.99"→199 + const sysInfo = uni.getSystemInfoSync(); + const wgtVer = sysInfo.appWgtVersion || sysInfo.appVersion || "0"; + const currentVersionCode = this.parseVersionCode(wgtVer); const baseUrl = uni.getStorageSync("env_base_url") || "http://track_back.iris-rs.cn/api/v1"; - console.log("[OTA] 本地 versionCode:", currentVersionCode); + console.log("[OTA] 本地版本:", wgtVer, "→ 数字:", currentVersionCode); uni.request({ url: `${baseUrl}/app/check-update`, @@ -67,6 +70,14 @@ export default { }); }, + /** 版本号→数字: "T1.0.10" → 1*100+10 = 110 */ + parseVersionCode(v) { + if (!v) return 0; + const nums = v.match(/\d+/g); + if (!nums || nums.length < 2) return 0; + return parseInt(nums[0], 10) * 100 + parseInt(nums[nums.length - 1], 10); + }, + downloadAndInstall(wgtUrl, newVersion, description) { if (!wgtUrl) { console.log("[OTA] 无 WGT 下载地址");