diff --git a/App.vue b/App.vue index 4f68a13..19c83d6 100644 --- a/App.vue +++ b/App.vue @@ -483,6 +483,18 @@ function checkUpdate(forceCheck = false) { const currentVersion = compareVersion(localWgtVersion, localVersion) > 0 ? localWgtVersion : localVersion; console.log('本地基座版本:', localVersion, '本地wgt版本:', localWgtVersion, '当前对比版本:', currentVersion, '远程版本:', remoteVersion); if (compareVersion(remoteVersion, currentVersion) > 0) { + // 检查版本兼容性 + if (!checkVersionCompatibility(remoteVersion, localVersion)) { + console.warn('版本不兼容,跳过更新'); + uni.showModal({ + title: '版本不兼容', + content: `新版本 ${remoteVersion} 与当前基座版本 ${localVersion} 不兼容,请通过应用商店更新完整版本。`, + showCancel: false, + confirmText: '确定' + }); + return; + } + // 检查是否已忽略当前版本(除非强制检查) const ignoredVersion = uni.getStorageSync('ignoredVersion'); if (!forceCheck && ignoredVersion === remoteVersion) { @@ -498,36 +510,88 @@ function checkUpdate(forceCheck = false) { showCancel: true, success: (modalRes) => { if (modalRes.confirm) { - uni.showLoading({title: '正在下载更新包...'}); + // 检查存储空间 + checkStorageSpace().then(() => { + uni.showLoading({title: '正在下载更新包...'}); + console.log('开始下载wgt包:', wgtUrl); uni.downloadFile({ url: wgtUrl, success: (downloadResult) => { uni.hideLoading(); + console.log('下载结果:', downloadResult); if (downloadResult.statusCode === 200) { - plus.runtime.install(downloadResult.tempFilePath, {force: true}, function() { - // 更新本地wgt版本号 - uni.setStorageSync('wgtVersion', remoteVersion); - uni.showModal({ - title: '更新完成', - content: '应用需要重启才能生效,是否立即重启?', - success: function (res) { - if (res.confirm) { - plus.runtime.restart(); + console.log('开始安装wgt包:', downloadResult.tempFilePath); + // 检查文件是否存在 + plus.io.resolveLocalFileSystemURL(downloadResult.tempFilePath, (entry) => { + console.log('文件存在,开始安装'); + plus.runtime.install(downloadResult.tempFilePath, {force: true}, function() { + console.log('wgt包安装成功'); + // 更新本地wgt版本号 + uni.setStorageSync('wgtVersion', remoteVersion); + uni.showModal({ + title: '更新完成', + content: '应用需要重启才能生效,是否立即重启?', + success: function (res) { + if (res.confirm) { + plus.runtime.restart(); + } } + }); + }, function(e) { + console.error('wgt包安装失败:', e); + let errorMsg = '安装失败'; + if (e && e.message) { + errorMsg += ': ' + e.message; } + if (e && e.code) { + errorMsg += ' (错误代码: ' + e.code + ')'; + } + uni.showModal({ + title: '安装失败', + content: errorMsg + '\n\n可能的原因:\n1. 版本不兼容\n2. 文件损坏\n3. 权限不足\n4. 存储空间不足', + showCancel: false, + confirmText: '确定' + }); + }); + }, (error) => { + console.error('文件不存在:', error); + uni.showModal({ + title: '安装失败', + content: '下载的文件不存在或已损坏', + showCancel: false, + confirmText: '确定' }); - }, function(e) { - uni.showToast({title: '安装失败: ' + e.message}); }); } else { - uni.showToast({title: '下载失败'}); + console.error('下载失败,状态码:', downloadResult.statusCode); + uni.showModal({ + title: '下载失败', + content: `服务器返回错误,状态码: ${downloadResult.statusCode}`, + showCancel: false, + confirmText: '确定' + }); } }, - fail: () => { + fail: (error) => { uni.hideLoading(); - uni.showToast({title: '下载失败'}); + console.error('下载失败:', error); + uni.showModal({ + title: '下载失败', + content: '网络连接异常,请检查网络后重试', + showCancel: false, + confirmText: '确定' + }); } }); + }).catch((error) => { + console.error('存储空间检查失败:', error); + uni.showModal({ + title: '存储空间不足', + content: '设备存储空间不足,无法下载更新包', + showCancel: false, + confirmText: '确定' + }); + }); } else { // 用户选择暂不更新,询问是否忽略此版本 uni.showModal({ @@ -550,7 +614,8 @@ function checkUpdate(forceCheck = false) { console.log('当前已是最新版本'); } }, - fail: () => { + fail: (error) => { + console.error('检查更新失败:', error); uni.showToast({title: '网络异常,请稍后重试'}); } }); @@ -588,12 +653,62 @@ function setIgnoredVersion(version) { console.log('已设置忽略版本:', version); } +// 检查版本兼容性 +function checkVersionCompatibility(wgtVersion, baseVersion) { + console.log('检查版本兼容性:', { wgtVersion, baseVersion }); + + // 提取主版本号进行比较 + const wgtMajor = extractVersionNum(wgtVersion).split('.')[0]; + const baseMajor = extractVersionNum(baseVersion).split('.')[0]; + + // 主版本号必须匹配 + if (wgtMajor !== baseMajor) { + console.warn('主版本号不匹配:', { wgtMajor, baseMajor }); + return false; + } + + // 检查wgt版本是否高于基座版本 + if (compareVersion(wgtVersion, baseVersion) <= 0) { + console.warn('wgt版本不高于基座版本'); + return false; + } + + return true; +} + +// 检查存储空间 +function checkStorageSpace() { + return new Promise((resolve, reject) => { + // #ifdef APP-PLUS + if (typeof plus !== 'undefined' && plus.io) { + plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => { + fs.root.getDirectory('temp', { create: true }, (dir) => { + // 简单检查,实际项目中可能需要更复杂的空间检查 + resolve(true); + }, (error) => { + console.error('检查存储空间失败:', error); + reject(error); + }); + }); + } else { + resolve(true); + } + // #endif + + // #ifndef APP-PLUS + resolve(true); + // #endif + }); +} + // 导出更新管理函数供其他页面使用 uni.$updateManager = { checkUpdate: (forceCheck = false) => checkUpdate(forceCheck), clearIgnoredVersion, getIgnoredVersion, - setIgnoredVersion + setIgnoredVersion, + checkVersionCompatibility, + checkStorageSpace }; diff --git a/manifest.json b/manifest.json index 03def19..03f46b8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name" : "德讯", - "appid" : "__UNI__AF08DA3", + "appid" : "__UNI__D705A34", "description" : "", "versionName" : "fad-im 4.0.0", "versionCode" : 345, @@ -21,7 +21,8 @@ "Camera" : {}, "Record" : {}, "Geolocation" : {}, - "Maps" : {} + "Maps" : {}, + "Push" : {} }, "distribute" : { "android" : { @@ -74,7 +75,7 @@ "push" : { "unipush" : { "offline" : true, - "oppo" : {} + "version" : "2" } } }, diff --git a/unpackage/release/fad.wgt b/unpackage/release/fad.wgt index 49c9896..0d179f7 100644 Binary files a/unpackage/release/fad.wgt and b/unpackage/release/fad.wgt differ