Commit b8e5f5a6 authored by 张烨's avatar 张烨
parents 20da8a93 7166fe46
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Tree, Table, Space, message, Modal, Form, Input } from 'antd'; import { Tree, Table, Space, message, Modal, Form, Input } from 'antd';
import { import {
UserAddOutlined,
UsergroupAddOutlined, UsergroupAddOutlined,
FileAddTwoTone, FileAddTwoTone,
FolderAddTwoTone, FolderAddTwoTone,
...@@ -10,10 +9,44 @@ import { ...@@ -10,10 +9,44 @@ import {
} from '@ant-design/icons'; } from '@ant-design/icons';
import { PageContainer } from '@ant-design/pro-layout'; import { PageContainer } from '@ant-design/pro-layout';
// import classnames from 'classnames'; // import classnames from 'classnames';
import { get, post } from '../../services'; import { get } from '../../services';
import styles from './UserManage.less'; import styles from './UserManage.less';
const columns = [ const UserManage = () => {
const time = new Date();
const [tableLoading, setTableLoading] = useState(false);
const [treeData, setTreeData] = useState([]); // 用户机构树
const [tableData, setTableData] = useState([]); // 用户表
const [userVisible, setUserVisible] = useState(false);
const [deleteUserVisible, setDeleteUserVisible] = useState(false);
const [orgTitle, setOrgTitle] = useState('机构');
const [orgID, setOrgID] = useState();
const [userID, setUserID] = useState('机构');
const [addUserForm] = Form.useForm();
// 渲染机构目录树
const mapTree = org => {
const haveChildren = Array.isArray(org.children) && org.children.length > 0;
return {
title: (
<div className={styles.iconWraper1}>
{org.text}
<FileAddTwoTone
onClick={e => addUser(e, org.text, org.id)}
title="添加用户"
/>
<FolderAddTwoTone onClick={addSubOrg} title="添加下级机构" />
<EditTwoTone onClick={editOrg} title="编辑" />
<DeleteTwoTone onClick={deleteOrg} title="删除" />
</div>
),
key: org.id,
// icon: <CaretDownOutlined />,
// 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
children: haveChildren ? org.children.map(i => mapTree(i)) : [],
};
};
// 用户表列名
const columns = [
{ {
title: '登录名', title: '登录名',
dataIndex: 'loginName', dataIndex: 'loginName',
...@@ -48,46 +81,18 @@ const columns = [ ...@@ -48,46 +81,18 @@ const columns = [
<a>更改机构</a> <a>更改机构</a>
<a>编辑</a> <a>编辑</a>
<a>冻结</a> <a>冻结</a>
<a>删除</a> <a onClick={() => deleteUser(record)}>删除</a>
</Space> </Space>
), ),
}, },
]; ];
const UserManage = () => {
const [tableLoading, setTableLoading] = useState(false);
const [treeData, setTreeData] = useState([]); // 用户机构树
const [tableData, setTableData] = useState([]); // 用户表
const [userVisible, setUserVisible] = useState(false);
const [orgTitle, setOrgTitle] = useState('机构');
const [orgID, setOrgID] = useState('机构');
const mapTree = org => {
const haveChildren = Array.isArray(org.children) && org.children.length > 0;
return {
title: (
<div className={styles.iconWraper1}>
{org.text}
<FileAddTwoTone
onClick={e => addUser(e, org.text, org.id)}
title="添加用户"
/>
<FolderAddTwoTone onClick={addUser} title="添加下级机构" />
<EditTwoTone onClick={addUser} title="编辑" />
<DeleteTwoTone onClick={addUser} title="删除" />
</div>
),
key: org.id,
// icon: <CaretDownOutlined />,
// 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
children: haveChildren ? org.children.map(i => mapTree(i)) : [],
};
};
// 获取用户机构列表 // 获取用户机构列表
useEffect(() => { useEffect(() => {
setTableLoading(true); setTableLoading(true);
get(`/Cityinterface/rest/services/OMS.svc/U_GetOUTree`, { get(`/Cityinterface/rest/services/OMS.svc/U_GetOUTree`, {
_version: 9999, _version: 9999,
_dc: time.getTime(),
node: -1, node: -1,
}) })
.then(res => { .then(res => {
...@@ -108,12 +113,17 @@ const UserManage = () => { ...@@ -108,12 +113,17 @@ const UserManage = () => {
setTableLoading(true); setTableLoading(true);
get(`/Cityinterface/rest/services/OMS.svc/U_GetOneOUUserListNew`, { get(`/Cityinterface/rest/services/OMS.svc/U_GetOneOUUserListNew`, {
_version: 9999, _version: 9999,
_dc: time.getTime(),
OUID: props[0], OUID: props[0],
}) })
.then(res => { .then(res => {
setTableLoading(false); setTableLoading(false);
if (res.root.length > 0) { if (res.root.length > 0) {
setTableData(res.root); const table = res.root.map((item, index) => {
item.key = index;
return item;
});
setTableData(table);
} }
}) })
.catch(err => { .catch(err => {
...@@ -128,8 +138,87 @@ const UserManage = () => { ...@@ -128,8 +138,87 @@ const UserManage = () => {
setOrgTitle(`在${title}下添加用户`); setOrgTitle(`在${title}下添加用户`);
setOrgID(id); setOrgID(id);
}; };
const submitAddUser = props => { const addSubOrg = (e, title, id) => {
e.stopPropagation();
// setUserVisible(true);
// setOrgTitle(`在${title}下添加机构`);
setOrgID(id);
};
const editOrg = (e, title, id) => {
e.stopPropagation();
// setUserVisible(true);
// setOrgTitle(`在${title}下添加用户`);
setOrgID(id);
};
const deleteOrg = (e, title, id) => {
e.stopPropagation();
// setUserVisible(true);
// setOrgTitle(`在${title}下添加用户`);
setOrgID(id);
};
// 提交-添加用户
const submitAddUser = () => {
get(`/Cityinterface/rest/services/OMS.svc/U_AddUser`, {
_version: 9999,
_dc: time.getTime(),
OUID: orgID,
loginName: addUserForm.getFieldValue('loginName'),
password: addUserForm.getFieldValue('password'),
userName: addUserForm.getFieldValue('userName'),
phone: addUserForm.getFieldValue('phone') || '',
email: addUserForm.getFieldValue('email') || '',
ddid: addUserForm.getFieldValue('ddid') || '',
wxid: addUserForm.getFieldValue('wxid') || '',
})
.then(res => {
if (res.message === '') {
Modal.success({
content: '添加成功',
});
setUserVisible(false); setUserVisible(false);
// 重新获取用户表
onSelect([orgID]);
} else {
Modal.error({
title: '添加失败',
content: res.message,
});
}
})
.catch(err => {
message.error(err);
});
};
const deleteUser = record => {
setDeleteUserVisible(true);
setUserID(record.userID);
};
const submitDeleteUser = () => {
get(`/Cityinterface/rest/services/OMS.svc/U_DeleteUser`, {
_version: 9999,
_dc: time.getTime(),
userID,
})
.then(res => {
if (res.message === '') {
Modal.success({
content: '删除成功',
});
setDeleteUserVisible(false);
// 重新获取用户表
onSelect([orgID]);
} else {
Modal.error({
title: '删除失败',
content: res.message,
});
}
})
.catch(err => {
setTableLoading(false);
message.error(err);
});
}; };
return ( return (
...@@ -140,6 +229,7 @@ const UserManage = () => { ...@@ -140,6 +229,7 @@ const UserManage = () => {
height: 'calc(100vh - 194px)', height: 'calc(100vh - 194px)',
background: 'white', background: 'white',
float: 'left', float: 'left',
padding: '10px',
}} }}
> >
<div style={{ padding: '8px' }}> <div style={{ padding: '8px' }}>
...@@ -160,6 +250,7 @@ const UserManage = () => { ...@@ -160,6 +250,7 @@ const UserManage = () => {
height: 'calc(100vh - 194px)', height: 'calc(100vh - 194px)',
background: 'white', background: 'white',
float: 'right', float: 'right',
padding: '20px',
}} }}
> >
<Table <Table
...@@ -180,7 +271,7 @@ const UserManage = () => { ...@@ -180,7 +271,7 @@ const UserManage = () => {
<UserAddOutlined style={{ color: 'blue', width: '40px' }} /> <UserAddOutlined style={{ color: 'blue', width: '40px' }} />
</div> */} </div> */}
{/* <div style={{ width: '80%', float: 'right' }}> */} {/* <div style={{ width: '80%', float: 'right' }}> */}
<Form> <Form form={addUserForm}>
<Form.Item <Form.Item
name="loginName" name="loginName"
label="登录名称" label="登录名称"
...@@ -203,7 +294,15 @@ const UserManage = () => { ...@@ -203,7 +294,15 @@ const UserManage = () => {
> >
<Input /> <Input />
</Form.Item> </Form.Item>
<Form.Item name="userName" label="用 户 姓 名"> <Form.Item
name="userName"
label="用户名称"
rules={[
{
required: true,
},
]}
>
<Input /> <Input />
</Form.Item> </Form.Item>
<Form.Item name="phone" label="手 机 号 码"> <Form.Item name="phone" label="手 机 号 码">
...@@ -221,6 +320,16 @@ const UserManage = () => { ...@@ -221,6 +320,16 @@ const UserManage = () => {
</Form> </Form>
{/* </div> */} {/* </div> */}
</Modal> </Modal>
<Modal
title="删除用户"
visible={deleteUserVisible}
onOk={submitDeleteUser}
onCancel={() => setDeleteUserVisible(false)}
okText="确认"
cancelText="取消"
>
<p>即将关联删除 主站点 用户关系,是否确认删除?</p>
</Modal>
</PageContainer> </PageContainer>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment