1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import React, { useState, useEffect } from 'react';
import { Form, Input, notification, Select, Radio, Tooltip, Switch } from 'antd';
import SiteModal from '@/components/Modal/SiteModa';
import { editRole, GetRoleGroup } from '@/services/RoleManage/api';
import { InfoCircleOutlined } from '@ant-design/icons';
const { Item } = Form;
const { Option } = Select;
const AddModal = props => {
const [form] = Form.useForm();
const [formLayout, setFormLayout] = useState('horizontal');
const [groupList, setGroupList] = useState([]);
const [loading, setLoading] = useState(false);
const { confirmModal = () => {}, itemObj, editVisible, onCancel } = props;
const [value, setValue] = useState('');
console.log(itemObj, 'itemObj');
useEffect(() => {
console.log(itemObj.BuiltInRole);
form.setFieldsValue({
roleName: itemObj.roleName,
description: itemObj.description,
group: itemObj.group,
subSystemValue: itemObj.subSystemValue,
BuiltInRole: itemObj.BuiltInRole,
});
setValue(itemObj.BuiltInRole);
}, [itemObj]);
const onSubmit = () => {
form
.validateFields()
.then(res => {
console.log(res, 'res');
setLoading(true);
console.log(value);
editRole({
roleID: itemObj.roleID,
roleName: res.roleName,
description: res.description,
remark: res.group,
BuiltInRole: value,
// subSystemValue: itemObj.subSystemValue || itemObj.visibleValue || '',
})
.then(res => {
setLoading(false);
if (res.msg === '') {
form.resetFields();
notification.success({
message: '提示',
duration: 3,
description: '编辑成功',
});
console.log(value);
if (value) {
confirmModal(true);
} else {
confirmModal(false);
}
form.resetFields();
onCancel();
} else {
notification.error({
message: '提示',
duration: 3,
description: res.msg,
});
}
})
.catch(err => {
setLoading(false);
notification.error({
message: '提示',
duration: 3,
description: err,
});
});
})
.catch(err => {
console.error(err);
});
};
const onChange = value => {
console.log(value);
const { length } = value;
form.setFieldsValue({
group: value[length - 1],
});
};
// 获取分组列表
const selectFocus = e => {
setGroupList([]);
GetRoleGroup({
subSystemValue: itemObj.subSystemValue || itemObj.visibleValue || '',
subSystemName: itemObj.subSystemValue || itemObj.visibleValue || '',
})
.then(res => {
if (res) {
setGroupList(res.data);
} else {
notification.error({
message: '提示',
duration: 15,
description: res.message,
});
setGroupList([]);
}
})
.catch(err => {
console.error(err);
});
};
const onChangeRadio = e => {
setValue(e);
};
const onFinish = value => {};
return (
<SiteModal
{...props}
title="编辑角色"
bodyStyle={{ width: '100%', minHeight: '100px' }}
style={{ top: 100 }}
width="600px"
destroyOnClose
cancelText="取消"
okText="确认"
onOk={() => onSubmit()}
confirmLoading={loading}
>
<Form form={form} layout={formLayout} onFinish={onFinish} labelCol={{ span: 4 }}>
<Item
label="角色名称"
name="roleName"
rules={[
{
required: true,
message: '请输入角色名称',
},
]}
>
<Input placeholder="请输入角色名称" maxLength="20" />
</Item>
<Item label="虚拟目录" name="subSystemValue">
{itemObj.subSystemValue || itemObj.visibleValue}
</Item>
<Item
label={
<div>
<Tooltip title="内置角色不能配置菜单权限">
<InfoCircleOutlined style={{ color: 'rgb(24, 144, 255)', marginRight: '5px' }} />
</Tooltip>
<span>内置角色</span>
</div>
}
name="BuiltInRole"
>
{console.log(value, 'nalie')}
<Switch
checkedChildren="是"
unCheckedChildren="否"
checked={value}
onChange={onChangeRadio}
/>
{/* <Radio.Group onChange={onChangeRadio} value={value}>
<Radio value={2}>否</Radio>
<Radio value={1}>是</Radio>
</Radio.Group> */}
</Item>
<Item label="角色分组" name="group">
<Select
mode="tags"
placeholder="请选择分组"
onFocus={() => {
selectFocus();
}}
onChange={e => {
onChange(e);
}}
>
{groupList.map((item, index) => (
<Option value={item.value} key={index}>
{item.text}
</Option>
))}
</Select>
</Item>
<Item label="角色描述" name="description">
<Input placeholder="请输入角色描述" maxLength="100" />
</Item>
</Form>
</SiteModal>
);
};
export default AddModal;