cfel-base-components 2.3.0 → 2.3.1

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