Browse Source

update:department editor, add upper department and manager

dev
powersir 11 months ago
parent
commit
2f18d86b90
2 changed files with 39 additions and 4 deletions
  1. +38
    -3
      src/pages/system/dept/create-department.tsx
  2. +1
    -1
      src/request/service/user.ts

+ 38
- 3
src/pages/system/dept/create-department.tsx View File

@@ -1,8 +1,9 @@
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import { Form, Input, InputNumber, Radio, Modal, Switch } from 'antd';
import { Form, Input, InputNumber, Radio, Modal, Select } from 'antd';
import departmentService from '@/request/service/deparatment'; import departmentService from '@/request/service/deparatment';
import userService from '@/request/service/user';
import { useRequest } from '@/hooks/use-request'; import { useRequest } from '@/hooks/use-request';
import type { DepartmentVO } from '@/models'
import type { DepartmentVO, UserDTO, UserVO } from '@/models'
import { antdUtils } from '@/utils/antd'; import { antdUtils } from '@/utils/antd';


const layout = { const layout = {
@@ -21,18 +22,45 @@ interface EditorProps {
const DepartmentEditor: React.FC<EditorProps> = (props) => { const DepartmentEditor: React.FC<EditorProps> = (props) => {


const { visible, onCancel, onSave, data } = props; const { visible, onCancel, onSave, data } = props;
const [ departments, setDepartments ] = useState<DepartmentVO[]>([]);
const [ userList, setUserList ] = useState<UserVO[]>([]);


const { runAsync: updatePostApi } = useRequest(departmentService.updateDeptApi, { manual: true }); const { runAsync: updatePostApi } = useRequest(departmentService.updateDeptApi, { manual: true });
const { runAsync: createPostApi } = useRequest(departmentService.createDeptApi, { manual: true }); const { runAsync: createPostApi } = useRequest(departmentService.createDeptApi, { manual: true });
const { runAsync: listSimpleDeptApi } = useRequest(departmentService.listSimpleDeptApi, {manual: true});
const { runAsync: listSimpleUsersApi } = useRequest(userService.getListSimpleUsersApi, {manual: true});


const isEdit = !!data; const isEdit = !!data;



const [saveLoading, setSaveLoading] = useState(false); const [saveLoading, setSaveLoading] = useState(false);
const [form] = Form.useForm(); const [form] = Form.useForm();


const loadDepartments = async () => {
const [error, { data, msg }] = await listSimpleDeptApi();
if(!error) {
setDepartments(data);
} else {
antdUtils.message?.error(msg ?? '获取部门列表数据失败');
}
}

const loadUserList = async () => {
const [error, { data, msg }] = await listSimpleUsersApi();
if(!error) {
setUserList(data);
} else {
antdUtils.message?.error(msg ?? '获取用户列表数据失败');
}
}

useEffect(() => { useEffect(() => {
if (visible) { if (visible) {
if(departments.length === 0) {
loadDepartments()
}
if(userList.length === 0) {
loadUserList();
}
if (data) { if (data) {
form.setFieldsValue(data); form.setFieldsValue(data);
} }
@@ -76,6 +104,9 @@ const DepartmentEditor: React.FC<EditorProps> = (props) => {
labelCol={{ flex: '0 0 100px' }} labelCol={{ flex: '0 0 100px' }}
wrapperCol={{ span: 16 }} wrapperCol={{ span: 16 }}
> >
<Form.Item name="parentId" label="上级部门">
<Select options={departments.map(it => ({ value: it.id, label: it.name }))} />
</Form.Item>
<Form.Item name="name" label="部门名称" <Form.Item name="name" label="部门名称"
rules={[ rules={[
{ {
@@ -87,6 +118,10 @@ const DepartmentEditor: React.FC<EditorProps> = (props) => {
<Input /> <Input />
</Form.Item> </Form.Item>


<Form.Item name="leaderUserId" label="负责人">
<Select options={userList.map(it => ({ value: it.id, label: it.nickname }))}/>
</Form.Item>

<Form.Item name="phone" label="联系电话" <Form.Item name="phone" label="联系电话"
rules={[ rules={[
{ {


+ 1
- 1
src/request/service/user.ts View File

@@ -64,7 +64,7 @@ export default {


// 获取用户精简信息列表 // 获取用户精简信息列表
getListSimpleUsersApi: () => { getListSimpleUsersApi: () => {
return request.get(`${BASE_URL}/list-all-simple`)
return request.get<UserVO[]>(`${BASE_URL}/list-all-simple`)
}, },


}; };

Loading…
Cancel
Save