登录时,直接从用户信息中,获取菜单。目的:加快首页的加载速度

(cherry picked from commit ee802d6335)
This commit is contained in:
YunaiV 2023-07-29 09:28:45 +08:00 committed by shizhong
parent 9fd5a9d7f4
commit 4cef3e3e5f
3 changed files with 2 additions and 9 deletions

View File

@ -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 })

View File

@ -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<unknown> {
return new Promise<void>(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一定要放到最后面

View File

@ -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()