还原appId
This commit is contained in:
127
App.vue
127
App.vue
@@ -483,6 +483,18 @@ function checkUpdate(forceCheck = false) {
|
|||||||
const currentVersion = compareVersion(localWgtVersion, localVersion) > 0 ? localWgtVersion : localVersion;
|
const currentVersion = compareVersion(localWgtVersion, localVersion) > 0 ? localWgtVersion : localVersion;
|
||||||
console.log('本地基座版本:', localVersion, '本地wgt版本:', localWgtVersion, '当前对比版本:', currentVersion, '远程版本:', remoteVersion);
|
console.log('本地基座版本:', localVersion, '本地wgt版本:', localWgtVersion, '当前对比版本:', currentVersion, '远程版本:', remoteVersion);
|
||||||
if (compareVersion(remoteVersion, currentVersion) > 0) {
|
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');
|
const ignoredVersion = uni.getStorageSync('ignoredVersion');
|
||||||
if (!forceCheck && ignoredVersion === remoteVersion) {
|
if (!forceCheck && ignoredVersion === remoteVersion) {
|
||||||
@@ -498,13 +510,22 @@ function checkUpdate(forceCheck = false) {
|
|||||||
showCancel: true,
|
showCancel: true,
|
||||||
success: (modalRes) => {
|
success: (modalRes) => {
|
||||||
if (modalRes.confirm) {
|
if (modalRes.confirm) {
|
||||||
|
// 检查存储空间
|
||||||
|
checkStorageSpace().then(() => {
|
||||||
uni.showLoading({title: '正在下载更新包...'});
|
uni.showLoading({title: '正在下载更新包...'});
|
||||||
|
console.log('开始下载wgt包:', wgtUrl);
|
||||||
uni.downloadFile({
|
uni.downloadFile({
|
||||||
url: wgtUrl,
|
url: wgtUrl,
|
||||||
success: (downloadResult) => {
|
success: (downloadResult) => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
|
console.log('下载结果:', downloadResult);
|
||||||
if (downloadResult.statusCode === 200) {
|
if (downloadResult.statusCode === 200) {
|
||||||
|
console.log('开始安装wgt包:', downloadResult.tempFilePath);
|
||||||
|
// 检查文件是否存在
|
||||||
|
plus.io.resolveLocalFileSystemURL(downloadResult.tempFilePath, (entry) => {
|
||||||
|
console.log('文件存在,开始安装');
|
||||||
plus.runtime.install(downloadResult.tempFilePath, {force: true}, function() {
|
plus.runtime.install(downloadResult.tempFilePath, {force: true}, function() {
|
||||||
|
console.log('wgt包安装成功');
|
||||||
// 更新本地wgt版本号
|
// 更新本地wgt版本号
|
||||||
uni.setStorageSync('wgtVersion', remoteVersion);
|
uni.setStorageSync('wgtVersion', remoteVersion);
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
@@ -517,17 +538,60 @@ function checkUpdate(forceCheck = false) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, function(e) {
|
}, function(e) {
|
||||||
uni.showToast({title: '安装失败: ' + e.message});
|
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: '确定'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({title: '下载失败'});
|
console.error('下载失败,状态码:', downloadResult.statusCode);
|
||||||
|
uni.showModal({
|
||||||
|
title: '下载失败',
|
||||||
|
content: `服务器返回错误,状态码: ${downloadResult.statusCode}`,
|
||||||
|
showCancel: false,
|
||||||
|
confirmText: '确定'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: (error) => {
|
||||||
uni.hideLoading();
|
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 {
|
} else {
|
||||||
// 用户选择暂不更新,询问是否忽略此版本
|
// 用户选择暂不更新,询问是否忽略此版本
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
@@ -550,7 +614,8 @@ function checkUpdate(forceCheck = false) {
|
|||||||
console.log('当前已是最新版本');
|
console.log('当前已是最新版本');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: (error) => {
|
||||||
|
console.error('检查更新失败:', error);
|
||||||
uni.showToast({title: '网络异常,请稍后重试'});
|
uni.showToast({title: '网络异常,请稍后重试'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -588,12 +653,62 @@ function setIgnoredVersion(version) {
|
|||||||
console.log('已设置忽略版本:', 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 = {
|
uni.$updateManager = {
|
||||||
checkUpdate: (forceCheck = false) => checkUpdate(forceCheck),
|
checkUpdate: (forceCheck = false) => checkUpdate(forceCheck),
|
||||||
clearIgnoredVersion,
|
clearIgnoredVersion,
|
||||||
getIgnoredVersion,
|
getIgnoredVersion,
|
||||||
setIgnoredVersion
|
setIgnoredVersion,
|
||||||
|
checkVersionCompatibility,
|
||||||
|
checkStorageSpace
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "德讯",
|
"name" : "德讯",
|
||||||
"appid" : "__UNI__AF08DA3",
|
"appid" : "__UNI__D705A34",
|
||||||
"description" : "",
|
"description" : "",
|
||||||
"versionName" : "fad-im 4.0.0",
|
"versionName" : "fad-im 4.0.0",
|
||||||
"versionCode" : 345,
|
"versionCode" : 345,
|
||||||
@@ -21,7 +21,8 @@
|
|||||||
"Camera" : {},
|
"Camera" : {},
|
||||||
"Record" : {},
|
"Record" : {},
|
||||||
"Geolocation" : {},
|
"Geolocation" : {},
|
||||||
"Maps" : {}
|
"Maps" : {},
|
||||||
|
"Push" : {}
|
||||||
},
|
},
|
||||||
"distribute" : {
|
"distribute" : {
|
||||||
"android" : {
|
"android" : {
|
||||||
@@ -74,7 +75,7 @@
|
|||||||
"push" : {
|
"push" : {
|
||||||
"unipush" : {
|
"unipush" : {
|
||||||
"offline" : true,
|
"offline" : true,
|
||||||
"oppo" : {}
|
"version" : "2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user