mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-04-05 19:41:59 +08:00
26 lines
487 B
TypeScript
26 lines
487 B
TypeScript
export * from './icon'
|
|
export * from './storage'
|
|
|
|
export function arrayToTree(arr) {
|
|
const map = {}
|
|
|
|
arr.forEach((item) => {
|
|
map[item.id] = { ...item }
|
|
})
|
|
|
|
arr.forEach((item) => {
|
|
if (item.pid !== 0) {
|
|
const parent = map[item.pid]
|
|
if (parent) {
|
|
parent.children = parent.children || []
|
|
parent.children.push(map[item.id])
|
|
}
|
|
}
|
|
})
|
|
|
|
// 找出根节点
|
|
const tree = Object.values(map).filter(item => item.pid === 0)
|
|
|
|
return tree
|
|
}
|