fix
parent
5fc1a9c8e4
commit
7cba6bcaa8
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue