组织管理
This commit is contained in:
188
src/pages/System/Department/index.tsx
Normal file
188
src/pages/System/Department/index.tsx
Normal file
@ -0,0 +1,188 @@
|
||||
import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table';
|
||||
import { Button, Form, Input, message, Modal, PageHeader, Select, Spin, Tree, TreeSelect } from 'antd';
|
||||
import { useRef, useState } from 'react';
|
||||
import { fetchAllDepartment, addOrg, deleteOrg, updateOrg, getDataById } from './service';
|
||||
import React from 'react';
|
||||
const Index: React.FC<{}> = () => {
|
||||
const [spin, spinSet] = useState<boolean>(false);
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [form] = Form.useForm();
|
||||
const [title, setTitle] = useState<string>('');
|
||||
const [open, setOpen] = useState<boolean>(false);
|
||||
const [org, orgSet] = useState<any>([]);
|
||||
const layout = {
|
||||
labelCol: { span: 6 },
|
||||
wrapperCol: { span: 13 },
|
||||
};
|
||||
const columns: ProColumns[] = [
|
||||
{
|
||||
title: '组织编码',
|
||||
dataIndex: 'orgNum',
|
||||
width: '10%',
|
||||
},
|
||||
{
|
||||
title: '组织名称',
|
||||
dataIndex: 'orgName',
|
||||
width: '30%',
|
||||
},
|
||||
{
|
||||
title: '组织全称',
|
||||
dataIndex: 'orgFullName',
|
||||
width: '45%',
|
||||
hideInSearch: true,
|
||||
},
|
||||
{
|
||||
title: '操作', width: '10%',
|
||||
valueType: 'option',
|
||||
render: (_, record) => [
|
||||
<Button type='text' onClick={() => { handleUpdate(record) }}>修改</Button>,
|
||||
<Button type='text' onClick={() => { handleDelete(record.orgId) }}>删除</Button>
|
||||
]
|
||||
},
|
||||
// {
|
||||
// title: '部门负责人',
|
||||
// dataIndex: 'leaderName',
|
||||
// width: '15%',
|
||||
// },
|
||||
];
|
||||
const handleAdd = async () => {
|
||||
setOpen(true);
|
||||
setTitle('添加组织');
|
||||
};
|
||||
|
||||
const handleUpdate = async (record: any) => {
|
||||
form.resetFields();
|
||||
const org = await getDataById(record.orgId);
|
||||
form.setFieldsValue(org.data);
|
||||
setOpen(true);
|
||||
setTitle('修改组织');
|
||||
};
|
||||
// 删除操作
|
||||
const handleDelete = (id: string) => {
|
||||
Modal.confirm({
|
||||
title: '确认删除该组织?',
|
||||
onOk: async () => {
|
||||
await deleteOrg(id).then((r: any) => {
|
||||
if (r.code == 200) {
|
||||
message.success('删除成功');
|
||||
}
|
||||
})
|
||||
.finally(() => actionRef.current?.reload());
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
const values = await form.validateFields();
|
||||
if (values.orgId) {
|
||||
await updateOrg(values).then((r: any) => {
|
||||
if (r.code == 200) {
|
||||
message.success('修改成功');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await addOrg(values).then((r: any) => {
|
||||
if (r.code == 200) {
|
||||
message.success('新增成功');
|
||||
}
|
||||
});
|
||||
}
|
||||
closeModal();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
const closeModal = async () => {
|
||||
actionRef.current?.reload();
|
||||
form.resetFields();
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const addModal = (
|
||||
<Modal
|
||||
title={title}
|
||||
visible={open}
|
||||
width="70%"
|
||||
centered
|
||||
destroyOnClose={true}
|
||||
bodyStyle={{ maxHeight: window.innerHeight * 0.96 - 108, overflowY: 'auto', paddingTop: 0 }}
|
||||
// footer={<Button onClick={() => setOpen(false)}>关闭</Button>}
|
||||
onOk={handleSubmit}
|
||||
onCancel={() => closeModal()}
|
||||
>
|
||||
<Form form={form} {...layout}>
|
||||
<Form.Item label="组织id" name="orgId" hidden>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item label="上级部门" name="upOrgId" >
|
||||
<TreeSelect
|
||||
style={{ width: '100%' }}
|
||||
// treeDefaultExpandedKeys={['OR1000000000']}
|
||||
placeholder="请选择部门,可搜索"
|
||||
treeData={org}
|
||||
showSearch={true}
|
||||
treeNodeFilterProp={'title'}
|
||||
allowClear
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="组织名称" name="orgName" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item label="组织编码" name="orgNum" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
//表格请求
|
||||
async function request(params: any) {
|
||||
console.log('org params:', params);
|
||||
const { data } = await fetchAllDepartment(params);
|
||||
console.log('org data:', data);
|
||||
// orgSet(data.children);
|
||||
orgSet(data);
|
||||
let result = {
|
||||
// data: data.children,
|
||||
data: data,
|
||||
success: true,
|
||||
total: data.length,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Spin spinning={spin}>
|
||||
<PageHeader title="组织管理" />
|
||||
<div style={{ maxHeight: innerHeight - 130, height: innerHeight - 130 }} className='xsy-entrust bgCWhite'>
|
||||
<ProTable
|
||||
actionRef={actionRef}//action触发后更新表格
|
||||
columns={columns}
|
||||
search={{ labelWidth: 'auto', span: 6 }}
|
||||
options={false}
|
||||
rowKey="orgId"
|
||||
size="small"
|
||||
// pagination={{
|
||||
// defaultPageSize: 10,
|
||||
// showSizeChanger: false,
|
||||
// onChange: (page, pageSize) => pageDataSet({ pageNo: page, pageSize: pageSize }),
|
||||
// onShowSizeChange: (current, size) => pageDataSet({ pageNo: current, pageSize: size }),
|
||||
// }}
|
||||
pagination={false}
|
||||
toolBarRender={() => [
|
||||
<Button onClick={() => { handleAdd() }} type="primary">
|
||||
新增
|
||||
</Button>,
|
||||
]
|
||||
}
|
||||
request={request}
|
||||
/>
|
||||
{addModal}
|
||||
</div>
|
||||
</Spin >
|
||||
);
|
||||
}
|
||||
|
||||
export default Index;
|
50
src/pages/System/Department/service.ts
Normal file
50
src/pages/System/Department/service.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export async function fetchAllDepartment(params: any) {
|
||||
return request(`/api/sys-manager-ebtp-project/v1/sysorg/queryAll`, {
|
||||
method: 'get',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
export async function addOrg(params: any) {
|
||||
return request('/api/sys-manager-ebtp-project/v1/sysorg/insert', {
|
||||
method: 'post',
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
export async function deleteOrg(id: any) {
|
||||
return request(`/api/sys-manager-ebtp-project/v1/sysorg/del/${id}`, {
|
||||
method: 'get',
|
||||
});
|
||||
}
|
||||
export async function updateOrg(params: any) {
|
||||
return request('/api/sys-manager-ebtp-project/v1/sysorg/update', {
|
||||
method: 'post',
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
export async function getDataById(id: any) {
|
||||
return request(`/api/sys-manager-ebtp-project/v1/sysorg/${id}`, {
|
||||
method: 'get',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export async function departmentList(options?: { [key: string]: any }): Promise<{ data: any }> {
|
||||
return request('/api/system/departmentList', {
|
||||
method: 'GET',
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
//根据部门id 查部门下所属部门及人员,立项用
|
||||
export async function getOrgUserIF(orgId: any) {
|
||||
return request(`/api/sysorg/user?orgId=${orgId}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
//查部门下所属部门及人员 全量
|
||||
export async function getAllOrgUserIF() {
|
||||
return request(` /api/sysorg/user/all`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
@ -67,8 +67,10 @@ const entrust: React.FC<{}> = () => {
|
||||
title: '确认删除该角色?',
|
||||
onOk: async () => {
|
||||
await deleteRole(id).then((r: any) => {
|
||||
if (r.code == 200) {
|
||||
if (r?.code == 200) {
|
||||
message.success('删除成功');
|
||||
} else {
|
||||
message.error('删除失败');
|
||||
}
|
||||
})
|
||||
.finally(() => actionRef.current?.reload());
|
||||
@ -127,7 +129,6 @@ const entrust: React.FC<{}> = () => {
|
||||
// const menus = await roleMenuTreeselect(record.roleId);
|
||||
// setMenuOptions(menus.data.menus || []);
|
||||
setMenuOptions(formatMenuOptions(menu) || []);
|
||||
console.log("role.data.menuIds",role.data.menuIds);
|
||||
setCheckedKeys(role.data.menuIds || []);
|
||||
form.setFieldsValue({
|
||||
...role.data,
|
||||
@ -151,14 +152,19 @@ const entrust: React.FC<{}> = () => {
|
||||
const values = await form.validateFields();
|
||||
if (values.roleId) {
|
||||
await updateRole(values).then((r: any) => {
|
||||
if (r.code == 200) {
|
||||
if (r?.code == 200) {
|
||||
message.success('修改成功');
|
||||
} else {
|
||||
message.error('修改失败');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await addRole(values).then((r: any) => {
|
||||
if (r.code == 200) {
|
||||
console.log("r?.code", r?.code)
|
||||
if (r?.code == 200) {
|
||||
message.success('新增成功');
|
||||
} else {
|
||||
message.error('新增失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -244,7 +250,7 @@ const entrust: React.FC<{}> = () => {
|
||||
})
|
||||
}
|
||||
toolBarRender={() => [
|
||||
<Button onClick={() => { console.log("点击新增"); handleAdd() }} type="primary">
|
||||
<Button onClick={() => { handleAdd() }} type="primary">
|
||||
新增
|
||||
</Button>,
|
||||
]
|
||||
|
Reference in New Issue
Block a user