tangjie 2026-07-09 10:03:36 +08:00
parent 5fc1a9c8e4
commit 7cba6bcaa8
1 changed files with 13 additions and 1 deletions

View File

@ -119,7 +119,19 @@ function DepartmentPositionPage(props) {
const tree = res?.data || []; const tree = res?.data || [];
setTreeData(tree); setTreeData(tree);
if (tree.length) { 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) { } catch (err) {
console.warn("[DepartmentPosition] loadTree failed:", err); console.warn("[DepartmentPosition] loadTree failed:", err);