@mu-cabin/opms-permission 0.9.3 → 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 +16 -12
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.mjs +16 -12
- package/package.json +1 -1
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
@@ -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,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,
|