From 4cef3e3e5fce0ef4dc46374dd09d1c4f457d019a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 29 Jul 2023 09:28:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=97=B6=EF=BC=8C=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E4=BB=8E=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E8=8E=B7=E5=8F=96=E8=8F=9C=E5=8D=95=E3=80=82=E7=9B=AE?= =?UTF-8?q?=E7=9A=84=EF=BC=9A=E5=8A=A0=E5=BF=AB=E9=A6=96=E9=A1=B5=E7=9A=84?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit ee802d6335f7b5e785620c45053dd31f4a95f785) --- src/api/login/index.ts | 5 ----- src/store/modules/permission.ts | 5 +---- src/store/modules/user.ts | 1 + 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/api/login/index.ts b/src/api/login/index.ts index 47d011a6..6ab3edc5 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -37,11 +37,6 @@ export const getInfoApi = () => { return request.get({ url: '/system/auth/get-permission-info' }) } -// 路由 -export const getAsyncRoutesApi = () => { - return request.get({ url: '/system/auth/list-menus' }) -} - //获取登录验证码 export const sendSmsCodeApi = (data: SmsCodeVO) => { return request.post({ url: '/system/auth/send-sms-code', data }) diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index 491bafdc..5f24a767 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -3,7 +3,6 @@ import { store } from '../index' import { cloneDeep } from 'lodash-es' import remainingRouter from '@/router/modules/remaining' import { generateRoute, flatMultiLevelRoutes } from '@/utils/routerHelper' -import { getAsyncRoutesApi } from '@/api/login' import { CACHE_KEY, useCache } from '@/hooks/web/useCache' const { wsCache } = useCache() @@ -34,12 +33,10 @@ export const usePermissionStore = defineStore('permission', { actions: { async generateRoutes(): Promise { return new Promise(async (resolve) => { + // 获得菜单列表,它在登录的时候,setUserInfoAction 方法中已经进行获取 let res: AppCustomRouteRecordRaw[] if (wsCache.get(CACHE_KEY.ROLE_ROUTERS)) { res = wsCache.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[] - } else { - res = await getAsyncRoutesApi() - wsCache.set(CACHE_KEY.ROLE_ROUTERS, res) } const routerMap: AppRouteRecordRaw[] = generateRoute(res as AppCustomRouteRecordRaw[]) // 动态路由,404一定要放到最后面 diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 16ff3902..430eab2e 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -58,6 +58,7 @@ export const useUserStore = defineStore('admin-user', { this.user = userInfo.user this.isSetUser = true wsCache.set(CACHE_KEY.USER, userInfo) + wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus) }, async loginOut() { await loginOutApi()