Commit 97edfa8c authored by 张烨's avatar 张烨

refactor: 整理userManager

parent aa8f5119
......@@ -41,6 +41,10 @@ import {
getUserByKey,
getUserRelationList,
getUserTree,
addUser as postAddUser,
deleteUser as postDeleteUser,
setUserState as postSetUserState,
editUser as postEditUser,
updateUserPassword,
} from '@/services/userCenter/userManage/api';
......@@ -55,7 +59,7 @@ const UserManage = () => {
const [treeData2, setTreeData2] = useState([]);
const [tableData, setTableData] = useState([]); // 用户表
const [searchData, setSearchData] = useState([]);
const [currentSelect, setCurrentSelect] = useState([]);
const [currentSelectOrg, setCurrentSelectOrg] = useState([]);
const [userVisible, setUserVisible] = useState(false);
const [searchUserVisible, setSearchUserVisible] = useState(false);
......@@ -66,7 +70,6 @@ const UserManage = () => {
const [changeOrgVisible, setChangeOrgVisible] = useState(false);
const [passwordVisible, setPasswordVisible] = useState(false);
const [editUserVisible, setEditUserVisible] = useState(false);
const [userState, setUserState] = useState(0);
const [treeState, setTreeState] = useState(true);
const [freezeUserVisible, setFreezeUserVisible] = useState(false);
const [deleteUserVisible, setDeleteUserVisible] = useState(false);
......@@ -74,7 +77,7 @@ const UserManage = () => {
const [orgTitle, setOrgTitle] = useState('机构');
const [orgID, setOrgID] = useState();
const [newOrgID, setNewOrgID] = useState();
const [userID, setUserID] = useState();
const [currentUser, setCurrentUser] = useState({});
const [rolelist, setRolelist] = useState([]);
const [stationlist, setStationlist] = useState([]);
......@@ -101,11 +104,6 @@ const UserManage = () => {
setStationValueList(result);
}, []);
let freezeText = '即将冻结该用户,是否确认冻结?';
if (userState) {
freezeText = '即将激活该用户,是否确认激活?';
}
// 用户表列名
const columns = [
{
......@@ -285,12 +283,12 @@ const UserManage = () => {
const onSelect = props => {
setTableLoading(true);
if (!props[0]) {
setCurrentSelect(currentSelect);
setCurrentSelectOrg(currentSelectOrg);
} else {
setCurrentSelect(props[0]);
setCurrentSelectOrg(props[0]);
}
setOrgID(props[0] || currentSelect);
getOneOUUserListNew(props[0] || currentSelect)
setOrgID(props[0] || currentSelectOrg);
getOneOUUserListNew(props[0] || currentSelectOrg)
.then(res => {
if (res.success) {
setTableLoading(false);
......@@ -342,29 +340,29 @@ const UserManage = () => {
setTreeState(true);
};
// 在userID变化后获取
// 在currentUser变化后获取
useEffect(() => {
if (userID) {
if (currentUser) {
getRoleList();
}
}, [userID]);
}, [currentUser]);
// 右侧表格相关操作
const relateRole = record => {
setRoleVisible(true);
setUserID(record.userID);
setCurrentUser(record);
};
const changeOrg = record => {
setChangeOrgVisible(true);
setTreeData2(treeData1);
setUserID(record.userID);
setCurrentUser(record);
};
const changePassword = record => {
setPasswordVisible(true);
passwordForm.setFieldsValue({
oldpassword: record.password,
});
setUserID(record.userID);
setCurrentUser(record);
};
const editUser = record => {
// console.log(record);
......@@ -375,15 +373,15 @@ const UserManage = () => {
phone: record.phone || '',
email: record.email || '',
});
setUserID(record.userID);
setCurrentUser(record);
};
const freezeUser = record => {
setFreezeUserVisible(true);
setUserID(record.userID);
setCurrentUser(record);
};
const deleteUser = record => {
setDeleteUserVisible(true);
setUserID(record.userID);
setCurrentUser(record);
};
// 查找用户
const submitSearchUser = () => {
......@@ -406,7 +404,7 @@ const UserManage = () => {
};
// 提交-添加用户
const submitAddUser = () => {
addUser({
postAddUser({
OUID: orgID,
loginName: addUserForm.getFieldValue('loginName'),
userName: addUserForm.getFieldValue('userName'),
......@@ -514,7 +512,7 @@ const UserManage = () => {
const getRoleList = () => {
setLoading(true);
getUserRelationList(userID)
getUserRelationList(currentUser.userID)
.then(res => {
setLoading(false);
if (res.success) {
......@@ -535,7 +533,7 @@ const UserManage = () => {
});
};
const submitRole = () => {
addToOrg(userID, orgID, newOrgID)
addToOrg(currentUser.userID, orgID, newOrgID)
.then(res => {
if (res.success) {
setChangeOrgVisible(false);
......@@ -556,7 +554,7 @@ const UserManage = () => {
});
};
const submitChangeOrg = () =>
addToOrg(userID, orgID, newOrgID)
addToOrg(currentUser.userID, orgID, newOrgID)
.then(res => {
if (res.success) {
setChangeOrgVisible(false);
......@@ -577,7 +575,7 @@ const UserManage = () => {
});
const submitChangePassword = () =>
updateUserPassword(
userID,
currentUser.userID,
passwordForm.getFieldValue('password'),
passwordForm.getFieldValue('newPassword'),
passwordForm.getFieldValue('passwordConfirm'),
......@@ -601,8 +599,8 @@ const UserManage = () => {
message.error(err);
});
const submitEditUser = () =>
editUser(
userID,
postEditUser(
currentUser.userID,
editUserForm.getFieldValue('loginName'),
editUserForm.getFieldValue('userName'),
editUserForm.getFieldValue('phone') || '',
......@@ -628,7 +626,7 @@ const UserManage = () => {
message.error(err);
});
const submitFreezeUser = () => {
setUserState(userID, +!userState)
postSetUserState(currentUser.userID, +!currentUser.state)
.then(res => {
if (res.success) {
setFreezeUserVisible(false);
......@@ -637,7 +635,6 @@ const UserManage = () => {
notification.success({
message: '提交成功',
});
setUserState(+!userState);
} else {
notification.error({
message: '提交失败',
......@@ -651,7 +648,7 @@ const UserManage = () => {
});
};
const submitDeleteUser = () => {
deleteUser(userID)
postDeleteUser(currentUser.userID)
.then(res => {
if (res.success) {
setDeleteUserVisible(false);
......@@ -702,7 +699,7 @@ const UserManage = () => {
showLine="true"
showIcon="true"
defaultExpandAll="true"
selectedKeys={[currentSelect]}
selectedKeys={[currentSelectOrg]}
loading={treeLoading}
onSelect={onSelect}
treeData={treeData.map(t => mapTree(t))}
......@@ -919,22 +916,23 @@ const UserManage = () => {
cancelText="取消"
width="330px"
>
{treeData2.length > 0 && (
<span>请选择要更改的目标机构:</span>
{changeOrgVisible && treeData2.length > 0 && (
<Tree
showLine="true"
showIcon="true"
defaultExpandAll="true"
// selectedKeys={[currentSelect]}
defaultSelectedKeys={[currentSelectOrg]}
onSelect={props => {
setNewOrgID(props[0]);
}}
treeData={mapTree1(treeData2)}
treeData={treeData2.map(t => mapTree1(t))}
/>
)}
</Modal>
{/* 修改密码 */}
<Modal
title="编辑用户"
title="修改密码"
visible={passwordVisible}
onOk={submitChangePassword}
onCancel={() => setPasswordVisible(false)}
......@@ -1017,7 +1015,12 @@ const UserManage = () => {
okText="确认"
cancelText="取消"
>
<p>{freezeText}</p>
<p>
即将{+currentUser.state ? '激活' : '冻结'}用户{' '}
<span className={styles.redText}>{currentUser.userName}</span>
,是否确认
{+currentUser.state ? '激活' : '冻结'}
</p>
</Modal>
<Modal
title="确认删除用户"
......@@ -1027,7 +1030,11 @@ const UserManage = () => {
okText="确认"
cancelText="取消"
>
<p>即将关联删除 主站点 用户关系,是否确认删除?</p>
<p>
将删除用户
<span className={styles.redText}>{currentUser.userName}</span>,
是否确认删除?
</p>
</Modal>
</div>
</PageContainer>
......
.redText{
color: red;
cursor: pointer;
}
.userManageContainer{
.ant-tree-treenode{
width: 100% !important;
......
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