39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
// 机构数据以扁平列表存储,前端/mock均通过 parentId 自行组装树
|
|
// org001 为一级机构(内置根机构),不可删除;admin 用户归属于此
|
|
export const orgs = [
|
|
{ id: 'org001', name: '总行', parentId: null, level: 1, remark: '内置根机构,不可删除', builtin: true, createdAt: '2026-01-01 00:00:00' },
|
|
{ id: 'org002', name: '华东分行', parentId: 'org001', level: 2, remark: '', builtin: false, createdAt: '2026-01-02 00:00:00' },
|
|
{ id: 'org003', name: '华南分行', parentId: 'org001', level: 2, remark: '', builtin: false, createdAt: '2026-01-02 00:00:00' },
|
|
{ id: 'org004', name: '上海分部', parentId: 'org002', level: 3, remark: '', builtin: false, createdAt: '2026-01-03 00:00:00' }
|
|
]
|
|
|
|
let seq = orgs.length
|
|
|
|
export function nextOrgId() {
|
|
seq += 1
|
|
return `org${String(seq).padStart(3, '0')}`
|
|
}
|
|
|
|
export function buildOrgTree(list) {
|
|
const map = new Map(list.map((o) => [o.id, { ...o, children: [] }]))
|
|
const roots = []
|
|
map.forEach((node) => {
|
|
if (node.parentId && map.has(node.parentId)) {
|
|
map.get(node.parentId).children.push(node)
|
|
} else {
|
|
roots.push(node)
|
|
}
|
|
})
|
|
return roots
|
|
}
|
|
|
|
export function collectDescendantIds(list, id) {
|
|
const result = []
|
|
const children = list.filter((o) => o.parentId === id)
|
|
children.forEach((c) => {
|
|
result.push(c.id)
|
|
result.push(...collectDescendantIds(list, c.id))
|
|
})
|
|
return result
|
|
}
|