From 9d1fc36d63964e0d9a578352690e9c849dc701ef Mon Sep 17 00:00:00 2001 From: tangxinyue <524779910@qq.com> Date: Fri, 24 Jul 2026 16:23:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=96=E6=B6=88=E6=98=93=E6=AD=BB?= =?UTF-8?q?=E9=94=81=E7=9A=84=20sessionStorage=20=E9=98=B2=E6=8A=96?= =?UTF-8?q?=E9=99=90=E5=88=B6=EF=BC=8C=E5=8A=A0=E5=85=A5=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E7=9A=84=20window.confirm=20=E5=BC=BA=E5=88=B6=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E6=89=93=E7=A0=B4=E6=97=A7=E7=89=88=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E4=B8=8E=20SW=20=E6=8B=A6=E6=88=AA=E6=AD=BB=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 88f4efa..7b1f8b5 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -48,16 +48,16 @@ router.beforeEach(async (to, from, next) => { router.onError((error) => { const pattern = /Failed to fetch dynamically imported module|Importing a module script failed/i if (pattern.test(error?.message || '')) { - const isReloaded = sessionStorage.getItem('chunk_reload_flag') - if (!isReloaded) { - sessionStorage.setItem('chunk_reload_flag', 'true') - - const forceReload = () => { - const url = new URL(window.location.href) - url.searchParams.set('t', Date.now()) - window.location.href = url.href - } + if (window._chunkErrorHandled) return + window._chunkErrorHandled = true + + const forceReload = () => { + const url = new URL(window.location.href) + url.searchParams.set('t', Date.now()) + window.location.href = url.href + } + const cleanAndReload = () => { if ('serviceWorker' in navigator) { navigator.serviceWorker.getRegistrations().then(registrations => { for (const registration of registrations) { @@ -69,6 +69,12 @@ router.onError((error) => { forceReload() } } + + if (window.confirm('系统检测到版本更新,当前页面数据已过期。点击【确定】立即刷新体验最新版本!')) { + cleanAndReload() + } else { + window._chunkErrorHandled = false + } } })