From 1a3550e9ba3b094a11cbad024cbc38717bb06b11 Mon Sep 17 00:00:00 2001 From: hzj <1304805162@qq.com> Date: Tue, 18 Nov 2025 12:07:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B5=E9=9D=A2=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=97=AE=E9=A2=98):=20=E5=8F=96=E6=B6=88=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=EF=BC=8C=E7=9B=B4=E6=8E=A5=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E7=BC=93=E5=AD=98=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=B9=B1=E8=B7=B3=E8=BD=AC=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 12 ++++-------- src/utils/versionChecker.js | 26 ++++++-------------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/main.js b/src/main.js index 11a3b4c..47ee3cc 100644 --- a/src/main.js +++ b/src/main.js @@ -12,13 +12,8 @@ import { useLangStore } from '@/stores/lang' // 移动到顶部 // 初始化环境信息 logEnvInfo() -// 版本检查 -versionChecker.checkVersion().then((hasUpdate) => { - if (hasUpdate) { - console.log('检测到新版本,正在更新...') - versionChecker.showUpdatePrompt() - } -}) +// 版本检查 - 不需要处理返回结果,因为会自动处理 +versionChecker.checkVersion() // 初始化权限系统 console.debug('🔐 Permission system initialized') @@ -43,7 +38,8 @@ if (versionChecker.enableCheck) { setInterval(async () => { const hasUpdate = await versionChecker.checkServerVersion() if (hasUpdate) { - versionChecker.showUpdatePrompt() + // 自动处理更新,不需要用户交互 + versionChecker.handleVersionUpdate() } }, 5 * 60 * 1000) } diff --git a/src/utils/versionChecker.js b/src/utils/versionChecker.js index f1f4cb5..ca806bc 100644 --- a/src/utils/versionChecker.js +++ b/src/utils/versionChecker.js @@ -76,6 +76,9 @@ export class VersionChecker { this.clearCache() localStorage.setItem(this.storageKey, this.currentVersion) localStorage.setItem(this.serverVersionKey, this.currentVersion) + + // 直接刷新页面 + this.forceReload() } // 清除应用缓存 @@ -133,32 +136,15 @@ export class VersionChecker { // 强制刷新页面 forceReload() { - // 尝试多种刷新方式确保生效 + // 直接刷新当前页面,不跳转到其他页面 try { - // 方法1: 强制重新加载 - if (window.location.reload) { - window.location.reload(true) - } - - // 方法2: 添加时间戳重新导航 - setTimeout(() => { - window.location.href = - window.location.origin + window.location.pathname + '?v=' + Date.now() - }, 100) + window.location.reload(true) } catch (error) { - // 方法3: 最后的备用方案 + // 备用方案 window.location.href = window.location.href } } - // 显示更新提示 - showUpdatePrompt() { - const shouldUpdate = confirm('发现新版本,是否立即更新?更新将获得更好的体验。') - if (shouldUpdate) { - this.forceReload() - } - } - // 获取当前版本 getCurrentVersion() { return this.currentVersion