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

优化事件关联权限功能

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