Commit c6e87c79 authored by 陈前坚's avatar 陈前坚

perf: 用户管理更改机构

parent 86f2ec75
...@@ -30,19 +30,24 @@ const UserManage = () => { ...@@ -30,19 +30,24 @@ const UserManage = () => {
const [treeLoading, setTreeLoading] = useState(false); const [treeLoading, setTreeLoading] = useState(false);
const [tableLoading, setTableLoading] = useState(false); const [tableLoading, setTableLoading] = useState(false);
const [treeData, setTreeData] = useState([]); // 用户机构树 const [treeData, setTreeData] = useState([]); // 用户机构树
const [treeData1, setTreeData1] = useState([]);
const [treeData2, setTreeData2] = useState([]);
const [tableData, setTableData] = useState([]); // 用户表 const [tableData, setTableData] = useState([]); // 用户表
const [currentSelect, setCurrentSelect] = useState([]); const [currentSelect, setCurrentSelect] = useState([]);
const [userVisible, setUserVisible] = useState(false); const [userVisible, setUserVisible] = useState(false);
const [addOrgVisible, setAddOrgVisible] = useState(false); const [addOrgVisible, setAddOrgVisible] = useState(false);
const [editOrgVisible, setEditOrgVisible] = useState(false); const [editOrgVisible, setEditOrgVisible] = useState(false);
const [deleteOrgVisible, setDeleteOrgVisible] = useState(false); const [deleteOrgVisible, setDeleteOrgVisible] = useState(false);
const [changeOrgVisible, setChangeOrgVisible] = useState(false);
const [passwordVisible, setPasswordVisible] = useState(false); const [passwordVisible, setPasswordVisible] = useState(false);
const [editUserVisible, setEditUserVisible] = useState(false); const [editUserVisible, setEditUserVisible] = useState(false);
const [userState, setUserState] = useState(0); const [userState, setUserState] = useState(0);
const [treeState, setTreeState] = useState(true);
const [freezeUserVisible, setFreezeUserVisible] = useState(false); const [freezeUserVisible, setFreezeUserVisible] = useState(false);
const [deleteUserVisible, setDeleteUserVisible] = useState(false); const [deleteUserVisible, setDeleteUserVisible] = useState(false);
const [orgTitle, setOrgTitle] = useState('机构'); const [orgTitle, setOrgTitle] = useState('机构');
const [orgID, setOrgID] = useState(); const [orgID, setOrgID] = useState();
const [newOrgID, setNewOrgID] = useState();
const [userID, setUserID] = useState(); const [userID, setUserID] = useState();
const [addUserForm] = Form.useForm(); const [addUserForm] = Form.useForm();
const [addOrgForm] = Form.useForm(); const [addOrgForm] = Form.useForm();
...@@ -53,7 +58,7 @@ const UserManage = () => { ...@@ -53,7 +58,7 @@ const UserManage = () => {
if (userState) { if (userState) {
freezeText = '即将激活该用户,是否确认激活?'; freezeText = '即将激活该用户,是否确认激活?';
} }
// 渲染机构目录 // 渲染机构树
const mapTree = org => { const mapTree = org => {
const haveChildren = Array.isArray(org.children) && org.children.length > 0; const haveChildren = Array.isArray(org.children) && org.children.length > 0;
return { return {
...@@ -82,6 +87,16 @@ const UserManage = () => { ...@@ -82,6 +87,16 @@ const UserManage = () => {
children: haveChildren ? org.children.map(i => mapTree(i)) : [], children: haveChildren ? org.children.map(i => mapTree(i)) : [],
}; };
}; };
const mapTree1 = org => {
const haveChildren = Array.isArray(org.children) && org.children.length > 0;
return {
title: `${org.text}`,
key: org.id,
// icon: <CaretDownOutlined />,
// 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
children: haveChildren ? org.children.map(i => mapTree1(i)) : [],
};
};
// 用户表列名 // 用户表列名
const columns = [ const columns = [
{ {
...@@ -170,14 +185,14 @@ const UserManage = () => { ...@@ -170,14 +185,14 @@ const UserManage = () => {
}, },
]; ];
// 获取用户机构列表 // 获取用户机构
useEffect(() => { useEffect(() => {
getUserTree(-1, -1); getUserTree(-1, -1);
}, []); }, []);
const getUserTree = (selectOU, node) => { const getUserTree = (selectOU, node) => {
setTreeLoading(true); setTreeLoading(true);
get(`/Cityinterface/rest/services/OMS.svc/U_GetOUTree`, { return get(`/Cityinterface/rest/services/OMS.svc/U_GetOUTree`, {
_version: 9999, _version: 9999,
_dc: time.getTime(), _dc: time.getTime(),
selectOU, selectOU,
...@@ -186,9 +201,14 @@ const UserManage = () => { ...@@ -186,9 +201,14 @@ const UserManage = () => {
.then(res => { .then(res => {
setTreeLoading(false); setTreeLoading(false);
if (res.length > 0) { if (res.length > 0) {
const orgTree = res.map(org => mapTree(org)); setTreeData1(res);
setTreeData(orgTree); const newTree = res.map(org => mapTree(org));
setTreeData(newTree);
// 第一次加载,默认选择第一个组织
if (treeState) {
onSelect([res[0].id]); onSelect([res[0].id]);
setTreeState(false);
}
} }
}) })
.catch(err => { .catch(err => {
...@@ -205,12 +225,14 @@ const UserManage = () => { ...@@ -205,12 +225,14 @@ const UserManage = () => {
} else { } else {
setCurrentSelect(props[0]); setCurrentSelect(props[0]);
} }
setOrgID(props[0] || currentSelect);
get(`/Cityinterface/rest/services/OMS.svc/U_GetOneOUUserListNew`, { get(`/Cityinterface/rest/services/OMS.svc/U_GetOneOUUserListNew`, {
_version: 9999, _version: 9999,
_dc: time.getTime(), _dc: time.getTime(),
OUID: props[0] || currentSelect, OUID: props[0] || currentSelect,
}) })
.then(res => { .then(res => {
if (res.success) {
setTableLoading(false); setTableLoading(false);
const table = res.root.map((item, index) => { const table = res.root.map((item, index) => {
item.key = index; item.key = index;
...@@ -219,6 +241,7 @@ const UserManage = () => { ...@@ -219,6 +241,7 @@ const UserManage = () => {
return item; return item;
}); });
setTableData(table); setTableData(table);
}
}) })
.catch(err => { .catch(err => {
setTableLoading(false); setTableLoading(false);
...@@ -252,6 +275,8 @@ const UserManage = () => { ...@@ -252,6 +275,8 @@ const UserManage = () => {
setDeleteOrgVisible(true); setDeleteOrgVisible(true);
setOrgTitle(`在${title}下添加用户`); setOrgTitle(`在${title}下添加用户`);
setOrgID(id); setOrgID(id);
// 删除后默认选择第一个组织
setTreeState(true);
}; };
// 右侧表格相关操作 // 右侧表格相关操作
...@@ -260,7 +285,9 @@ const UserManage = () => { ...@@ -260,7 +285,9 @@ const UserManage = () => {
setUserID(record.userID); setUserID(record.userID);
}; };
const changeOrg = record => { const changeOrg = record => {
// setDeleteUserVisible(true); setChangeOrgVisible(true);
const newTree = treeData1.map(org => mapTree1(org));
setTreeData2(newTree);
setUserID(record.userID); setUserID(record.userID);
}; };
const changePassword = record => { const changePassword = record => {
...@@ -337,8 +364,10 @@ const UserManage = () => { ...@@ -337,8 +364,10 @@ const UserManage = () => {
message: '提交成功', message: '提交成功',
}); });
// 重新获取机构树与用户表 // 重新获取机构树与用户表
getUserTree(-1, -1); getUserTree(-1, -1).then(() => {
// onSelect([res.OUID]); // 只能是字符串,数字没有选择效果
onSelect([`${res.OUID}`]);
});
} else { } else {
notification.error({ notification.error({
message: '提交失败', message: '提交失败',
...@@ -370,9 +399,9 @@ const UserManage = () => { ...@@ -370,9 +399,9 @@ const UserManage = () => {
notification.success({ notification.success({
message: '提交成功', message: '提交成功',
}); });
// 重新获取机构树与用户表
getUserTree(-1, -1); getUserTree(-1, -1);
// 重新获取用户表 onSelect([orgID]);
// onSelect([orgID]);
} else { } else {
notification.error({ notification.error({
message: '提交失败', message: '提交失败',
...@@ -396,9 +425,8 @@ const UserManage = () => { ...@@ -396,9 +425,8 @@ const UserManage = () => {
notification.success({ notification.success({
message: '提交成功', message: '提交成功',
}); });
// 重新获取用户表 // 重新获取机构树与用户表
getUserTree(-1, -1); getUserTree(-1, -1);
// onSelect([orgID]);
} else { } else {
notification.error({ notification.error({
message: '提交失败', message: '提交失败',
...@@ -412,6 +440,33 @@ const UserManage = () => { ...@@ -412,6 +440,33 @@ const UserManage = () => {
}); });
}; };
const submitChangeOrg = () => {
get(`/Cityinterface/rest/services/OMS.svc/U_JumpToAnotherOU`, {
_version: 9999,
_dc: time.getTime(),
userID,
oldOUID: orgID,
newOUID: newOrgID,
})
.then(res => {
if (res.success) {
setChangeOrgVisible(false);
// 跳转到新组织机构下的用户表
onSelect([newOrgID]);
notification.success({
message: '提交成功',
});
} else {
notification.error({
message: '提交失败',
description: res.message,
});
}
})
.catch(err => {
message.error(err);
});
};
const submitChangePassword = () => { const submitChangePassword = () => {
get(`/Cityinterface/rest/services/OMS.svc/U_UpdatePassword`, { get(`/Cityinterface/rest/services/OMS.svc/U_UpdatePassword`, {
_version: 9999, _version: 9999,
...@@ -541,6 +596,7 @@ const UserManage = () => { ...@@ -541,6 +596,7 @@ const UserManage = () => {
<Tree <Tree
showLine="true" showLine="true"
showIcon="true" showIcon="true"
defaultExpandAll="true"
selectedKeys={[currentSelect]} selectedKeys={[currentSelect]}
loading={treeLoading} loading={treeLoading}
onSelect={onSelect} onSelect={onSelect}
...@@ -667,6 +723,26 @@ const UserManage = () => { ...@@ -667,6 +723,26 @@ const UserManage = () => {
> >
<p>即将删除该机构,是否确认删除?</p> <p>即将删除该机构,是否确认删除?</p>
</Modal> </Modal>
<Modal
title="更改机构"
visible={changeOrgVisible}
onOk={submitChangeOrg}
onCancel={() => setChangeOrgVisible(false)}
okText="确认"
cancelText="取消"
width="330px"
>
<Tree
showLine="true"
showIcon="true"
defaultExpandAll="true"
// selectedKeys={[currentSelect]}
onSelect={props => {
setNewOrgID(props[0]);
}}
treeData={treeData2}
/>
</Modal>
{/* 修改密码 */} {/* 修改密码 */}
<Modal <Modal
title="编辑用户" title="编辑用户"
......
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