From a93b88d0cfe1ea5f49d2a775c4d25cee2e086ffa Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sun, 5 Jan 2025 19:59:59 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E8=BF=98=E5=8E=9F=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=AE=88=E5=8D=AB=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/guard.ts | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/router/guard.ts b/src/router/guard.ts index 79046a07..8464a85f 100644 --- a/src/router/guard.ts +++ b/src/router/guard.ts @@ -91,21 +91,27 @@ export const setupRouterGuard = (router: Router) => { next() } else { if (!hasRouteFlag) { - await userStore.getInfo() - if (userStore.userInfo.pwdExpired && to.path !== '/pwdExpired') { - Message.warning('密码已过期,请修改密码') - next('/pwdExpired') - } - const accessRoutes = await routeStore.generateRoutes() - accessRoutes.forEach((route) => { - if (!isHttp(route.path)) { - router.addRoute(route) // 动态添加可访问路由表 + try { + await userStore.getInfo() + if (userStore.userInfo.pwdExpired && to.path !== '/pwdExpired') { + Message.warning('密码已过期,请修改密码') + next('/pwdExpired') } - }) - hasRouteFlag = true - // 确保添加路由已完成 - // 设置 replace: true, 因此导航将不会留下历史记录 - next({ ...to, replace: true }) + const accessRoutes = await routeStore.generateRoutes() + accessRoutes.forEach((route) => { + if (!isHttp(route.path)) { + router.addRoute(route) // 动态添加可访问路由表 + } + }) + hasRouteFlag = true + // 确保添加路由已完成 + // 设置 replace: true, 因此导航将不会留下历史记录 + next({ ...to, replace: true }) + } catch (error: any) { + // 过程中发生任何错误,都直接重置 Token,并重定向到登录页面 + await userStore.logoutCallBack() + next(`/login?redirect=${to.path}`) + } } else { next() }