This commit is contained in:
qsh
2025-05-28 12:04:02 +08:00
parent 33965c55f9
commit e5e86e24e5
14 changed files with 370 additions and 23 deletions

View File

@@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
import { store } from '../index'
import { cloneDeep } from 'lodash-es'
import remainingRouter from '@/router/modules/remaining'
import staticRouter from '@/router/modules/static'
import { generateRoute, flatMultiLevelRoutes } from '@/utils/routerHelper'
import { CACHE_KEY } from '@/hooks/web/useCache'
@@ -37,6 +38,25 @@ export const usePermissionStore = defineStore('permission', {
if (cache.local.get(CACHE_KEY.ROLE_ROUTERS)) {
res = cache.local.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[]
}
const staticRouters = cloneDeep(staticRouter)
// 与动态路由比较,首先判断目录是否存在,如果存在就合并,并替换动态路由中的目录
staticRouters.forEach((item) => {
const index = res.findIndex((item2) => item2.path === item.path)
if (index !== -1) {
const arr = []
if (!item.children || item.children.length === 0) {
item.children = arr
}
if (res[index].children && res[index].children.length > 0) {
item.children = item.children.concat(res[index].children)
}
// routerMap[index].children = item.children
// 插入动态路由数组的第二位
res[index] = { ...res, ...item }
} else {
res = [...staticRouters, ...res]
}
})
const routerMap: AppRouteRecordRaw[] = generateRoute(res)
// 动态路由404一定要放到最后面
this.addRouters = routerMap.concat([
@@ -50,6 +70,7 @@ export const usePermissionStore = defineStore('permission', {
}
}
])
// 渲染菜单的所有路由
this.routers = cloneDeep(remainingRouter).concat(routerMap)
resolve()

View File

@@ -75,6 +75,7 @@ export const useUserStore = defineStore('admin-user', {
avatar: '',
nickname: ''
}
cache.local.delete(CACHE_KEY.USER)
},
refresh() {
cache.local.delete(CACHE_KEY.USER)