Commit dd52e920 authored by Maofei94's avatar Maofei94

merge: merge

parents 317391c8 96d89c11
......@@ -26,7 +26,9 @@ const ListCardItem = props => {
useEffect(() => {
if (isGroup) {
const keys = item.children
.map(child => checkChildrenByCondition(child, c => getId(c), 'map'))
.map(child =>
checkChildrenByCondition(child, c => getId(c), true, 'map'),
)
.flat(Infinity);
setChildrenKeys(keys);
} else {
......
......@@ -10,14 +10,21 @@ export const getId = item =>
item.userID || item.roleID || item.stationID || item.id;
export const checkIsGroup = node =>
['widgetGroup'].includes(node?.type || node) && node.children?.length > 0;
export const checkChildrenByCondition = (item, fn, tag = 'every') => {
// 递归遍历节点的方法
export const checkChildrenByCondition = (
item,
fn,
withGroup = true,
method = 'every',
) => {
if (!checkIsGroup(item)) {
return fn(item);
}
return [
getId(item),
...item.children[tag](t => checkChildrenByCondition(t, fn, tag)),
];
const childrenResults = item.children[method](t =>
checkChildrenByCondition(t, fn, withGroup, method),
);
return withGroup ? [fn(item), ...childrenResults] : [...childrenResults];
};
const ListCard = props => {
......
......@@ -90,10 +90,10 @@ class PicturesWall extends React.Component<PicturesWallType> {
uid: uuid(8, 16),
name: '熊猫运维中台系统',
status: 'done',
url: this.getImageUrl(this.state.curSelectedImg),
url: this.state.curSelectedImg,
},
];
this.props.onChange && this.props.onChange(fileList);
this.props.onChange && this.props.onChange(this.props.maxLen === 1 ? fileList[0].url : fileList.map(f => f.url));
this.setState({ fileList, wallModalVisible: false });
};
......
......@@ -39,7 +39,7 @@ const Login = props => {
msg,
} = result;
if (pass === true) {
localStorage.setItem('token', token?.access_token);
localStorage.setItem('token', token?.access_token || '');
setUserMode(userMode);
if (userMode === USER_MODE.ADMIN || userMode === USER_MODE.SUPER) {
const authority = [AUTHORITY.LOGIN, AUTHORITY[userMode]];
......
......@@ -51,6 +51,7 @@ import {
deleteOrg as postDeleteOrg,
updateUserPassword,
setUserRelation,
setUserRelations,
multiDeleteUsers,
} from '@/services/userCenter/userManage/api';
import classnames from 'classnames';
......@@ -97,6 +98,7 @@ const UserManage = () => {
const [orgIDs, setOrgIDs] = useState(''); // 批量操作的机构
const [multiDelete, setMultiDelete] = useState(false); // 是否批量删除用户
const [multiChangeOrgs, setMultiChangeOrgs] = useState(false); // 是否批量更改机构
const [multiRelateRoles, setMultiRelateRoles] = useState(false); // 是否批量更改机构
const [rolelist, setRolelist] = useState([]); // 角色列表
const [stationlist, setStationlist] = useState([]); // 站点列表
......@@ -279,7 +281,7 @@ const UserManage = () => {
onChange: (selectedRowKeys, selectedRows) => {
console.log(selectedRowKeys.toString());
console.log(selectedRows.map(item => item.OUID).toString());
setUserIDs(selectedRowKeys.toString());
setUserIDs(selectedRowKeys.toString()); // 数组转字符串,逗号连接
setOrgIDs(selectedRows.map(item => item.OUID).toString());
// 选中行数大于1时设置批量操作可行
if (selectedRows.length > 1) {
......@@ -451,7 +453,9 @@ const UserManage = () => {
/** ***用户批量操作****** */
// 用户关联
const relateRoles = () => {
getEmptyRoleList();
setRoleVisible(true);
setMultiRelateRoles(true);
};
// 更改机构
const changeOrgs = () => {
......@@ -667,6 +671,29 @@ const UserManage = () => {
message.error(err);
});
};
// 获取全部未勾选的角色列表与站点列表
const getEmptyRoleList = () => {
setLoading(true);
getUserRelationList('')
.then(res => {
setLoading(false);
if (res.roleList && res.roleList.length > 0) {
const { roleList, stationList } = res;
setRolelist(roleList);
setStationlist(stationList);
} else {
notification.error({
message: '提交失败',
description: res.message,
});
}
})
.catch(err => {
setLoading(false);
setTableLoading(false);
message.error(err);
});
};
// 提交-关联角色
const submitRole = () => {
setUserRelation(
......@@ -698,6 +725,38 @@ const UserManage = () => {
message.error(err);
});
};
// 提交-批量关联角色
const submitRoles = () => {
setUserRelations(
userIDs,
Object.keys(roleValueList)
.map(k => roleValueList[k])
.flat()
.toString(),
Object.keys(stationValueList)
.map(k => stationValueList[k])
.flat()
.toString(),
)
.then(res => {
if (res.code === 0) {
setRoleVisible(false);
// 跳转到组织
onSelect([currentSelectOrg]);
notification.success({
message: '提交成功',
});
} else {
notification.error({
message: '提交失败',
description: '角色不能为空',
});
}
})
.catch(err => {
message.error(err);
});
};
// 提交-更改机构
const submitChangeOrg = () =>
addToOrg(currentUser.userID, currentUser.OUID, newOrgID)
......@@ -727,6 +786,10 @@ const UserManage = () => {
if (res.code === 0) {
setChangeOrgVisible(false);
// 跳转到新组织机构下的用户表
const temp = orgIDs.split(',');
// 批量更改机构成功后设置老的orgIDs为全部是newOrgID的数组,并转字符串
setOrgIDs(temp.map(() => newOrgID).toString());
// console.log(temp.map(() => newOrgID).toString());
onSelect([newOrgID]);
notification.success({
message: '提交成功',
......@@ -1144,8 +1207,11 @@ const UserManage = () => {
<Modal
title="用户关联"
visible={roleVisible}
onOk={submitRole}
onCancel={() => setRoleVisible(false)}
onOk={multiRelateRoles ? submitRoles : submitRole}
onCancel={() => {
setRoleVisible(false);
setMultiRelateRoles(false);
}}
okText="确认"
cancelText="取消"
width="960px"
......@@ -1272,7 +1338,7 @@ const UserManage = () => {
},
]}
>
<Input placeholder="请输入手机号码" />
<Input placeholder="请输入手机号码" autoComplete="off" />
</Form.Item>
<Form.Item
name="email"
......
......@@ -136,6 +136,7 @@ const SiteManage = () => {
checkChildrenByCondition(
l,
it => (it.isChecked ? [getId(it)] : []),
true,
'map',
).flat(Infinity),
)
......
......@@ -102,13 +102,12 @@ const SiteManage = () => {
setValueList(
finalList
.map(l =>
l.children.map(item =>
checkChildrenByCondition(
item,
l,
it => (it.isChecked ? [getId(it)] : []),
true,
'map',
).flat(Infinity),
),
)
.flat(Infinity)
.filter(Boolean),
......
......@@ -176,3 +176,9 @@ export const setUserRelation = (userID, roleList = [], stationList) =>
},
},
);
export const setUserRelations = (userIDs, roleList, stationList) =>
get(`${PUBLISH_SERVICE}/UserCenter/SetUserRoleMap`, {
userIds: userIDs,
roleIds: roleList || '',
stationList: stationList || '',
});
......@@ -24,11 +24,11 @@ const getMatchedConfig = requestConfig => {
return null;
}
};
axios.defaults.withCredentials = false
axios.defaults.withCredentials = true
axios.interceptors.request.use( function (request){
const token = localStorage.getItem('token')
if(token){
request.headers.token = token
request.headers.Authorization = 'Bearer ' + token
}
return request
}, function (error) {
......
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