From c858c829507bd76ec0d7bdc832915baf89738d34 Mon Sep 17 00:00:00 2001 From: Yer11214 <17633066053@163.com> Date: Thu, 5 Jun 2025 17:40:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96app=E4=B8=AD=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=8D=87=E7=BA=A7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/APPUpdate/index.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/APPUpdate/index.js b/plugins/APPUpdate/index.js index b980d1c..ff52c63 100644 --- a/plugins/APPUpdate/index.js +++ b/plugins/APPUpdate/index.js @@ -5,6 +5,27 @@ import { getAppVersion } from "@/api/message.js"; const platform = uni.getSystemInfoSync().platform; + +// 版本号比较函数 +function compareVersion(version1, version2) { + const v1Parts = version1.split('.').map(Number); + const v2Parts = version2.split('.').map(Number); + + const maxLength = Math.max(v1Parts.length, v2Parts.length); + + for (let i = 0; i < maxLength; i++) { + const v1Part = v1Parts[i] || 0; + const v2Part = v2Parts[i] || 0; + + if (v1Part > v2Part) { + return 1; + } else if (v1Part < v2Part) { + return -1; + } + } + + return 0; +} // 主颜色 const $mainColor = "#1ABC9C"; // 弹窗图标url @@ -29,7 +50,7 @@ export const getServerNo = function (callback) { platform == "android" ? (type = "ANDROID") : (type = "IOS"); getAppVersion(type).then((res) => { - if (res.data.success && res.data.result.downloadUrl) { + if (res.data.success && res.data.result && res.data.result.downloadUrl) { let response = res.data.result; let result = {}; result.versionCode = response.version; @@ -854,11 +875,9 @@ function downloadPopup(data, callback, cancelCallback, rebootCallback) { export default function (isPrompt = false) { getCurrentNo((version) => { getServerNo((res) => { - - if (res.versionCode.replace(/\./g, "") <= version.version.replace(/\./g, "")) { + if (compareVersion(res.versionCode, version.version) <= 0) { return false; } - if (res.forceUpdate) { if (/\.wgt$/i.test(res.downloadUrl)) { getDownload(res);