@mu-cabin/opms-permission 0.8.7 → 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;
@@ -414,19 +450,16 @@ var Permission = class {
414
450
  }
415
451
  }
416
452
  async queryCompanies() {
417
- try {
418
- let orgCompanyList = storage.getItem(ORG_COMPANY_KEY);
419
- if (!orgCompanyList) {
420
- const { obj } = await queryOrgCompanies(this.baseUrl, {
421
- queryAllBranches: true
422
- });
423
- orgCompanyList = obj;
424
- storage.setItem(ORG_COMPANY_KEY, orgCompanyList);
425
- }
426
- this._orgCompany = orgCompanyList;
427
- } catch (error) {
428
- console.log(error);
453
+ let orgCompanyList = storage.getItem(ORG_COMPANY_KEY);
454
+ if (!orgCompanyList) {
455
+ const { obj } = await queryOrgCompanies(this.baseUrl, {
456
+ queryAllBranches: true
457
+ });
458
+ orgCompanyList = obj;
459
+ storage.setItem(ORG_COMPANY_KEY, orgCompanyList);
429
460
  }
461
+ this._orgCompany = orgCompanyList;
462
+ return orgCompanyList;
430
463
  }
431
464
  isLogin() {
432
465
  return !!storage.getItem(TOKEN_KEY);
@@ -482,16 +515,12 @@ var Permission = class {
482
515
  get unitOptions() {
483
516
  const orgTree = this._orgTree;
484
517
  if (!orgTree) return [];
485
- return orgTree.disabled ? orgTree.children ?? [] : [orgTree];
518
+ return DataHandler.getUnitOptions(orgTree);
486
519
  }
487
520
  get allUnitOptions() {
488
521
  const orgTree = this._orgTree;
489
522
  if (!orgTree) return [];
490
- const newTree = iterateNestedArray(
491
- [orgTree],
492
- ({ disabled, ...other }) => ({ ...other })
493
- )?.[0];
494
- return newTree ? newTree.children ?? [] : [];
523
+ return DataHandler.getAllUnitOptions(orgTree);
495
524
  }
496
525
  get firstUnitOrgCode() {
497
526
  if (this.hasRootAuth) {
@@ -504,9 +533,7 @@ var Permission = class {
504
533
  get topLevelUnitOrgCodes() {
505
534
  const orgTree = this._orgTree;
506
535
  if (!orgTree) return [];
507
- return findAllEnableTopLevelCodes(
508
- Array.isArray(orgTree) ? orgTree : [orgTree]
509
- );
536
+ return DataHandler.topLevelUnitOrgCodes(orgTree);
510
537
  }
511
538
  };
512
539
 
package/dist/index.d.mts CHANGED
@@ -1,3 +1,13 @@
1
+ interface OrgRecord {
2
+ orgId: number;
3
+ orgName: string;
4
+ orgShortName: string;
5
+ orgCode: string;
6
+ nodeLevel: number;
7
+ hasPermission: boolean;
8
+ children?: OrgRecord[];
9
+ }
10
+
1
11
  interface Resource {
2
12
  resourceId: number;
3
13
  resourceCode: string;
@@ -35,6 +45,10 @@ interface UserOrganization {
35
45
  orgShortName: string;
36
46
  orgType: string;
37
47
  }
48
+ interface Option {
49
+ label: string;
50
+ value: string;
51
+ }
38
52
 
39
53
  interface PermissionOptions {
40
54
  systemId: string;
@@ -72,6 +86,12 @@ declare class Permission {
72
86
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
73
87
  */
74
88
  getResources(): Promise<{
89
+ resources: Resource[];
90
+ menuList: MenuItem[];
91
+ menuMap: Record<number, MenuItem>;
92
+ resourceMap?: undefined;
93
+ widgetMap?: undefined;
94
+ } | {
75
95
  resources: Resource[];
76
96
  resourceMap: {
77
97
  [path: string]: Resource;
@@ -86,18 +106,18 @@ declare class Permission {
86
106
  * Query and process organization tree
87
107
  */
88
108
  queryOrgs(): Promise<any>;
89
- queryCompanies(): Promise<void>;
109
+ queryCompanies(): Promise<OrgRecord[]>;
90
110
  isLogin(): boolean;
91
111
  getToken(): string | null;
92
112
  setToken(token: string): void;
93
113
  get userInfo(): UserInfo | null;
94
114
  get hasRootAuth(): boolean;
95
115
  get userOrganizations(): UserOrganization[];
96
- get allCompanyOptions(): any;
97
- get companyOptions(): any;
116
+ get allCompanyOptions(): Option[];
117
+ get companyOptions(): Option[];
98
118
  get firstCompanyOrgCode(): string;
99
- get unitOptions(): any;
100
- get allUnitOptions(): any;
119
+ get unitOptions(): Option[];
120
+ get allUnitOptions(): Option[];
101
121
  get firstUnitOrgCode(): string;
102
122
  get topLevelUnitOrgCodes(): string[];
103
123
  }
@@ -124,4 +144,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
124
144
  clientId?: string;
125
145
  }): void;
126
146
 
127
- export { type MenuItem, Permission as OpmsPermission, type Resource, type UserInfo, type UserOrganization, jumpToSSOLogin, jumpToSSOLogout };
147
+ export { type MenuItem, Permission as OpmsPermission, type Option, type Resource, type UserInfo, type UserOrganization, jumpToSSOLogin, jumpToSSOLogout };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,13 @@
1
+ interface OrgRecord {
2
+ orgId: number;
3
+ orgName: string;
4
+ orgShortName: string;
5
+ orgCode: string;
6
+ nodeLevel: number;
7
+ hasPermission: boolean;
8
+ children?: OrgRecord[];
9
+ }
10
+
1
11
  interface Resource {
2
12
  resourceId: number;
3
13
  resourceCode: string;
@@ -35,6 +45,10 @@ interface UserOrganization {
35
45
  orgShortName: string;
36
46
  orgType: string;
37
47
  }
48
+ interface Option {
49
+ label: string;
50
+ value: string;
51
+ }
38
52
 
39
53
  interface PermissionOptions {
40
54
  systemId: string;
@@ -72,6 +86,12 @@ declare class Permission {
72
86
  * Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
73
87
  */
74
88
  getResources(): Promise<{
89
+ resources: Resource[];
90
+ menuList: MenuItem[];
91
+ menuMap: Record<number, MenuItem>;
92
+ resourceMap?: undefined;
93
+ widgetMap?: undefined;
94
+ } | {
75
95
  resources: Resource[];
76
96
  resourceMap: {
77
97
  [path: string]: Resource;
@@ -86,18 +106,18 @@ declare class Permission {
86
106
  * Query and process organization tree
87
107
  */
88
108
  queryOrgs(): Promise<any>;
89
- queryCompanies(): Promise<void>;
109
+ queryCompanies(): Promise<OrgRecord[]>;
90
110
  isLogin(): boolean;
91
111
  getToken(): string | null;
92
112
  setToken(token: string): void;
93
113
  get userInfo(): UserInfo | null;
94
114
  get hasRootAuth(): boolean;
95
115
  get userOrganizations(): UserOrganization[];
96
- get allCompanyOptions(): any;
97
- get companyOptions(): any;
116
+ get allCompanyOptions(): Option[];
117
+ get companyOptions(): Option[];
98
118
  get firstCompanyOrgCode(): string;
99
- get unitOptions(): any;
100
- get allUnitOptions(): any;
119
+ get unitOptions(): Option[];
120
+ get allUnitOptions(): Option[];
101
121
  get firstUnitOrgCode(): string;
102
122
  get topLevelUnitOrgCodes(): string[];
103
123
  }
@@ -124,4 +144,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
124
144
  clientId?: string;
125
145
  }): void;
126
146
 
127
- export { type MenuItem, Permission as OpmsPermission, type Resource, type UserInfo, type UserOrganization, jumpToSSOLogin, jumpToSSOLogout };
147
+ export { 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;
@@ -376,19 +412,16 @@ var Permission = class {
376
412
  }
377
413
  }
378
414
  async queryCompanies() {
379
- try {
380
- let orgCompanyList = storage.getItem(ORG_COMPANY_KEY);
381
- if (!orgCompanyList) {
382
- const { obj } = await queryOrgCompanies(this.baseUrl, {
383
- queryAllBranches: true
384
- });
385
- orgCompanyList = obj;
386
- storage.setItem(ORG_COMPANY_KEY, orgCompanyList);
387
- }
388
- this._orgCompany = orgCompanyList;
389
- } catch (error) {
390
- console.log(error);
415
+ let orgCompanyList = storage.getItem(ORG_COMPANY_KEY);
416
+ if (!orgCompanyList) {
417
+ const { obj } = await queryOrgCompanies(this.baseUrl, {
418
+ queryAllBranches: true
419
+ });
420
+ orgCompanyList = obj;
421
+ storage.setItem(ORG_COMPANY_KEY, orgCompanyList);
391
422
  }
423
+ this._orgCompany = orgCompanyList;
424
+ return orgCompanyList;
392
425
  }
393
426
  isLogin() {
394
427
  return !!storage.getItem(TOKEN_KEY);
@@ -444,16 +477,12 @@ var Permission = class {
444
477
  get unitOptions() {
445
478
  const orgTree = this._orgTree;
446
479
  if (!orgTree) return [];
447
- return orgTree.disabled ? orgTree.children ?? [] : [orgTree];
480
+ return DataHandler.getUnitOptions(orgTree);
448
481
  }
449
482
  get allUnitOptions() {
450
483
  const orgTree = this._orgTree;
451
484
  if (!orgTree) return [];
452
- const newTree = iterateNestedArray(
453
- [orgTree],
454
- ({ disabled, ...other }) => ({ ...other })
455
- )?.[0];
456
- return newTree ? newTree.children ?? [] : [];
485
+ return DataHandler.getAllUnitOptions(orgTree);
457
486
  }
458
487
  get firstUnitOrgCode() {
459
488
  if (this.hasRootAuth) {
@@ -466,9 +495,7 @@ var Permission = class {
466
495
  get topLevelUnitOrgCodes() {
467
496
  const orgTree = this._orgTree;
468
497
  if (!orgTree) return [];
469
- return findAllEnableTopLevelCodes(
470
- Array.isArray(orgTree) ? orgTree : [orgTree]
471
- );
498
+ return DataHandler.topLevelUnitOrgCodes(orgTree);
472
499
  }
473
500
  };
474
501
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mu-cabin/opms-permission",
3
- "version": "0.8.7",
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",