feat: 登录页增加手动检查版本更新
This commit is contained in:
@@ -111,6 +111,7 @@
|
|||||||
<view class="version-info">
|
<view class="version-info">
|
||||||
<text class="version-text">版本: {{ appVersion }}</text>
|
<text class="version-text">版本: {{ appVersion }}</text>
|
||||||
<text class="env-text" v-if="envName">({{ envName }})</text>
|
<text class="env-text" v-if="envName">({{ envName }})</text>
|
||||||
|
<text class="check-upgrade-btn" @click="checkUpgrade">{{ checkingUpgrade ? '检查中...' : '检查更新' }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
@@ -137,6 +138,7 @@ export default {
|
|||||||
password: ""
|
password: ""
|
||||||
},
|
},
|
||||||
showApiUrlPicker: false,
|
showApiUrlPicker: false,
|
||||||
|
checkingUpgrade: false,
|
||||||
// 登录默认正式环境,本地已选过的地址仍会在 onShow 里恢复
|
// 登录默认正式环境,本地已选过的地址仍会在 onShow 里恢复
|
||||||
selectedApiUrl: (config.devApiUrlOptions.find(item => item.label === '正式环境') || {}).value || config.productionApiUrl,
|
selectedApiUrl: (config.devApiUrlOptions.find(item => item.label === '正式环境') || {}).value || config.productionApiUrl,
|
||||||
customApiUrl: 'http://192.168.1.66:50002/hcscm/pda/v1',
|
customApiUrl: 'http://192.168.1.66:50002/hcscm/pda/v1',
|
||||||
@@ -400,45 +402,55 @@ export default {
|
|||||||
qqLogin() {
|
qqLogin() {
|
||||||
this.$u.toast('QQ 登录');
|
this.$u.toast('QQ 登录');
|
||||||
},
|
},
|
||||||
// 自动检查版本更新
|
// 自动检查版本更新(有新版本才弹窗,已是最新不提示)
|
||||||
autoCheckUpgrade() {
|
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;
|
const self = this;
|
||||||
|
this.checkingUpgrade = true;
|
||||||
app_upgrade(async (versionCode) => {
|
app_upgrade(async () => {
|
||||||
console.log('app_upgrade 回调被执行, versionCode:', versionCode);
|
|
||||||
try {
|
try {
|
||||||
// 获取应用信息
|
|
||||||
const appInfo = await new Promise((resolve) => {
|
const appInfo = await new Promise((resolve) => {
|
||||||
plus.runtime.getProperty(plus.runtime.appid, (inf) => {
|
plus.runtime.getProperty(plus.runtime.appid, (inf) => {
|
||||||
resolve(inf);
|
resolve(inf);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.log('appInfo:', appInfo);
|
|
||||||
|
|
||||||
const res = await self.$u.api.upgradeCheck({
|
const res = await self.$u.api.upgradeCheck({
|
||||||
app_name: config.upgradeName,
|
app_name: config.upgradeName,
|
||||||
current_version: appInfo.version
|
current_version: appInfo.version
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('自动检查版本更新结果:', res);
|
|
||||||
|
|
||||||
if (!res || !res.download_url) {
|
if (!res || !res.download_url) {
|
||||||
// 当前已是最新版本,不提示
|
if (!silentWhenLatest) {
|
||||||
console.log('当前已是最新版本');
|
self.$u.toast('当前版本已是最新版');
|
||||||
|
}
|
||||||
return { status: 0 };
|
return { status: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
changelog: res.message + ',最新版本:' + res.latest_version,
|
changelog: res.message + ',最新版本:' + res.latest_version,
|
||||||
status: res.need_update ? 1 : 0, // 0 无新版本 | 1 有新版本
|
status: res.need_update ? 1 : 0,
|
||||||
path: res.download_url // 新apk地址
|
path: res.download_url
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('检查版本更新失败:', error);
|
console.log('检查版本更新失败:', error);
|
||||||
|
if (!silentWhenLatest) {
|
||||||
|
self.$u.toast('检查更新失败,请稍后重试');
|
||||||
|
}
|
||||||
return { status: 0 };
|
return { status: 0 };
|
||||||
|
} finally {
|
||||||
|
self.checkingUpgrade = false;
|
||||||
}
|
}
|
||||||
}, 1); // 使用 type=1 强制检查,跳过时间戳检查
|
}, 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleBlurInputUrl(e) {
|
handleBlurInputUrl(e) {
|
||||||
@@ -587,18 +599,28 @@ export default {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
padding: 0 24rpx 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.version-text {
|
.version-text {
|
||||||
font-size: 24rpx;
|
font-size: 32rpx;
|
||||||
color: #999999;
|
color: #999999;
|
||||||
}
|
}
|
||||||
|
|
||||||
.env-text {
|
.env-text {
|
||||||
font-size: 24rpx;
|
font-size: 32rpx;
|
||||||
color: #5473e8;
|
color: #5473e8;
|
||||||
margin-left: 10rpx;
|
margin-left: 10rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.check-upgrade-btn {
|
||||||
|
font-size: 34rpx;
|
||||||
|
color: #5473e8;
|
||||||
|
margin-left: 24rpx;
|
||||||
|
padding: 16rpx 8rpx;
|
||||||
|
min-height: 64rpx;
|
||||||
|
line-height: 64rpx;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.login-env-picker {
|
.login-env-picker {
|
||||||
|
|||||||
Reference in New Issue
Block a user