|
|
@ -16,6 +16,7 @@ import { |
|
|
|
storageSession, |
|
|
|
isIncludeAllChildren |
|
|
|
} from "@pureadmin/utils"; |
|
|
|
import { getConfig } from "@/config"; |
|
|
|
import { buildHierarchyTree } from "@/utils/tree"; |
|
|
|
import { cloneDeep, intersection } from "lodash-unified"; |
|
|
|
import { sessionKey, type DataInfo } from "@/utils/auth"; |
|
|
@ -151,15 +152,12 @@ function addPathMatch() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** 初始化路由 */ |
|
|
|
function initRouter() { |
|
|
|
return new Promise(resolve => { |
|
|
|
getAsyncRoutes().then(({ data }) => { |
|
|
|
if (data.length === 0) { |
|
|
|
usePermissionStoreHook().handleWholeMenus(data); |
|
|
|
resolve(router); |
|
|
|
/** 处理动态路由(后端返回的路由) */ |
|
|
|
function handleAsyncRoutes(routeList) { |
|
|
|
if (routeList.length === 0) { |
|
|
|
usePermissionStoreHook().handleWholeMenus(routeList); |
|
|
|
} else { |
|
|
|
formatFlatteningRoutes(addAsyncRoutes(data)).map( |
|
|
|
formatFlatteningRoutes(addAsyncRoutes(routeList)).map( |
|
|
|
(v: RouteRecordRaw) => { |
|
|
|
// 防止重复添加路由
|
|
|
|
if ( |
|
|
@ -179,13 +177,35 @@ function initRouter() { |
|
|
|
.find(n => n.path === "/"); |
|
|
|
router.addRoute(flattenRouters); |
|
|
|
} |
|
|
|
resolve(router); |
|
|
|
} |
|
|
|
); |
|
|
|
usePermissionStoreHook().handleWholeMenus(data); |
|
|
|
usePermissionStoreHook().handleWholeMenus(routeList); |
|
|
|
} |
|
|
|
addPathMatch(); |
|
|
|
} |
|
|
|
|
|
|
|
/** 初始化路由 */ |
|
|
|
function initRouter() { |
|
|
|
return new Promise(resolve => { |
|
|
|
if (getConfig()?.CachingAsyncRoutes) { |
|
|
|
// 开启动态路由缓存本地sessionStorage
|
|
|
|
const key = "async-routes"; |
|
|
|
const asyncRouteList = storageSession.getItem(key) as any; |
|
|
|
if (asyncRouteList?.length > 0) { |
|
|
|
handleAsyncRoutes(asyncRouteList); |
|
|
|
} else { |
|
|
|
getAsyncRoutes().then(({ data }) => { |
|
|
|
handleAsyncRoutes(data); |
|
|
|
storageSession.setItem(key, data); |
|
|
|
}); |
|
|
|
} |
|
|
|
resolve(router); |
|
|
|
} else { |
|
|
|
getAsyncRoutes().then(({ data }) => { |
|
|
|
handleAsyncRoutes(data); |
|
|
|
resolve(router); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|