diff --git a/App.vue b/App.vue index ff79f69..9a4dbbc 100644 --- a/App.vue +++ b/App.vue @@ -448,12 +448,16 @@ export default { function checkUpdate() { const localVersion = plus.runtime.version; + const localWgtVersion = uni.getStorageSync('wgtVersion') || localVersion; uni.request({ - url: 'https://your-server.com/update/version.json', + url: 'http://47.117.71.33:11295/fadapp-update/version.json?t=' + Date.now(), success: (res) => { const remoteVersion = res.data.version; const wgtUrl = res.data.wgtUrl; - if (compareVersion(remoteVersion, localVersion) > 0) { + // 取本地基座和本地wgt的最大版本 + const currentVersion = compareVersion(localWgtVersion, localVersion) > 0 ? localWgtVersion : localVersion; + console.log('本地基座版本:', localVersion, '本地wgt版本:', localWgtVersion, '当前对比版本:', currentVersion, '远程版本:', remoteVersion); + if (compareVersion(remoteVersion, currentVersion) > 0) { uni.showModal({ title: '发现新版本', content: `检测到新版本(${remoteVersion}),是否立即下载并更新?`, @@ -468,6 +472,8 @@ function checkUpdate() { uni.hideLoading(); if (downloadResult.statusCode === 200) { plus.runtime.install(downloadResult.tempFilePath, {force: true}, function() { + // 更新本地wgt版本号 + uni.setStorageSync('wgtVersion', remoteVersion); uni.showModal({ title: '更新完成', content: '应用需要重启才能生效,是否立即重启?', @@ -501,13 +507,17 @@ function checkUpdate() { } }); } +function extractVersionNum(str) { + const match = str.match(/(\\d+\\.\\d+(?:\\.\\d+)?)/); + return match ? match[1] : '0.0.0'; +} function compareVersion(v1, v2) { - v1 = v1.split('.'); - v2 = v2.split('.'); - for (let i = 0; i < v1.length; ++i) { - const n1 = parseInt(v1[i] || '0'); - const n2 = parseInt(v2[i] || '0'); + v1 = extractVersionNum(v1).split('.').map(Number); + v2 = extractVersionNum(v2).split('.').map(Number); + for (let i = 0; i < Math.max(v1.length, v2.length); i++) { + const n1 = v1[i] || 0; + const n2 = v2[i] || 0; if (n1 > n2) return 1; if (n1 < n2) return -1; } diff --git a/pages/workbench/index/index.vue b/pages/workbench/index/index.vue index 9558eda..14d0e90 100644 --- a/pages/workbench/index/index.vue +++ b/pages/workbench/index/index.vue @@ -10,6 +10,15 @@ 每日报工 +