@mu-cabin/opms-permission 0.9.21 → 0.9.23

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.
package/dist/index.cjs CHANGED
@@ -32,6 +32,7 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  ApiClient: () => ApiClient,
34
34
  DataHandler: () => DataHandler,
35
+ EnumOrgBindType: () => EnumOrgBindType,
35
36
  EnumOrgQueryMode: () => EnumOrgQueryMode,
36
37
  EnumOrgQueryScope: () => EnumOrgQueryScope,
37
38
  EventEmitter: () => EventEmitter,
@@ -288,6 +289,70 @@ function handlePermissionTree(data, key) {
288
289
  noAuthMap
289
290
  };
290
291
  }
292
+ var filterTreeByOrgCodes = (tree, orgCodes) => {
293
+ if (!orgCodes.length) return [];
294
+ const result = [];
295
+ const containsTargetCode = (node) => {
296
+ if (orgCodes.includes(node.value)) return true;
297
+ if (node.children) {
298
+ return node.children.some(containsTargetCode);
299
+ }
300
+ return false;
301
+ };
302
+ const hasTargetDescendants = (node) => {
303
+ if (!node.children) return false;
304
+ return node.children.some((child) => {
305
+ return orgCodes.includes(child.value) || hasTargetDescendants(child);
306
+ });
307
+ };
308
+ const shouldDisableNode = (node) => {
309
+ const isTarget = orgCodes.includes(node.value);
310
+ if (!isTarget) return true;
311
+ return hasTargetDescendants(node);
312
+ };
313
+ const buildPathToTargets = (node) => {
314
+ const isTarget = orgCodes.includes(node.value);
315
+ const hasTargetChildren = node.children ? node.children.some(containsTargetCode) : false;
316
+ if (isTarget || hasTargetChildren) {
317
+ const processedChildren = node.children ? node.children.map((child) => buildPathToTargets(child)).filter(
318
+ (childSubtree) => childSubtree !== null
319
+ ) : void 0;
320
+ return {
321
+ ...node,
322
+ // 根据优化规则设置禁用状态
323
+ disabled: shouldDisableNode(node),
324
+ // 只包含目标节点或通往目标的路径节点的子节点
325
+ children: processedChildren || []
326
+ };
327
+ }
328
+ return null;
329
+ };
330
+ tree.forEach((node) => {
331
+ if (containsTargetCode(node)) {
332
+ const processedSubtree = buildPathToTargets(node);
333
+ if (processedSubtree) {
334
+ result.push(processedSubtree);
335
+ }
336
+ }
337
+ });
338
+ return result;
339
+ };
340
+ var excludeTreeByOrgCodes = (tree, excludeCodes) => {
341
+ if (excludeCodes.length === 0) {
342
+ return tree;
343
+ }
344
+ const removeExcludedNodes = (nodes) => {
345
+ return nodes.filter((node) => !excludeCodes.includes(node.value)).map((node) => {
346
+ const processedChildren = node.children ? removeExcludedNodes(node.children) : [];
347
+ return {
348
+ ...node,
349
+ // 递归处理子节点
350
+ children: processedChildren
351
+ };
352
+ });
353
+ };
354
+ return removeExcludedNodes(tree);
355
+ };
291
356
 
292
357
  // src/config.ts
293
358
  var USER_INFO_KEY = "opms_user_info";
@@ -487,6 +552,11 @@ var ApiClient = class {
487
552
  );
488
553
  }
489
554
  };
555
+ var EnumOrgBindType = /* @__PURE__ */ ((EnumOrgBindType2) => {
556
+ EnumOrgBindType2["PRIMARY"] = "PRIMARY";
557
+ EnumOrgBindType2["SECONDARY"] = "SECONDARY";
558
+ return EnumOrgBindType2;
559
+ })(EnumOrgBindType || {});
490
560
  var EnumOrgQueryMode = /* @__PURE__ */ ((EnumOrgQueryMode2) => {
491
561
  EnumOrgQueryMode2["BY_ROLES"] = "BY_ROLES";
492
562
  EnumOrgQueryMode2["BY_DEPT"] = "BY_DEPT";
@@ -559,7 +629,9 @@ var DataHandler = {
559
629
  return findFirstEnableCode(orgTree) ?? "";
560
630
  },
561
631
  findFirstEnableNode,
562
- handlePermissionTree
632
+ handlePermissionTree,
633
+ filterTreeByOrgCodes,
634
+ excludeTreeByOrgCodes
563
635
  };
564
636
  var Permission = class {
565
637
  constructor(options) {
@@ -1005,6 +1077,7 @@ function jumpToSSOLogout({
1005
1077
  0 && (module.exports = {
1006
1078
  ApiClient,
1007
1079
  DataHandler,
1080
+ EnumOrgBindType,
1008
1081
  EnumOrgQueryMode,
1009
1082
  EnumOrgQueryScope,
1010
1083
  EventEmitter,
package/dist/index.d.mts CHANGED
@@ -131,6 +131,10 @@ interface OrgRecord$1 {
131
131
  children?: OrgRecord$1[];
132
132
  orgQueryMode?: EnumOrgQueryMode;
133
133
  }
134
+ declare enum EnumOrgBindType {
135
+ PRIMARY = "PRIMARY",
136
+ SECONDARY = "SECONDARY"
137
+ }
134
138
  interface UserOrganization$1 {
135
139
  orgId: number;
136
140
  orgCode: string;
@@ -144,7 +148,7 @@ interface UserOrganization$1 {
144
148
  showOrder: number | null;
145
149
  orgCodeSearchPath: string;
146
150
  positionInfo: any[];
147
- orgBindType: string;
151
+ orgBindType: keyof typeof EnumOrgBindType;
148
152
  csmOrgCode: string | null;
149
153
  hasPermission: boolean;
150
154
  canModify: boolean;
@@ -389,6 +393,8 @@ declare const DataHandler: {
389
393
  getFirstUnitOrgCode(orgTree: OrgTreeItem[]): string;
390
394
  findFirstEnableNode: typeof findFirstEnableNode;
391
395
  handlePermissionTree: typeof handlePermissionTree;
396
+ filterTreeByOrgCodes: (tree: OrgTreeItem[], orgCodes: string[]) => OrgTreeItem[];
397
+ excludeTreeByOrgCodes: (tree: OrgTreeItem[], excludeCodes: string[]) => OrgTreeItem[];
392
398
  };
393
399
  declare class Permission {
394
400
  private systemId;
@@ -553,4 +559,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
553
559
  clientId?: string;
554
560
  }): void;
555
561
 
556
- export { ApiClient, type ApiResponse, type BaseListResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type OpmsUserInfo, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, type QueryUserInfoParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, type SearchUserInfoPageParams, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_ORG_NO_AUTH_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, jumpToSSOLogin, jumpToSSOLogout };
562
+ export { ApiClient, type ApiResponse, type BaseListResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgBindType, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type OpmsUserInfo, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, type QueryUserInfoParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, type SearchUserInfoPageParams, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_ORG_NO_AUTH_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, jumpToSSOLogin, jumpToSSOLogout };
package/dist/index.d.ts CHANGED
@@ -131,6 +131,10 @@ interface OrgRecord$1 {
131
131
  children?: OrgRecord$1[];
132
132
  orgQueryMode?: EnumOrgQueryMode;
133
133
  }
134
+ declare enum EnumOrgBindType {
135
+ PRIMARY = "PRIMARY",
136
+ SECONDARY = "SECONDARY"
137
+ }
134
138
  interface UserOrganization$1 {
135
139
  orgId: number;
136
140
  orgCode: string;
@@ -144,7 +148,7 @@ interface UserOrganization$1 {
144
148
  showOrder: number | null;
145
149
  orgCodeSearchPath: string;
146
150
  positionInfo: any[];
147
- orgBindType: string;
151
+ orgBindType: keyof typeof EnumOrgBindType;
148
152
  csmOrgCode: string | null;
149
153
  hasPermission: boolean;
150
154
  canModify: boolean;
@@ -389,6 +393,8 @@ declare const DataHandler: {
389
393
  getFirstUnitOrgCode(orgTree: OrgTreeItem[]): string;
390
394
  findFirstEnableNode: typeof findFirstEnableNode;
391
395
  handlePermissionTree: typeof handlePermissionTree;
396
+ filterTreeByOrgCodes: (tree: OrgTreeItem[], orgCodes: string[]) => OrgTreeItem[];
397
+ excludeTreeByOrgCodes: (tree: OrgTreeItem[], excludeCodes: string[]) => OrgTreeItem[];
392
398
  };
393
399
  declare class Permission {
394
400
  private systemId;
@@ -553,4 +559,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
553
559
  clientId?: string;
554
560
  }): void;
555
561
 
556
- export { ApiClient, type ApiResponse, type BaseListResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type OpmsUserInfo, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, type QueryUserInfoParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, type SearchUserInfoPageParams, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_ORG_NO_AUTH_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, jumpToSSOLogin, jumpToSSOLogout };
562
+ export { ApiClient, type ApiResponse, type BaseListResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgBindType, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type OpmsUserInfo, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, type QueryUserInfoParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, type SearchUserInfoPageParams, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_ORG_NO_AUTH_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, jumpToSSOLogin, jumpToSSOLogout };
package/dist/index.mjs CHANGED
@@ -239,6 +239,70 @@ function handlePermissionTree(data, key) {
239
239
  noAuthMap
240
240
  };
241
241
  }
242
+ var filterTreeByOrgCodes = (tree, orgCodes) => {
243
+ if (!orgCodes.length) return [];
244
+ const result = [];
245
+ const containsTargetCode = (node) => {
246
+ if (orgCodes.includes(node.value)) return true;
247
+ if (node.children) {
248
+ return node.children.some(containsTargetCode);
249
+ }
250
+ return false;
251
+ };
252
+ const hasTargetDescendants = (node) => {
253
+ if (!node.children) return false;
254
+ return node.children.some((child) => {
255
+ return orgCodes.includes(child.value) || hasTargetDescendants(child);
256
+ });
257
+ };
258
+ const shouldDisableNode = (node) => {
259
+ const isTarget = orgCodes.includes(node.value);
260
+ if (!isTarget) return true;
261
+ return hasTargetDescendants(node);
262
+ };
263
+ const buildPathToTargets = (node) => {
264
+ const isTarget = orgCodes.includes(node.value);
265
+ const hasTargetChildren = node.children ? node.children.some(containsTargetCode) : false;
266
+ if (isTarget || hasTargetChildren) {
267
+ const processedChildren = node.children ? node.children.map((child) => buildPathToTargets(child)).filter(
268
+ (childSubtree) => childSubtree !== null
269
+ ) : void 0;
270
+ return {
271
+ ...node,
272
+ // 根据优化规则设置禁用状态
273
+ disabled: shouldDisableNode(node),
274
+ // 只包含目标节点或通往目标的路径节点的子节点
275
+ children: processedChildren || []
276
+ };
277
+ }
278
+ return null;
279
+ };
280
+ tree.forEach((node) => {
281
+ if (containsTargetCode(node)) {
282
+ const processedSubtree = buildPathToTargets(node);
283
+ if (processedSubtree) {
284
+ result.push(processedSubtree);
285
+ }
286
+ }
287
+ });
288
+ return result;
289
+ };
290
+ var excludeTreeByOrgCodes = (tree, excludeCodes) => {
291
+ if (excludeCodes.length === 0) {
292
+ return tree;
293
+ }
294
+ const removeExcludedNodes = (nodes) => {
295
+ return nodes.filter((node) => !excludeCodes.includes(node.value)).map((node) => {
296
+ const processedChildren = node.children ? removeExcludedNodes(node.children) : [];
297
+ return {
298
+ ...node,
299
+ // 递归处理子节点
300
+ children: processedChildren
301
+ };
302
+ });
303
+ };
304
+ return removeExcludedNodes(tree);
305
+ };
242
306
 
243
307
  // src/config.ts
244
308
  var USER_INFO_KEY = "opms_user_info";
@@ -438,6 +502,11 @@ var ApiClient = class {
438
502
  );
439
503
  }
440
504
  };
505
+ var EnumOrgBindType = /* @__PURE__ */ ((EnumOrgBindType2) => {
506
+ EnumOrgBindType2["PRIMARY"] = "PRIMARY";
507
+ EnumOrgBindType2["SECONDARY"] = "SECONDARY";
508
+ return EnumOrgBindType2;
509
+ })(EnumOrgBindType || {});
441
510
  var EnumOrgQueryMode = /* @__PURE__ */ ((EnumOrgQueryMode2) => {
442
511
  EnumOrgQueryMode2["BY_ROLES"] = "BY_ROLES";
443
512
  EnumOrgQueryMode2["BY_DEPT"] = "BY_DEPT";
@@ -510,7 +579,9 @@ var DataHandler = {
510
579
  return findFirstEnableCode(orgTree) ?? "";
511
580
  },
512
581
  findFirstEnableNode,
513
- handlePermissionTree
582
+ handlePermissionTree,
583
+ filterTreeByOrgCodes,
584
+ excludeTreeByOrgCodes
514
585
  };
515
586
  var Permission = class {
516
587
  constructor(options) {
@@ -955,6 +1026,7 @@ function jumpToSSOLogout({
955
1026
  export {
956
1027
  ApiClient,
957
1028
  DataHandler,
1029
+ EnumOrgBindType,
958
1030
  EnumOrgQueryMode,
959
1031
  EnumOrgQueryScope,
960
1032
  EventEmitter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mu-cabin/opms-permission",
3
- "version": "0.9.21",
3
+ "version": "0.9.23",
4
4
  "description": "Frontend SDK for OPMS permission and auth management.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",