Commit dd52e920 authored by Maofei94's avatar Maofei94

merge: merge

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