|
|
@@ -7,39 +7,28 @@ import { connect } from 'dva'
|
|
|
import { ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-form'
|
|
|
|
|
|
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 => {
|
|
|
- setAddDepartment({ ...addDepartment, loading: true })
|
|
|
- const { code = -1 } = await apiaddDepartment({ ...values, parentId })
|
|
|
+ const { code = -1 } = await apiaddDepartment({ ...values })
|
|
|
if (code === consts.RET_CODE.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(() => {
|
|
|
if (!departments.length) {
|
|
|
- dispatch({
|
|
|
- type: 'staff/fetchDepartments'
|
|
|
- })
|
|
|
+ initData()
|
|
|
}
|
|
|
}, [])
|
|
|
|
|
|
@@ -56,8 +45,11 @@ const RoleMenu = props => {
|
|
|
创建部门
|
|
|
</Button>
|
|
|
}
|
|
|
- onFinish={handleAddDepartment}
|
|
|
- parentId={{ parentId }}>
|
|
|
+ onFinish={async values => {
|
|
|
+ await handleAddDepartment(values)
|
|
|
+ message.success('添加成功')
|
|
|
+ return true
|
|
|
+ }}>
|
|
|
<ProFormText name="backstageMenuId" hidden />
|
|
|
<ProFormText name="name" label="新增部门" rules={[{ message: '请输入部门名称' }]} />
|
|
|
<ProFormSelect
|
|
|
@@ -73,7 +65,8 @@ const RoleMenu = props => {
|
|
|
{departments.map(item => (
|
|
|
<li
|
|
|
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>
|
|
|
</li>
|
|
|
))}
|
|
|
@@ -84,7 +77,6 @@ const RoleMenu = props => {
|
|
|
}
|
|
|
|
|
|
// export default RoleMenu
|
|
|
-export default connect(({ staff, refresh }) => ({
|
|
|
- departments: staff.departments,
|
|
|
- shouldUpdate: refresh.department
|
|
|
+export default connect(({ staff }) => ({
|
|
|
+ departments: staff.departments
|
|
|
}))(RoleMenu)
|