update 优化 前端处理路由函数代码
This commit is contained in:
parent
7be0723c31
commit
f2adc5e5fa
@ -23,6 +23,9 @@ export const usePermissionStore = defineStore('permission', () => {
|
|||||||
const getRoutes = (): RouteRecordRaw[] => {
|
const getRoutes = (): RouteRecordRaw[] => {
|
||||||
return routes.value as RouteRecordRaw[];
|
return routes.value as RouteRecordRaw[];
|
||||||
};
|
};
|
||||||
|
const getDefaultRoutes = (): RouteRecordRaw[] => {
|
||||||
|
return defaultRoutes.value as RouteRecordRaw[];
|
||||||
|
};
|
||||||
const getSidebarRoutes = (): RouteRecordRaw[] => {
|
const getSidebarRoutes = (): RouteRecordRaw[] => {
|
||||||
return sidebarRouters.value as RouteRecordRaw[];
|
return sidebarRouters.value as RouteRecordRaw[];
|
||||||
};
|
};
|
||||||
@ -97,29 +100,14 @@ export const usePermissionStore = defineStore('permission', () => {
|
|||||||
};
|
};
|
||||||
const filterChildren = (childrenMap: RouteRecordRaw[], lastRouter?: RouteRecordRaw): RouteRecordRaw[] => {
|
const filterChildren = (childrenMap: RouteRecordRaw[], lastRouter?: RouteRecordRaw): RouteRecordRaw[] => {
|
||||||
let children: RouteRecordRaw[] = [];
|
let children: RouteRecordRaw[] = [];
|
||||||
childrenMap.forEach((el) => {
|
childrenMap.forEach(el => {
|
||||||
if (el.children && el.children.length) {
|
el.path = lastRouter ? lastRouter.path + '/' + el.path : el.path;
|
||||||
if (el.component?.toString() === 'ParentView' && !lastRouter) {
|
if (el.children && el.children.length && el.component?.toString() === 'ParentView') {
|
||||||
el.children.forEach((c) => {
|
children = children.concat(filterChildren(el.children, el));
|
||||||
c.path = el.path + '/' + c.path;
|
} else {
|
||||||
if (c.children && c.children.length) {
|
children.push(el);
|
||||||
children = children.concat(filterChildren(c.children, c));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
children.push(c);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (lastRouter) {
|
})
|
||||||
el.path = lastRouter.path + '/' + el.path;
|
|
||||||
if (el.children && el.children.length) {
|
|
||||||
children = children.concat(filterChildren(el.children, el));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
children = children.concat(el);
|
|
||||||
});
|
|
||||||
return children;
|
return children;
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
@ -129,6 +117,7 @@ export const usePermissionStore = defineStore('permission', () => {
|
|||||||
defaultRoutes,
|
defaultRoutes,
|
||||||
|
|
||||||
getRoutes,
|
getRoutes,
|
||||||
|
getDefaultRoutes,
|
||||||
getSidebarRoutes,
|
getSidebarRoutes,
|
||||||
getTopbarRoutes,
|
getTopbarRoutes,
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user