fix: OTA版本对比改用plus.runtime.versionCode直接对比,修复T1.0.10误判为旧版
This commit is contained in:
@ -31,13 +31,11 @@ export default {
|
|||||||
// OTA 热更新雷达 — 版本检测 + WGT 下载 + 静默安装
|
// OTA 热更新雷达 — 版本检测 + WGT 下载 + 静默安装
|
||||||
// ==========================================================
|
// ==========================================================
|
||||||
checkUpdate() {
|
checkUpdate() {
|
||||||
// 获取当前 App 的 WGT 资源版本号(uni-app 编译后的版本标识)
|
// 🔧 直接用 manifest.json 的 versionCode 与服务器对比(避免 parseVersionCode 精度丢失)
|
||||||
const sysInfo = uni.getSystemInfoSync();
|
const currentVersionCode = plus.runtime.versionCode || 0;
|
||||||
const currentWgtVersion = sysInfo.appWgtVersion || sysInfo.appVersion || "0";
|
|
||||||
const currentVersionCode = this.parseVersionCode(currentWgtVersion);
|
|
||||||
const baseUrl = uni.getStorageSync("env_base_url") || "http://track_back.iris-rs.cn/api/v1";
|
const baseUrl = uni.getStorageSync("env_base_url") || "http://track_back.iris-rs.cn/api/v1";
|
||||||
|
|
||||||
console.log("[OTA] 本地WGT版本:", currentWgtVersion, "| 数字版本:", currentVersionCode);
|
console.log("[OTA] 本地 versionCode:", currentVersionCode);
|
||||||
|
|
||||||
uni.request({
|
uni.request({
|
||||||
url: `${baseUrl}/app/check-update`,
|
url: `${baseUrl}/app/check-update`,
|
||||||
@ -69,15 +67,6 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/** 从版本字符串提取数字版本号用于对比 */
|
|
||||||
parseVersionCode(versionStr) {
|
|
||||||
if (!versionStr) return 0;
|
|
||||||
const nums = versionStr.match(/\d+/g);
|
|
||||||
if (!nums) return 0;
|
|
||||||
// 取后三位拼成整数: "T1.0.2" → [1,0,1] → 101
|
|
||||||
return parseInt(nums.slice(-3).join("").padEnd(3, "0").slice(0, 3), 10);
|
|
||||||
},
|
|
||||||
|
|
||||||
downloadAndInstall(wgtUrl, newVersion, description) {
|
downloadAndInstall(wgtUrl, newVersion, description) {
|
||||||
if (!wgtUrl) {
|
if (!wgtUrl) {
|
||||||
console.log("[OTA] 无 WGT 下载地址");
|
console.log("[OTA] 无 WGT 下载地址");
|
||||||
|
|||||||
Reference in New Issue
Block a user