| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import React, { useState, useEffect } from 'react'
- import { Button, message, Tree, TreeSelect, Form } from 'antd'
- import { PlusOutlined } from '@ant-design/icons'
- import consts from '@/consts'
- import { apiaddDepartment } from '@/services/department'
- import { connect } from 'dva'
- import { ModalForm, ProFormText } from '@ant-design/pro-form'
- const RoleMenu = props => {
- const { dispatch, departments = [], onSelect } = props
- const { DirectoryTree } = Tree
- const initData = () => {
- dispatch({
- type: 'staff/fetchDepartments'
- })
- }
- const handleAddDepartment = async values => {
- const { code = -1 } = await apiaddDepartment({ ...values })
- if (code === consts.RET_CODE.SUCCESS) {
- // message.success('新增成功')
- initData()
- }
- }
- useEffect(() => {
- if (!departments.length) {
- initData()
- }
- }, [])
- const saveActiveId = id => {
- // console.log(keys)
- if (onSelect) {
- onSelect(id)
- }
- }
- const onExpand = () => {}
- return (
- <div className="h-full w-max-234px rounded-4px roleMenu">
- <div className="p-4 pb-3 border-b-1 border-solid border-black border-opacity-10 bg-[#f7f9fa] flex justify-around items-center">
- <span className="text-[0.9375rem]">组织架构</span>
- <ModalForm
- title="创建部门"
- width="500px"
- trigger={
- <Button size="small" type="primary" ghost>
- <PlusOutlined />
- 创建部门
- </Button>
- }
- onFinish={async values => {
- await handleAddDepartment(values)
- message.success('添加成功')
- return true
- }}>
- <ProFormText name="backstageMenuId" hidden />
- <ProFormText name="name" label="新增部门" rules={[{ message: '请输入部门名称' }]} />
- <Form.Item label="上级部门" name="parentId">
- <TreeSelect
- style={{ width: '100%' }}
- placeholder="请选择上司"
- treeDefaultExpandAll
- treeData={departments}
- allowClear
- />
- </Form.Item>
- {/* <ProFormTreeSelect
- width="md"
- options={departments.map(item => ({ label: item.name, value: item.id }))}
- name="parentId"
- label="上级部门"
- /> */}
- </ModalForm>
- </div>
- <div className="p-4 bg-white" style={{ height: 'calc(100% - 1rem*2 - 20px)' }}>
- {departments.length && (
- <DirectoryTree
- multiple
- defaultExpandAll
- defaultSelectedKeys={['McjlMdO0O0Oi']}
- onSelect={keys => saveActiveId(keys[0])}
- onExpand={onExpand}
- showIcon={false}
- treeData={departments}
- />
- )}
- </div>
- </div>
- )
- }
- // export default RoleMenu
- export default connect(({ staff }) => ({
- departments: staff.departments
- }))(RoleMenu)
|