feat(app): 添加自动检查版本更新功能
- 引入 app_upgrade 模块用于版本检测 - 实现 autoCheckUpgrade 方法自动检查版本更新 - 在 APP-PLUS 平台的 onLoad 生命周期调用自动更新检查 - 调用后端接口获取升级信息并判断是否需要更新 - 支持强制检查新版本,跳过时间戳限制 - 优化日志打印,便于排查版本升级过程中的问题
This commit is contained in:
parent
9272ed0e23
commit
e0b00cc62b
@ -124,6 +124,7 @@ import util from '@/common/util.js';
|
|||||||
import md5 from '@/common/md5.js';
|
import md5 from '@/common/md5.js';
|
||||||
import manifest from '@/manifest.json';
|
import manifest from '@/manifest.json';
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
|
import app_upgrade from '@/uni_modules/app-upgrade/js_sdk/index.js'
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -177,25 +178,21 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.getStorage({
|
uni.getStorage({
|
||||||
key: 'UserInfo',
|
key: 'UserInfo',
|
||||||
success: (e) => {
|
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.username = e.data.username;
|
||||||
this.login.password = e.data.password;
|
this.login.password = e.data.password;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
/*
|
// #ifdef APP-PLUS
|
||||||
this.$u.api.index({loginCheck: true}).then(res => {
|
// 打开APP后自动检查版本更新
|
||||||
if (res.code == '200'){
|
this.autoCheckUpgrade();
|
||||||
uni.reLaunch({
|
// #endif
|
||||||
url: '/pages/sys/msg/index'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
clearInput: function (event) {
|
clearInput: function (event) {
|
||||||
@ -417,6 +414,47 @@ export default {
|
|||||||
qqLogin() {
|
qqLogin() {
|
||||||
this.$u.toast('QQ 登录');
|
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) {
|
handleBlurInputUrl(e) {
|
||||||
// 只在开发环境处理自定义URL
|
// 只在开发环境处理自定义URL
|
||||||
if (config.isDevelopment) {
|
if (config.isDevelopment) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user