Initial commit

This commit is contained in:
2026-04-07 09:03:48 +08:00
commit c9ffb52b7f
713 changed files with 111641 additions and 0 deletions

26
web-admin/src/lib/tree.ts Normal file
View File

@@ -0,0 +1,26 @@
import type { Authority, MenuNode } from '@/types/system'
export function flattenAuthorities(authorities: Authority[], depth = 0): Array<Authority & { depth: number }> {
return authorities.flatMap((authority) => [
{ ...authority, depth },
...flattenAuthorities(authority.children || [], depth + 1),
])
}
export function flattenMenusForOptions(menus: MenuNode[], depth = 0): Array<MenuNode & { depth: number }> {
return menus.flatMap((menu) => [
{ ...menu, depth },
...flattenMenusForOptions(menu.children || [], depth + 1),
])
}
export function collectCheckedLeafMenus(menus: MenuNode[], checkedKeys: Set<number>): MenuNode[] {
return menus.flatMap((menu) => {
const children = menu.children || []
if (!children.length) {
return checkedKeys.has(menu.ID) ? [menu] : []
}
return collectCheckedLeafMenus(children, checkedKeys)
})
}