fix(页面缓存问题): 取消弹窗提示,直接自动清除缓存,修复页面乱跳转的问题
This commit is contained in:
parent
4ae363342c
commit
1a3550e9ba
12
src/main.js
12
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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user