com-angel-authorization 1.0.16 → 1.0.17

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.
@@ -49,11 +49,13 @@ __export(vue_exports, {
49
49
  buildCreateBody: () => buildCreateBody,
50
50
  buildCreateMenuBody: () => buildCreateMenuBody,
51
51
  buildCreateRoleBody: () => buildCreateRoleBody,
52
+ buildPermissionTreeIndex: () => buildPermissionTreeIndex,
52
53
  buildSavePermissionsBody: () => buildSavePermissionsBody,
53
54
  buildUpdateBody: () => buildUpdateBody,
54
55
  buildUpdateMenuBody: () => buildUpdateMenuBody,
55
56
  buildUpdateRoleBody: () => buildUpdateRoleBody,
56
57
  collectTreeResourceIds: () => collectTreeResourceIds,
58
+ countCheckedDescendants: () => countCheckedDescendants,
57
59
  createAuthorizationResourceApi: () => createAuthorizationResourceApi,
58
60
  createDefaultResourceRequest: () => createDefaultResourceRequest,
59
61
  createMenuResourceApi: () => createMenuResourceApi,
@@ -65,7 +67,9 @@ __export(vue_exports, {
65
67
  extractRecords: () => extractRecords,
66
68
  getAppClientId: () => getAppClientId,
67
69
  getDeviceWorkerId: () => getDeviceWorkerId,
70
+ hasCheckedDescendant: () => hasCheckedDescendant,
68
71
  isMenuLeaf: () => isMenuLeaf,
72
+ isPermissionNodeIndeterminate: () => isPermissionNodeIndeterminate,
69
73
  mapAuthorizationResource: () => mapAuthorizationResource,
70
74
  mapMenuResource: () => mapMenuResource,
71
75
  mapPermissionTreeNode: () => mapPermissionTreeNode,
@@ -73,6 +77,7 @@ __export(vue_exports, {
73
77
  mapSystemRole: () => mapSystemRole,
74
78
  resolveMenuDepth: () => resolveMenuDepth,
75
79
  snowyflake: () => snowyflake,
80
+ togglePermissionCheck: () => togglePermissionCheck,
76
81
  useHasPermission: () => useHasPermission,
77
82
  useHasRole: () => useHasRole,
78
83
  usePermission: () => usePermission
@@ -2447,6 +2452,72 @@ function mapRolePermissions(payload) {
2447
2452
  function collectTreeResourceIds(node) {
2448
2453
  return [node.resourceId, ...node.children.flatMap(collectTreeResourceIds)];
2449
2454
  }
2455
+ function buildPermissionTreeIndex(tree) {
2456
+ const parentMap = /* @__PURE__ */ new Map();
2457
+ const nodeMap = /* @__PURE__ */ new Map();
2458
+ const walk = (nodes, parentId) => {
2459
+ for (const node of nodes) {
2460
+ parentMap.set(node.resourceId, parentId);
2461
+ nodeMap.set(node.resourceId, node);
2462
+ if (node.children.length > 0) {
2463
+ walk(node.children, node.resourceId);
2464
+ }
2465
+ }
2466
+ };
2467
+ walk(tree, null);
2468
+ return { parentMap, nodeMap };
2469
+ }
2470
+ function togglePermissionCheck(tree, checked, node) {
2471
+ const next = new Set(checked);
2472
+ const ids = collectTreeResourceIds(node);
2473
+ const shouldCheck = !checked.has(node.resourceId);
2474
+ if (shouldCheck) {
2475
+ ids.forEach((id) => next.add(id));
2476
+ } else {
2477
+ ids.forEach((id) => next.delete(id));
2478
+ }
2479
+ const { parentMap, nodeMap } = buildPermissionTreeIndex(tree);
2480
+ let parentId = parentMap.get(node.resourceId) ?? null;
2481
+ while (parentId) {
2482
+ const parent = nodeMap.get(parentId);
2483
+ if (!parent) break;
2484
+ const allChildrenChecked = parent.children.every(
2485
+ (child) => next.has(child.resourceId)
2486
+ );
2487
+ if (allChildrenChecked && parent.children.length > 0) {
2488
+ next.add(parentId);
2489
+ } else {
2490
+ next.delete(parentId);
2491
+ }
2492
+ parentId = parentMap.get(parentId) ?? null;
2493
+ }
2494
+ return next;
2495
+ }
2496
+ function countCheckedDescendants(node, checked) {
2497
+ let total = 0;
2498
+ let checkedCount = 0;
2499
+ const walk = (n) => {
2500
+ for (const child of n.children) {
2501
+ total += 1;
2502
+ if (checked.has(child.resourceId)) checkedCount += 1;
2503
+ walk(child);
2504
+ }
2505
+ };
2506
+ walk(node);
2507
+ return { total, checkedCount };
2508
+ }
2509
+ function hasCheckedDescendant(node, checked) {
2510
+ for (const child of node.children) {
2511
+ if (checked.has(child.resourceId) || hasCheckedDescendant(child, checked)) {
2512
+ return true;
2513
+ }
2514
+ }
2515
+ return false;
2516
+ }
2517
+ function isPermissionNodeIndeterminate(node, checked) {
2518
+ if (checked.has(node.resourceId) || node.children.length === 0) return false;
2519
+ return hasCheckedDescendant(node, checked);
2520
+ }
2450
2521
  function buildListUrl2(params) {
2451
2522
  const parts = [];
2452
2523
  appendQueryParam(parts, "keyword", params?.keyword ?? "");
@@ -2536,19 +2607,6 @@ function emptyForm3() {
2536
2607
  description: ""
2537
2608
  };
2538
2609
  }
2539
- function countCheckedDescendants(node, checked) {
2540
- let total = 0;
2541
- let checkedCount = 0;
2542
- const walk = (n) => {
2543
- for (const child of n.children) {
2544
- total += 1;
2545
- if (checked.has(child.resourceId)) checkedCount += 1;
2546
- walk(child);
2547
- }
2548
- };
2549
- walk(node);
2550
- return { total, checkedCount };
2551
- }
2552
2610
  var s3 = {
2553
2611
  root: {
2554
2612
  display: "flex",
@@ -2954,15 +3012,11 @@ var RoleManager = (0, import_vue5.defineComponent)({
2954
3012
  };
2955
3013
  }
2956
3014
  function toggleCheck(node) {
2957
- const next = new Set(authChecked.value);
2958
- const ids = collectTreeResourceIds(node);
2959
- const shouldCheck = !authChecked.value.has(node.resourceId);
2960
- if (shouldCheck) {
2961
- ids.forEach((id) => next.add(id));
2962
- } else {
2963
- ids.forEach((id) => next.delete(id));
2964
- }
2965
- authChecked.value = next;
3015
+ authChecked.value = togglePermissionCheck(
3016
+ authTree.value,
3017
+ authChecked.value,
3018
+ node
3019
+ );
2966
3020
  }
2967
3021
  async function saveAuthorize() {
2968
3022
  if (!authRole.value) return;
@@ -2985,11 +3039,10 @@ var RoleManager = (0, import_vue5.defineComponent)({
2985
3039
  const hasChildren = node.children.length > 0;
2986
3040
  const expanded = Boolean(authExpanded.value[node.resourceId]);
2987
3041
  const checked = authChecked.value.has(node.resourceId);
2988
- const { total, checkedCount } = countCheckedDescendants(
3042
+ const indeterminate = isPermissionNodeIndeterminate(
2989
3043
  node,
2990
3044
  authChecked.value
2991
3045
  );
2992
- const indeterminate = hasChildren && checkedCount > 0 && checkedCount < total && !checked;
2993
3046
  return (0, import_vue5.h)("div", { key: node.resourceId }, [
2994
3047
  (0, import_vue5.h)(
2995
3048
  "div",
@@ -3596,11 +3649,13 @@ var SystemAdmin = (0, import_vue6.defineComponent)({
3596
3649
  buildCreateBody,
3597
3650
  buildCreateMenuBody,
3598
3651
  buildCreateRoleBody,
3652
+ buildPermissionTreeIndex,
3599
3653
  buildSavePermissionsBody,
3600
3654
  buildUpdateBody,
3601
3655
  buildUpdateMenuBody,
3602
3656
  buildUpdateRoleBody,
3603
3657
  collectTreeResourceIds,
3658
+ countCheckedDescendants,
3604
3659
  createAuthorizationResourceApi,
3605
3660
  createDefaultResourceRequest,
3606
3661
  createMenuResourceApi,
@@ -3612,7 +3667,9 @@ var SystemAdmin = (0, import_vue6.defineComponent)({
3612
3667
  extractRecords,
3613
3668
  getAppClientId,
3614
3669
  getDeviceWorkerId,
3670
+ hasCheckedDescendant,
3615
3671
  isMenuLeaf,
3672
+ isPermissionNodeIndeterminate,
3616
3673
  mapAuthorizationResource,
3617
3674
  mapMenuResource,
3618
3675
  mapPermissionTreeNode,
@@ -3620,6 +3677,7 @@ var SystemAdmin = (0, import_vue6.defineComponent)({
3620
3677
  mapSystemRole,
3621
3678
  resolveMenuDepth,
3622
3679
  snowyflake,
3680
+ togglePermissionCheck,
3623
3681
  useHasPermission,
3624
3682
  useHasRole,
3625
3683
  usePermission