diff --git a/react-ui/src/pages/System/User/components/DeptTree.tsx b/react-ui/src/pages/System/User/components/DeptTree.tsx index 395cf7a0..160d41ba 100644 --- a/react-ui/src/pages/System/User/components/DeptTree.tsx +++ b/react-ui/src/pages/System/User/components/DeptTree.tsx @@ -28,8 +28,11 @@ const DeptTree: React.FC = (props) => { const res = await getDeptTree({}); const treeData = res.map((item: any) => ({ ...item, key: item.id })); setTreeData(treeData); - setExpandedKeys([treeData[0].key]); - setSelectedKeys([treeData[0].key]); + if (treeData.length > 0) { + onSelect(treeData[0]); + setExpandedKeys([treeData[0].key]); + setSelectedKeys([treeData[0].key]); + } hide(); return true; } catch (error) { @@ -41,12 +44,6 @@ const DeptTree: React.FC = (props) => { fetchDeptList(); }, []); - useEffect(() => { - if (treeData.length > 0) { - onSelect(treeData[0]); - } - }, [treeData, onSelect]); - const handleSelect = (keys: React.Key[], info: any) => { setSelectedKeys(keys); onSelect(info.node);