|
@@ -1,5 +1,5 @@
|
1
|
1
|
import React, { useState, useEffect, useRef } from 'react';
|
2
|
|
-import { Button, Popconfirm, Modal, Form, Input, message, Radio, Select } from 'antd';
|
|
2
|
+import { Button, Popconfirm, Modal, Form, Input, message, Radio, Select, Checkbox } from 'antd';
|
3
|
3
|
import { PlusOutlined } from '@ant-design/icons';
|
4
|
4
|
import { getCooperativeList } from '@/services/cooperative';
|
5
|
5
|
import {
|
|
@@ -10,6 +10,8 @@ import {
|
10
|
10
|
getDefaultPassword,
|
11
|
11
|
getUserDetail,
|
12
|
12
|
} from '@/services/user';
|
|
13
|
+import { getRoleList } from '@/services/role';
|
|
14
|
+import { getUserRoleList, addUserUserRole, deleteUserRole } from '@/services/userRole';
|
13
|
15
|
import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
14
|
16
|
import PageTable from '@/components/PageTable';
|
15
|
17
|
import moment from 'moment';
|
|
@@ -30,6 +32,11 @@ export default (props) => {
|
30
|
32
|
const [password, setPassWord] = useState('');
|
31
|
33
|
const [cooperativeList, setCooperativeList] = useState([]);
|
32
|
34
|
|
|
35
|
+ const [editRoleModal, setEditRoleModal] = useState(false);
|
|
36
|
+ const [rLoading, setRLoading] = useState(false);
|
|
37
|
+ const [rUserId, setRUserId] = useState();
|
|
38
|
+ const [roleList, setRoleList] = useState([]);
|
|
39
|
+ const [currentCheckbox, setCurrentCheckbox] = useState();
|
33
|
40
|
//列表数据
|
34
|
41
|
const actionRef = useRef();
|
35
|
42
|
|
|
@@ -76,7 +83,7 @@ export default (props) => {
|
76
|
83
|
const handelChange = () => {};
|
77
|
84
|
|
78
|
85
|
// 列表点击编辑按钮
|
79
|
|
- const handelEdit = (val) => {
|
|
86
|
+ const handleEdit = (val) => {
|
80
|
87
|
setuserId(val.userId);
|
81
|
88
|
setEditModal(true);
|
82
|
89
|
};
|
|
@@ -112,6 +119,61 @@ export default (props) => {
|
112
|
119
|
},
|
113
|
120
|
});
|
114
|
121
|
};
|
|
122
|
+
|
|
123
|
+ const handleRole = (val) => {
|
|
124
|
+ setRUserId(val.userId);
|
|
125
|
+ getUserRoleList({ user_id: val.userId }).then((res) => {
|
|
126
|
+ if (res.length !== 0) {
|
|
127
|
+ setCurrentCheckbox(res.map((item) => item.roleId));
|
|
128
|
+ }
|
|
129
|
+ });
|
|
130
|
+ setEditRoleModal(true);
|
|
131
|
+ };
|
|
132
|
+ //授权弹窗点击取消按钮
|
|
133
|
+ const onRoleCancel = () => {
|
|
134
|
+ setRUserId();
|
|
135
|
+ setCurrentCheckbox();
|
|
136
|
+ form.resetFields();
|
|
137
|
+ setEditRoleModal(false);
|
|
138
|
+ };
|
|
139
|
+ const handelOk = () => {
|
|
140
|
+ if (!currentCheckbox) {
|
|
141
|
+ message.info('请选择角色');
|
|
142
|
+ return;
|
|
143
|
+ }
|
|
144
|
+ setRLoading(true);
|
|
145
|
+ if (currentCheckbox.length === 0) {
|
|
146
|
+ deleteUserRole(rUserId)
|
|
147
|
+ .then(() => {
|
|
148
|
+ message.success('取消授权角色成功');
|
|
149
|
+ setRLoading(false);
|
|
150
|
+ onRoleCancel();
|
|
151
|
+ })
|
|
152
|
+ .catch((err) => {
|
|
153
|
+ message.error(err);
|
|
154
|
+ setRLoading(false);
|
|
155
|
+ });
|
|
156
|
+ } else {
|
|
157
|
+ addUserUserRole(
|
|
158
|
+ rUserId,
|
|
159
|
+ currentCheckbox.map((item) => {
|
|
160
|
+ return { userId: rUserId, roleId: item };
|
|
161
|
+ }),
|
|
162
|
+ )
|
|
163
|
+ .then(() => {
|
|
164
|
+ message.success('授权角色成功');
|
|
165
|
+ setRLoading(false);
|
|
166
|
+ onRoleCancel();
|
|
167
|
+ })
|
|
168
|
+ .catch((err) => {
|
|
169
|
+ message.error(err);
|
|
170
|
+ setRLoading(false);
|
|
171
|
+ });
|
|
172
|
+ }
|
|
173
|
+ };
|
|
174
|
+ const handleCheckboxChange = (list) => {
|
|
175
|
+ setCurrentCheckbox(list);
|
|
176
|
+ };
|
115
|
177
|
useEffect(() => {
|
116
|
178
|
//获取账号默认密码
|
117
|
179
|
getDefaultPassword().then((res) => {
|
|
@@ -121,6 +183,12 @@ export default (props) => {
|
121
|
183
|
getCooperativeList().then((res) => {
|
122
|
184
|
setCooperativeList(res.records);
|
123
|
185
|
});
|
|
186
|
+ //获取角色列表数据
|
|
187
|
+ getRoleList().then((res) => {
|
|
188
|
+ setRoleList(res.records);
|
|
189
|
+ });
|
|
190
|
+ }, []);
|
|
191
|
+ useEffect(() => {
|
124
|
192
|
if (userId) {
|
125
|
193
|
getUserDetail(userId).then((res) => {
|
126
|
194
|
if (res.orgId === '-1') {
|
|
@@ -196,11 +264,14 @@ export default (props) => {
|
196
|
264
|
<Button type="link" key={1} onClick={() => handleOK(record)}>
|
197
|
265
|
{record.status === 0 ? '启用' : '禁用'}
|
198
|
266
|
</Button>,
|
199
|
|
- <a key={2} onClick={() => handelEdit(record)}>
|
|
267
|
+ <a key={2} onClick={() => handleEdit(record)}>
|
200
|
268
|
编辑
|
201
|
269
|
</a>,
|
|
270
|
+ <a key={3} onClick={() => handleRole(record)}>
|
|
271
|
+ 授权角色
|
|
272
|
+ </a>,
|
202
|
273
|
<Popconfirm
|
203
|
|
- key={3}
|
|
274
|
+ key={4}
|
204
|
275
|
title="您是否确认删除 ?"
|
205
|
276
|
onConfirm={() => handleDelete(record.userId)}
|
206
|
277
|
okText="确定"
|
|
@@ -225,6 +296,7 @@ export default (props) => {
|
225
|
296
|
scroll={{ x: 1000 }}
|
226
|
297
|
/>
|
227
|
298
|
<Modal
|
|
299
|
+ forceRender
|
228
|
300
|
title={userId ? '人员编辑' : '人员新增'}
|
229
|
301
|
visible={editModal}
|
230
|
302
|
onCancel={onCancel}
|
|
@@ -234,18 +306,6 @@ export default (props) => {
|
234
|
306
|
footer={null}
|
235
|
307
|
>
|
236
|
308
|
<Form {...formItemLayout} onFinish={Submit} form={form}>
|
237
|
|
- <FormItem label="登录账号">
|
238
|
|
- <Input.Group compact>
|
239
|
|
- <Form.Item
|
240
|
|
- name="loginName"
|
241
|
|
- noStyle
|
242
|
|
- rules={[{ required: true, message: '请输入登录账号' }]}
|
243
|
|
- >
|
244
|
|
- <Input placeholder="请输入" />
|
245
|
|
- </Form.Item>
|
246
|
|
- <span style={{ opacity: '0.7' }}>默认密码{password}</span>
|
247
|
|
- </Input.Group>
|
248
|
|
- </FormItem>
|
249
|
309
|
<FormItem label="用户名" name="userName" rules={[{ required: true, message: '请输入' }]}>
|
250
|
310
|
<Input placeholder="请输入" />
|
251
|
311
|
</FormItem>
|
|
@@ -261,6 +321,18 @@ export default (props) => {
|
261
|
321
|
<FormItem label="邮箱" name="email" rules={[{ required: true, message: '请输入' }]}>
|
262
|
322
|
<Input placeholder="请输入" />
|
263
|
323
|
</FormItem>
|
|
324
|
+ <FormItem label="登录账号">
|
|
325
|
+ <Input.Group compact>
|
|
326
|
+ <Form.Item
|
|
327
|
+ name="loginName"
|
|
328
|
+ noStyle
|
|
329
|
+ rules={[{ required: true, message: '请输入登录账号' }]}
|
|
330
|
+ >
|
|
331
|
+ <Input placeholder="请输入" />
|
|
332
|
+ </Form.Item>
|
|
333
|
+ <span style={{ opacity: '0.7' }}>默认密码{password}</span>
|
|
334
|
+ </Input.Group>
|
|
335
|
+ </FormItem>
|
264
|
336
|
<FormItem label="所属机构" name="orgId" rules={[{ required: true, message: '请输入' }]}>
|
265
|
337
|
<Search placeholder="请选择机构" onChange={handelChange} />
|
266
|
338
|
{/* <Select
|
|
@@ -297,6 +369,32 @@ export default (props) => {
|
297
|
369
|
</FormItem>
|
298
|
370
|
</Form>
|
299
|
371
|
</Modal>
|
|
372
|
+ <Modal
|
|
373
|
+ forceRender
|
|
374
|
+ title="角色授权"
|
|
375
|
+ visible={editRoleModal}
|
|
376
|
+ onCancel={onRoleCancel}
|
|
377
|
+ keyboard={false}
|
|
378
|
+ maskClosable={false}
|
|
379
|
+ destroyOnClose={true}
|
|
380
|
+ onOk={handelOk}
|
|
381
|
+ confirmLoading={rLoading}
|
|
382
|
+ >
|
|
383
|
+ <Checkbox.Group
|
|
384
|
+ style={{ width: '100%' }}
|
|
385
|
+ value={currentCheckbox}
|
|
386
|
+ onChange={handleCheckboxChange}
|
|
387
|
+ >
|
|
388
|
+ {roleList.map((item) => {
|
|
389
|
+ return (
|
|
390
|
+ <div key={item.roleId}>
|
|
391
|
+ <Checkbox value={item.roleId}>{item.name}</Checkbox>
|
|
392
|
+ <br />
|
|
393
|
+ </div>
|
|
394
|
+ );
|
|
395
|
+ })}
|
|
396
|
+ </Checkbox.Group>
|
|
397
|
+ </Modal>
|
300
|
398
|
</PageHeaderWrapper>
|
301
|
399
|
);
|
302
|
400
|
};
|