diff --git a/src/router/index.ts b/src/router/index.ts index a844906..8113db3 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,7 @@ import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'; import NProgress from 'nprogress'; import 'nprogress/nprogress.css'; +import { ElMessage } from 'element-plus'; import pinia from '/@/stores/index'; import { storeToRefs } from 'pinia'; import { useKeepALiveNames } from '/@/stores/keepAliveNames'; @@ -140,5 +141,30 @@ router.afterEach(() => { NProgress.done(); }); +// 开发服务器短暂重启或网络抖动会使浏览器缓存一次失败的动态 import。 +// 重新请求同一个模块并不能清除该失败记录,必须重新加载文档;每个目标页限一次,避免故障持续时循环刷新。 +router.onError((error, to) => { + NProgress.done(); + const message = error instanceof Error ? error.message : String(error); + if (!/Failed to fetch dynamically imported module|Importing a module script failed|error loading dynamically imported module/i.test(message)) return; + if (!navigator.onLine) { + ElMessage.error('网络已断开,恢复连接后请重新进入该页面'); + return; + } + const href = router.resolve(to).href; + const retryKey = `route-import-retry:${href}`; + try { + const lastRetry = Number(sessionStorage.getItem(retryKey) || 0); + if (Date.now() - lastRetry > 60_000) { + sessionStorage.setItem(retryKey, String(Date.now())); + window.location.replace(new URL(href, window.location.href).href); + return; + } + } catch (storageError) { + console.warn('无法记录路由模块重试状态', storageError); + } + ElMessage.error('页面资源加载失败,请确认本地服务正常运行后刷新页面'); +}); + // 导出路由 export default router; diff --git a/src/views/scoring/checkin-screen/index.vue b/src/views/scoring/checkin-screen/index.vue index bdcdf13..305cd20 100644 --- a/src/views/scoring/checkin-screen/index.vue +++ b/src/views/scoring/checkin-screen/index.vue @@ -4,14 +4,14 @@
-
CHECK-IN PROGRESS

{{ data.eventName || route.query.eventName || '赛事检录大屏' }}

检录进度
+

{{ data.eventName || route.query.eventName || '赛事检录大屏' }}

检录进度CHECK-IN PROGRESS
{{ timeText }}{{ dateText }} · {{ week }}