cfel-base-components 2.3.2 → 2.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cfel-base-components",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "cfel-base-components",
5
5
  "main": "/src/index.tsx",
6
6
  "types": "src/index.d.ts",
@@ -146,7 +146,7 @@ export default function AccountInfo() {
146
146
  Promise.all([queryBoundRoles({ accountId: pageId }), rolelistRole()]).then((res) => {
147
147
  let boundRoles: any = res[0]
148
148
  let roleList: any = res[1]
149
- let result = []
149
+ let result :any= []
150
150
  for (var i = 0; i < roleList.length; i++) {
151
151
  var item = roleList[i]
152
152
  var repeat = false
@@ -36,9 +36,21 @@ export default function Account({
36
36
  title: '名称',
37
37
  dataIndex: 'name',
38
38
  key: 'name',
39
- render: (text: any) => {
40
- return <span>{text}</span>
41
- }
39
+ render: (text: any, data: any) => {
40
+ return (
41
+ <span
42
+ style={{ cursor: "pointer", color: "#1677ff" }}
43
+ onClick={() => {
44
+ historyAction?.push({
45
+ pathname: `/account-info`,
46
+ search: `?id=${data.id}`,
47
+ });
48
+ }}
49
+ >
50
+ {data?.name}
51
+ </span>
52
+ );
53
+ },
42
54
  },
43
55
  {
44
56
  title: '账号',
@@ -0,0 +1,80 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { Button, Drawer, Select, Form, Space } from 'antd';
3
+
4
+ interface propsType {
5
+ open: boolean;
6
+ editOpenStatus: Function;
7
+ isBoundRolesFunc: Function;
8
+ rolelistRoleData: any;
9
+ roleCheckData: any;
10
+ }
11
+ export default function index({
12
+ open,
13
+ editOpenStatus,
14
+ isBoundRolesFunc,
15
+ rolelistRoleData,
16
+ roleCheckData,
17
+ }: propsType) {
18
+
19
+ const [form] = Form.useForm();
20
+ useEffect(() => {
21
+ if (!open) return
22
+ form.setFieldsValue({
23
+ roleCodes: roleCheckData || [],
24
+ })
25
+ }, [open])
26
+
27
+ const onCloseDrawer = () => {
28
+ editOpenStatus(false)
29
+ }
30
+ const onFinishForm = () => {
31
+ form.validateFields()
32
+ .then((values) => {
33
+ isBoundRolesFunc(true, values).then((res: any) => {
34
+ form.resetFields()
35
+ })
36
+ })
37
+ }
38
+ return (<Drawer
39
+ title="绑定的角色"
40
+ closable={false}
41
+ open={open}
42
+ destroyOnClose={true}
43
+ onClose={() => { onCloseDrawer() }}
44
+ footer={<Space>
45
+ <Button
46
+ type="primary"
47
+ onClick={() => {
48
+ onFinishForm()
49
+ }}
50
+ >保存</Button>
51
+ <Button
52
+ onClick={() => { onCloseDrawer() }}
53
+ >取消</Button>
54
+ </Space>
55
+ }
56
+ >
57
+ <Form
58
+ form={form}
59
+ layout={'vertical'}
60
+ initialValues={{ remember: true }}
61
+ autoComplete="off"
62
+ >
63
+ <Form.Item
64
+ name="roleCodes"
65
+ label="绑定角色"
66
+ rules={[{ required: true, message: '' }]} >
67
+ <Select
68
+ mode="multiple"
69
+ allowClear
70
+ placeholder="请选择"
71
+ options={rolelistRoleData?.map((d: any) => ({
72
+ label: d.roleName,
73
+ value: d.roleCode,
74
+ }))}
75
+ />
76
+ </Form.Item>
77
+ </Form>
78
+ </Drawer >
79
+ );
80
+ }
@@ -0,0 +1,41 @@
1
+ import request from "../../../apiRequest/config"
2
+
3
+ //按账号id查询账号信息
4
+ export const getAccount= (data?: any) => {
5
+ return request.post("/api/permission/account/getAccount.json", { ...data })
6
+ }
7
+ //根据账号查询绑定的角色 分页
8
+ export const pageBoundRoles= (data?: any) => {
9
+ return request.post("/api/permission/accountRole/pageBoundRoles.json", { ...data })
10
+ }
11
+ //根据账号查询绑定的角色
12
+ export const queryBoundRoles= (data?: any) => {
13
+ return request.post("/api/permission/accountRole/queryBoundRoles.json", { ...data })
14
+ }
15
+ //获取所有角色
16
+ export const rolelistRole = (data?: any) => {
17
+ return request.get("/api/permission/role/listRole.json", { ...data })
18
+ }
19
+ //账号下绑定角色
20
+ export const accountBoundRoles= (data?: any) => {
21
+ return request.post("/api/permission/accountRole/accountBoundRoles.json", { ...data })
22
+ }
23
+ //账号下解绑角色
24
+ export const accountUnboundRoles= (data?: any) => {
25
+ return request.post("/api/permission/accountRole/accountUnboundRoles.json", { ...data })
26
+ }
27
+
28
+ //查询账号下的资源订阅树
29
+ export const getAuthTree = (data?: any) => {
30
+ return request.post(
31
+ "/sdk/permission/rbac/console/resource-account/getAuthTree.json",
32
+ { ...data },
33
+ );
34
+ };
35
+ //分页查询账号权限策略授权信息
36
+ export const accountAuthorizePage = (data?: any) => {
37
+ return request.post(
38
+ "/sdk/permission/abac/console/account-authorize/page.json",
39
+ { ...data },
40
+ );
41
+ };
@@ -0,0 +1,26 @@
1
+ .basicInfoWrap {
2
+ padding: 0 24px;
3
+ }
4
+ .jsonWarp {
5
+ padding: 0px 44px 10px;
6
+ }
7
+ .tableActionWarp {
8
+ float: right;
9
+ margin-bottom: 15px;
10
+ }
11
+ .paginBox {
12
+ display: flex;
13
+ justify-content: space-between;
14
+ align-items: center;
15
+ margin: 10px 0px;
16
+ }
17
+ .deviceTopTitle {
18
+ display: flex;
19
+ align-items: center;
20
+ .deviceTopDivider {
21
+ flex: 1;
22
+ }
23
+ .deviceTopButton {
24
+ margin: 0px 5px;
25
+ }
26
+ }
@@ -0,0 +1,468 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import PageContainer from '../../base-component/PageContainer';
3
+ import QueryFilter from '../../base-component/QueryFilter';
4
+ import ProTable from '../../base-component/ProTable';
5
+ import Pagination from '../../base-component/Pagination';
6
+ import { get } from 'lodash';
7
+ import { Modal, Button, Divider, Descriptions, Space, message, Avatar,
8
+ Spin,
9
+ Tabs,
10
+ Table, } from 'antd';
11
+ import { UserOutlined } from '@ant-design/icons';
12
+ import EditAccountDrawer from './EditAccountDrawer/index'
13
+ import useTableHooks from "../../../hooks/useTableHooks"
14
+ import { timeFormatter, getUrlParams } from '../../../utils';
15
+ import {
16
+ getAccount,
17
+ pageBoundRoles,
18
+ queryBoundRoles,
19
+ rolelistRole,
20
+ accountBoundRoles,
21
+ accountUnboundRoles,
22
+ getAuthTree,
23
+ accountAuthorizePage,
24
+ } from './api'
25
+ import "./index.scss"
26
+ import { InteractionOutlined } from "@ant-design/icons";
27
+ import dayjs from "dayjs";
28
+
29
+
30
+ export interface RoleInfoProps {
31
+ isShowTab: {
32
+ main: boolean;
33
+ tableResource: boolean;
34
+ tableEmpower: boolean;
35
+ tableData: boolean;
36
+ };
37
+ getAuthTree?: any;
38
+ }
39
+ export default function AccountInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
40
+ const [accountInfo, setAccountInfoInfo]: any = useState({});
41
+ const [pageId, setPageId] = useState(getUrlParams("id"));
42
+ const [rolelistRoleData, setRolelistRoleData]: any = useState([]); // 角色总数据
43
+ const [roleCheckData, setRoleCheckData]: any = useState([]); //当前选中的角色list
44
+ const [editAccountOpen, setEditAccountOpen] = useState(false);
45
+
46
+ const [loading, setLoading] = useState(false);
47
+ const [tabCheck, setTabCheck] = useState("main");
48
+ const [ResourceTableData, setResourceTableData]: any = useState([]); //关联资源
49
+ const [isTableLoading, setisTableLoading] = useState(false);
50
+ const [TableItemData, setTableItemData]: any = useState([
51
+ {
52
+ key: "main",
53
+ label: `关联角色`,
54
+ icon: <InteractionOutlined />,
55
+ },
56
+ ]); //tab 数据
57
+ const TableResource: any = [
58
+ {
59
+ title: "资源名称",
60
+ dataIndex: "name",
61
+ key: "name",
62
+ },
63
+ ];
64
+ const columns: any = [
65
+ {
66
+ title: "角色名称",
67
+ dataIndex: "roleName",
68
+ key: "roleName",
69
+ },
70
+ {
71
+ title: "角色编码",
72
+ dataIndex: "roleCode",
73
+ key: "roleCode",
74
+ width: 300,
75
+ },
76
+ {
77
+ title: "来源",
78
+ dataIndex: "source",
79
+ key: "source",
80
+ render: (cell: any) => {
81
+ if (cell == "system") {
82
+ return "系统创建";
83
+ } else if (cell == "user") {
84
+ return "用户自建";
85
+ } else if (cell == "user") {
86
+ return "未知";
87
+ }
88
+ },
89
+ },
90
+ {
91
+ title: "描述",
92
+ dataIndex: "description",
93
+ key: "description",
94
+ },
95
+ {
96
+ title: "创建时间",
97
+ dataIndex: "gmtCreate",
98
+ key: "gmtCreate",
99
+ render: (cell: any) => {
100
+ return timeFormatter(cell);
101
+ },
102
+ },
103
+ {
104
+ title: "修改时间",
105
+ dataIndex: "gmtModified",
106
+ key: "gmtModified",
107
+ render: (cell: any) => {
108
+ return timeFormatter(cell);
109
+ },
110
+ },
111
+ {
112
+ title: "操作",
113
+ width: 80,
114
+ fixed: "right",
115
+ render: (rowdata: any) => (
116
+ <Space>
117
+ <a
118
+ onClick={() => {
119
+ Modal.confirm({
120
+ title: "确认解绑吗?",
121
+ content: "",
122
+ onOk: () => {
123
+ isBoundRolesFunc(false, { roleCodes: [rowdata.roleCode] });
124
+ },
125
+ });
126
+ }}
127
+ >
128
+ 解绑
129
+ </a>
130
+ </Space>
131
+ ),
132
+ },
133
+ ];
134
+ const TablePolicy: any = [
135
+ {
136
+ title: "授权主体",
137
+ dataIndex: "subject",
138
+ key: "subject",
139
+ },
140
+ {
141
+ title: "权限策略",
142
+ dataIndex: "policy",
143
+ key: "policy",
144
+ },
145
+ {
146
+ title: "资源组",
147
+ dataIndex: "group",
148
+ key: "group",
149
+ },
150
+ {
151
+ title: "授权时间",
152
+ dataIndex: "gmtModified",
153
+ key: "gmtModified",
154
+ render: (text: any, data: any) => {
155
+ return dayjs(text).format("YYYY-MM-DD HH:mm:ss") || "数据格式错误";
156
+ },
157
+ },
158
+ ];
159
+ useEffect(() => {
160
+ init();
161
+ getAccountFunc({ id: pageId });
162
+ }, []);
163
+ const init = () => {
164
+ let data: any = [];
165
+ if (isShowTab?.tableResource) {
166
+ data.push({
167
+ label: "关联资源",
168
+ key: "tableResource",
169
+ icon: <InteractionOutlined />,
170
+ });
171
+ }
172
+ if (isShowTab?.tableEmpower) {
173
+ data.push({
174
+ label: "关联授权",
175
+ key: "tableEmpower",
176
+ icon: <InteractionOutlined />,
177
+ });
178
+ }
179
+ if (isShowTab?.tableData) {
180
+ data.push({
181
+ label: "关联数据",
182
+ key: "tableData",
183
+ icon: <InteractionOutlined />,
184
+ });
185
+ }
186
+ setTableItemData([...TableItemData, ...data]);
187
+ };
188
+
189
+ const tabCheckFunc = () => {
190
+ if (tabCheck == "tableEmpower") {
191
+ policy?.execute({
192
+ accountId: pageId,
193
+ }); // 获取授权策略
194
+ } else if (tabCheck == "tableResource") {
195
+ getAuthTreeFunc(); // 获取关联资源
196
+ } else {
197
+ execute({ accountId: pageId });
198
+ }
199
+ };
200
+
201
+ useEffect(() => {
202
+ tabCheckFunc();
203
+ }, [tabCheck]);
204
+
205
+ const getAccountFunc = (data: any) => {
206
+ setAccountInfoInfo({});
207
+ setLoading(true);
208
+ getAccount({
209
+ ...data,
210
+ }).then((res: any) => {
211
+ setLoading(false);
212
+ setAccountInfoInfo(res || {});
213
+ tabCheckFunc();
214
+ });
215
+ };
216
+
217
+ //获取关联资源
218
+ const getAuthTreeFunc = () => {
219
+ setisTableLoading(true);
220
+ getAuthTree &&
221
+ getAuthTree({
222
+ accountId: pageId,
223
+ }).then((res: any) => {
224
+ setisTableLoading(false);
225
+ let data: any = resourceAction(res);
226
+ setResourceTableData(data);
227
+ });
228
+ };
229
+ const resourceAction: any = (data: any) => {
230
+ if (Object.prototype.toString.call(data) === "[object Array]") {
231
+ data.map((item: any) => {
232
+ return resourceAction(item);
233
+ });
234
+ return data;
235
+ } else if (Object.prototype.toString.call(data) === "[object Object]") {
236
+ if (data.children && data.children.length !== 0) {
237
+ return resourceAction(data.children);
238
+ } else {
239
+ delete data.children;
240
+ return data;
241
+ }
242
+ }
243
+ };
244
+ const readDataList = ({
245
+ innerPageNo,
246
+ innerPageSize,
247
+ ...otherOptions
248
+ }: any) => {
249
+ return pageBoundRoles({
250
+ currentPage: innerPageNo,
251
+ pageSize: innerPageSize,
252
+ ...otherOptions,
253
+ }).then((res: any) => {
254
+ let records = get(res, "records", []);
255
+ let total = get(res, "total", 0);
256
+ return {
257
+ dataList: records,
258
+ totalCount: total,
259
+ };
260
+ });
261
+ };
262
+ const { execute, dataList, isLoading, pagination } = useTableHooks({
263
+ asyncFunction: readDataList,
264
+ });
265
+
266
+ const getQueryBoundRolesFunc = () => {
267
+ Promise.all([queryBoundRoles({ accountId: pageId }), rolelistRole()]).then(
268
+ (res) => {
269
+ let boundRoles: any = res[0];
270
+ let roleList: any = res[1];
271
+ let result :any= [];
272
+ for (var i = 0; i < roleList.length; i++) {
273
+ var item = roleList[i];
274
+ var repeat = false;
275
+ for (var j = 0; j < boundRoles.length; j++) {
276
+ if (item.roleCode === boundRoles[j].roleCode) {
277
+ repeat = true;
278
+ break;
279
+ }
280
+ }
281
+ if (repeat) {
282
+ result.push(item.roleCode);
283
+ }
284
+ }
285
+ setRolelistRoleData(roleList);
286
+ setRoleCheckData(result);
287
+ setEditAccountOpen(true);
288
+ },
289
+ );
290
+ };
291
+ const isBoundRolesFunc = (type: any, { roleCodes }: any) => {
292
+ return (type ? accountBoundRoles : accountUnboundRoles)({
293
+ accountId: pageId,
294
+ roleCodes: roleCodes,
295
+ }).then(() => {
296
+ message.success(`${type ? "绑定" : "解绑"}成功`);
297
+ execute({ accountId: pageId });
298
+ setEditAccountOpen(false);
299
+ });
300
+ };
301
+
302
+ const accountAuthorizePageFunc = ({
303
+ innerPageNo,
304
+ innerPageSize,
305
+ ...otherOptions
306
+ }: any) => {
307
+ return accountAuthorizePage({
308
+ currentPage: innerPageNo,
309
+ pageSize: innerPageSize,
310
+ ...otherOptions,
311
+ }).then((res: any) => {
312
+ let records = get(res, "records", []);
313
+ let total = get(res, "total", 0);
314
+ return {
315
+ dataList: records,
316
+ totalCount: total,
317
+ };
318
+ });
319
+ };
320
+ let policy = useTableHooks({
321
+ asyncFunction: accountAuthorizePageFunc,
322
+ });
323
+ return (
324
+ <PageContainer>
325
+ <Spin spinning={loading}>
326
+ <div className="deviceTopTitle">
327
+ <div className="deviceTopDivider">
328
+ <Divider orientation="left">
329
+ <Avatar
330
+ style={{ backgroundColor: "#1677ff", marginRight: "8px" }}
331
+ draggable={false}
332
+ icon={<UserOutlined />}
333
+ src={!!accountInfo.avatar ? accountInfo.avatar : undefined}
334
+ />
335
+ {accountInfo?.name || ""}
336
+ </Divider>
337
+ </div>
338
+ <Button
339
+ className="deviceTopButton"
340
+ onClick={() => {
341
+ getAccountFunc({ id: pageId });
342
+ }}
343
+ >
344
+ 刷新
345
+ </Button>
346
+ </div>
347
+ <Descriptions className="basicInfoWrap">
348
+ <Descriptions.Item label="账号">
349
+ {accountInfo?.account || ""}
350
+ </Descriptions.Item>
351
+ <Descriptions.Item label="员工工号">
352
+ {accountInfo?.jobNumber || ""}
353
+ </Descriptions.Item>
354
+ <Descriptions.Item label="名称">
355
+ {accountInfo?.name || ""}
356
+ </Descriptions.Item>
357
+ <Descriptions.Item label="手机号">
358
+ {accountInfo?.mobile || ""}
359
+ </Descriptions.Item>
360
+ <Descriptions.Item label="邮箱">
361
+ {accountInfo?.email || ""}
362
+ </Descriptions.Item>
363
+ <Descriptions.Item label="是否企业管理员">
364
+ {accountInfo?.isAdmin ? "是" : "否"}
365
+ </Descriptions.Item>
366
+ <Descriptions.Item label="创建时间">
367
+ {timeFormatter(accountInfo?.gmtCreate)}
368
+ </Descriptions.Item>
369
+ <Descriptions.Item label="修改时间">
370
+ {timeFormatter(accountInfo?.gmtModified)}
371
+ </Descriptions.Item>
372
+ </Descriptions>
373
+ <div>
374
+ <Divider orientation="left">当前账号关联内容</Divider>
375
+ <div className="jsonWarp">
376
+ <Tabs
377
+ onChange={(e) => {
378
+ setTabCheck(e);
379
+ }}
380
+ items={TableItemData}
381
+ />
382
+ {tabCheck == "main" && (
383
+ <>
384
+ <div className="tableActionWarp">
385
+ <Button
386
+ type="primary"
387
+ onClick={() => {
388
+ getQueryBoundRolesFunc();
389
+ }}
390
+ >
391
+ 绑定
392
+ </Button>
393
+ </div>
394
+ <Table
395
+ scroll={{
396
+ x: 1200,
397
+ }}
398
+ size="small"
399
+ rowKey="id"
400
+ dataSource={dataList}
401
+ loading={isLoading}
402
+ columns={columns}
403
+ pagination={false}
404
+ />
405
+ <Pagination
406
+ {...pagination}
407
+ onChange={(innerPageNo: number, innerPageSize: number) => {
408
+ execute({
409
+ innerPageNo,
410
+ innerPageSize,
411
+ accountId: pageId,
412
+ });
413
+ }}
414
+ />
415
+ </>
416
+ )}
417
+ {tabCheck == "tableResource" && (
418
+ <>
419
+ <Table
420
+ style={{ width: "100%" }}
421
+ size="small"
422
+ rowKey="id"
423
+ loading={isTableLoading}
424
+ pagination={false}
425
+ columns={TableResource}
426
+ dataSource={ResourceTableData || []}
427
+ />
428
+ </>
429
+ )}
430
+
431
+ {tabCheck == "tableEmpower" && (
432
+ <>
433
+ <Table
434
+ style={{ width: "100%" }}
435
+ size="small"
436
+ rowKey="id"
437
+ dataSource={policy?.dataList}
438
+ loading={policy?.isLoading}
439
+ columns={TablePolicy}
440
+ pagination={false}
441
+ />
442
+ <Pagination
443
+ {...policy?.pagination}
444
+ onChange={(innerPageNo: number, innerPageSize: number) => {
445
+ policy?.execute({
446
+ innerPageNo,
447
+ innerPageSize,
448
+ accountId: pageId,
449
+ });
450
+ }}
451
+ />
452
+ </>
453
+ )}
454
+ {tabCheck == "tableData" && <></>}
455
+ </div>
456
+ </div>
457
+ {/* */}
458
+ </Spin>
459
+ <EditAccountDrawer
460
+ open={editAccountOpen} // 状态
461
+ editOpenStatus={setEditAccountOpen} //修改弹框显隐事件
462
+ rolelistRoleData={rolelistRoleData} //总角色
463
+ roleCheckData={roleCheckData} //当前角色选中数据
464
+ isBoundRolesFunc={isBoundRolesFunc}
465
+ ></EditAccountDrawer>
466
+ </PageContainer>
467
+ );
468
+ }