From 6fc2ad3b34100cc0048618f6cedbf829a742a7b8 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 21 二月 2024 09:49:54 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/utils/tree-util.js          |   11 +++++++++++
 zy-asrs-flow/src/pages/system/user/index.jsx |   23 +++++++++++++++--------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/zy-asrs-flow/src/pages/system/user/index.jsx b/zy-asrs-flow/src/pages/system/user/index.jsx
index 7504506..913c542 100644
--- a/zy-asrs-flow/src/pages/system/user/index.jsx
+++ b/zy-asrs-flow/src/pages/system/user/index.jsx
@@ -11,7 +11,7 @@
 import Http from '@/utils/http';
 import Edit from './components/edit'
 import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch'
-import { transformTreeData } from '@/utils/tree-util'
+import { transformTreeData, getTreeAllKeys } from '@/utils/tree-util'
 
 const handleSave = async (val) => {
     const hide = message.loading('姝e湪娣诲姞');
@@ -97,6 +97,7 @@
     const [searchParam, setSearchParam] = useState({});
     const [boxHeight, setBoxHeight] = useState();
     const [deptTreeData, setDeptTreeData] = useState([]);
+    const [deptExpandedKeys, setDeptExpandedKeys] = useState([]);
 
     useEffect(() => {
         const handleResize = () => setBoxHeight(window.innerHeight - 368);
@@ -104,8 +105,12 @@
         handleResize();
 
         Http.doPostPromise('/api/dept/tree', {}, (res) => {
-            const treeData = transformTreeData(res.data);
+            const rootMenu = { id: 0, name: '鍏ㄩ儴', value: 0, children: [] };
+            rootMenu.children = res.data;
+            const treeData = transformTreeData([rootMenu]);
             setDeptTreeData(treeData);
+            const treeAllKeys = getTreeAllKeys(treeData);
+            setDeptExpandedKeys(treeAllKeys);
         })
 
         return () => window.removeEventListener('resize', handleResize);
@@ -433,7 +438,7 @@
                 <Col lg={6} md={24}>
                     <Card title="閮ㄩ棬" style={{ width: '100%', height: 'calc(100vh - 200px)' }}>
                         <Input
-                            style={{ marginBottom: 8 }}
+                            style={{ marginBottom: 10 }}
                             placeholder="Search"
                             onChange={(e) => {
                                 const { value } = e.target;
@@ -442,13 +447,15 @@
                         />
                         <Tree
                             showLine
-                            switcherIcon={<DownOutlined />}
                             blockNode
-                            defaultExpandAll
-                            onSelect={(selectedKeys, info) => {
-                                console.log(selectedKeys[0]);
-                            }}
+                            defaultExpandAll    // 寮傛鍔犺浇澶辨晥
+                            expandedKeys={deptExpandedKeys}
                             treeData={deptTreeData}
+                            switcherIcon={<DownOutlined />}
+                            onSelect={(selectedKeys, info) => {
+                                const deptId = selectedKeys[0];
+                                console.log(deptId);
+                            }}
                         />
                     </Card>
                 </Col>
diff --git a/zy-asrs-flow/src/utils/tree-util.js b/zy-asrs-flow/src/utils/tree-util.js
index b51f864..a64efff 100644
--- a/zy-asrs-flow/src/utils/tree-util.js
+++ b/zy-asrs-flow/src/utils/tree-util.js
@@ -14,3 +14,14 @@
     return newItem;
   });
 }
+
+export function getTreeAllKeys(data) {
+  let keys = [];
+  for (let item of data) {
+      keys.push(item.key);
+      if (item.children) {
+          keys = keys.concat(getTreeAllKeys(item.children));
+      }
+  }
+  return keys;
+}
\ No newline at end of file

--
Gitblit v1.9.1