diff --git a/src/pages/sys/login/index.vue b/src/pages/sys/login/index.vue index 9663b8b..6f3440a 100644 --- a/src/pages/sys/login/index.vue +++ b/src/pages/sys/login/index.vue @@ -111,6 +111,7 @@ 版本: {{ appVersion }} ({{ envName }}) + {{ checkingUpgrade ? '检查中...' : '检查更新' }} @@ -137,6 +138,7 @@ export default { password: "" }, showApiUrlPicker: false, + checkingUpgrade: false, // 登录默认正式环境,本地已选过的地址仍会在 onShow 里恢复 selectedApiUrl: (config.devApiUrlOptions.find(item => item.label === '正式环境') || {}).value || config.productionApiUrl, customApiUrl: 'http://192.168.1.66:50002/hcscm/pda/v1', @@ -400,45 +402,55 @@ export default { qqLogin() { this.$u.toast('QQ 登录'); }, - // 自动检查版本更新 + // 自动检查版本更新(有新版本才弹窗,已是最新不提示) autoCheckUpgrade() { - console.log('autoCheckUpgrade 开始执行'); + this.runUpgradeCheck({ silentWhenLatest: true }); + }, + // 手动检查版本更新 + checkUpgrade() { + if (this.checkingUpgrade) return; + // #ifndef APP-PLUS + this.$u.toast('小程序端或H5端已是最新版,无需检查更新!'); + // #endif + // #ifdef APP-PLUS + this.runUpgradeCheck({ silentWhenLatest: false }); + // #endif + }, + runUpgradeCheck({ silentWhenLatest }) { const self = this; - - app_upgrade(async (versionCode) => { - console.log('app_upgrade 回调被执行, versionCode:', versionCode); + this.checkingUpgrade = true; + app_upgrade(async () => { 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('当前已是最新版本'); + if (!silentWhenLatest) { + self.$u.toast('当前版本已是最新版'); + } return { status: 0 }; } - return { changelog: res.message + ',最新版本:' + res.latest_version, - status: res.need_update ? 1 : 0, // 0 无新版本 | 1 有新版本 - path: res.download_url // 新apk地址 + status: res.need_update ? 1 : 0, + path: res.download_url }; } catch (error) { console.log('检查版本更新失败:', error); + if (!silentWhenLatest) { + self.$u.toast('检查更新失败,请稍后重试'); + } return { status: 0 }; + } finally { + self.checkingUpgrade = false; } - }, 1); // 使用 type=1 强制检查,跳过时间戳检查 + }, 1); }, handleBlurInputUrl(e) { @@ -587,18 +599,28 @@ export default { justify-content: center; align-items: center; flex-wrap: wrap; + padding: 0 24rpx 20rpx; } .version-text { - font-size: 24rpx; + font-size: 32rpx; color: #999999; } .env-text { - font-size: 24rpx; + font-size: 32rpx; color: #5473e8; margin-left: 10rpx; } + +.check-upgrade-btn { + font-size: 34rpx; + color: #5473e8; + margin-left: 24rpx; + padding: 16rpx 8rpx; + min-height: 64rpx; + line-height: 64rpx; +}