zjk
2026-08-31 fe965950f398e55d28f87e8f4d1d3b856d658bf8
fix(app-version): 修复应用版本更新误提示问题

新增版本对比工具函数,改用前端实际比对版本号替代后端hasUpdate标记,修正版本更新检查逻辑;同时在mine.vue和home.vue中适配新逻辑,完善home页运行时版本获取。
3个文件已修改
60 ■■■■■ 已修改文件
traditionalApp/pages/home/home.vue 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/pages/mine/mine.vue 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/utils/app-version.js 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/pages/home/home.vue
@@ -153,7 +153,8 @@
    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';
@@ -224,6 +225,7 @@
        const versionPopupContent = ref('');
        const versionPopupForceUpdate = ref(false);
        const versionDownloadUrl = ref('');
        const manifestVersionName = String(manifestConfig.versionName || '');
        const versionUpdating = ref(false);
        const versionUpdateButtonText = ref('立即更新');
@@ -309,7 +311,8 @@
                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(
traditionalApp/pages/mine/mine.vue
@@ -72,7 +72,7 @@
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'
@@ -484,7 +484,7 @@
        const currentVersion = normalizeVersionText(appVersionText.value)
        const latestVersion = normalizeVersionText(versionInfo.latestVersionNo)
        if (!versionInfo.hasUpdate) {
        if (!shouldShowVersionUpdate(currentVersion, latestVersion)) {
            uni.showToast({
                title: `当前已是最新版本 V${latestVersion}`,
                icon: 'none',
traditionalApp/utils/app-version.js
@@ -52,6 +52,22 @@
}
/**
 * 比较当前版本与最新版本是否真的存在升级。
 * 即使后端误返回 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 = '') {
@@ -272,3 +288,36 @@
        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))
}