@mu-cabin/opms-permission 0.8.13 → 0.8.16
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 +42 -53
- package/dist/index.d.mts +6 -13
- package/dist/index.d.ts +6 -13
- package/dist/index.mjs +42 -53
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -245,10 +245,9 @@ async function queryResource(baseUrl, params) {
|
|
245
245
|
params
|
246
246
|
);
|
247
247
|
}
|
248
|
-
async function getUserOrgTree(baseUrl
|
248
|
+
async function getUserOrgTree(baseUrl) {
|
249
249
|
return await axiosClient.post(
|
250
|
-
`${baseUrl}/
|
251
|
-
params
|
250
|
+
`${baseUrl}/user/userInfo`
|
252
251
|
);
|
253
252
|
}
|
254
253
|
async function queryOrgCompanies(baseUrl, params) {
|
@@ -261,7 +260,7 @@ async function queryOrgCompanies(baseUrl, params) {
|
|
261
260
|
// src/permission.ts
|
262
261
|
var DataHandler = {
|
263
262
|
iterateOrgTree(orgTree) {
|
264
|
-
return iterateNestedArray(
|
263
|
+
return iterateNestedArray(orgTree, (item) => {
|
265
264
|
return {
|
266
265
|
label: item.orgShortName,
|
267
266
|
value: item.orgCode,
|
@@ -273,27 +272,28 @@ var DataHandler = {
|
|
273
272
|
orgType: item.orgType,
|
274
273
|
orgId: item.orgId
|
275
274
|
};
|
276
|
-
})
|
275
|
+
});
|
277
276
|
},
|
278
277
|
// 获取单位组织
|
279
|
-
getUnitOptions(orgTree) {
|
280
|
-
|
281
|
-
|
282
|
-
},
|
278
|
+
// getUnitOptions(orgTree: OrgTreeItem[]): Option[] {
|
279
|
+
// if (!orgTree) return [];
|
280
|
+
// return orgTree.disabled ? (orgTree.children ?? []) : [orgTree];
|
281
|
+
// },
|
283
282
|
// 获取所有单位组织
|
284
283
|
getAllUnitOptions(orgTree) {
|
285
284
|
if (!orgTree) return [];
|
286
285
|
const newTree = iterateNestedArray(
|
287
|
-
|
286
|
+
orgTree,
|
288
287
|
({ disabled, ...other }) => ({ ...other })
|
289
288
|
)?.[0];
|
290
289
|
return newTree ? newTree.children ?? [] : [];
|
291
290
|
},
|
292
291
|
getCompaniesOptions(orgTree, hasRootAuth) {
|
293
292
|
if (!orgTree) return [];
|
294
|
-
const list = (orgTree
|
295
|
-
|
296
|
-
|
293
|
+
const list = (orgTree || []).map(({ children, ...others }) => ({
|
294
|
+
...others,
|
295
|
+
disabled: false
|
296
|
+
}));
|
297
297
|
if (hasRootAuth) {
|
298
298
|
list.unshift({ ...orgTree, label: "\u5168\u516C\u53F8", children: [] });
|
299
299
|
}
|
@@ -302,9 +302,7 @@ var DataHandler = {
|
|
302
302
|
// 获取所有顶级单位组织代码
|
303
303
|
topLevelUnitOrgCodes(orgTree) {
|
304
304
|
if (!orgTree) return [];
|
305
|
-
return findAllEnableTopLevelCodes(
|
306
|
-
Array.isArray(orgTree) ? orgTree : [orgTree]
|
307
|
-
);
|
305
|
+
return findAllEnableTopLevelCodes(orgTree);
|
308
306
|
},
|
309
307
|
// 获取资源数据, 包含资源map和组件map
|
310
308
|
getResourceData(resources) {
|
@@ -315,7 +313,7 @@ var DataHandler = {
|
|
315
313
|
return createMenuList(resources);
|
316
314
|
},
|
317
315
|
getFirstUnitOrgCode(orgTree) {
|
318
|
-
return findFirstEnableCode(
|
316
|
+
return findFirstEnableCode(orgTree) ?? "";
|
319
317
|
}
|
320
318
|
};
|
321
319
|
var Permission = class {
|
@@ -392,24 +390,24 @@ var Permission = class {
|
|
392
390
|
*/
|
393
391
|
async getResources() {
|
394
392
|
let resources = storage.getItem(RESOURCE_KEY) || null;
|
395
|
-
if (resources) {
|
396
|
-
const {
|
397
|
-
|
398
|
-
resources,
|
399
|
-
menuList: menuList2,
|
400
|
-
menuMap: menuMap2
|
401
|
-
};
|
402
|
-
}
|
403
|
-
const { obj, success, msg, code } = await queryResource(this.baseUrl, {
|
404
|
-
systemId: this.systemId
|
405
|
-
});
|
406
|
-
if (!success) {
|
407
|
-
return Promise.reject({
|
408
|
-
code,
|
409
|
-
msg
|
393
|
+
if (!resources) {
|
394
|
+
const { obj, success, msg, code } = await queryResource(this.baseUrl, {
|
395
|
+
systemId: this.systemId
|
410
396
|
});
|
397
|
+
if (!success) {
|
398
|
+
return Promise.reject({
|
399
|
+
code,
|
400
|
+
msg
|
401
|
+
});
|
402
|
+
}
|
403
|
+
resources = obj;
|
404
|
+
storage.setItem(
|
405
|
+
RESOURCE_KEY,
|
406
|
+
resources,
|
407
|
+
60 * 24
|
408
|
+
// 24 hours
|
409
|
+
);
|
411
410
|
}
|
412
|
-
resources = obj;
|
413
411
|
const { resourceMap, widgetMap } = createResourceMap(resources);
|
414
412
|
const { menuList, menuMap } = createMenuList(resources);
|
415
413
|
this.resources = resources;
|
@@ -417,12 +415,6 @@ var Permission = class {
|
|
417
415
|
this.widgetMap = widgetMap;
|
418
416
|
this.menuList = menuList;
|
419
417
|
this.menuMap = menuMap;
|
420
|
-
storage.setItem(
|
421
|
-
RESOURCE_KEY,
|
422
|
-
resources,
|
423
|
-
60 * 24
|
424
|
-
// 24 hours
|
425
|
-
);
|
426
418
|
return {
|
427
419
|
resources,
|
428
420
|
resourceMap,
|
@@ -434,21 +426,17 @@ var Permission = class {
|
|
434
426
|
/**
|
435
427
|
* Query and process organization tree
|
436
428
|
*/
|
437
|
-
async
|
429
|
+
async queryUserOrgs() {
|
438
430
|
try {
|
439
|
-
const
|
440
|
-
|
441
|
-
name: "COS"
|
442
|
-
});
|
443
|
-
const { obj, success, msg, code } = data;
|
431
|
+
const res = await getUserOrgTree(this.baseUrl);
|
432
|
+
const { data, success, msg, code } = res;
|
444
433
|
if (!success) {
|
445
434
|
return Promise.reject({
|
446
435
|
code,
|
447
436
|
msg
|
448
437
|
});
|
449
438
|
}
|
450
|
-
const
|
451
|
-
const newTree = iterateNestedArray([orgTree], (item) => {
|
439
|
+
const newTree = iterateNestedArray(data, (item) => {
|
452
440
|
return {
|
453
441
|
label: item.orgShortName,
|
454
442
|
value: item.orgCode,
|
@@ -460,7 +448,7 @@ var Permission = class {
|
|
460
448
|
orgType: item.orgType,
|
461
449
|
orgId: item.orgId
|
462
450
|
};
|
463
|
-
})
|
451
|
+
});
|
464
452
|
this._orgTree = newTree;
|
465
453
|
return newTree;
|
466
454
|
} catch (error) {
|
@@ -520,9 +508,10 @@ var Permission = class {
|
|
520
508
|
get companyOptions() {
|
521
509
|
const orgTree = this._orgTree;
|
522
510
|
if (!orgTree) return [];
|
523
|
-
const list =
|
524
|
-
|
525
|
-
|
511
|
+
const list = orgTree.map(({ children, ...others }) => ({
|
512
|
+
...others,
|
513
|
+
disabled: false
|
514
|
+
}));
|
526
515
|
if (this.hasRootAuth) {
|
527
516
|
list.unshift({ ...orgTree, label: "\u5168\u516C\u53F8", children: [] });
|
528
517
|
}
|
@@ -534,7 +523,7 @@ var Permission = class {
|
|
534
523
|
get unitOptions() {
|
535
524
|
const orgTree = this._orgTree;
|
536
525
|
if (!orgTree) return [];
|
537
|
-
return
|
526
|
+
return orgTree;
|
538
527
|
}
|
539
528
|
get allUnitOptions() {
|
540
529
|
const orgTree = this._orgTree;
|
@@ -547,7 +536,7 @@ var Permission = class {
|
|
547
536
|
}
|
548
537
|
const orgTree = this._orgTree;
|
549
538
|
if (!orgTree) return "";
|
550
|
-
return findFirstEnableCode(
|
539
|
+
return findFirstEnableCode(orgTree) ?? "";
|
551
540
|
}
|
552
541
|
get topLevelUnitOrgCodes() {
|
553
542
|
const orgTree = this._orgTree;
|
package/dist/index.d.mts
CHANGED
@@ -99,11 +99,10 @@ interface PermissionOptions {
|
|
99
99
|
* 组织树处理工具
|
100
100
|
*/
|
101
101
|
declare const DataHandler: {
|
102
|
-
iterateOrgTree(orgTree: OrgRecord$1): OrgTreeItem;
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
topLevelUnitOrgCodes(orgTree: OrgTreeItem): string[];
|
102
|
+
iterateOrgTree(orgTree: OrgRecord$1[]): OrgTreeItem[];
|
103
|
+
getAllUnitOptions(orgTree: OrgTreeItem[]): Option[];
|
104
|
+
getCompaniesOptions(orgTree: OrgTreeItem[], hasRootAuth: boolean): Option[];
|
105
|
+
topLevelUnitOrgCodes(orgTree: OrgTreeItem[]): string[];
|
107
106
|
getResourceData(resources: Resource[]): {
|
108
107
|
resourceMap: {
|
109
108
|
[path: string]: Resource;
|
@@ -118,7 +117,7 @@ declare const DataHandler: {
|
|
118
117
|
[path: string]: MenuItem;
|
119
118
|
};
|
120
119
|
};
|
121
|
-
getFirstUnitOrgCode(orgTree: OrgTreeItem): string;
|
120
|
+
getFirstUnitOrgCode(orgTree: OrgTreeItem[]): string;
|
122
121
|
};
|
123
122
|
declare class Permission {
|
124
123
|
private _userInfo;
|
@@ -152,12 +151,6 @@ declare class Permission {
|
|
152
151
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
153
152
|
*/
|
154
153
|
getResources(): Promise<{
|
155
|
-
resources: Resource[];
|
156
|
-
menuList: MenuItem[];
|
157
|
-
menuMap: Record<number, MenuItem>;
|
158
|
-
resourceMap?: undefined;
|
159
|
-
widgetMap?: undefined;
|
160
|
-
} | {
|
161
154
|
resources: Resource[];
|
162
155
|
resourceMap: {
|
163
156
|
[path: string]: Resource;
|
@@ -171,7 +164,7 @@ declare class Permission {
|
|
171
164
|
/**
|
172
165
|
* Query and process organization tree
|
173
166
|
*/
|
174
|
-
|
167
|
+
queryUserOrgs(): Promise<any[] | null>;
|
175
168
|
queryCompanies(): Promise<OrgRecord$1[]>;
|
176
169
|
isLogin(): boolean;
|
177
170
|
getToken(): string | null;
|
package/dist/index.d.ts
CHANGED
@@ -99,11 +99,10 @@ interface PermissionOptions {
|
|
99
99
|
* 组织树处理工具
|
100
100
|
*/
|
101
101
|
declare const DataHandler: {
|
102
|
-
iterateOrgTree(orgTree: OrgRecord$1): OrgTreeItem;
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
topLevelUnitOrgCodes(orgTree: OrgTreeItem): string[];
|
102
|
+
iterateOrgTree(orgTree: OrgRecord$1[]): OrgTreeItem[];
|
103
|
+
getAllUnitOptions(orgTree: OrgTreeItem[]): Option[];
|
104
|
+
getCompaniesOptions(orgTree: OrgTreeItem[], hasRootAuth: boolean): Option[];
|
105
|
+
topLevelUnitOrgCodes(orgTree: OrgTreeItem[]): string[];
|
107
106
|
getResourceData(resources: Resource[]): {
|
108
107
|
resourceMap: {
|
109
108
|
[path: string]: Resource;
|
@@ -118,7 +117,7 @@ declare const DataHandler: {
|
|
118
117
|
[path: string]: MenuItem;
|
119
118
|
};
|
120
119
|
};
|
121
|
-
getFirstUnitOrgCode(orgTree: OrgTreeItem): string;
|
120
|
+
getFirstUnitOrgCode(orgTree: OrgTreeItem[]): string;
|
122
121
|
};
|
123
122
|
declare class Permission {
|
124
123
|
private _userInfo;
|
@@ -152,12 +151,6 @@ declare class Permission {
|
|
152
151
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
153
152
|
*/
|
154
153
|
getResources(): Promise<{
|
155
|
-
resources: Resource[];
|
156
|
-
menuList: MenuItem[];
|
157
|
-
menuMap: Record<number, MenuItem>;
|
158
|
-
resourceMap?: undefined;
|
159
|
-
widgetMap?: undefined;
|
160
|
-
} | {
|
161
154
|
resources: Resource[];
|
162
155
|
resourceMap: {
|
163
156
|
[path: string]: Resource;
|
@@ -171,7 +164,7 @@ declare class Permission {
|
|
171
164
|
/**
|
172
165
|
* Query and process organization tree
|
173
166
|
*/
|
174
|
-
|
167
|
+
queryUserOrgs(): Promise<any[] | null>;
|
175
168
|
queryCompanies(): Promise<OrgRecord$1[]>;
|
176
169
|
isLogin(): boolean;
|
177
170
|
getToken(): string | null;
|
package/dist/index.mjs
CHANGED
@@ -206,10 +206,9 @@ async function queryResource(baseUrl, params) {
|
|
206
206
|
params
|
207
207
|
);
|
208
208
|
}
|
209
|
-
async function getUserOrgTree(baseUrl
|
209
|
+
async function getUserOrgTree(baseUrl) {
|
210
210
|
return await axiosClient.post(
|
211
|
-
`${baseUrl}/
|
212
|
-
params
|
211
|
+
`${baseUrl}/user/userInfo`
|
213
212
|
);
|
214
213
|
}
|
215
214
|
async function queryOrgCompanies(baseUrl, params) {
|
@@ -222,7 +221,7 @@ async function queryOrgCompanies(baseUrl, params) {
|
|
222
221
|
// src/permission.ts
|
223
222
|
var DataHandler = {
|
224
223
|
iterateOrgTree(orgTree) {
|
225
|
-
return iterateNestedArray(
|
224
|
+
return iterateNestedArray(orgTree, (item) => {
|
226
225
|
return {
|
227
226
|
label: item.orgShortName,
|
228
227
|
value: item.orgCode,
|
@@ -234,27 +233,28 @@ var DataHandler = {
|
|
234
233
|
orgType: item.orgType,
|
235
234
|
orgId: item.orgId
|
236
235
|
};
|
237
|
-
})
|
236
|
+
});
|
238
237
|
},
|
239
238
|
// 获取单位组织
|
240
|
-
getUnitOptions(orgTree) {
|
241
|
-
|
242
|
-
|
243
|
-
},
|
239
|
+
// getUnitOptions(orgTree: OrgTreeItem[]): Option[] {
|
240
|
+
// if (!orgTree) return [];
|
241
|
+
// return orgTree.disabled ? (orgTree.children ?? []) : [orgTree];
|
242
|
+
// },
|
244
243
|
// 获取所有单位组织
|
245
244
|
getAllUnitOptions(orgTree) {
|
246
245
|
if (!orgTree) return [];
|
247
246
|
const newTree = iterateNestedArray(
|
248
|
-
|
247
|
+
orgTree,
|
249
248
|
({ disabled, ...other }) => ({ ...other })
|
250
249
|
)?.[0];
|
251
250
|
return newTree ? newTree.children ?? [] : [];
|
252
251
|
},
|
253
252
|
getCompaniesOptions(orgTree, hasRootAuth) {
|
254
253
|
if (!orgTree) return [];
|
255
|
-
const list = (orgTree
|
256
|
-
|
257
|
-
|
254
|
+
const list = (orgTree || []).map(({ children, ...others }) => ({
|
255
|
+
...others,
|
256
|
+
disabled: false
|
257
|
+
}));
|
258
258
|
if (hasRootAuth) {
|
259
259
|
list.unshift({ ...orgTree, label: "\u5168\u516C\u53F8", children: [] });
|
260
260
|
}
|
@@ -263,9 +263,7 @@ var DataHandler = {
|
|
263
263
|
// 获取所有顶级单位组织代码
|
264
264
|
topLevelUnitOrgCodes(orgTree) {
|
265
265
|
if (!orgTree) return [];
|
266
|
-
return findAllEnableTopLevelCodes(
|
267
|
-
Array.isArray(orgTree) ? orgTree : [orgTree]
|
268
|
-
);
|
266
|
+
return findAllEnableTopLevelCodes(orgTree);
|
269
267
|
},
|
270
268
|
// 获取资源数据, 包含资源map和组件map
|
271
269
|
getResourceData(resources) {
|
@@ -276,7 +274,7 @@ var DataHandler = {
|
|
276
274
|
return createMenuList(resources);
|
277
275
|
},
|
278
276
|
getFirstUnitOrgCode(orgTree) {
|
279
|
-
return findFirstEnableCode(
|
277
|
+
return findFirstEnableCode(orgTree) ?? "";
|
280
278
|
}
|
281
279
|
};
|
282
280
|
var Permission = class {
|
@@ -353,24 +351,24 @@ var Permission = class {
|
|
353
351
|
*/
|
354
352
|
async getResources() {
|
355
353
|
let resources = storage.getItem(RESOURCE_KEY) || null;
|
356
|
-
if (resources) {
|
357
|
-
const {
|
358
|
-
|
359
|
-
resources,
|
360
|
-
menuList: menuList2,
|
361
|
-
menuMap: menuMap2
|
362
|
-
};
|
363
|
-
}
|
364
|
-
const { obj, success, msg, code } = await queryResource(this.baseUrl, {
|
365
|
-
systemId: this.systemId
|
366
|
-
});
|
367
|
-
if (!success) {
|
368
|
-
return Promise.reject({
|
369
|
-
code,
|
370
|
-
msg
|
354
|
+
if (!resources) {
|
355
|
+
const { obj, success, msg, code } = await queryResource(this.baseUrl, {
|
356
|
+
systemId: this.systemId
|
371
357
|
});
|
358
|
+
if (!success) {
|
359
|
+
return Promise.reject({
|
360
|
+
code,
|
361
|
+
msg
|
362
|
+
});
|
363
|
+
}
|
364
|
+
resources = obj;
|
365
|
+
storage.setItem(
|
366
|
+
RESOURCE_KEY,
|
367
|
+
resources,
|
368
|
+
60 * 24
|
369
|
+
// 24 hours
|
370
|
+
);
|
372
371
|
}
|
373
|
-
resources = obj;
|
374
372
|
const { resourceMap, widgetMap } = createResourceMap(resources);
|
375
373
|
const { menuList, menuMap } = createMenuList(resources);
|
376
374
|
this.resources = resources;
|
@@ -378,12 +376,6 @@ var Permission = class {
|
|
378
376
|
this.widgetMap = widgetMap;
|
379
377
|
this.menuList = menuList;
|
380
378
|
this.menuMap = menuMap;
|
381
|
-
storage.setItem(
|
382
|
-
RESOURCE_KEY,
|
383
|
-
resources,
|
384
|
-
60 * 24
|
385
|
-
// 24 hours
|
386
|
-
);
|
387
379
|
return {
|
388
380
|
resources,
|
389
381
|
resourceMap,
|
@@ -395,21 +387,17 @@ var Permission = class {
|
|
395
387
|
/**
|
396
388
|
* Query and process organization tree
|
397
389
|
*/
|
398
|
-
async
|
390
|
+
async queryUserOrgs() {
|
399
391
|
try {
|
400
|
-
const
|
401
|
-
|
402
|
-
name: "COS"
|
403
|
-
});
|
404
|
-
const { obj, success, msg, code } = data;
|
392
|
+
const res = await getUserOrgTree(this.baseUrl);
|
393
|
+
const { data, success, msg, code } = res;
|
405
394
|
if (!success) {
|
406
395
|
return Promise.reject({
|
407
396
|
code,
|
408
397
|
msg
|
409
398
|
});
|
410
399
|
}
|
411
|
-
const
|
412
|
-
const newTree = iterateNestedArray([orgTree], (item) => {
|
400
|
+
const newTree = iterateNestedArray(data, (item) => {
|
413
401
|
return {
|
414
402
|
label: item.orgShortName,
|
415
403
|
value: item.orgCode,
|
@@ -421,7 +409,7 @@ var Permission = class {
|
|
421
409
|
orgType: item.orgType,
|
422
410
|
orgId: item.orgId
|
423
411
|
};
|
424
|
-
})
|
412
|
+
});
|
425
413
|
this._orgTree = newTree;
|
426
414
|
return newTree;
|
427
415
|
} catch (error) {
|
@@ -481,9 +469,10 @@ var Permission = class {
|
|
481
469
|
get companyOptions() {
|
482
470
|
const orgTree = this._orgTree;
|
483
471
|
if (!orgTree) return [];
|
484
|
-
const list =
|
485
|
-
|
486
|
-
|
472
|
+
const list = orgTree.map(({ children, ...others }) => ({
|
473
|
+
...others,
|
474
|
+
disabled: false
|
475
|
+
}));
|
487
476
|
if (this.hasRootAuth) {
|
488
477
|
list.unshift({ ...orgTree, label: "\u5168\u516C\u53F8", children: [] });
|
489
478
|
}
|
@@ -495,7 +484,7 @@ var Permission = class {
|
|
495
484
|
get unitOptions() {
|
496
485
|
const orgTree = this._orgTree;
|
497
486
|
if (!orgTree) return [];
|
498
|
-
return
|
487
|
+
return orgTree;
|
499
488
|
}
|
500
489
|
get allUnitOptions() {
|
501
490
|
const orgTree = this._orgTree;
|
@@ -508,7 +497,7 @@ var Permission = class {
|
|
508
497
|
}
|
509
498
|
const orgTree = this._orgTree;
|
510
499
|
if (!orgTree) return "";
|
511
|
-
return findFirstEnableCode(
|
500
|
+
return findFirstEnableCode(orgTree) ?? "";
|
512
501
|
}
|
513
502
|
get topLevelUnitOrgCodes() {
|
514
503
|
const orgTree = this._orgTree;
|