index.jsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React, { useState, useEffect } from 'react'
  2. import { Button, message } from 'antd'
  3. import { PlusOutlined } from '@ant-design/icons'
  4. import consts from '@/consts'
  5. import { apiaddDepartment } from '@/services/department'
  6. import { connect } from 'dva'
  7. import { ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-form'
  8. const RoleMenu = props => {
  9. const { dispatch, departments = [] } = props
  10. const [state, setState] = useState({
  11. params: {},
  12. visible: false
  13. })
  14. const [addDepartment, setAddDepartment] = useState({
  15. visible: false,
  16. loading: false
  17. })
  18. const handleAddDepartment = async values => {
  19. setAddDepartment({ ...addDepartment, loading: true })
  20. const { code = -1 } = await apiaddDepartment({ ...values })
  21. if (code === consts.RET_CODE.SUCCESS) {
  22. message.success('新增成功')
  23. setState({ ...state, data: values })
  24. }
  25. // 请求完了
  26. setAddDepartment({ ...addDepartment, loading: false, visible: false })
  27. // 刷新数据
  28. dispatch({
  29. type: 'refresh/commitAction',
  30. payload: 'contact'
  31. })
  32. }
  33. useEffect(() => {
  34. if (!departments.length) {
  35. dispatch({
  36. type: 'staff/fetchDepartments'
  37. })
  38. }
  39. }, [])
  40. return (
  41. <div className="h-full w-max-234px rounded-4px roleMenu">
  42. <div className="p-4 border-b-1 border-solid border-black border-opacity-10 bg-[#f7f9fa] flex justify-around items-center">
  43. <span className="text-[0.9375rem]">组织架构</span>
  44. <ModalForm
  45. title="创建部门"
  46. width="500px"
  47. trigger={
  48. <Button size="small" type="primary" ghost>
  49. <PlusOutlined />
  50. 创建部门
  51. </Button>
  52. }
  53. onFinish={handleAddDepartment}>
  54. <ProFormText name="backstageMenuId" hidden />
  55. <ProFormText name="name" label="新增部门" rules={[{ message: '请输入部门名称' }]} />
  56. <ProFormSelect
  57. width="md"
  58. options={[
  59. {
  60. value: 'time',
  61. label: '总部'
  62. },
  63. {
  64. value: 'timea',
  65. label: '研究中心'
  66. }
  67. ]}
  68. name="unusedMode"
  69. label="上级部门"
  70. />
  71. </ModalForm>
  72. </div>
  73. <div className="p-4 bg-white" style={{ height: 'calc(100% - 1rem*2 - 20px)' }}>
  74. <ul className="p-0 m-0 list-none text-primary flex flex-col flex-1">
  75. <li>全公司</li>
  76. </ul>
  77. </div>
  78. </div>
  79. )
  80. }
  81. // export default RoleMenu
  82. export default connect(({ staff }) => ({
  83. departments: staff.departments
  84. }))(RoleMenu)