From c6493767ce3c3270bb1676b0b8196c2f5a5164a4 Mon Sep 17 00:00:00 2001 From: lehug Date: Mon, 4 Sep 2023 14:48:50 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8DisToken=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/axios/service.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/config/axios/service.ts b/src/config/axios/service.ts index 1a4741b69..46637e79b 100644 --- a/src/config/axios/service.ts +++ b/src/config/axios/service.ts @@ -47,8 +47,7 @@ service.interceptors.request.use( let isToken = (config!.headers || {}).isToken === false whiteList.some((v) => { if (config.url) { - config.url.indexOf(v) > -1 - return (isToken = false) + return (isToken = config.url.indexOf(v) > -1) } }) if (getAccessToken() && !isToken) { From 34fdcd44f4bf1bf926d1dca641ff8127417d96db Mon Sep 17 00:00:00 2001 From: lehug Date: Mon, 4 Sep 2023 15:34:45 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=90=8E=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E8=8E=B7=E5=8F=96=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/user.ts | 5 +++-- src/views/Login/components/LoginForm.vue | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 1f801fefa..392dde9fc 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -44,13 +44,14 @@ export const useUserStore = defineStore('admin-user', { } }, actions: { - async setUserInfoAction() { + async setUserInfoAction(force = false) { if (!getAccessToken()) { this.resetState() return null } let userInfo = wsCache.get(CACHE_KEY.USER) - if (!userInfo) { + // 登录时指定force=true,强制更新菜单,避免停留在login的窗口登录后用户信息依然没有替换为最后一次登录用户的问题 + if (force || !userInfo) { userInfo = await getInfo() } this.permissions = userInfo.permissions diff --git a/src/views/Login/components/LoginForm.vue b/src/views/Login/components/LoginForm.vue index ffadf8b57..e47816444 100644 --- a/src/views/Login/components/LoginForm.vue +++ b/src/views/Login/components/LoginForm.vue @@ -152,6 +152,7 @@ import { useIcon } from '@/hooks/web/useIcon' import * as authUtil from '@/utils/auth' import { usePermissionStore } from '@/store/modules/permission' +import { useUserStoreWithOut } from '@/store/modules/user' import * as LoginApi from '@/api/login' import { LoginStateEnum, useFormValid, useLoginState } from './useLogin' @@ -255,6 +256,8 @@ const handleLogin = async (params) => { authUtil.removeLoginForm() } authUtil.setToken(res) + const userStore = useUserStoreWithOut() + await userStore.setUserInfoAction(true) if (!redirect.value) { redirect.value = '/' } From 253c48666f87b19c349739628ba5a251f51f48c9 Mon Sep 17 00:00:00 2001 From: lehug Date: Mon, 11 Sep 2023 10:48:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=90=8E=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8F=9C=E5=8D=95=E9=87=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Login/components/LoginForm.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/views/Login/components/LoginForm.vue b/src/views/Login/components/LoginForm.vue index e47816444..5af13006d 100644 --- a/src/views/Login/components/LoginForm.vue +++ b/src/views/Login/components/LoginForm.vue @@ -258,6 +258,8 @@ const handleLogin = async (params) => { authUtil.setToken(res) const userStore = useUserStoreWithOut() await userStore.setUserInfoAction(true) + await permissionStore.generateRoutes() + if (!redirect.value) { redirect.value = '/' }