From c77612e4dc3675bbdab4ec24b1d9b012e446496e Mon Sep 17 00:00:00 2001 From: joylink_fanyuhong <18706759286@163.com> Date: Mon, 21 Oct 2024 10:20:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 6e3504c..3d656d2 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -45,15 +45,18 @@ export default route(function (/* { store, ssrContext } */) { next({ path: '/login' }); } else { try { - const userInfo = await getUserInfo(); const userStore = useUserStore(); - userStore.defaultRole = userInfo.defaultRole; - userStore.roles = userInfo.roles; - userStore.remainingSecond = userInfo.remainingSecond; - setTimeout( - () => handleRefreshToken(), - userInfo.remainingSecond * 1000 - 10000 - ); + if (!userStore.remainingSecond) { + const userInfo = await getUserInfo(); + userStore.defaultRole = userInfo.defaultRole; + userStore.roles = userInfo.roles; + userStore.remainingSecond = userInfo.remainingSecond; + setTimeout( + () => handleRefreshToken(), + userInfo.remainingSecond * 1000 - 10000 + ); + } + next(); } catch (e) { console.error('获取用户信息出错:', e); @@ -66,7 +69,7 @@ export default route(function (/* { store, ssrContext } */) { return Router; }); -async function handleRefreshToken() { +export async function handleRefreshToken() { try { const tokenInfo = await refreshToken(); saveJwtToken(tokenInfo.token);