cfel-base-components 2.3.4-base → 2.3.4-base3

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.
@@ -9,7 +9,7 @@ import Layout from '../../src/components/layout';
9
9
  // import Account from '../../src/components/universal-pages/account';
10
10
  // import AccountInfo from '../../src/components/universal-pages/accountInfo';
11
11
  import CpcRole from '../../src/components/universal-pages/cpcRole';
12
- // import RoleInfo from '../../src/components/universal-pages/roleInfo';
12
+ import CpcRoleInfo from '../../src/components/universal-pages/cpcRoleInfo';
13
13
 
14
14
  const App = () => {
15
15
  return <ConfigProvider
@@ -59,7 +59,13 @@ const App = () => {
59
59
  logoutUrl={(window)?.g_config?.logoutUrl}
60
60
  switchTenantUrl={(window)?.g_config?.switchTenantUrl}
61
61
  >
62
- <CpcRole></CpcRole>
62
+ <CpcRoleInfo
63
+ isShowTab={{
64
+ main: true,
65
+ tableResource: true,
66
+ tableEmpower: true,
67
+ tableData: false,
68
+ }}></CpcRoleInfo>
63
69
  </Layout>
64
70
  </ConfigProvider>
65
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cfel-base-components",
3
- "version": "2.3.4-base",
3
+ "version": "2.3.4-base3",
4
4
  "description": "cfel-base-components",
5
5
  "main": "/src/index.tsx",
6
6
  "types": "src/index.d.ts",
@@ -199,6 +199,7 @@ export default function AccountInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
199
199
  };
200
200
 
201
201
  useEffect(() => {
202
+ if(!tabCheck) return
202
203
  tabCheckFunc();
203
204
  }, [tabCheck]);
204
205
 
@@ -99,7 +99,7 @@ export default function Role({
99
99
  pathname: `/role-info`,
100
100
  search: `?roleCode=${rowdata.roleCode}`,
101
101
  });
102
- }}>赋予账号</a>
102
+ }}>配置</a>
103
103
  {
104
104
  rowdata.source !== "system" &&
105
105
  <a onClick={() => {
@@ -14,13 +14,28 @@
14
14
  align-items: center;
15
15
  margin: 10px 0px;
16
16
  }
17
- .deviceTopTitle{
17
+ .deviceTopTitle {
18
18
  display: flex;
19
19
  align-items: center;
20
- .deviceTopDivider{
20
+ .deviceTopDivider {
21
21
  flex: 1;
22
22
  }
23
- .deviceTopButton{
23
+ .deviceTopButton {
24
24
  margin: 0px 5px;
25
25
  }
26
- }
26
+ }
27
+ .deleteBox {
28
+ div {
29
+ margin-bottom: 5px;
30
+ display: flex;
31
+ span:first-child {
32
+ width: 80px;
33
+ text-align: right;
34
+ padding-right: 15px;
35
+ box-sizing: border-box;
36
+ }
37
+ div {
38
+ flex: 1;
39
+ }
40
+ }
41
+ }
@@ -26,7 +26,6 @@ import {
26
26
  roleUnboundAccounts,
27
27
  getRole,
28
28
  queryByKeyword,
29
- // getAuthTree,
30
29
  policyAuthorizePage,
31
30
  } from "./api";
32
31
  import "./index.scss";
@@ -41,9 +40,11 @@ export interface RoleInfoProps {
41
40
  tableData: boolean;
42
41
  };
43
42
  getAuthTree?: any;
43
+ empowerCom?: any;
44
+
44
45
  }
45
46
 
46
- export default function RoleInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
47
+ export default function RoleInfo({ isShowTab, getAuthTree , empowerCom}: RoleInfoProps) {
47
48
  const searchFormRef: any = useRef();
48
49
  const [roleCode, setRoleCode] = useState(getUrlParams("roleCode"));
49
50
  const [roleInfo, setRoleInfo]: any = useState({});
@@ -52,8 +53,10 @@ export default function RoleInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
52
53
 
53
54
  const [ResourceTableData, setResourceTableData]: any = useState([]); //关联资源
54
55
  const [isTableLoading, setisTableLoading] = useState(false);
55
- const [loading, setLoading] = useState(false)
56
-
56
+ const [loading, setLoading] = useState(false);
57
+ const [rowKeys, setRowKeys]: any = useState([]); //关联多选数据
58
+ const [selectedRowKeys, setselectedRowKeys]: any = useState([]);
59
+ const [defaultExpandedRowKeys, setdefaultExpandedRowKeys]: any = useState([]);
57
60
  const [TableItemData, setTableItemData]: any = useState([
58
61
  {
59
62
  key: "main",
@@ -172,6 +175,58 @@ export default function RoleInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
172
175
  return dayjs(text).format("YYYY-MM-DD HH:mm:ss") || "数据格式错误";
173
176
  },
174
177
  },
178
+ {
179
+ title: "操作",
180
+ width: 80,
181
+ fixed: "right",
182
+ render: (rowdata: any) => (
183
+ <Space>
184
+ <a
185
+ onClick={() => {
186
+ let data = [
187
+ {
188
+ groupId: rowdata?.groupId,
189
+ policyId: rowdata?.policyId,
190
+ subjectCode: rowdata?.subjectCode,
191
+ },
192
+ ];
193
+ Modal.confirm({
194
+ title: `确认解除指定的授权吗?`,
195
+ onOk: () => {
196
+ DeleteFunc(data);
197
+ },
198
+ content: (
199
+ <div className="deleteBox">
200
+ <div>
201
+ <span>授权主体:</span>
202
+ <div>{rowdata.subject}</div>
203
+ </div>
204
+ <div>
205
+ <span>权限策略:</span>
206
+ <div>{rowdata.policy}</div>
207
+ </div>
208
+ <div>
209
+ <span>资源组:</span>
210
+ <div>{rowdata.group}</div>
211
+ </div>
212
+ <div>
213
+ <span>授权时间:</span>
214
+ <div>
215
+ {dayjs(rowdata.gmtModified).format(
216
+ "YYYY-MM-DD HH:mm:ss",
217
+ )}
218
+ </div>
219
+ </div>
220
+ </div>
221
+ ),
222
+ });
223
+ }}
224
+ >
225
+ 解除授权
226
+ </a>
227
+ </Space>
228
+ ),
229
+ },
175
230
  ];
176
231
  useEffect(() => {
177
232
  init();
@@ -187,7 +242,7 @@ export default function RoleInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
187
242
  icon: <InteractionOutlined />,
188
243
  });
189
244
  }
190
- if (isShowTab?.tableEmpower) {
245
+ if (isShowTab?.tableEmpower && roleCode !== "admin") {
191
246
  data.push({
192
247
  label: "关联授权",
193
248
  key: "tableEmpower",
@@ -203,12 +258,12 @@ export default function RoleInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
203
258
  }
204
259
  setTableItemData([...TableItemData, ...data]);
205
260
  };
206
-
207
261
  const tabCheckFunc = () => {
208
262
  if (tabCheck == "tableEmpower") {
209
263
  policy?.execute({
210
264
  subjectCodes: [roleCode],
211
265
  }); // 获取授权策略
266
+ empowerCom?.empowerInit();
212
267
  } else if (tabCheck == "tableResource") {
213
268
  getAuthTreeFunc(); // 获取关联资源
214
269
  } else {
@@ -222,32 +277,43 @@ export default function RoleInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
222
277
  //获取关联资源
223
278
  const getAuthTreeFunc = () => {
224
279
  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
- });
280
+ getAuthTree &&
281
+ getAuthTree({
282
+ roleCode: roleCode,
283
+ }).then((res: any) => {
284
+ let listId :Array<[]>= []
285
+ let defaultRowKeys :Array<[]>= []
286
+ let {data,list,drkey}: any = resourceAction(res,listId,defaultRowKeys);
287
+ setselectedRowKeys(list)
288
+ setdefaultExpandedRowKeys(drkey)
289
+ setResourceTableData(data);
290
+ setisTableLoading(false);
291
+ });
232
292
  };
233
293
 
234
- const resourceAction: any = (data: any) => {
294
+ const resourceAction: any = (data: any,list:any,drkey:any) => {
235
295
  if (Object.prototype.toString.call(data) === "[object Array]") {
236
296
  data.map((item: any) => {
237
- return resourceAction(item);
297
+ return resourceAction(item,list,drkey);
238
298
  });
239
- return data;
299
+ return {
300
+ data,
301
+ list,
302
+ drkey
303
+ }
240
304
  } else if (Object.prototype.toString.call(data) === "[object Object]") {
241
305
  if (data.children && data.children.length !== 0) {
242
- return resourceAction(data.children);
306
+ drkey.push(data.id)
307
+ return resourceAction(data.children,list,drkey);
243
308
  } else {
244
309
  delete data.children;
310
+ if(data.checked)list.push(data.id)
311
+ drkey.push(data.id)
245
312
  return data;
246
313
  }
247
314
  }
248
315
  };
249
316
 
250
-
251
317
  const getRoleFunc = (data: any) => {
252
318
  setRoleInfo({});
253
319
  setLoading(true);
@@ -351,130 +417,190 @@ export default function RoleInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
351
417
  let policy = useTableHooks({
352
418
  asyncFunction: readDataListByPolicy,
353
419
  });
420
+ //批量解绑
421
+ const DeleteFunc = (authorizeList: any) => {
422
+ empowerCom?.RevokeFunc({ authorizeList }).then((res: any) => {
423
+ message.success("解除成功");
424
+ setRowKeys([]);
425
+ policy?.execute({ subjectCodes: [roleCode] });
426
+ });
427
+ };
354
428
 
355
429
  return (
356
430
  <PageContainer>
357
431
  <Spin spinning={loading}>
358
- <div className="deviceTopTitle">
432
+ <div className="deviceTopTitle">
359
433
  <div className="deviceTopDivider">
360
434
  <Divider orientation="left">{roleInfo?.roleName || "-"}</Divider>
361
435
  </div>
362
- <Button className="deviceTopButton" onClick={(() => {
436
+ <Button
437
+ className="deviceTopButton"
438
+ onClick={() => {
363
439
  getRoleFunc({ roleCode });
364
- })} >刷新</Button>
365
- </div>
366
- <Descriptions className="basicInfoWrap">
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>
382
- </Descriptions>
383
-
384
- <div>
385
- <Divider orientation="left">当前角色关联内容</Divider>
386
- <div className="jsonWarp">
387
- <Tabs
388
- onChange={(e) => {
389
- setTabCheck(e);
390
440
  }}
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
- />
441
+ >
442
+ 刷新
443
+ </Button>
444
+ </div>
445
+ <Descriptions className="basicInfoWrap">
446
+ <Descriptions.Item label="角色名称">
447
+ {roleInfo?.roleName || ""}
448
+ </Descriptions.Item>
449
+ <Descriptions.Item label="角色编码">
450
+ {roleInfo?.roleCode || ""}
451
+ </Descriptions.Item>
452
+ <Descriptions.Item label="角色描述">
453
+ {roleInfo?.description || ""}
454
+ </Descriptions.Item>
455
+ <Descriptions.Item label="创建时间">
456
+ {timeFormatter(roleInfo?.gmtCreate) || ""}
457
+ </Descriptions.Item>
458
+ <Descriptions.Item label="更新时间">
459
+ {timeFormatter(roleInfo?.gmtModified) || ""}
460
+ </Descriptions.Item>
461
+ </Descriptions>
425
462
 
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
- )}
463
+ <div>
464
+ <Divider orientation="left">当前角色关联内容</Divider>
465
+ <div className="jsonWarp">
466
+ <Tabs
467
+ onChange={(e) => {
468
+ setTabCheck(e);
469
+ }}
470
+ items={TableItemData}
471
+ />
472
+ {tabCheck == "main" && (
473
+ <>
474
+ <QueryFilter
475
+ style={{ padding: "0px" }}
476
+ size="middle"
477
+ onReset={handleOnReset}
478
+ onFinish={handleOnFinish}
479
+ >
480
+ <ProFormText name="keyword" label="关键词" />
481
+ </QueryFilter>
482
+ <ProTable
483
+ size="small"
484
+ dataSource={dataList}
485
+ loading={isLoading}
486
+ columns={columns}
487
+ rowKey="id"
488
+ options={{
489
+ reload: handleRoload,
490
+ }}
491
+ toolBarRender={() => {
492
+ return [
493
+ <Button
494
+ type="primary"
495
+ onClick={() => {
496
+ getQueryBoundRolesFunc();
497
+ }}
498
+ >
499
+ 添加账号
500
+ </Button>,
501
+ ];
502
+ }}
503
+ />
451
504
 
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" && <></>}
505
+ <Pagination
506
+ {...pagination}
507
+ onChange={(innerPageNo: number, innerPageSize: number) => {
508
+ execute({
509
+ innerPageNo,
510
+ innerPageSize,
511
+ roleCode: roleCode,
512
+ });
513
+ }}
514
+ />
515
+ </>
516
+ )}
517
+ {tabCheck == "tableResource" && (
518
+ <>
519
+ <Table
520
+ style={{ width: "100%" }}
521
+ size="small"
522
+ rowKey="id"
523
+ loading={isTableLoading}
524
+ pagination={false}
525
+ columns={TableResource}
526
+ dataSource={ResourceTableData || []}
527
+ rowSelection={{
528
+ selectedRowKeys:selectedRowKeys,
529
+ }}
530
+ expandable={{
531
+ expandedRowKeys:defaultExpandedRowKeys, //defaultExpandAllRows 无效
532
+ }}
533
+ />
534
+ </>
535
+ )}
536
+
537
+ {tabCheck == "tableEmpower" && (
538
+ <>
539
+ <div className="tableActionWarp">
540
+ <Button
541
+ size="middle"
542
+ type="primary"
543
+ onClick={() => {
544
+ console.log(empowerCom?.action);
545
+ empowerCom?.action?.editOpenStatus(true);
546
+ }}
547
+ >
548
+ 新增
549
+ </Button>
550
+ </div>
551
+ <Table
552
+ style={{ width: "100%" }}
553
+ size="small"
554
+ rowKey="id"
555
+ dataSource={policy?.dataList}
556
+ loading={policy?.isLoading}
557
+ columns={TablePolicy}
558
+ pagination={false}
559
+ rowSelection={{
560
+ type: "checkbox",
561
+ // selectedRowKeys: rowKeys,
562
+ onChange: (selectedRowKeys: any, list: any) => {
563
+ let data = list?.map((item: any) => {
564
+ return {
565
+ groupId: item?.groupId,
566
+ policyId: item?.policyId,
567
+ subjectCode: item?.subjectCode,
568
+ };
569
+ });
570
+ setRowKeys(data);
571
+ },
572
+ }}
573
+ />
574
+ <div className="paginBox">
575
+ <Button
576
+ disabled={rowKeys.length > 0 ? false : true}
577
+ onClick={() => {
578
+ Modal.confirm({
579
+ title: `确认批量解绑吗?`,
580
+ onOk: () => {
581
+ DeleteFunc(rowKeys);
582
+ },
583
+ });
584
+ }}
585
+ >
586
+ 批量解绑
587
+ </Button>
588
+ <Pagination
589
+ {...policy?.pagination}
590
+ onChange={(innerPageNo: number, innerPageSize: number) => {
591
+ policy?.execute({
592
+ innerPageNo,
593
+ innerPageSize,
594
+ subjectCodes: [roleCode],
595
+ });
596
+ }}
597
+ />
598
+ </div>
599
+ </>
600
+ )}
601
+ {tabCheck === "tableData" && <></>}
602
+ </div>
476
603
  </div>
477
- </div>
478
604
  </Spin>
479
605
  {/* */}
480
606
  <EditAccountDrawer
@@ -483,6 +609,15 @@ export default function RoleInfo({ isShowTab, getAuthTree }: RoleInfoProps) {
483
609
  roleBoundAccountsFunc={roleBoundAccountsFunc}
484
610
  queryByKeywordFunc={queryByKeywordFunc} //搜索事件
485
611
  ></EditAccountDrawer>
612
+ <empowerCom.drawer
613
+ {...empowerCom?.action}
614
+ actionFunc={(data: any) => {
615
+ return empowerCom?.action?.actionFunc(data).then(() => {
616
+ message.success("新增成功");
617
+ policy?.execute({ subjectCodes: [roleCode] });
618
+ });
619
+ }}
620
+ />
486
621
  </PageContainer>
487
622
  );
488
623
  }
package/src/index.tsx CHANGED
@@ -13,7 +13,7 @@ import request from './apiRequest/config'
13
13
  import iotRequest from './apiRequest/iotConfig'
14
14
  import { hosts } from './apiRequest/hosts'
15
15
  import CpcAccount from './components/universal-pages/cpcAccount' //cp列表c账号
16
- import cpcAccountInfo from './components/universal-pages/cpcAccountInfo' //cpc账号详情
16
+ import CpcAccountInfo from './components/universal-pages/cpcAccountInfo' //cpc账号详情
17
17
  import CpcRole from './components/universal-pages/cpcRole' //cpc 角色
18
18
  import CpcRoleInfo from './components/universal-pages/cpcRoleInfo' //cpc角色详情
19
19
  import { getUrlParams, downloadFile, timeFormatter } from './utils/index'
@@ -40,7 +40,7 @@ export {
40
40
  timeFormatter,
41
41
 
42
42
  CpcAccount,
43
- cpcAccountInfo,
43
+ CpcAccountInfo,
44
44
  CpcRole,
45
45
  CpcRoleInfo
46
46
  }