Commit 3ca83472 authored by 皮倩雯's avatar 皮倩雯

优化事件关联权限功能

parent e3e71d8b
import React, { useEffect } from 'react'; import React, { useEffect, useState } from 'react';
import { Modal, Form, Input, notification, message } from 'antd'; import { Modal, Form, Input, notification, message, TreeSelect } from 'antd';
import { addUser } from '@/services/userManage/api'; import { addUser, GetUserRelationListNew } from '@/services/userManage/api';
import { ok } from '../../../assets/images/icons/ok.svg'; import { ok } from '../../../assets/images/icons/ok.svg';
const { SHOW_CHILD } = TreeSelect;
const AddUserModal = props => { const AddUserModal = props => {
const { visible, orgID, onCancel, updateTrees1, orgTitle1, onSelect } = props; const { visible, orgID, onCancel, updateTrees1, orgTitle1, onSelect } = props;
...@@ -12,11 +13,56 @@ const AddUserModal = props => { ...@@ -12,11 +13,56 @@ const AddUserModal = props => {
const isEmail = new RegExp( const isEmail = new RegExp(
/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\.[a-z]{2,}$/, /^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\.[a-z]{2,}$/,
); // 邮箱 ); // 邮箱
const [value, setValue] = useState(['0-1-1']);
const [treeData, setTreeData] = useState([]);
const onChange = newValue => {
console.log('onChange ', value);
setValue(newValue);
};
useEffect(() => { useEffect(() => {
addUserForm.resetFields(); if (visible) {
console.log(orgID); addUserForm.resetFields();
}, [orgID]); getEmptyRoleList();
}
}, [orgID, visible]);
// 获取全部未勾选站点列表
const getEmptyRoleList = () => {
GetUserRelationListNew({ userID: 0 })
.then(res => {
if (res.code === 0) {
let aa = {};
console.log(res.data.stationList);
res.data.stationList.map(i => {
aa.title = i.visibleTitle;
aa.value = i.visibleValue;
aa.key = i.visibleValue;
aa.children = [];
i.stationList.map(j => {
let bb = {};
bb.title = j.stationName;
bb.value = j.stationID;
bb.key = j.stationID;
aa.children.push(bb);
});
});
console.log(aa);
let data = [];
data.push(aa);
setTreeData(data);
} else {
notification.error({
message: '获取失败',
description: res.msg,
});
}
})
.catch(err => {
message.error(err);
});
};
// 提交-添加用户 // 提交-添加用户
const submitAddUser = () => { const submitAddUser = () => {
...@@ -25,6 +71,8 @@ const AddUserModal = props => { ...@@ -25,6 +71,8 @@ const AddUserModal = props => {
const password = addUserForm.getFieldValue('password') || ''; const password = addUserForm.getFieldValue('password') || '';
const phone = addUserForm.getFieldValue('phone') || ''; const phone = addUserForm.getFieldValue('phone') || '';
const email = addUserForm.getFieldValue('email') || ''; const email = addUserForm.getFieldValue('email') || '';
const stationList = addUserForm.getFieldValue('stationList').toString() || '';
console.log(stationList);
// 正则验证 // 正则验证
if (loginName === '') { if (loginName === '') {
notification.error({ notification.error({
...@@ -70,7 +118,7 @@ const AddUserModal = props => { ...@@ -70,7 +118,7 @@ const AddUserModal = props => {
(phone === '' || isPhone.test(phone)) && (phone === '' || isPhone.test(phone)) &&
(email === '' || isEmail.test(email)) (email === '' || isEmail.test(email))
) { ) {
addUser({ OUID: orgID.id, loginName, userName, password, phone, email }) addUser({ OUID: orgID.id, loginName, userName, password, phone, email, stationList })
.then(res => { .then(res => {
if (res.code === 0) { if (res.code === 0) {
addUserForm.resetFields(); addUserForm.resetFields();
...@@ -81,7 +129,6 @@ const AddUserModal = props => { ...@@ -81,7 +129,6 @@ const AddUserModal = props => {
}); });
updateTrees1(orgID.id); updateTrees1(orgID.id);
onSelect([`${orgID.id}`]); onSelect([`${orgID.id}`]);
// 重新获取用户表 // 重新获取用户表
} else { } else {
notification.error({ notification.error({
...@@ -102,6 +149,18 @@ const AddUserModal = props => { ...@@ -102,6 +149,18 @@ const AddUserModal = props => {
</span> </span>
); );
const tProps = {
treeData,
value,
onChange,
treeCheckable: true,
showCheckedStrategy: SHOW_CHILD,
placeholder: '请选择关联站点',
style: {
width: '100%',
},
};
return ( return (
<Modal <Modal
title={title} title={title}
...@@ -186,6 +245,9 @@ const AddUserModal = props => { ...@@ -186,6 +245,9 @@ const AddUserModal = props => {
> >
<Input placeholder="请输入电子邮箱" autoComplete="off" /> <Input placeholder="请输入电子邮箱" autoComplete="off" />
</Form.Item> </Form.Item>
{/* <Form.Item name="stationList" label="关联站点" rules={[{ required: true }]}>
<TreeSelect {...tProps} showSearch treeDefaultExpandAll />
</Form.Item> */}
</Form> </Form>
</Modal> </Modal>
); );
......
...@@ -24,6 +24,7 @@ const RelateRoleModal = props => { ...@@ -24,6 +24,7 @@ const RelateRoleModal = props => {
const [roleValueList, setRoleValueList] = useState({}); // 勾选的角色列表 const [roleValueList, setRoleValueList] = useState({}); // 勾选的角色列表
const [stationValueList, setStationValueList] = useState({}); // 勾选的站点列表 const [stationValueList, setStationValueList] = useState({}); // 勾选的站点列表
const authority = localStorage.getItem('panda-oms-authority'); const authority = localStorage.getItem('panda-oms-authority');
const [activeKey, setActiveKey] = useState('1');
const getRoleValueCallback = useCallback((value, index) => { const getRoleValueCallback = useCallback((value, index) => {
console.log(value); console.log(value);
...@@ -41,6 +42,9 @@ const RelateRoleModal = props => { ...@@ -41,6 +42,9 @@ const RelateRoleModal = props => {
}, []); }, []);
useEffect(() => { useEffect(() => {
if (!visible) {
setActiveKey('1');
}
console.log(currentUser); console.log(currentUser);
console.log(multiRoleList); console.log(multiRoleList);
console.log(multistationList); console.log(multistationList);
...@@ -127,13 +131,17 @@ const RelateRoleModal = props => { ...@@ -127,13 +131,17 @@ const RelateRoleModal = props => {
const title1 = ( const title1 = (
<span> <span>
<span> <span>
关联角色 关联权限
<span style={{ fontWeight: 'bold', color: 'rgb(24, 144, 255)' }}> <span style={{ fontWeight: 'bold', color: 'rgb(24, 144, 255)' }}>
{currentUser.userName} {currentUser.userName}
</span> </span>
</span> </span>
</span> </span>
); );
const onChange = e => {
console.log(e);
setActiveKey(e);
};
if (mult == 'Yes') { if (mult == 'Yes') {
return ( return (
<Modal <Modal
...@@ -148,7 +156,7 @@ const RelateRoleModal = props => { ...@@ -148,7 +156,7 @@ const RelateRoleModal = props => {
width="500px" width="500px"
> >
<Spin spinning={loading} tip="loading"> <Spin spinning={loading} tip="loading">
<Tabs defaultActiveKey="1" style={{ marginTop: '-16px' }}> <Tabs activeKey={activeKey} onChange={onChange} style={{ marginTop: '-16px' }}>
<TabPane tab="角色" key="1"> <TabPane tab="角色" key="1">
{visible && {visible &&
rolelist.map((role, index) => ( rolelist.map((role, index) => (
...@@ -195,7 +203,7 @@ const RelateRoleModal = props => { ...@@ -195,7 +203,7 @@ const RelateRoleModal = props => {
width="500px" width="500px"
> >
<Spin spinning={loading} tip="loading"> <Spin spinning={loading} tip="loading">
<Tabs defaultActiveKey="1" style={{ marginTop: '-16px' }}> <Tabs activeKey={activeKey} onChange={onChange} style={{ marginTop: '-16px' }}>
<TabPane tab="角色" key="1"> <TabPane tab="角色" key="1">
{visible && {visible &&
rolelist.map((role, index) => ( rolelist.map((role, index) => (
......
...@@ -251,7 +251,7 @@ const UserManage = () => { ...@@ -251,7 +251,7 @@ const UserManage = () => {
align: 'center', align: 'center',
render: record => ( render: record => (
<Space size="middle"> <Space size="middle">
<Tooltip title="关联角色"> <Tooltip title="关联权限">
<IdcardOutlined <IdcardOutlined
onClick={() => relateRole(record)} onClick={() => relateRole(record)}
style={{ fontSize: '20px', color: '#1890FF' }} style={{ fontSize: '20px', color: '#1890FF' }}
......
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