fix: 部门列表空/职务无法启用 — fetchTree适配树形API响应, positions表加status/code/description字段

This commit is contained in:
li
2026-03-14 18:15:36 +08:00
parent f12cb4a2e0
commit 444065d496
4 changed files with 42 additions and 6 deletions
@@ -74,9 +74,15 @@ async function fetchTree() {
loading.value = true
try {
const res = await departmentApi.getList({ per_page: 500 })
const flat = res.data?.list || res.data?.data || []
flatDepts.value = flat.map(d => ({ id: d.id, name: d.name }))
treeData.value = buildTree(flat)
// Backend already returns a tree array directly in res.data
if (Array.isArray(res.data)) {
treeData.value = res.data
flatDepts.value = flattenTree(res.data)
} else {
const flat = res.data?.list || res.data?.data || []
flatDepts.value = flat.map(d => ({ id: d.id, name: d.name }))
treeData.value = buildTree(flat)
}
} catch {
//
} finally {
@@ -84,9 +90,9 @@ async function fetchTree() {
}
}
function buildTree(nodes, parentId = null) {
function buildTree(nodes, parentId = 0) {
return nodes
.filter(n => (n.parent_id ?? null) === parentId)
.filter(n => (n.parent_id ?? 0) === parentId)
.map(n => ({ ...n, children: buildTree(nodes, n.id) }))
}