feat(升级中心): 实现备用更新方案并优化版本检查逻辑

This commit is contained in:
2025-12-26 17:11:58 +08:00
parent e76e6da008
commit e5415a8784
10 changed files with 245 additions and 53 deletions

View File

@@ -66,7 +66,7 @@
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { ref, computed, onMounted } from 'vue'
import { useSysStore } from '@/stores/sys'
import { useUserStore } from '@/stores/user'
import { useI18n } from 'vue-i18n'
@@ -74,6 +74,7 @@ import { useMessage } from '@/uni_modules/wot-design-uni'
import { makePhoneCall, copyToClipboard } from '@/utils/index'
// #ifdef APP-PLUS
import update from "@/uni_modules/uni-upgrade-center-app/utils/check-update";
import { getCurrentVersion } from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version'
// #endif
const { t, locale } = useI18n()
@@ -89,6 +90,9 @@ const statusBarHeight = ref(0)
const showQrCode = ref(false)
const showLanguageSelect = ref(false)
// 当前版本号
const currentVersion = ref('')
// 可选语言列表
const availableLanguages = computed(() => [
{ code: 'zh-Hans', name: t('locale.zh-hans') },
@@ -131,7 +135,7 @@ const settingItems = computed(() => [
{
id: 4,
label: t('user.checkVersion'),
value: '',
value: currentVersion.value,
type: 'version'
}
])
@@ -163,14 +167,14 @@ const handleSettingClick = (item: any) => {
* 拨打电话
*/
const handlePhoneCall = (phoneNumber: string, title: string) => {
makePhoneCall(phoneNumber, title, t)
makePhoneCall(phoneNumber, title)
}
/**
* 复制到剪贴板
*/
const handleCopyEmail = (content: string, title: string) => {
copyToClipboard(content, title, t)
copyToClipboard(content, title)
}
/**
@@ -209,14 +213,27 @@ const selectLanguage = (languageCode: string) => {
*/
const checkVersion = async () => {
// #ifdef APP-PLUS
var info = await update();
console.log('版本检测信息', info)
if(info.result.code == 0){
uni.showLoading()
try {
const info = await update();
if(info.result.code == 0){
uni.showToast({
title:info.result.message,
icon:'none'
})
}
} catch (error: any) {
console.error('版本检测失败:', error)
const msg = error?.hasOwnProperty('message') && error.message
uni.showToast({
title:info.result.message,
icon:'none'
title: msg || t('user.checkVersionFailed'),
icon: 'none',
duration: 5000
})
} finally {
uni.hideLoading()
}
// #endif
// #ifndef APP-PLUS
@@ -272,6 +289,12 @@ const performLogout = () => {
url: '/pages/login/login'
})
}
onMounted(async () => {
// #ifdef APP-PLUS
currentVersion.value = await getCurrentVersion()
// #endif
})
</script>
<style lang="scss" scoped>