@mu-cabin/opms-permission 0.9.3 → 0.9.5

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
@@ -162,15 +162,18 @@ var Storage = class {
162
162
  var storage = new Storage();
163
163
 
164
164
  // src/utils/dataHandler.ts
165
- var getCompletePath = (item) => {
165
+ var getCompletePath = (item, hasSubApp) => {
166
166
  const menuUrl = item.openIndicator === "INNER_COMPONENT" ? item.componentPath : item.defaultUrl;
167
+ if (!hasSubApp) {
168
+ return menuUrl ?? "";
169
+ }
167
170
  const path = item.prefix && item.openIndicator === "INNER_COMPONENT" ? `${item.prefix}${menuUrl}` : menuUrl ?? "";
168
171
  return path;
169
172
  };
170
173
  function getMenuName(item) {
171
174
  return item.resourceType !== "FOLDER" ? item.resourceName || "" : (item.showName ?? item.resourceName) || "";
172
175
  }
173
- function createResourceMap(items) {
176
+ function createResourceMap(items, hasSubApp) {
174
177
  const resourceMap = {};
175
178
  const widgetMap = {};
176
179
  function addToMap(items2) {
@@ -179,7 +182,7 @@ function createResourceMap(items) {
179
182
  if (newItem.defaultResourceType === "WIDGET") {
180
183
  if (newItem.componentPath) widgetMap[newItem.componentPath] = newItem;
181
184
  } else {
182
- const path = getCompletePath(newItem);
185
+ const path = getCompletePath(newItem, hasSubApp);
183
186
  if (path) {
184
187
  resourceMap[path] = newItem;
185
188
  }
@@ -196,13 +199,13 @@ function isMenuItem(item) {
196
199
  const resourceType = item.resourceType ?? item.defaultResourceType;
197
200
  return resourceType !== "WIDGET";
198
201
  }
199
- function createMenuList(items) {
202
+ function createMenuList(items, hasSubApp) {
200
203
  const menus = [];
201
204
  const menuMap = {};
202
205
  const filterMenus = (items2, container) => {
203
206
  items2.forEach((item) => {
204
207
  const icon = item.icon || item.defaultIcon;
205
- const path = getCompletePath(item);
208
+ const path = getCompletePath(item, hasSubApp);
206
209
  const name = getMenuName(item);
207
210
  const newItem = {
208
211
  icon,
@@ -542,12 +545,12 @@ var DataHandler = {
542
545
  return findAllEnableTopLevelCodes(orgTree);
543
546
  },
544
547
  // 获取资源数据, 包含资源map和组件map
545
- getResourceData(resources) {
546
- return createResourceMap(resources);
548
+ getResourceData(resources, hasSubApp) {
549
+ return createResourceMap(resources, hasSubApp);
547
550
  },
548
551
  // 获取菜单数据, 包含菜单列表和菜单map
549
- getMenuData(resources) {
550
- return createMenuList(resources);
552
+ getMenuData(resources, hasSubApp) {
553
+ return createMenuList(resources, hasSubApp);
551
554
  },
552
555
  getFirstUnitOrgCode(orgTree) {
553
556
  return findFirstEnableCode(orgTree) ?? "";
@@ -557,16 +560,17 @@ var DataHandler = {
557
560
  };
558
561
  var Permission = class {
559
562
  constructor(options) {
560
- this._userInfo = null;
561
563
  this.resources = [];
562
564
  this.resourceMap = {};
563
565
  this.widgetMap = {};
564
566
  this.menuList = [];
565
567
  this.menuMap = {};
568
+ this.hasSubApp = false;
566
569
  // Event emitter instance - only allow tokenChange event
567
570
  this.eventEmitter = new EventEmitter(["tokenChange"]);
568
571
  this.baseUrl = options.baseUrl;
569
572
  this.systemId = options.systemId;
573
+ this.hasSubApp = options.hasSubApp ?? false;
570
574
  storage.setSystemId(this.systemId);
571
575
  storage.setVersion("1.0.0");
572
576
  }
@@ -684,8 +688,8 @@ var Permission = class {
684
688
  // 12 hours
685
689
  );
686
690
  }
687
- const { resourceMap, widgetMap } = createResourceMap(resources);
688
- const { menuList, menuMap } = createMenuList(resources);
691
+ const { resourceMap, widgetMap } = createResourceMap(resources, this.hasSubApp);
692
+ const { menuList, menuMap } = createMenuList(resources, this.hasSubApp);
689
693
  return {
690
694
  resources,
691
695
  resourceMap,
package/dist/index.d.mts CHANGED
@@ -27,7 +27,6 @@ interface Resource {
27
27
  icon?: string;
28
28
  openIndicator: OpenIndicatorType;
29
29
  orgQueryMode: EnumOrgQueryMode;
30
- orgQueryScope: EnumOrgQueryScope;
31
30
  }
32
31
  type CodeSourceType = 'FLY_NET' | 'COS' | 'CSM';
33
32
  interface OrgRecord$1 {
@@ -122,7 +121,7 @@ interface MenuItem {
122
121
  name: string;
123
122
  children: MenuItem[];
124
123
  resourceId: number;
125
- openIndicator: string;
124
+ openIndicator: OpenIndicatorType;
126
125
  }
127
126
  interface UserInfo {
128
127
  account: string;
@@ -253,6 +252,7 @@ declare class EventEmitter<TEventMap extends Record<string, any> = PermissionEve
253
252
  interface PermissionOptions {
254
253
  systemId: string;
255
254
  baseUrl: string;
255
+ hasSubApp?: boolean;
256
256
  }
257
257
  /**
258
258
  * 组织树处理工具
@@ -263,7 +263,7 @@ declare const DataHandler: {
263
263
  getAllUnitOptions(orgTree: OrgTreeItem[]): Option[];
264
264
  getCompaniesOptions(orgTree: OrgTreeItem[], hasRootAuth: boolean): Option[];
265
265
  topLevelUnitOrgCodes(orgTree: OrgTreeItem[]): string[];
266
- getResourceData(resources: Resource[]): {
266
+ getResourceData(resources: Resource[], hasSubApp: boolean): {
267
267
  resourceMap: {
268
268
  [path: string]: Resource;
269
269
  };
@@ -271,7 +271,7 @@ declare const DataHandler: {
271
271
  [path: string]: Resource;
272
272
  };
273
273
  };
274
- getMenuData(resources: Resource[]): {
274
+ getMenuData(resources: Resource[], hasSubApp: boolean): {
275
275
  menuList: MenuItem[];
276
276
  menuMap: {
277
277
  [path: string]: MenuItem;
@@ -282,7 +282,6 @@ declare const DataHandler: {
282
282
  handlePermissionTree: typeof handlePermissionTree;
283
283
  };
284
284
  declare class Permission {
285
- private _userInfo;
286
285
  private systemId;
287
286
  private baseUrl;
288
287
  resources: Resource[];
@@ -296,6 +295,7 @@ declare class Permission {
296
295
  menuMap: {
297
296
  [path: string]: MenuItem;
298
297
  };
298
+ hasSubApp: boolean;
299
299
  private eventEmitter;
300
300
  constructor(options: PermissionOptions);
301
301
  /**
package/dist/index.d.ts CHANGED
@@ -27,7 +27,6 @@ interface Resource {
27
27
  icon?: string;
28
28
  openIndicator: OpenIndicatorType;
29
29
  orgQueryMode: EnumOrgQueryMode;
30
- orgQueryScope: EnumOrgQueryScope;
31
30
  }
32
31
  type CodeSourceType = 'FLY_NET' | 'COS' | 'CSM';
33
32
  interface OrgRecord$1 {
@@ -122,7 +121,7 @@ interface MenuItem {
122
121
  name: string;
123
122
  children: MenuItem[];
124
123
  resourceId: number;
125
- openIndicator: string;
124
+ openIndicator: OpenIndicatorType;
126
125
  }
127
126
  interface UserInfo {
128
127
  account: string;
@@ -253,6 +252,7 @@ declare class EventEmitter<TEventMap extends Record<string, any> = PermissionEve
253
252
  interface PermissionOptions {
254
253
  systemId: string;
255
254
  baseUrl: string;
255
+ hasSubApp?: boolean;
256
256
  }
257
257
  /**
258
258
  * 组织树处理工具
@@ -263,7 +263,7 @@ declare const DataHandler: {
263
263
  getAllUnitOptions(orgTree: OrgTreeItem[]): Option[];
264
264
  getCompaniesOptions(orgTree: OrgTreeItem[], hasRootAuth: boolean): Option[];
265
265
  topLevelUnitOrgCodes(orgTree: OrgTreeItem[]): string[];
266
- getResourceData(resources: Resource[]): {
266
+ getResourceData(resources: Resource[], hasSubApp: boolean): {
267
267
  resourceMap: {
268
268
  [path: string]: Resource;
269
269
  };
@@ -271,7 +271,7 @@ declare const DataHandler: {
271
271
  [path: string]: Resource;
272
272
  };
273
273
  };
274
- getMenuData(resources: Resource[]): {
274
+ getMenuData(resources: Resource[], hasSubApp: boolean): {
275
275
  menuList: MenuItem[];
276
276
  menuMap: {
277
277
  [path: string]: MenuItem;
@@ -282,7 +282,6 @@ declare const DataHandler: {
282
282
  handlePermissionTree: typeof handlePermissionTree;
283
283
  };
284
284
  declare class Permission {
285
- private _userInfo;
286
285
  private systemId;
287
286
  private baseUrl;
288
287
  resources: Resource[];
@@ -296,6 +295,7 @@ declare class Permission {
296
295
  menuMap: {
297
296
  [path: string]: MenuItem;
298
297
  };
298
+ hasSubApp: boolean;
299
299
  private eventEmitter;
300
300
  constructor(options: PermissionOptions);
301
301
  /**
package/dist/index.mjs CHANGED
@@ -113,15 +113,18 @@ var Storage = class {
113
113
  var storage = new Storage();
114
114
 
115
115
  // src/utils/dataHandler.ts
116
- var getCompletePath = (item) => {
116
+ var getCompletePath = (item, hasSubApp) => {
117
117
  const menuUrl = item.openIndicator === "INNER_COMPONENT" ? item.componentPath : item.defaultUrl;
118
+ if (!hasSubApp) {
119
+ return menuUrl ?? "";
120
+ }
118
121
  const path = item.prefix && item.openIndicator === "INNER_COMPONENT" ? `${item.prefix}${menuUrl}` : menuUrl ?? "";
119
122
  return path;
120
123
  };
121
124
  function getMenuName(item) {
122
125
  return item.resourceType !== "FOLDER" ? item.resourceName || "" : (item.showName ?? item.resourceName) || "";
123
126
  }
124
- function createResourceMap(items) {
127
+ function createResourceMap(items, hasSubApp) {
125
128
  const resourceMap = {};
126
129
  const widgetMap = {};
127
130
  function addToMap(items2) {
@@ -130,7 +133,7 @@ function createResourceMap(items) {
130
133
  if (newItem.defaultResourceType === "WIDGET") {
131
134
  if (newItem.componentPath) widgetMap[newItem.componentPath] = newItem;
132
135
  } else {
133
- const path = getCompletePath(newItem);
136
+ const path = getCompletePath(newItem, hasSubApp);
134
137
  if (path) {
135
138
  resourceMap[path] = newItem;
136
139
  }
@@ -147,13 +150,13 @@ function isMenuItem(item) {
147
150
  const resourceType = item.resourceType ?? item.defaultResourceType;
148
151
  return resourceType !== "WIDGET";
149
152
  }
150
- function createMenuList(items) {
153
+ function createMenuList(items, hasSubApp) {
151
154
  const menus = [];
152
155
  const menuMap = {};
153
156
  const filterMenus = (items2, container) => {
154
157
  items2.forEach((item) => {
155
158
  const icon = item.icon || item.defaultIcon;
156
- const path = getCompletePath(item);
159
+ const path = getCompletePath(item, hasSubApp);
157
160
  const name = getMenuName(item);
158
161
  const newItem = {
159
162
  icon,
@@ -493,12 +496,12 @@ var DataHandler = {
493
496
  return findAllEnableTopLevelCodes(orgTree);
494
497
  },
495
498
  // 获取资源数据, 包含资源map和组件map
496
- getResourceData(resources) {
497
- return createResourceMap(resources);
499
+ getResourceData(resources, hasSubApp) {
500
+ return createResourceMap(resources, hasSubApp);
498
501
  },
499
502
  // 获取菜单数据, 包含菜单列表和菜单map
500
- getMenuData(resources) {
501
- return createMenuList(resources);
503
+ getMenuData(resources, hasSubApp) {
504
+ return createMenuList(resources, hasSubApp);
502
505
  },
503
506
  getFirstUnitOrgCode(orgTree) {
504
507
  return findFirstEnableCode(orgTree) ?? "";
@@ -508,16 +511,17 @@ var DataHandler = {
508
511
  };
509
512
  var Permission = class {
510
513
  constructor(options) {
511
- this._userInfo = null;
512
514
  this.resources = [];
513
515
  this.resourceMap = {};
514
516
  this.widgetMap = {};
515
517
  this.menuList = [];
516
518
  this.menuMap = {};
519
+ this.hasSubApp = false;
517
520
  // Event emitter instance - only allow tokenChange event
518
521
  this.eventEmitter = new EventEmitter(["tokenChange"]);
519
522
  this.baseUrl = options.baseUrl;
520
523
  this.systemId = options.systemId;
524
+ this.hasSubApp = options.hasSubApp ?? false;
521
525
  storage.setSystemId(this.systemId);
522
526
  storage.setVersion("1.0.0");
523
527
  }
@@ -635,8 +639,8 @@ var Permission = class {
635
639
  // 12 hours
636
640
  );
637
641
  }
638
- const { resourceMap, widgetMap } = createResourceMap(resources);
639
- const { menuList, menuMap } = createMenuList(resources);
642
+ const { resourceMap, widgetMap } = createResourceMap(resources, this.hasSubApp);
643
+ const { menuList, menuMap } = createMenuList(resources, this.hasSubApp);
640
644
  return {
641
645
  resources,
642
646
  resourceMap,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mu-cabin/opms-permission",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "Frontend SDK for OPMS permission and auth management.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",