@mu-cabin/opms-permission 0.8.8 → 0.8.9

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
@@ -258,6 +258,47 @@ async function queryOrgCompanies(baseUrl, params) {
258
258
  }
259
259
 
260
260
  // src/permission.ts
261
+ var DataHandler = {
262
+ // 获取单位组织
263
+ getUnitOptions(orgTree) {
264
+ if (!orgTree) return [];
265
+ return orgTree.disabled ? orgTree.children ?? [] : [orgTree];
266
+ },
267
+ // 获取所有单位组织
268
+ getAllUnitOptions(orgTree) {
269
+ if (!orgTree) return [];
270
+ const newTree = iterateNestedArray(
271
+ [orgTree],
272
+ ({ disabled, ...other }) => ({ ...other })
273
+ )?.[0];
274
+ return newTree ? newTree.children ?? [] : [];
275
+ },
276
+ getCompaniesOptions(orgTree, hasRootAuth) {
277
+ if (!orgTree) return [];
278
+ const list = (orgTree.children || []).map(
279
+ ({ children, ...others }) => ({ ...others, disabled: false })
280
+ );
281
+ if (hasRootAuth) {
282
+ list.unshift({ ...orgTree, label: "\u5168\u516C\u53F8", children: [] });
283
+ }
284
+ return list;
285
+ },
286
+ // 获取所有顶级单位组织代码
287
+ topLevelUnitOrgCodes(orgTree) {
288
+ if (!orgTree) return [];
289
+ return findAllEnableTopLevelCodes(
290
+ Array.isArray(orgTree) ? orgTree : [orgTree]
291
+ );
292
+ },
293
+ // 获取资源数据, 包含资源map和组件map
294
+ getResourceData(resources) {
295
+ return createResourceMap(resources);
296
+ },
297
+ // 获取菜单数据, 包含菜单列表和菜单map
298
+ getMenuData(resources) {
299
+ return createMenuList(resources);
300
+ }
301
+ };
261
302
  var Permission = class {
262
303
  constructor(options) {
263
304
  this._userInfo = null;
@@ -331,13 +372,11 @@ var Permission = class {
331
372
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
332
373
  */
333
374
  async getResources() {
334
- const resourcesObj = storage.getItem(RESOURCE_KEY) || null;
335
- if (resourcesObj) {
336
- const { menuList: menuList2, menuMap: menuMap2 } = createMenuList(resourcesObj.resources);
375
+ let resources = storage.getItem(RESOURCE_KEY) || null;
376
+ if (resources) {
377
+ const { menuList: menuList2, menuMap: menuMap2 } = createMenuList(resources);
337
378
  return {
338
- resources: resourcesObj.resources,
339
- resourceMap: resourcesObj.resourceMap,
340
- widgetMap: resourcesObj.widgetMap,
379
+ resources,
341
380
  menuList: menuList2,
342
381
  menuMap: menuMap2
343
382
  };
@@ -351,7 +390,7 @@ var Permission = class {
351
390
  msg
352
391
  });
353
392
  }
354
- const resources = obj;
393
+ resources = obj;
355
394
  const { resourceMap, widgetMap } = createResourceMap(resources);
356
395
  const { menuList, menuMap } = createMenuList(resources);
357
396
  this.resources = resources;
@@ -361,11 +400,7 @@ var Permission = class {
361
400
  this.menuMap = menuMap;
362
401
  storage.setItem(
363
402
  RESOURCE_KEY,
364
- {
365
- resources,
366
- resourceMap,
367
- widgetMap
368
- },
403
+ resources,
369
404
  60 * 24
370
405
  // 24 hours
371
406
  );
@@ -403,7 +438,8 @@ var Permission = class {
403
438
  nodeLevel: item.nodeLevel,
404
439
  children: item.children,
405
440
  disabled: !item.hasPermission,
406
- orgType: item.orgType
441
+ orgType: item.orgType,
442
+ orgId: item.orgId
407
443
  };
408
444
  })?.[0];
409
445
  this._orgTree = newTree;
@@ -479,16 +515,12 @@ var Permission = class {
479
515
  get unitOptions() {
480
516
  const orgTree = this._orgTree;
481
517
  if (!orgTree) return [];
482
- return orgTree.disabled ? orgTree.children ?? [] : [orgTree];
518
+ return DataHandler.getUnitOptions(orgTree);
483
519
  }
484
520
  get allUnitOptions() {
485
521
  const orgTree = this._orgTree;
486
522
  if (!orgTree) return [];
487
- const newTree = iterateNestedArray(
488
- [orgTree],
489
- ({ disabled, ...other }) => ({ ...other })
490
- )?.[0];
491
- return newTree ? newTree.children ?? [] : [];
523
+ return DataHandler.getAllUnitOptions(orgTree);
492
524
  }
493
525
  get firstUnitOrgCode() {
494
526
  if (this.hasRootAuth) {
@@ -501,9 +533,7 @@ var Permission = class {
501
533
  get topLevelUnitOrgCodes() {
502
534
  const orgTree = this._orgTree;
503
535
  if (!orgTree) return [];
504
- return findAllEnableTopLevelCodes(
505
- Array.isArray(orgTree) ? orgTree : [orgTree]
506
- );
536
+ return DataHandler.topLevelUnitOrgCodes(orgTree);
507
537
  }
508
538
  };
509
539
 
package/dist/index.d.mts CHANGED
@@ -86,6 +86,12 @@ declare class Permission {
86
86
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
87
87
  */
88
88
  getResources(): Promise<{
89
+ resources: Resource[];
90
+ menuList: MenuItem[];
91
+ menuMap: Record<number, MenuItem>;
92
+ resourceMap?: undefined;
93
+ widgetMap?: undefined;
94
+ } | {
89
95
  resources: Resource[];
90
96
  resourceMap: {
91
97
  [path: string]: Resource;
package/dist/index.d.ts CHANGED
@@ -86,6 +86,12 @@ declare class Permission {
86
86
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
87
87
  */
88
88
  getResources(): Promise<{
89
+ resources: Resource[];
90
+ menuList: MenuItem[];
91
+ menuMap: Record<number, MenuItem>;
92
+ resourceMap?: undefined;
93
+ widgetMap?: undefined;
94
+ } | {
89
95
  resources: Resource[];
90
96
  resourceMap: {
91
97
  [path: string]: Resource;
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
 
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.9",
4
4
  "description": "Frontend SDK for OPMS permission and auth management.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",