@mu-cabin/opms-permission 0.8.8 → 0.8.10

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
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ DataHandler: () => DataHandler,
33
34
  OpmsPermission: () => Permission,
34
35
  jumpToSSOLogin: () => jumpToSSOLogin,
35
36
  jumpToSSOLogout: () => jumpToSSOLogout
@@ -258,6 +259,47 @@ async function queryOrgCompanies(baseUrl, params) {
258
259
  }
259
260
 
260
261
  // src/permission.ts
262
+ var DataHandler = {
263
+ // 获取单位组织
264
+ getUnitOptions(orgTree) {
265
+ if (!orgTree) return [];
266
+ return orgTree.disabled ? orgTree.children ?? [] : [orgTree];
267
+ },
268
+ // 获取所有单位组织
269
+ getAllUnitOptions(orgTree) {
270
+ if (!orgTree) return [];
271
+ const newTree = iterateNestedArray(
272
+ [orgTree],
273
+ ({ disabled, ...other }) => ({ ...other })
274
+ )?.[0];
275
+ return newTree ? newTree.children ?? [] : [];
276
+ },
277
+ getCompaniesOptions(orgTree, hasRootAuth) {
278
+ if (!orgTree) return [];
279
+ const list = (orgTree.children || []).map(
280
+ ({ children, ...others }) => ({ ...others, disabled: false })
281
+ );
282
+ if (hasRootAuth) {
283
+ list.unshift({ ...orgTree, label: "\u5168\u516C\u53F8", children: [] });
284
+ }
285
+ return list;
286
+ },
287
+ // 获取所有顶级单位组织代码
288
+ topLevelUnitOrgCodes(orgTree) {
289
+ if (!orgTree) return [];
290
+ return findAllEnableTopLevelCodes(
291
+ Array.isArray(orgTree) ? orgTree : [orgTree]
292
+ );
293
+ },
294
+ // 获取资源数据, 包含资源map和组件map
295
+ getResourceData(resources) {
296
+ return createResourceMap(resources);
297
+ },
298
+ // 获取菜单数据, 包含菜单列表和菜单map
299
+ getMenuData(resources) {
300
+ return createMenuList(resources);
301
+ }
302
+ };
261
303
  var Permission = class {
262
304
  constructor(options) {
263
305
  this._userInfo = null;
@@ -331,13 +373,11 @@ var Permission = class {
331
373
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
332
374
  */
333
375
  async getResources() {
334
- const resourcesObj = storage.getItem(RESOURCE_KEY) || null;
335
- if (resourcesObj) {
336
- const { menuList: menuList2, menuMap: menuMap2 } = createMenuList(resourcesObj.resources);
376
+ let resources = storage.getItem(RESOURCE_KEY) || null;
377
+ if (resources) {
378
+ const { menuList: menuList2, menuMap: menuMap2 } = createMenuList(resources);
337
379
  return {
338
- resources: resourcesObj.resources,
339
- resourceMap: resourcesObj.resourceMap,
340
- widgetMap: resourcesObj.widgetMap,
380
+ resources,
341
381
  menuList: menuList2,
342
382
  menuMap: menuMap2
343
383
  };
@@ -351,7 +391,7 @@ var Permission = class {
351
391
  msg
352
392
  });
353
393
  }
354
- const resources = obj;
394
+ resources = obj;
355
395
  const { resourceMap, widgetMap } = createResourceMap(resources);
356
396
  const { menuList, menuMap } = createMenuList(resources);
357
397
  this.resources = resources;
@@ -361,11 +401,7 @@ var Permission = class {
361
401
  this.menuMap = menuMap;
362
402
  storage.setItem(
363
403
  RESOURCE_KEY,
364
- {
365
- resources,
366
- resourceMap,
367
- widgetMap
368
- },
404
+ resources,
369
405
  60 * 24
370
406
  // 24 hours
371
407
  );
@@ -403,7 +439,8 @@ var Permission = class {
403
439
  nodeLevel: item.nodeLevel,
404
440
  children: item.children,
405
441
  disabled: !item.hasPermission,
406
- orgType: item.orgType
442
+ orgType: item.orgType,
443
+ orgId: item.orgId
407
444
  };
408
445
  })?.[0];
409
446
  this._orgTree = newTree;
@@ -479,16 +516,12 @@ var Permission = class {
479
516
  get unitOptions() {
480
517
  const orgTree = this._orgTree;
481
518
  if (!orgTree) return [];
482
- return orgTree.disabled ? orgTree.children ?? [] : [orgTree];
519
+ return DataHandler.getUnitOptions(orgTree);
483
520
  }
484
521
  get allUnitOptions() {
485
522
  const orgTree = this._orgTree;
486
523
  if (!orgTree) return [];
487
- const newTree = iterateNestedArray(
488
- [orgTree],
489
- ({ disabled, ...other }) => ({ ...other })
490
- )?.[0];
491
- return newTree ? newTree.children ?? [] : [];
524
+ return DataHandler.getAllUnitOptions(orgTree);
492
525
  }
493
526
  get firstUnitOrgCode() {
494
527
  if (this.hasRootAuth) {
@@ -501,9 +534,7 @@ var Permission = class {
501
534
  get topLevelUnitOrgCodes() {
502
535
  const orgTree = this._orgTree;
503
536
  if (!orgTree) return [];
504
- return findAllEnableTopLevelCodes(
505
- Array.isArray(orgTree) ? orgTree : [orgTree]
506
- );
537
+ return DataHandler.topLevelUnitOrgCodes(orgTree);
507
538
  }
508
539
  };
509
540
 
@@ -543,6 +574,7 @@ function jumpToSSOLogout({
543
574
  }
544
575
  // Annotate the CommonJS export names for ESM import in node:
545
576
  0 && (module.exports = {
577
+ DataHandler,
546
578
  OpmsPermission,
547
579
  jumpToSSOLogin,
548
580
  jumpToSSOLogout
package/dist/index.d.mts CHANGED
@@ -54,6 +54,40 @@ interface PermissionOptions {
54
54
  systemId: string;
55
55
  baseUrl: string;
56
56
  }
57
+ interface OrgTreeItem {
58
+ label: string;
59
+ value: string;
60
+ title: string;
61
+ key: string;
62
+ nodeLevel: number;
63
+ children: OrgTreeItem[];
64
+ disabled: boolean;
65
+ orgType: string;
66
+ orgId: string;
67
+ }
68
+ /**
69
+ * 组织树处理工具
70
+ */
71
+ declare const DataHandler: {
72
+ getUnitOptions(orgTree: OrgTreeItem): Option[];
73
+ getAllUnitOptions(orgTree: OrgTreeItem): Option[];
74
+ getCompaniesOptions(orgTree: OrgTreeItem, hasRootAuth: boolean): Option[];
75
+ topLevelUnitOrgCodes(orgTree: OrgTreeItem): string[];
76
+ getResourceData(resources: Resource[]): {
77
+ resourceMap: {
78
+ [path: string]: Resource;
79
+ };
80
+ widgetMap: {
81
+ [path: string]: Resource;
82
+ };
83
+ };
84
+ getMenuData(resources: Resource[]): {
85
+ menuList: MenuItem[];
86
+ menuMap: {
87
+ [path: string]: MenuItem;
88
+ };
89
+ };
90
+ };
57
91
  declare class Permission {
58
92
  private _userInfo;
59
93
  private _orgTree;
@@ -86,6 +120,12 @@ declare class Permission {
86
120
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
87
121
  */
88
122
  getResources(): Promise<{
123
+ resources: Resource[];
124
+ menuList: MenuItem[];
125
+ menuMap: Record<number, MenuItem>;
126
+ resourceMap?: undefined;
127
+ widgetMap?: undefined;
128
+ } | {
89
129
  resources: Resource[];
90
130
  resourceMap: {
91
131
  [path: string]: Resource;
@@ -138,4 +178,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
138
178
  clientId?: string;
139
179
  }): void;
140
180
 
141
- export { type MenuItem, Permission as OpmsPermission, type Option, type Resource, type UserInfo, type UserOrganization, jumpToSSOLogin, jumpToSSOLogout };
181
+ export { DataHandler, type MenuItem, Permission as OpmsPermission, type Option, type Resource, type UserInfo, type UserOrganization, jumpToSSOLogin, jumpToSSOLogout };
package/dist/index.d.ts CHANGED
@@ -54,6 +54,40 @@ interface PermissionOptions {
54
54
  systemId: string;
55
55
  baseUrl: string;
56
56
  }
57
+ interface OrgTreeItem {
58
+ label: string;
59
+ value: string;
60
+ title: string;
61
+ key: string;
62
+ nodeLevel: number;
63
+ children: OrgTreeItem[];
64
+ disabled: boolean;
65
+ orgType: string;
66
+ orgId: string;
67
+ }
68
+ /**
69
+ * 组织树处理工具
70
+ */
71
+ declare const DataHandler: {
72
+ getUnitOptions(orgTree: OrgTreeItem): Option[];
73
+ getAllUnitOptions(orgTree: OrgTreeItem): Option[];
74
+ getCompaniesOptions(orgTree: OrgTreeItem, hasRootAuth: boolean): Option[];
75
+ topLevelUnitOrgCodes(orgTree: OrgTreeItem): string[];
76
+ getResourceData(resources: Resource[]): {
77
+ resourceMap: {
78
+ [path: string]: Resource;
79
+ };
80
+ widgetMap: {
81
+ [path: string]: Resource;
82
+ };
83
+ };
84
+ getMenuData(resources: Resource[]): {
85
+ menuList: MenuItem[];
86
+ menuMap: {
87
+ [path: string]: MenuItem;
88
+ };
89
+ };
90
+ };
57
91
  declare class Permission {
58
92
  private _userInfo;
59
93
  private _orgTree;
@@ -86,6 +120,12 @@ declare class Permission {
86
120
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
87
121
  */
88
122
  getResources(): Promise<{
123
+ resources: Resource[];
124
+ menuList: MenuItem[];
125
+ menuMap: Record<number, MenuItem>;
126
+ resourceMap?: undefined;
127
+ widgetMap?: undefined;
128
+ } | {
89
129
  resources: Resource[];
90
130
  resourceMap: {
91
131
  [path: string]: Resource;
@@ -138,4 +178,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
138
178
  clientId?: string;
139
179
  }): void;
140
180
 
141
- export { type MenuItem, Permission as OpmsPermission, type Option, type Resource, type UserInfo, type UserOrganization, jumpToSSOLogin, jumpToSSOLogout };
181
+ export { DataHandler, type MenuItem, Permission as OpmsPermission, type Option, type Resource, type UserInfo, type UserOrganization, jumpToSSOLogin, jumpToSSOLogout };
package/dist/index.mjs CHANGED
@@ -220,6 +220,47 @@ async function queryOrgCompanies(baseUrl, params) {
220
220
  }
221
221
 
222
222
  // src/permission.ts
223
+ var DataHandler = {
224
+ // 获取单位组织
225
+ getUnitOptions(orgTree) {
226
+ if (!orgTree) return [];
227
+ return orgTree.disabled ? orgTree.children ?? [] : [orgTree];
228
+ },
229
+ // 获取所有单位组织
230
+ getAllUnitOptions(orgTree) {
231
+ if (!orgTree) return [];
232
+ const newTree = iterateNestedArray(
233
+ [orgTree],
234
+ ({ disabled, ...other }) => ({ ...other })
235
+ )?.[0];
236
+ return newTree ? newTree.children ?? [] : [];
237
+ },
238
+ getCompaniesOptions(orgTree, hasRootAuth) {
239
+ if (!orgTree) return [];
240
+ const list = (orgTree.children || []).map(
241
+ ({ children, ...others }) => ({ ...others, disabled: false })
242
+ );
243
+ if (hasRootAuth) {
244
+ list.unshift({ ...orgTree, label: "\u5168\u516C\u53F8", children: [] });
245
+ }
246
+ return list;
247
+ },
248
+ // 获取所有顶级单位组织代码
249
+ topLevelUnitOrgCodes(orgTree) {
250
+ if (!orgTree) return [];
251
+ return findAllEnableTopLevelCodes(
252
+ Array.isArray(orgTree) ? orgTree : [orgTree]
253
+ );
254
+ },
255
+ // 获取资源数据, 包含资源map和组件map
256
+ getResourceData(resources) {
257
+ return createResourceMap(resources);
258
+ },
259
+ // 获取菜单数据, 包含菜单列表和菜单map
260
+ getMenuData(resources) {
261
+ return createMenuList(resources);
262
+ }
263
+ };
223
264
  var Permission = class {
224
265
  constructor(options) {
225
266
  this._userInfo = null;
@@ -293,13 +334,11 @@ var Permission = class {
293
334
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
294
335
  */
295
336
  async getResources() {
296
- const resourcesObj = storage.getItem(RESOURCE_KEY) || null;
297
- if (resourcesObj) {
298
- const { menuList: menuList2, menuMap: menuMap2 } = createMenuList(resourcesObj.resources);
337
+ let resources = storage.getItem(RESOURCE_KEY) || null;
338
+ if (resources) {
339
+ const { menuList: menuList2, menuMap: menuMap2 } = createMenuList(resources);
299
340
  return {
300
- resources: resourcesObj.resources,
301
- resourceMap: resourcesObj.resourceMap,
302
- widgetMap: resourcesObj.widgetMap,
341
+ resources,
303
342
  menuList: menuList2,
304
343
  menuMap: menuMap2
305
344
  };
@@ -313,7 +352,7 @@ var Permission = class {
313
352
  msg
314
353
  });
315
354
  }
316
- const resources = obj;
355
+ resources = obj;
317
356
  const { resourceMap, widgetMap } = createResourceMap(resources);
318
357
  const { menuList, menuMap } = createMenuList(resources);
319
358
  this.resources = resources;
@@ -323,11 +362,7 @@ var Permission = class {
323
362
  this.menuMap = menuMap;
324
363
  storage.setItem(
325
364
  RESOURCE_KEY,
326
- {
327
- resources,
328
- resourceMap,
329
- widgetMap
330
- },
365
+ resources,
331
366
  60 * 24
332
367
  // 24 hours
333
368
  );
@@ -365,7 +400,8 @@ var Permission = class {
365
400
  nodeLevel: item.nodeLevel,
366
401
  children: item.children,
367
402
  disabled: !item.hasPermission,
368
- orgType: item.orgType
403
+ orgType: item.orgType,
404
+ orgId: item.orgId
369
405
  };
370
406
  })?.[0];
371
407
  this._orgTree = newTree;
@@ -441,16 +477,12 @@ var Permission = class {
441
477
  get unitOptions() {
442
478
  const orgTree = this._orgTree;
443
479
  if (!orgTree) return [];
444
- return orgTree.disabled ? orgTree.children ?? [] : [orgTree];
480
+ return DataHandler.getUnitOptions(orgTree);
445
481
  }
446
482
  get allUnitOptions() {
447
483
  const orgTree = this._orgTree;
448
484
  if (!orgTree) return [];
449
- const newTree = iterateNestedArray(
450
- [orgTree],
451
- ({ disabled, ...other }) => ({ ...other })
452
- )?.[0];
453
- return newTree ? newTree.children ?? [] : [];
485
+ return DataHandler.getAllUnitOptions(orgTree);
454
486
  }
455
487
  get firstUnitOrgCode() {
456
488
  if (this.hasRootAuth) {
@@ -463,9 +495,7 @@ var Permission = class {
463
495
  get topLevelUnitOrgCodes() {
464
496
  const orgTree = this._orgTree;
465
497
  if (!orgTree) return [];
466
- return findAllEnableTopLevelCodes(
467
- Array.isArray(orgTree) ? orgTree : [orgTree]
468
- );
498
+ return DataHandler.topLevelUnitOrgCodes(orgTree);
469
499
  }
470
500
  };
471
501
 
@@ -504,6 +534,7 @@ function jumpToSSOLogout({
504
534
  window.location.href = logoutUrl.toString();
505
535
  }
506
536
  export {
537
+ DataHandler,
507
538
  Permission as OpmsPermission,
508
539
  jumpToSSOLogin,
509
540
  jumpToSSOLogout
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mu-cabin/opms-permission",
3
- "version": "0.8.8",
3
+ "version": "0.8.10",
4
4
  "description": "Frontend SDK for OPMS permission and auth management.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",