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