From 9837d9fb41e503160fea34b8313c9a48443895aa Mon Sep 17 00:00:00 2001 From: Sisyphus Date: Mon, 20 Jul 2026 14:57:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(F006):=20=E6=9C=AA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=20/admin/=20=E6=97=B6=E4=B8=9A=E5=8A=A1=20co?= =?UTF-8?q?de:401=20=E8=87=AA=E5=8A=A8=E8=B7=B3=E7=99=BB=E5=BD=95=E9=A1=B5?= =?UTF-8?q?(=E4=B8=8D=E5=86=8D=E7=99=BD=E5=B1=8F=E6=9C=AA=E6=8E=88?= =?UTF-8?q?=E6=9D=83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index 517d556..d89714e 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -41,9 +41,13 @@ http.interceptors.response.use( const body = response.data as ApiEnvelope | undefined if (body && typeof body === 'object' && 'code' in body) { if (body.code === 0) return response - // 业务级 code:401 (如 /openapi/** 带 token 时 Spring Security 返未授权) - // 不清 token 不跳登录,只 reject 给调用方处理 - // 真正的 token 过期走 error 拦截器 (HTTP status 401) + // 业务级 code:401 + // 未登录(无 token)访问受保护接口(如 /sys/menu/nav)→ 跳登录页 + // 已登录但权限不足(如 /openapi/** 带 token 被 Spring Security 拒)→ 保持 reject 给调用方 + if (body.code === 401 && !localStorage.getItem(STORAGE_KEY)) { + handleAuthExpired() + return Promise.reject(body) + } return Promise.reject(body) } return response