lanjianrong преди 5 години
родител
ревизия
a778a74e55
променени са 1 файла, в които са добавени 23 реда и са изтрити 31 реда
  1. 23 31
      src/pages/Staff/RoleMenu/index.jsx

+ 23 - 31
src/pages/Staff/RoleMenu/index.jsx

@@ -7,39 +7,28 @@ import { connect } from 'dva'
 import { ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-form'
 import { ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-form'
 
 
 const RoleMenu = props => {
 const RoleMenu = props => {
-  const { dispatch, departments = [], parentId } = props
-  const [state, setState] = useState({
-    params: {},
-    visible: false
-  })
-  const [addDepartment, setAddDepartment] = useState({
-    visible: false,
-    loading: false
-  })
+  const { dispatch, departments = [] } = props
+  // eslint-disable-next-line no-unused-vars
+  const [activeId, setActiveId] = useState('')
+
+  const initData = () => {
+    dispatch({
+      type: 'staff/fetchDepartments'
+    })
+  }
+
   const handleAddDepartment = async values => {
   const handleAddDepartment = async values => {
-    setAddDepartment({ ...addDepartment, loading: true })
-    const { code = -1 } = await apiaddDepartment({ ...values, parentId })
+    const { code = -1 } = await apiaddDepartment({ ...values })
     if (code === consts.RET_CODE.SUCCESS) {
     if (code === consts.RET_CODE.SUCCESS) {
       message.success('新增成功')
       message.success('新增成功')
-      setState({ ...state, data: values })
+
+      initData()
     }
     }
-    // 请求完了
-    setAddDepartment({ ...addDepartment, loading: false, visible: false })
-    // 刷新数据
-    dispatch({
-      type: 'refresh/commitAction',
-      payload: 'department'
-    })
   }
   }
-  useEffect(() => {
-    setState({ ...state, params: { ...state.params, parentId } })
-  }, [parentId])
 
 
   useEffect(() => {
   useEffect(() => {
     if (!departments.length) {
     if (!departments.length) {
-      dispatch({
-        type: 'staff/fetchDepartments'
-      })
+      initData()
     }
     }
   }, [])
   }, [])
 
 
@@ -56,8 +45,11 @@ const RoleMenu = props => {
               创建部门
               创建部门
             </Button>
             </Button>
           }
           }
-          onFinish={handleAddDepartment}
-          parentId={{ parentId }}>
+          onFinish={async values => {
+            await handleAddDepartment(values)
+            message.success('添加成功')
+            return true
+          }}>
           <ProFormText name="backstageMenuId" hidden />
           <ProFormText name="backstageMenuId" hidden />
           <ProFormText name="name" label="新增部门" rules={[{ message: '请输入部门名称' }]} />
           <ProFormText name="name" label="新增部门" rules={[{ message: '请输入部门名称' }]} />
           <ProFormSelect
           <ProFormSelect
@@ -73,7 +65,8 @@ const RoleMenu = props => {
           {departments.map(item => (
           {departments.map(item => (
             <li
             <li
               key={item.id}
               key={item.id}
-              className="flex justify-between items-center py-2 px-5 cursor-pointer">
+              className="flex justify-between items-center py-2 px-5 cursor-pointer"
+              onClick={() => setActiveId(item.id)}>
               <span>{item.name}</span>
               <span>{item.name}</span>
             </li>
             </li>
           ))}
           ))}
@@ -84,7 +77,6 @@ const RoleMenu = props => {
 }
 }
 
 
 // export default RoleMenu
 // export default RoleMenu
-export default connect(({ staff, refresh }) => ({
-  departments: staff.departments,
-  shouldUpdate: refresh.department
+export default connect(({ staff }) => ({
+  departments: staff.departments
 }))(RoleMenu)
 }))(RoleMenu)