From 34fdcd44f4bf1bf926d1dca641ff8127417d96db Mon Sep 17 00:00:00 2001 From: lehug Date: Mon, 4 Sep 2023 15:34:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=90=8E=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=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 = '/' }