diff --git a/src/pages/Container/EnterpriseInfo/DepartmentPosition/index.js b/src/pages/Container/EnterpriseInfo/DepartmentPosition/index.js index d147edd..6aa21de 100644 --- a/src/pages/Container/EnterpriseInfo/DepartmentPosition/index.js +++ b/src/pages/Container/EnterpriseInfo/DepartmentPosition/index.js @@ -119,7 +119,19 @@ function DepartmentPositionPage(props) { const tree = res?.data || []; setTreeData(tree); if (tree.length) { - setSelectedDept(tree[0]); + const findById = (nodes, id) => { + for (const n of nodes) { + if (n.id === id) return n; + if (n.children?.length) { + const found = findById(n.children, id); + if (found) return found; + } + } + return null; + }; + const matched = selectedDept?.id && findById(tree, selectedDept.id); + console.log(matched); + setSelectedDept(matched || tree[0]); } } catch (err) { console.warn("[DepartmentPosition] loadTree failed:", err);