feat(app): 添加自动检查版本更新功能

- 引入 app_upgrade 模块用于版本检测
- 实现 autoCheckUpgrade 方法自动检查版本更新
- 在 APP-PLUS 平台的 onLoad 生命周期调用自动更新检查
- 调用后端接口获取升级信息并判断是否需要更新
- 支持强制检查新版本,跳过时间戳限制
- 优化日志打印,便于排查版本升级过程中的问题
This commit is contained in:
郭鸿轩 2026-01-04 14:16:00 +08:00
parent 9272ed0e23
commit e0b00cc62b

View File

@ -124,6 +124,7 @@ import util from '@/common/util.js';
import md5 from '@/common/md5.js';
import manifest from '@/manifest.json';
import { mapState } from 'vuex'
import app_upgrade from '@/uni_modules/app-upgrade/js_sdk/index.js'
export default {
data() {
return {
@ -177,25 +178,21 @@ export default {
}
});
}
uni.getStorage({
key: 'UserInfo',
success: (e) => {
console.log("---->>>" + e.data.username + '--->>' + e.data.password);
console.log("---->>>" + e.data.username + '--->>>' + e.data.password);
this.login.username = e.data.username;
this.login.password = e.data.password;
}
})
},
onLoad() {
/*
this.$u.api.index({loginCheck: true}).then(res => {
if (res.code == '200'){
uni.reLaunch({
url: '/pages/sys/msg/index'
});
}
});
*/
// #ifdef APP-PLUS
// APP
this.autoCheckUpgrade();
// #endif
},
methods: {
clearInput: function (event) {
@ -417,6 +414,47 @@ export default {
qqLogin() {
this.$u.toast('QQ 登录');
},
//
autoCheckUpgrade() {
console.log('autoCheckUpgrade 开始执行');
const self = this;
app_upgrade(async (versionCode) => {
console.log('app_upgrade 回调被执行, versionCode:', versionCode);
try {
//
const appInfo = await new Promise((resolve) => {
plus.runtime.getProperty(plus.runtime.appid, (inf) => {
resolve(inf);
});
});
console.log('appInfo:', appInfo);
const res = await self.$u.api.upgradeCheck({
app_name: config.upgradeName,
current_version: appInfo.version
});
console.log('自动检查版本更新结果:', res);
if (!res || !res.download_url) {
//
console.log('当前已是最新版本');
return { status: 0 };
}
return {
changelog: res.message + ',最新版本:' + res.latest_version,
status: res.need_update ? 1 : 0, // 0 | 1
path: res.download_url // apk
};
} catch (error) {
console.log('检查版本更新失败:', error);
return { status: 0 };
}
}, 1); // 使 type=1
},
handleBlurInputUrl(e) {
// URL
if (config.isDevelopment) {