diff --git a/src/api/login/index.ts b/src/api/login/index.ts index 536f6a66..b65a90cf 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -37,11 +37,6 @@ export const getInfo = () => { return request.get({ url: '/system/auth/get-permission-info' }) } -// 路由 -export const getAsyncRoutes = () => { - return request.get({ url: '/system/auth/list-menus' }) -} - //获取登录验证码 export const sendSmsCode = (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 9d3b8dda..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 { getAsyncRoutes } 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 getAsyncRoutes() - 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 99c11c2e..1f801fef 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 loginOut()