| | |
| | | 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('正在添加'); |
| | |
| | | const [searchParam, setSearchParam] = useState({}); |
| | | const [boxHeight, setBoxHeight] = useState(); |
| | | const [deptTreeData, setDeptTreeData] = useState([]); |
| | | const [deptExpandedKeys, setDeptExpandedKeys] = useState([]); |
| | | |
| | | useEffect(() => { |
| | | const handleResize = () => setBoxHeight(window.innerHeight - 368); |
| | |
| | | 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); |
| | |
| | | <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; |
| | |
| | | /> |
| | | <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> |