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.
@@ -499,6 +499,27 @@ declare function mapPermissionTreeNode(item: unknown): RolePermissionTreeNode |
499
499
  declare function mapRolePermissions(payload: unknown): RolePermissionsResult;
500
500
  /** 收集节点及其全部子孙 resourceId */
501
501
  declare function collectTreeResourceIds(node: RolePermissionTreeNode): string[];
502
+ type PermissionTreeIndex = {
503
+ parentMap: Map<string, string | null>;
504
+ nodeMap: Map<string, RolePermissionTreeNode>;
505
+ };
506
+ /** 建立父节点索引,供父子联动向上回写 */
507
+ declare function buildPermissionTreeIndex(tree: RolePermissionTreeNode[]): PermissionTreeIndex;
508
+ /**
509
+ * 父子联动勾选:
510
+ * - 勾选:当前节点 + 全部子孙选中,并向上:子节点全选则父节点选中
511
+ * - 取消:当前节点 + 全部子孙取消,并向上:任一子未选则父节点取消(半选由 UI 展示)
512
+ */
513
+ declare function togglePermissionCheck(tree: RolePermissionTreeNode[], checked: ReadonlySet<string>, node: RolePermissionTreeNode): Set<string>;
514
+ /** 子孙勾选统计(不含自身),用于半选态 */
515
+ declare function countCheckedDescendants(node: RolePermissionTreeNode, checked: ReadonlySet<string>): {
516
+ total: number;
517
+ checkedCount: number;
518
+ };
519
+ /** 是否存在已勾选的子孙节点 */
520
+ declare function hasCheckedDescendant(node: RolePermissionTreeNode, checked: ReadonlySet<string>): boolean;
521
+ /** 半选:自身未勾选,但存在已勾选的子孙 */
522
+ declare function isPermissionNodeIndeterminate(node: RolePermissionTreeNode, checked: ReadonlySet<string>): boolean;
502
523
  declare function buildCreateRoleBody(values: SystemRoleFormValues): CreateSystemRoleBody;
503
524
  declare function buildUpdateRoleBody(values: SystemRoleFormValues): UpdateSystemRoleBody;
504
525
  declare function buildSavePermissionsBody(resourceIds: string[]): SaveRolePermissionsBody;
@@ -651,4 +672,4 @@ declare const snowyflake: ConfigurableSnowflake;
651
672
  declare function getAppClientId(): string;
652
673
  declare function getDeviceWorkerId(): string;
653
674
 
654
- export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type CreateMenuResourceBody, type CreateSystemRoleBody, type FetchAuthorizationResourcesParams, type FetchMenuResourcesParams, type FetchSystemRolesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, MENU_LEAF_NO, MENU_LEAF_YES, MENU_LIST_TYPE_PARAM, MENU_TYPE_BUTTON, MENU_TYPE_LABEL, MENU_TYPE_MENU, MENU_TYPE_OPTIONS, MENU_TYPE_PAGE, MENU_VISIBILITY_OPTIONS, type MatchMode, MenuManager, type MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, PERMISSION_STORE_KEY, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionDirectiveValue, type PermissionListener, type PermissionPluginOptions, type PermissionState, PermissionStore, type PermissionStoreAPI, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, ROOT_MENU_DEPTH, ROOT_PARENT_ID, type ResourceHttpRequest, ResourceManager, type ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, RoleManager, type RolePermissionTreeNode, type RolePermissionsResult, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, type SaveRolePermissionsBody, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminSubMenu, type SystemRole, type SystemRoleApi, type SystemRoleFormValues, type SystemRoleListResult, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UpdateSystemRoleBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildCreateRoleBody, buildSavePermissionsBody, buildUpdateBody, buildUpdateMenuBody, buildUpdateRoleBody, collectTreeResourceIds, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionPlugin, createPermissionStore, createSystemRoleApi, createVPermission, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, isMenuLeaf, mapAuthorizationResource, mapMenuResource, mapPermissionTreeNode, mapRolePermissions, mapSystemRole, resolveMenuDepth, snowyflake, useHasPermission, useHasRole, usePermission };
675
+ export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type CreateMenuResourceBody, type CreateSystemRoleBody, type FetchAuthorizationResourcesParams, type FetchMenuResourcesParams, type FetchSystemRolesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, MENU_LEAF_NO, MENU_LEAF_YES, MENU_LIST_TYPE_PARAM, MENU_TYPE_BUTTON, MENU_TYPE_LABEL, MENU_TYPE_MENU, MENU_TYPE_OPTIONS, MENU_TYPE_PAGE, MENU_VISIBILITY_OPTIONS, type MatchMode, MenuManager, type MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, PERMISSION_STORE_KEY, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionDirectiveValue, type PermissionListener, type PermissionPluginOptions, type PermissionState, PermissionStore, type PermissionStoreAPI, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, ROOT_MENU_DEPTH, ROOT_PARENT_ID, type ResourceHttpRequest, ResourceManager, type ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, RoleManager, type RolePermissionTreeNode, type RolePermissionsResult, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, type SaveRolePermissionsBody, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminSubMenu, type SystemRole, type SystemRoleApi, type SystemRoleFormValues, type SystemRoleListResult, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UpdateSystemRoleBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildCreateRoleBody, buildPermissionTreeIndex, buildSavePermissionsBody, buildUpdateBody, buildUpdateMenuBody, buildUpdateRoleBody, collectTreeResourceIds, countCheckedDescendants, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionPlugin, createPermissionStore, createSystemRoleApi, createVPermission, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, hasCheckedDescendant, isMenuLeaf, isPermissionNodeIndeterminate, mapAuthorizationResource, mapMenuResource, mapPermissionTreeNode, mapRolePermissions, mapSystemRole, resolveMenuDepth, snowyflake, togglePermissionCheck, useHasPermission, useHasRole, usePermission };
@@ -499,6 +499,27 @@ declare function mapPermissionTreeNode(item: unknown): RolePermissionTreeNode |
499
499
  declare function mapRolePermissions(payload: unknown): RolePermissionsResult;
500
500
  /** 收集节点及其全部子孙 resourceId */
501
501
  declare function collectTreeResourceIds(node: RolePermissionTreeNode): string[];
502
+ type PermissionTreeIndex = {
503
+ parentMap: Map<string, string | null>;
504
+ nodeMap: Map<string, RolePermissionTreeNode>;
505
+ };
506
+ /** 建立父节点索引,供父子联动向上回写 */
507
+ declare function buildPermissionTreeIndex(tree: RolePermissionTreeNode[]): PermissionTreeIndex;
508
+ /**
509
+ * 父子联动勾选:
510
+ * - 勾选:当前节点 + 全部子孙选中,并向上:子节点全选则父节点选中
511
+ * - 取消:当前节点 + 全部子孙取消,并向上:任一子未选则父节点取消(半选由 UI 展示)
512
+ */
513
+ declare function togglePermissionCheck(tree: RolePermissionTreeNode[], checked: ReadonlySet<string>, node: RolePermissionTreeNode): Set<string>;
514
+ /** 子孙勾选统计(不含自身),用于半选态 */
515
+ declare function countCheckedDescendants(node: RolePermissionTreeNode, checked: ReadonlySet<string>): {
516
+ total: number;
517
+ checkedCount: number;
518
+ };
519
+ /** 是否存在已勾选的子孙节点 */
520
+ declare function hasCheckedDescendant(node: RolePermissionTreeNode, checked: ReadonlySet<string>): boolean;
521
+ /** 半选:自身未勾选,但存在已勾选的子孙 */
522
+ declare function isPermissionNodeIndeterminate(node: RolePermissionTreeNode, checked: ReadonlySet<string>): boolean;
502
523
  declare function buildCreateRoleBody(values: SystemRoleFormValues): CreateSystemRoleBody;
503
524
  declare function buildUpdateRoleBody(values: SystemRoleFormValues): UpdateSystemRoleBody;
504
525
  declare function buildSavePermissionsBody(resourceIds: string[]): SaveRolePermissionsBody;
@@ -651,4 +672,4 @@ declare const snowyflake: ConfigurableSnowflake;
651
672
  declare function getAppClientId(): string;
652
673
  declare function getDeviceWorkerId(): string;
653
674
 
654
- export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type CreateMenuResourceBody, type CreateSystemRoleBody, type FetchAuthorizationResourcesParams, type FetchMenuResourcesParams, type FetchSystemRolesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, MENU_LEAF_NO, MENU_LEAF_YES, MENU_LIST_TYPE_PARAM, MENU_TYPE_BUTTON, MENU_TYPE_LABEL, MENU_TYPE_MENU, MENU_TYPE_OPTIONS, MENU_TYPE_PAGE, MENU_VISIBILITY_OPTIONS, type MatchMode, MenuManager, type MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, PERMISSION_STORE_KEY, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionDirectiveValue, type PermissionListener, type PermissionPluginOptions, type PermissionState, PermissionStore, type PermissionStoreAPI, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, ROOT_MENU_DEPTH, ROOT_PARENT_ID, type ResourceHttpRequest, ResourceManager, type ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, RoleManager, type RolePermissionTreeNode, type RolePermissionsResult, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, type SaveRolePermissionsBody, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminSubMenu, type SystemRole, type SystemRoleApi, type SystemRoleFormValues, type SystemRoleListResult, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UpdateSystemRoleBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildCreateRoleBody, buildSavePermissionsBody, buildUpdateBody, buildUpdateMenuBody, buildUpdateRoleBody, collectTreeResourceIds, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionPlugin, createPermissionStore, createSystemRoleApi, createVPermission, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, isMenuLeaf, mapAuthorizationResource, mapMenuResource, mapPermissionTreeNode, mapRolePermissions, mapSystemRole, resolveMenuDepth, snowyflake, useHasPermission, useHasRole, usePermission };
675
+ export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type CreateMenuResourceBody, type CreateSystemRoleBody, type FetchAuthorizationResourcesParams, type FetchMenuResourcesParams, type FetchSystemRolesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, MENU_LEAF_NO, MENU_LEAF_YES, MENU_LIST_TYPE_PARAM, MENU_TYPE_BUTTON, MENU_TYPE_LABEL, MENU_TYPE_MENU, MENU_TYPE_OPTIONS, MENU_TYPE_PAGE, MENU_VISIBILITY_OPTIONS, type MatchMode, MenuManager, type MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, PERMISSION_STORE_KEY, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionDirectiveValue, type PermissionListener, type PermissionPluginOptions, type PermissionState, PermissionStore, type PermissionStoreAPI, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, ROOT_MENU_DEPTH, ROOT_PARENT_ID, type ResourceHttpRequest, ResourceManager, type ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, RoleManager, type RolePermissionTreeNode, type RolePermissionsResult, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, type SaveRolePermissionsBody, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminSubMenu, type SystemRole, type SystemRoleApi, type SystemRoleFormValues, type SystemRoleListResult, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UpdateSystemRoleBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildCreateRoleBody, buildPermissionTreeIndex, buildSavePermissionsBody, buildUpdateBody, buildUpdateMenuBody, buildUpdateRoleBody, collectTreeResourceIds, countCheckedDescendants, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionPlugin, createPermissionStore, createSystemRoleApi, createVPermission, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, hasCheckedDescendant, isMenuLeaf, isPermissionNodeIndeterminate, mapAuthorizationResource, mapMenuResource, mapPermissionTreeNode, mapRolePermissions, mapSystemRole, resolveMenuDepth, snowyflake, togglePermissionCheck, useHasPermission, useHasRole, usePermission };
package/dist/vue/index.js CHANGED
@@ -2393,6 +2393,72 @@ function mapRolePermissions(payload) {
2393
2393
  function collectTreeResourceIds(node) {
2394
2394
  return [node.resourceId, ...node.children.flatMap(collectTreeResourceIds)];
2395
2395
  }
2396
+ function buildPermissionTreeIndex(tree) {
2397
+ const parentMap = /* @__PURE__ */ new Map();
2398
+ const nodeMap = /* @__PURE__ */ new Map();
2399
+ const walk = (nodes, parentId) => {
2400
+ for (const node of nodes) {
2401
+ parentMap.set(node.resourceId, parentId);
2402
+ nodeMap.set(node.resourceId, node);
2403
+ if (node.children.length > 0) {
2404
+ walk(node.children, node.resourceId);
2405
+ }
2406
+ }
2407
+ };
2408
+ walk(tree, null);
2409
+ return { parentMap, nodeMap };
2410
+ }
2411
+ function togglePermissionCheck(tree, checked, node) {
2412
+ const next = new Set(checked);
2413
+ const ids = collectTreeResourceIds(node);
2414
+ const shouldCheck = !checked.has(node.resourceId);
2415
+ if (shouldCheck) {
2416
+ ids.forEach((id) => next.add(id));
2417
+ } else {
2418
+ ids.forEach((id) => next.delete(id));
2419
+ }
2420
+ const { parentMap, nodeMap } = buildPermissionTreeIndex(tree);
2421
+ let parentId = parentMap.get(node.resourceId) ?? null;
2422
+ while (parentId) {
2423
+ const parent = nodeMap.get(parentId);
2424
+ if (!parent) break;
2425
+ const allChildrenChecked = parent.children.every(
2426
+ (child) => next.has(child.resourceId)
2427
+ );
2428
+ if (allChildrenChecked && parent.children.length > 0) {
2429
+ next.add(parentId);
2430
+ } else {
2431
+ next.delete(parentId);
2432
+ }
2433
+ parentId = parentMap.get(parentId) ?? null;
2434
+ }
2435
+ return next;
2436
+ }
2437
+ function countCheckedDescendants(node, checked) {
2438
+ let total = 0;
2439
+ let checkedCount = 0;
2440
+ const walk = (n) => {
2441
+ for (const child of n.children) {
2442
+ total += 1;
2443
+ if (checked.has(child.resourceId)) checkedCount += 1;
2444
+ walk(child);
2445
+ }
2446
+ };
2447
+ walk(node);
2448
+ return { total, checkedCount };
2449
+ }
2450
+ function hasCheckedDescendant(node, checked) {
2451
+ for (const child of node.children) {
2452
+ if (checked.has(child.resourceId) || hasCheckedDescendant(child, checked)) {
2453
+ return true;
2454
+ }
2455
+ }
2456
+ return false;
2457
+ }
2458
+ function isPermissionNodeIndeterminate(node, checked) {
2459
+ if (checked.has(node.resourceId) || node.children.length === 0) return false;
2460
+ return hasCheckedDescendant(node, checked);
2461
+ }
2396
2462
  function buildListUrl2(params) {
2397
2463
  const parts = [];
2398
2464
  appendQueryParam(parts, "keyword", params?.keyword ?? "");
@@ -2482,19 +2548,6 @@ function emptyForm3() {
2482
2548
  description: ""
2483
2549
  };
2484
2550
  }
2485
- function countCheckedDescendants(node, checked) {
2486
- let total = 0;
2487
- let checkedCount = 0;
2488
- const walk = (n) => {
2489
- for (const child of n.children) {
2490
- total += 1;
2491
- if (checked.has(child.resourceId)) checkedCount += 1;
2492
- walk(child);
2493
- }
2494
- };
2495
- walk(node);
2496
- return { total, checkedCount };
2497
- }
2498
2551
  var s3 = {
2499
2552
  root: {
2500
2553
  display: "flex",
@@ -2900,15 +2953,11 @@ var RoleManager = defineComponent4({
2900
2953
  };
2901
2954
  }
2902
2955
  function toggleCheck(node) {
2903
- const next = new Set(authChecked.value);
2904
- const ids = collectTreeResourceIds(node);
2905
- const shouldCheck = !authChecked.value.has(node.resourceId);
2906
- if (shouldCheck) {
2907
- ids.forEach((id) => next.add(id));
2908
- } else {
2909
- ids.forEach((id) => next.delete(id));
2910
- }
2911
- authChecked.value = next;
2956
+ authChecked.value = togglePermissionCheck(
2957
+ authTree.value,
2958
+ authChecked.value,
2959
+ node
2960
+ );
2912
2961
  }
2913
2962
  async function saveAuthorize() {
2914
2963
  if (!authRole.value) return;
@@ -2931,11 +2980,10 @@ var RoleManager = defineComponent4({
2931
2980
  const hasChildren = node.children.length > 0;
2932
2981
  const expanded = Boolean(authExpanded.value[node.resourceId]);
2933
2982
  const checked = authChecked.value.has(node.resourceId);
2934
- const { total, checkedCount } = countCheckedDescendants(
2983
+ const indeterminate = isPermissionNodeIndeterminate(
2935
2984
  node,
2936
2985
  authChecked.value
2937
2986
  );
2938
- const indeterminate = hasChildren && checkedCount > 0 && checkedCount < total && !checked;
2939
2987
  return h3("div", { key: node.resourceId }, [
2940
2988
  h3(
2941
2989
  "div",
@@ -3541,11 +3589,13 @@ export {
3541
3589
  buildCreateBody,
3542
3590
  buildCreateMenuBody,
3543
3591
  buildCreateRoleBody,
3592
+ buildPermissionTreeIndex,
3544
3593
  buildSavePermissionsBody,
3545
3594
  buildUpdateBody,
3546
3595
  buildUpdateMenuBody,
3547
3596
  buildUpdateRoleBody,
3548
3597
  collectTreeResourceIds,
3598
+ countCheckedDescendants,
3549
3599
  createAuthorizationResourceApi,
3550
3600
  createDefaultResourceRequest,
3551
3601
  createMenuResourceApi,
@@ -3557,7 +3607,9 @@ export {
3557
3607
  extractRecords,
3558
3608
  getAppClientId,
3559
3609
  getDeviceWorkerId,
3610
+ hasCheckedDescendant,
3560
3611
  isMenuLeaf,
3612
+ isPermissionNodeIndeterminate,
3561
3613
  mapAuthorizationResource,
3562
3614
  mapMenuResource,
3563
3615
  mapPermissionTreeNode,
@@ -3565,6 +3617,7 @@ export {
3565
3617
  mapSystemRole,
3566
3618
  resolveMenuDepth,
3567
3619
  snowyflake,
3620
+ togglePermissionCheck,
3568
3621
  useHasPermission,
3569
3622
  useHasRole,
3570
3623
  usePermission