Download packages/utils/src/helpers/find-menu-by-path.ts from binhugg3/admin: direct link, hf CLI and curl.
- Browser
- Download file 819 Bytes
-
https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/utils/src/helpers/find-menu-by-path.ts
- Command line
-
hf download hf://spaces/binhugg3/admin/packages/utils/src/helpers/find-menu-by-path.ts
-
curl -L -o find-menu-by-path.ts https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/utils/src/helpers/find-menu-by-path.ts
819 Bytes
| 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) { | |
| const findMenu = findMenuByPath(menus, path); | |
| const rootMenuPath = findMenu?.parents?.[0]; | |
| const rootMenu = rootMenuPath | |
| ? menus.find((item) => item.path === rootMenuPath) | |
| : undefined; | |
| return { | |
| findMenu, | |
| rootMenu, | |
| rootMenuPath, | |
| }; | |
| } | |
| export { findMenuByPath, findRootMenuByPath }; | |