cfel-base-components 2.3.0 → 2.3.2

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "typescript.tsdk": "node_modules/typescript/lib"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cfel-base-components",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "cfel-base-components",
5
5
  "main": "/src/index.tsx",
6
6
  "types": "src/index.d.ts",
@@ -0,0 +1,10 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import React from 'react';
5
+ import { HelmetProvider } from '/Users/wujingang/Desktop/workspace/base-components/node_modules/@umijs/renderer-react';
6
+ import { context } from './helmetContext';
7
+
8
+ export const innerProvider = (container) => {
9
+ return React.createElement(HelmetProvider, { context }, container);
10
+ }
@@ -0,0 +1,4 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ export const context = {};
@@ -20,7 +20,6 @@ import "./index.scss"
20
20
  export interface RoleProps {
21
21
  historyAction: any;
22
22
  }
23
-
24
23
  export default function Role({
25
24
  historyAction
26
25
  }: RoleProps) {
@@ -41,6 +40,21 @@ export default function Role({
41
40
  title: '角色名称',
42
41
  dataIndex: 'roleName',
43
42
  key: 'roleName',
43
+ render: (text: any, data: any) => {
44
+ return (
45
+ <span
46
+ style={{ cursor: "pointer", color: "#1677ff" }}
47
+ onClick={() => {
48
+ historyAction?.push({
49
+ pathname: `/role-info`,
50
+ search: `?roleCode=${data.roleCode}`,
51
+ });
52
+ }}
53
+ >
54
+ {data?.roleName}
55
+ </span>
56
+ );
57
+ },
44
58
  },
45
59
  {
46
60
  title: '角色编码',
@@ -20,3 +20,18 @@ export const roleUnboundAccounts= (data?: any) => {
20
20
  export const getRole= (data?: any) => {
21
21
  return request.post("/api/permission/role/getRole.json", { ...data })
22
22
  }
23
+ //返回角色下的资源订阅树
24
+ export const getAuthTree = (data?: any) => {
25
+ return request.post(
26
+ "/sdk/permission/rbac/console/resource-role/getAuthTree.json",
27
+ { ...data },
28
+ );
29
+ };
30
+ //分页查询权限策略授权信息
31
+ export const policyAuthorizePage = (data?: any) => {
32
+ return request.post(
33
+ "/sdk/permission/abac/console/policy-authorize/page.json",
34
+ { ...data },
35
+ );
36
+ };
37
+
@@ -1,3 +1,26 @@
1
1
  .basicInfoWrap {
2
- padding: 0 24px
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
+ }
3
26
  }
@@ -1,134 +1,273 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import useTableHooks from "../../../hooks/useTableHooks"
3
-
4
- import PageContainer from '../../base-component/PageContainer';
5
- import QueryFilter from '../../base-component/QueryFilter';
6
- import ProTable from '../../base-component/ProTable';
7
- import Pagination from '../../base-component/Pagination';
8
- import { get } from 'lodash';
9
- import { ProFormText, } from '@ant-design/pro-components';
10
- import { Button, Divider, Modal, Descriptions, Space, message } from 'antd';
11
- import EditAccountDrawer from './EditAccountDrawer/index'
12
- import { timeFormatter, getUrlParams } from '../../../utils';
1
+ import React, { useEffect, useRef, useState } from "react";
2
+ import useTableHooks from "../../../hooks/useTableHooks";
3
+
4
+ import PageContainer from "../../base-component/PageContainer";
5
+ import QueryFilter from "../../base-component/QueryFilter";
6
+ import ProTable from "../../base-component/ProTable";
7
+ import Pagination from "../../base-component/Pagination";
8
+ import { get } from "lodash";
9
+ import { ProFormText } from "@ant-design/pro-components";
10
+ import {
11
+ Button,
12
+ Divider,
13
+ Modal,
14
+ Descriptions,
15
+ Space,
16
+ message,
17
+ Tabs,
18
+ Table,
19
+ Spin
20
+ } from "antd";
21
+ import EditAccountDrawer from "./EditAccountDrawer/index";
22
+ import { timeFormatter, getUrlParams } from "../../../utils";
13
23
  import {
14
24
  pageBoundAccounts,
15
25
  roleBoundAccounts,
16
26
  roleUnboundAccounts,
17
27
  getRole,
18
- queryByKeyword
19
- } from './api'
20
- import "./index.scss"
21
-
22
- export default function RoleInfo() {
23
- const searchFormRef: any = useRef()
24
- const [roleCode, setRoleCode] = useState('')
25
- const [roleInfo, setRoleInfo]: any = useState({})
28
+ queryByKeyword,
29
+ // getAuthTree,
30
+ policyAuthorizePage,
31
+ } from "./api";
32
+ import "./index.scss";
33
+ import { InteractionOutlined } from "@ant-design/icons";
34
+ import dayjs from "dayjs";
35
+
36
+ export interface RoleInfoProps {
37
+ isShowTab: {
38
+ main: boolean;
39
+ tableResource: boolean;
40
+ tableEmpower: boolean;
41
+ tableData: boolean;
42
+ };
43
+ getAuthTree?: any;
44
+ }
45
+
46
+ export default function RoleInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
47
+ const searchFormRef: any = useRef();
48
+ const [roleCode, setRoleCode] = useState(getUrlParams("roleCode"));
49
+ const [roleInfo, setRoleInfo]: any = useState({});
26
50
  const [editAccountOpen, setEditAccountOpen] = useState(false);
51
+ const [tabCheck, setTabCheck] = useState("main");
52
+
53
+ const [ResourceTableData, setResourceTableData]: any = useState([]); //关联资源
54
+ const [isTableLoading, setisTableLoading] = useState(false);
55
+ const [loading, setLoading] = useState(false)
56
+
57
+ const [TableItemData, setTableItemData]: any = useState([
58
+ {
59
+ key: "main",
60
+ label: `关联账号`,
61
+ icon: <InteractionOutlined />,
62
+ },
63
+ ]); //tab 数据
27
64
 
28
65
  const columns: any = [
29
66
  {
30
- title: '名称',
31
- dataIndex: 'name',
32
- key: 'name',
67
+ title: "名称",
68
+ dataIndex: "name",
69
+ key: "name",
33
70
  },
34
71
  {
35
- title: '账号',
36
- dataIndex: 'account',
37
- key: 'account',
72
+ title: "账号",
73
+ dataIndex: "account",
74
+ key: "account",
38
75
  },
39
76
  {
40
- title: '工号',
41
- dataIndex: 'jobNumber',
42
- key: 'jobNumber',
77
+ title: "工号",
78
+ dataIndex: "jobNumber",
79
+ key: "jobNumber",
43
80
  },
44
81
  {
45
- title: '手机号',
46
- dataIndex: 'mobile',
47
- key: 'mobile',
82
+ title: "手机号",
83
+ dataIndex: "mobile",
84
+ key: "mobile",
48
85
  },
49
86
  {
50
- title: '邮箱',
51
- dataIndex: 'email',
52
- key: 'email',
87
+ title: "邮箱",
88
+ dataIndex: "email",
89
+ key: "email",
53
90
  copyable: true,
54
91
  },
55
92
  {
56
- title: '是否企业管理员',
57
- dataIndex: 'isAdmin',
58
- key: 'isAdmin',
93
+ title: "是否企业管理员",
94
+ dataIndex: "isAdmin",
95
+ key: "isAdmin",
59
96
  render: (cell: any) => {
60
97
  if (cell) {
61
- return ''
98
+ return "";
62
99
  } else {
63
- return ''
100
+ return "";
64
101
  }
65
- }
102
+ },
66
103
  },
67
104
  {
68
- title: '创建时间',
69
- dataIndex: 'gmtCreate',
70
- key: 'gmtCreate',
105
+ title: "创建时间",
106
+ dataIndex: "gmtCreate",
107
+ key: "gmtCreate",
71
108
  render: (cell: any) => {
72
- return timeFormatter(cell)
73
- }
109
+ return timeFormatter(cell);
110
+ },
74
111
  },
75
112
  {
76
- title: '修改时间',
77
- dataIndex: 'gmtModified',
78
- key: 'gmtModified',
113
+ title: "修改时间",
114
+ dataIndex: "gmtModified",
115
+ key: "gmtModified",
79
116
  render: (cell: any) => {
80
- return timeFormatter(cell)
81
- }
117
+ return timeFormatter(cell);
118
+ },
82
119
  },
83
120
  {
84
- title: '操作',
121
+ title: "操作",
85
122
  width: 80,
86
123
  fixed: "right",
87
- render: (rowdata: any,) => <Space>
88
- <a onClick={() => {
89
- Modal.confirm({
90
- title: "确认解绑吗?",
91
- content: '',
92
- onOk: () => {
93
- roleUnboundAccountsFunc(rowdata.id)
94
- }
95
- })
96
-
97
- }}>解绑</a>
98
- </Space>
124
+ render: (rowdata: any) => (
125
+ <Space>
126
+ <a
127
+ onClick={() => {
128
+ Modal.confirm({
129
+ title: "确认解绑吗?",
130
+ content: "",
131
+ onOk: () => {
132
+ roleUnboundAccountsFunc(rowdata.id);
133
+ },
134
+ });
135
+ }}
136
+ >
137
+ 解绑
138
+ </a>
139
+ </Space>
140
+ ),
99
141
  },
100
142
  ];
101
143
 
144
+ const TableResource: any = [
145
+ {
146
+ title: "资源名称",
147
+ dataIndex: "name",
148
+ key: "name",
149
+ },
150
+ ];
151
+ const TablePolicy: any = [
152
+ {
153
+ title: "授权主体",
154
+ dataIndex: "subject",
155
+ key: "subject",
156
+ },
157
+ {
158
+ title: "权限策略",
159
+ dataIndex: "policy",
160
+ key: "policy",
161
+ },
162
+ {
163
+ title: "资源组",
164
+ dataIndex: "group",
165
+ key: "group",
166
+ },
167
+ {
168
+ title: "授权时间",
169
+ dataIndex: "gmtModified",
170
+ key: "gmtModified",
171
+ render: (text: any, data: any) => {
172
+ return dayjs(text).format("YYYY-MM-DD HH:mm:ss") || "数据格式错误";
173
+ },
174
+ },
175
+ ];
176
+ useEffect(() => {
177
+ init();
178
+ getRoleFunc({ roleCode });
179
+ }, []);
180
+
181
+ const init = () => {
182
+ let data: any = [];
183
+ if (isShowTab?.tableResource) {
184
+ data.push({
185
+ label: "关联资源",
186
+ key: "tableResource",
187
+ icon: <InteractionOutlined />,
188
+ });
189
+ }
190
+ if (isShowTab?.tableEmpower) {
191
+ data.push({
192
+ label: "关联授权",
193
+ key: "tableEmpower",
194
+ icon: <InteractionOutlined />,
195
+ });
196
+ }
197
+ if (isShowTab?.tableData) {
198
+ data.push({
199
+ label: "关联数据",
200
+ key: "tableData",
201
+ icon: <InteractionOutlined />,
202
+ });
203
+ }
204
+ setTableItemData([...TableItemData, ...data]);
205
+ };
206
+
207
+ const tabCheckFunc = () => {
208
+ if (tabCheck == "tableEmpower") {
209
+ policy?.execute({
210
+ subjectCodes: [roleCode],
211
+ }); // 获取授权策略
212
+ } else if (tabCheck == "tableResource") {
213
+ getAuthTreeFunc(); // 获取关联资源
214
+ } else {
215
+ execute({ roleCode: roleCode });
216
+ }
217
+ };
102
218
  useEffect(() => {
103
- initGetData('init', true)
104
- }, [])
105
-
106
- //初始化请求数据
107
- const initGetData = (type: string, msgType: any) => {
108
- let roleCode = getUrlParams('roleCode')
109
- setRoleCode(roleCode)
110
- if (roleCode) {
111
- getRoleFunc({ roleCode })
112
- execute({ "roleCode": roleCode })
219
+ tabCheckFunc();
220
+ }, [tabCheck]);
221
+
222
+ //获取关联资源
223
+ const getAuthTreeFunc = () => {
224
+ setisTableLoading(true);
225
+ getAuthTree && getAuthTree({
226
+ roleCode: roleCode,
227
+ }).then((res: any) => {
228
+ setisTableLoading(false);
229
+ let data: any = resourceAction(res);
230
+ setResourceTableData(data);
231
+ });
232
+ };
233
+
234
+ const resourceAction: any = (data: any) => {
235
+ if (Object.prototype.toString.call(data) === "[object Array]") {
236
+ data.map((item: any) => {
237
+ return resourceAction(item);
238
+ });
239
+ return data;
240
+ } else if (Object.prototype.toString.call(data) === "[object Object]") {
241
+ if (data.children && data.children.length !== 0) {
242
+ return resourceAction(data.children);
243
+ } else {
244
+ delete data.children;
245
+ return data;
246
+ }
113
247
  }
114
- }
248
+ };
249
+
250
+
115
251
  const getRoleFunc = (data: any) => {
116
- setRoleInfo({})
252
+ setRoleInfo({});
253
+ setLoading(true);
117
254
  getRole({
118
255
  ...data,
119
256
  }).then((res: any) => {
120
- setRoleInfo(res || {})
121
- })
122
- }
257
+ setLoading(false);
258
+ setRoleInfo(res || {});
259
+ tabCheckFunc();
260
+ });
261
+ };
123
262
  const roleUnboundAccountsFunc = (account: any) => {
124
263
  roleUnboundAccounts({
125
- "accountIds": [account],
126
- "roleCode": roleCode
264
+ accountIds: [account],
265
+ roleCode: roleCode,
127
266
  }).then((res: any) => {
128
- message.success('解绑成功')
129
- execute({ "roleCode": roleCode })
130
- })
131
- }
267
+ message.success("解绑成功");
268
+ execute({ roleCode: roleCode });
269
+ });
270
+ };
132
271
 
133
272
  const readDataList = ({
134
273
  innerPageNo,
@@ -139,108 +278,211 @@ export default function RoleInfo() {
139
278
  currentPage: innerPageNo,
140
279
  pageSize: innerPageSize,
141
280
  ...searchFormRef.current,
142
- ...otherOptions
281
+ ...otherOptions,
143
282
  }).then((res: any) => {
144
- let records = get(res, "records", [])
145
- let total = get(res, "total", 0)
283
+ let records = get(res, "records", []);
284
+ let total = get(res, "total", 0);
146
285
  return {
147
286
  dataList: records,
148
- totalCount: total
149
- }
150
- })
151
- }
287
+ totalCount: total,
288
+ };
289
+ });
290
+ };
152
291
  const { execute, dataList, isLoading, pagination } = useTableHooks({
153
- asyncFunction: readDataList
154
- })
292
+ asyncFunction: readDataList,
293
+ });
155
294
 
156
295
  const handleRoload = () => {
157
- execute({ "roleCode": roleCode })
158
- }
296
+ execute({ roleCode: roleCode });
297
+ };
159
298
 
160
299
  const getQueryBoundRolesFunc = async () => {
161
- setEditAccountOpen(true)
162
- }
300
+ setEditAccountOpen(true);
301
+ };
163
302
 
164
303
  const roleBoundAccountsFunc = ({ accountIds }: any) => {
165
304
  return roleBoundAccounts({
166
- "accountIds": accountIds,
167
- "roleCode": roleCode
305
+ accountIds: accountIds,
306
+ roleCode: roleCode,
168
307
  }).then((res: any) => {
169
- message.success(`添加账号成功`)
170
- execute({ "roleCode": roleCode })
171
- setEditAccountOpen(false)
172
- })
173
- }
308
+ message.success(`添加账号成功`);
309
+ execute({ roleCode: roleCode });
310
+ setEditAccountOpen(false);
311
+ });
312
+ };
174
313
  //搜索关键字
175
314
  const queryByKeywordFunc = ({ keyword }: any) => {
176
315
  return queryByKeyword({
177
- keyword
178
- })
179
- }
316
+ keyword,
317
+ });
318
+ };
180
319
 
181
320
  const handleOnReset: any = async (values: any) => {
182
- searchFormRef.current = { ...values }
321
+ searchFormRef.current = { ...values };
183
322
  execute({
184
323
  innerPageNo: 1,
185
- "roleCode": roleCode
186
- })
187
- }
324
+ roleCode: roleCode,
325
+ });
326
+ };
188
327
 
189
328
  const handleOnFinish: any = async (values: any) => {
190
- searchFormRef.current = { ...values }
191
- execute({ "roleCode": roleCode })
192
- }
329
+ searchFormRef.current = { ...values };
330
+ execute({ roleCode: roleCode });
331
+ };
332
+
333
+ const readDataListByPolicy = ({
334
+ innerPageNo,
335
+ innerPageSize,
336
+ ...otherOptions
337
+ }: any) => {
338
+ return policyAuthorizePage({
339
+ currentPage: innerPageNo,
340
+ pageSize: innerPageSize,
341
+ ...otherOptions,
342
+ }).then((res: any) => {
343
+ let records = get(res, "records", []);
344
+ let total = get(res, "total", 0);
345
+ return {
346
+ dataList: records,
347
+ totalCount: total,
348
+ };
349
+ });
350
+ };
351
+ let policy = useTableHooks({
352
+ asyncFunction: readDataListByPolicy,
353
+ });
354
+
193
355
  return (
194
356
  <PageContainer>
195
- <Divider orientation="left">{roleInfo?.roleName || "-"}</Divider>
357
+ <Spin spinning={loading}>
358
+ <div className="deviceTopTitle">
359
+ <div className="deviceTopDivider">
360
+ <Divider orientation="left">{roleInfo?.roleName || "-"}</Divider>
361
+ </div>
362
+ <Button className="deviceTopButton" onClick={(() => {
363
+ getRoleFunc({ roleCode });
364
+ })} >刷新</Button>
365
+ </div>
196
366
  <Descriptions className="basicInfoWrap">
197
- <Descriptions.Item label="角色名称">{roleInfo?.roleName || ''}</Descriptions.Item>
198
- <Descriptions.Item label="角色编码">{roleInfo?.roleCode || ''}</Descriptions.Item>
199
- <Descriptions.Item label="角色描述">{roleInfo?.description || ''}</Descriptions.Item>
200
- <Descriptions.Item label="创建时间">{timeFormatter(roleInfo?.gmtCreate) || ''}</Descriptions.Item>
201
- <Descriptions.Item label="更新时间">{timeFormatter(roleInfo?.gmtModified) || ''}</Descriptions.Item>
367
+ <Descriptions.Item label="角色名称">
368
+ {roleInfo?.roleName || ""}
369
+ </Descriptions.Item>
370
+ <Descriptions.Item label="角色编码">
371
+ {roleInfo?.roleCode || ""}
372
+ </Descriptions.Item>
373
+ <Descriptions.Item label="角色描述">
374
+ {roleInfo?.description || ""}
375
+ </Descriptions.Item>
376
+ <Descriptions.Item label="创建时间">
377
+ {timeFormatter(roleInfo?.gmtCreate) || ""}
378
+ </Descriptions.Item>
379
+ <Descriptions.Item label="更新时间">
380
+ {timeFormatter(roleInfo?.gmtModified) || ""}
381
+ </Descriptions.Item>
202
382
  </Descriptions>
203
383
 
204
- <QueryFilter
205
- onReset={handleOnReset}
206
- onFinish={handleOnFinish}
207
- >
208
- <ProFormText name="keyword" label="关键词" />
209
- </QueryFilter>
210
-
211
- <ProTable
212
- headerTitle={"角色下绑定的账号"}
213
- dataSource={dataList}
214
- loading={isLoading}
215
- columns={columns}
216
- rowKey="id"
217
- options={{
218
- reload: handleRoload
219
- }}
220
- toolBarRender={() => {
221
- return [
222
- <Button type="primary" onClick={(() => {
223
- getQueryBoundRolesFunc()
224
- })}>添加账号</Button>
225
- ];
226
- }}
227
- />
228
-
229
- <Pagination {...pagination}
230
- onChange={(innerPageNo: number, innerPageSize: number) => {
231
- execute({
232
- innerPageNo,
233
- innerPageSize,
234
- "roleCode": roleCode
235
- })
236
- }}/>
384
+ <div>
385
+ <Divider orientation="left">当前角色关联内容</Divider>
386
+ <div className="jsonWarp">
387
+ <Tabs
388
+ onChange={(e) => {
389
+ setTabCheck(e);
390
+ }}
391
+ items={TableItemData}
392
+ />
393
+ {tabCheck == "main" && (
394
+ <>
395
+ <QueryFilter
396
+ style={{ padding: "0px" }}
397
+ size="middle"
398
+ onReset={handleOnReset}
399
+ onFinish={handleOnFinish}
400
+ >
401
+ <ProFormText name="keyword" label="关键词" />
402
+ </QueryFilter>
403
+ <ProTable
404
+ size="small"
405
+ dataSource={dataList}
406
+ loading={isLoading}
407
+ columns={columns}
408
+ rowKey="id"
409
+ options={{
410
+ reload: handleRoload,
411
+ }}
412
+ toolBarRender={() => {
413
+ return [
414
+ <Button
415
+ type="primary"
416
+ onClick={() => {
417
+ getQueryBoundRolesFunc();
418
+ }}
419
+ >
420
+ 添加账号
421
+ </Button>,
422
+ ];
423
+ }}
424
+ />
425
+
426
+ <Pagination
427
+ {...pagination}
428
+ onChange={(innerPageNo: number, innerPageSize: number) => {
429
+ execute({
430
+ innerPageNo,
431
+ innerPageSize,
432
+ roleCode: roleCode,
433
+ });
434
+ }}
435
+ />
436
+ </>
437
+ )}
438
+ {tabCheck == "tableResource" && (
439
+ <>
440
+ <Table
441
+ style={{ width: "100%" }}
442
+ size="small"
443
+ rowKey="id"
444
+ loading={isTableLoading}
445
+ pagination={false}
446
+ columns={TableResource}
447
+ dataSource={ResourceTableData || []}
448
+ />
449
+ </>
450
+ )}
451
+
452
+ {tabCheck == "tableEmpower" && (
453
+ <>
454
+ <Table
455
+ style={{ width: "100%" }}
456
+ size="small"
457
+ rowKey="id"
458
+ dataSource={policy?.dataList}
459
+ loading={policy?.isLoading}
460
+ columns={TablePolicy}
461
+ pagination={false}
462
+ />
463
+ <Pagination
464
+ {...policy?.pagination}
465
+ onChange={(innerPageNo: number, innerPageSize: number) => {
466
+ policy?.execute({
467
+ innerPageNo,
468
+ innerPageSize,
469
+ subjectCodes: [roleCode],
470
+ });
471
+ }}
472
+ />
473
+ </>
474
+ )}
475
+ {tabCheck == "tableData" && <></>}
476
+ </div>
477
+ </div>
478
+ </Spin>
479
+ {/* */}
237
480
  <EditAccountDrawer
238
481
  open={editAccountOpen} // 状态
239
482
  editOpenStatus={setEditAccountOpen} //修改弹框显隐事件
240
483
  roleBoundAccountsFunc={roleBoundAccountsFunc}
241
484
  queryByKeywordFunc={queryByKeywordFunc} //搜索事件
242
485
  ></EditAccountDrawer>
243
-
244
486
  </PageContainer>
245
- )
246
- };
487
+ );
488
+ }