From 8a14c5244ee49c606eabaf3a87a76c3a87498a70 Mon Sep 17 00:00:00 2001 From: gaoxq <376340421@qq.com> Date: Fri, 3 Apr 2026 17:45:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=8E=E7=AB=AF=E6=8E=A2=E6=B5=8B?= =?UTF-8?q?=E5=8A=A05=E7=A7=92=E8=B6=85=E6=97=B6=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E5=88=B7=E6=96=B0=E9=95=BF=E6=97=B6=E9=97=B4=E7=AD=89?= =?UTF-8?q?=E5=BE=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web-vue/src/router/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web-vue/src/router/index.js b/web-vue/src/router/index.js index 3253342..1925754 100644 --- a/web-vue/src/router/index.js +++ b/web-vue/src/router/index.js @@ -52,9 +52,13 @@ router.beforeEach(async (to, from, next) => { } else if (to.path === '/login' && token) { next('/desktop') } else if (to.meta.requiresAuth && token) { - // 有 token 且要进需认证页面,先验证后端是否可用 + // 有 token 且要进需认证页面,先验证后端是否可用(5秒超时) try { - await fetch('/api/files/test') + const controller = new AbortController() + const timeoutId = setTimeout(() => controller.abort(), 5000) + const res = await fetch('/api/files/test', { signal: controller.signal }) + clearTimeout(timeoutId) + if (!res.ok) throw new Error('backend error') next() } catch { // 后端不可用,清除登录状态跳转登录页