fix(app-version): 修复应用版本更新误提示问题
新增版本对比工具函数,改用前端实际比对版本号替代后端hasUpdate标记,修正版本更新检查逻辑;同时在mine.vue和home.vue中适配新逻辑,完善home页运行时版本获取。
| | |
| | | import { onPullDownRefresh, onShow } from "@dcloudio/uni-app"; |
| | | import UpdatePopup from '@/components/updatePopup.vue'; |
| | | import { createLiveRoomEntry, getBannerList, getHomeFeaturedContent, getHomeLiveCourseList, getLiveRoomSetting } from "./service"; |
| | | import { checkAppVersion, normalizeVersionCheckData, shouldAutoCheckVersionOnLaunch, startVersionUpdate } from '@/utils/app-version.js'; |
| | | import { checkAppVersion, normalizeVersionCheckData, resolveRuntimeVersion, shouldAutoCheckVersionOnLaunch, shouldShowVersionUpdate, startVersionUpdate } from '@/utils/app-version.js'; |
| | | import manifestConfig from '../../manifest.json'; |
| | | import { HardwareAPI } from '@/utils/visitorDevice.js'; |
| | | import { resolveCurrentAppUserId } from "@/utils/app-user.js"; |
| | | import { jumpToMiniProgramPay } from '@/utils/weizan-pay-bridge.js'; |
| | |
| | | const versionPopupContent = ref(''); |
| | | const versionPopupForceUpdate = ref(false); |
| | | const versionDownloadUrl = ref(''); |
| | | const manifestVersionName = String(manifestConfig.versionName || ''); |
| | | const versionUpdating = ref(false); |
| | | const versionUpdateButtonText = ref('立即更新'); |
| | | |
| | |
| | | try { |
| | | const response = await checkAppVersion(false); |
| | | const versionInfo = normalizeVersionCheckData(response?.data); |
| | | if (!versionInfo.hasUpdate) { |
| | | const currentVersion = resolveRuntimeVersion(manifestVersionName || '1.0.0'); |
| | | if (!shouldShowVersionUpdate(currentVersion, versionInfo.latestVersionNo)) { |
| | | return; |
| | | } |
| | | openVersionPopup( |
| | |
| | | import { getNoticeList } from '../notice/service' |
| | | import { getUserCenter } from './service' |
| | | import { hasStoredSession } from '@/utils/auth-session.js' |
| | | import { checkAppVersion, normalizeVersionCheckData, normalizeVersionText, resolveRuntimeVersion, startVersionUpdate } from '@/utils/app-version.js' |
| | | import { checkAppVersion, normalizeVersionCheckData, normalizeVersionText, resolveRuntimeVersion, shouldShowVersionUpdate, startVersionUpdate } from '@/utils/app-version.js' |
| | | import manifestConfig from '../../manifest.json' |
| | | |
| | | type UserRole = 'personal' | 'doctor' |
| | |
| | | const currentVersion = normalizeVersionText(appVersionText.value) |
| | | const latestVersion = normalizeVersionText(versionInfo.latestVersionNo) |
| | | |
| | | if (!versionInfo.hasUpdate) { |
| | | if (!shouldShowVersionUpdate(currentVersion, latestVersion)) { |
| | | uni.showToast({ |
| | | title: `当前已是最新版本 V${latestVersion}`, |
| | | icon: 'none', |
| | |
| | | } |
| | | |
| | | /** |
| | | * 比较当前版本与最新版本是否真的存在升级。 |
| | | * 即使后端误返回 hasUpdate=true,只要版本号相同,前端也不再弹更新提示。 |
| | | */ |
| | | export function shouldShowVersionUpdate(currentVersion, latestVersion) { |
| | | const safeCurrentVersion = normalizeVersionText(currentVersion) |
| | | const safeLatestVersion = normalizeVersionText(latestVersion) |
| | | if (!safeCurrentVersion || !safeLatestVersion) { |
| | | return false |
| | | } |
| | | if (safeCurrentVersion === safeLatestVersion) { |
| | | return false |
| | | } |
| | | return compareVersionText(safeCurrentVersion, safeLatestVersion) < 0 |
| | | } |
| | | |
| | | /** |
| | | * 优先读取运行时版本号,取不到时回退 manifest 配置版本。 |
| | | */ |
| | | export function resolveRuntimeVersion(fallbackVersion = '') { |
| | |
| | | console.warn('[app-version] 更新进度回调失败:', e) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 逐段比较版本号,返回值: |
| | | * -1:current < latest |
| | | * 0:current = latest |
| | | * 1:current > latest |
| | | */ |
| | | function compareVersionText(currentVersion, latestVersion) { |
| | | const currentParts = splitVersionText(currentVersion) |
| | | const latestParts = splitVersionText(latestVersion) |
| | | const maxLength = Math.max(currentParts.length, latestParts.length) |
| | | for (let index = 0; index < maxLength; index += 1) { |
| | | const currentPart = currentParts[index] || 0 |
| | | const latestPart = latestParts[index] || 0 |
| | | if (currentPart < latestPart) { |
| | | return -1 |
| | | } |
| | | if (currentPart > latestPart) { |
| | | return 1 |
| | | } |
| | | } |
| | | return 0 |
| | | } |
| | | |
| | | /** |
| | | * 把版本号拆成数字数组,便于逐段比较。 |
| | | */ |
| | | function splitVersionText(versionText) { |
| | | return String(versionText || '') |
| | | .split('.') |
| | | .map((item) => Number.parseInt(item, 10)) |
| | | .filter((item) => Number.isFinite(item)) |
| | | } |