/** * 全局仅维护一个版本号字符串(如 1.0.2) * * - 本地存储 APP_GLOBAL_VERSION_INFO:只存版本名字符串(每次进入应用 onShow 会重新写入) * - 编译注入:走 vue.config 时 __APP_MANIFEST_VERSION__ 来自 manifest 的 versionName;否则用 FALLBACK */ import { getCurrentAppVersionInfo } from '@/common/utils/appVersion.js' const FALLBACK_VERSION = '1.0.1' /** 与 manifest 同步的展示用版本(未注入构建时等于 FALLBACK) */ export const APP_GLOBAL_VERSION = typeof __APP_MANIFEST_VERSION__ !== 'undefined' ? __APP_MANIFEST_VERSION__ : FALLBACK_VERSION export const APP_GLOBAL_VERSION_STORAGE_KEY = 'APP_GLOBAL_VERSION_INFO' /** * 重新读取当前运行版本名并写入本地(仅存字符串,无 versionCode / 无二次写入) */ export function syncGlobalVersionToLocalStorage() { try { const info = getCurrentAppVersionInfo() const v = String(info.versionName || '').trim() uni.setStorageSync(APP_GLOBAL_VERSION_STORAGE_KEY, v || APP_GLOBAL_VERSION) } catch (e) { console.warn('[appVersionConfig] syncGlobalVersionToLocalStorage', e) } } /** * 读取本地已保存的版本名字符串;无则 null * 兼容旧版曾写入对象 { versionName, versionCode } 的情况 */ export function readGlobalVersionFromStorage() { try { const raw = uni.getStorageSync(APP_GLOBAL_VERSION_STORAGE_KEY) if (raw == null || raw === '') return null if (typeof raw === 'string') return raw.trim() || null if (typeof raw === 'object' && raw !== null) { const n = raw.versionName != null ? String(raw.versionName).trim() : '' if (n) return n const v = raw.version != null ? String(raw.version).trim() : '' if (v) return v } } catch (e) {} return null }