mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): 面包屑
This commit is contained in:
35
src/utils/router/breadcrumb.ts
Normal file
35
src/utils/router/breadcrumb.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import type { GlobalMenuOption, GlobalBreadcrumb } from '@/interface';
|
||||
|
||||
/**
|
||||
* 获取面包屑数据
|
||||
* @param activeKey - 当前页面路由的key
|
||||
* @param menus - 菜单数据
|
||||
* @param rootPath - 根路由路径
|
||||
*/
|
||||
export function getBreadcrumbByRouteKey(activeKey: string, menus: GlobalMenuOption[], rootPath: string) {
|
||||
return menus.map(menu => getBreadcrumbItem(activeKey, menu, rootPath)).flat(1);
|
||||
}
|
||||
|
||||
function getBreadcrumbItem(activeKey: string, menu: GlobalMenuOption, rootPath: string) {
|
||||
const list: GlobalBreadcrumb[] = [];
|
||||
if (activeKey.includes(menu.routeName)) {
|
||||
const breadcrumb: GlobalBreadcrumb = {
|
||||
key: menu.routeName,
|
||||
label: menu.label as string,
|
||||
routeName: menu.routeName,
|
||||
disabled: menu.routePath === rootPath,
|
||||
hasChildren: false
|
||||
};
|
||||
if (menu.icon) {
|
||||
breadcrumb.icon = menu.icon;
|
||||
}
|
||||
if (menu.children && menu.children.length) {
|
||||
breadcrumb.hasChildren = true;
|
||||
breadcrumb.children = menu.children
|
||||
.map(item => getBreadcrumbItem(activeKey, item as GlobalMenuOption, rootPath))
|
||||
.flat(1);
|
||||
}
|
||||
list.push(breadcrumb);
|
||||
}
|
||||
return list;
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
export * from './helpers';
|
||||
export * from './menu';
|
||||
export * from './breadcrumb';
|
||||
export * from './regexp';
|
||||
|
Reference in New Issue
Block a user