Skip to content

Commit ee802d6

Browse files
committed
登录时,直接从用户信息中,获取菜单。目的:加快首页的加载速度
1 parent 40a93ca commit ee802d6

File tree

3 files changed

+2
-9
lines changed

3 files changed

+2
-9
lines changed

src/api/login/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ export const getInfo = () => {
3737
return request.get({ url: '/system/auth/get-permission-info' })
3838
}
3939

40-
// 路由
41-
export const getAsyncRoutes = () => {
42-
return request.get({ url: '/system/auth/list-menus' })
43-
}
44-
4540
//获取登录验证码
4641
export const sendSmsCode = (data: SmsCodeVO) => {
4742
return request.post({ url: '/system/auth/send-sms-code', data })

src/store/modules/permission.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { store } from '../index'
33
import { cloneDeep } from 'lodash-es'
44
import remainingRouter from '@/router/modules/remaining'
55
import { generateRoute, flatMultiLevelRoutes } from '@/utils/routerHelper'
6-
import { getAsyncRoutes } from '@/api/login'
76
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
87

98
const { wsCache } = useCache()
@@ -34,12 +33,10 @@ export const usePermissionStore = defineStore('permission', {
3433
actions: {
3534
async generateRoutes(): Promise<unknown> {
3635
return new Promise<void>(async (resolve) => {
36+
// 获得菜单列表,它在登录的时候,setUserInfoAction 方法中已经进行获取
3737
let res: AppCustomRouteRecordRaw[]
3838
if (wsCache.get(CACHE_KEY.ROLE_ROUTERS)) {
3939
res = wsCache.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[]
40-
} else {
41-
res = await getAsyncRoutes()
42-
wsCache.set(CACHE_KEY.ROLE_ROUTERS, res)
4340
}
4441
const routerMap: AppRouteRecordRaw[] = generateRoute(res as AppCustomRouteRecordRaw[])
4542
// 动态路由,404一定要放到最后面

src/store/modules/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const useUserStore = defineStore('admin-user', {
5858
this.user = userInfo.user
5959
this.isSetUser = true
6060
wsCache.set(CACHE_KEY.USER, userInfo)
61+
wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
6162
},
6263
async loginOut() {
6364
await loginOut()

0 commit comments

Comments
 (0)