From e0b00cc62ba51ed1e41b7d7b0e6eafd4278b315b Mon Sep 17 00:00:00 2001 From: xuan <1359774872@qq.com> Date: Sun, 4 Jan 2026 14:16:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=A3=80=E6=9F=A5=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入 app_upgrade 模块用于版本检测 - 实现 autoCheckUpgrade 方法自动检查版本更新 - 在 APP-PLUS 平台的 onLoad 生命周期调用自动更新检查 - 调用后端接口获取升级信息并判断是否需要更新 - 支持强制检查新版本,跳过时间戳限制 - 优化日志打印,便于排查版本升级过程中的问题 --- src/pages/sys/login/index.vue | 58 +++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/src/pages/sys/login/index.vue b/src/pages/sys/login/index.vue index 86719ce..3f7eb07 100644 --- a/src/pages/sys/login/index.vue +++ b/src/pages/sys/login/index.vue @@ -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) {