1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| import type { MenuRecordRaw } from '@vben-core/typings';
|
| function findMenuByPath(
| list: MenuRecordRaw[],
| path?: string,
| ): MenuRecordRaw | null {
| for (const menu of list) {
| if (menu.path === path) {
| return menu;
| }
| const findMenu = menu.children && findMenuByPath(menu.children, path);
| if (findMenu) {
| return findMenu;
| }
| }
| return null;
| }
|
| /**
| * 查找根菜单
| * @param menus
| * @param path
| */
| function findRootMenuByPath(menus: MenuRecordRaw[], path?: string, level = 0) {
| const findMenu = findMenuByPath(menus, path);
| const rootMenuPath = findMenu?.parents?.[level];
| const rootMenu = rootMenuPath
| ? menus.find((item) => item.path === rootMenuPath)
| : undefined;
| return {
| findMenu,
| rootMenu,
| rootMenuPath,
| };
| }
|
| export { findMenuByPath, findRootMenuByPath };
|
|