@mu-cabin/opms-permission 0.9.11 → 0.9.13
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 +113 -169
- package/dist/index.d.mts +73 -77
- package/dist/index.d.ts +73 -77
- package/dist/index.mjs +111 -159
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
30
30
|
// src/index.ts
|
31
31
|
var index_exports = {};
|
32
32
|
__export(index_exports, {
|
33
|
+
ApiClient: () => ApiClient,
|
33
34
|
DataHandler: () => DataHandler,
|
34
35
|
EnumOrgQueryMode: () => EnumOrgQueryMode,
|
35
36
|
EnumOrgQueryScope: () => EnumOrgQueryScope,
|
@@ -40,45 +41,16 @@ __export(index_exports, {
|
|
40
41
|
USER_INFO_KEY: () => USER_INFO_KEY,
|
41
42
|
USER_ORG_KEY: () => USER_ORG_KEY,
|
42
43
|
USER_TOTAL_COMPANY_KEY: () => USER_TOTAL_COMPANY_KEY,
|
43
|
-
getOrgTree: () => getOrgTree,
|
44
|
-
getUserInfo: () => getUserInfo,
|
45
|
-
getUserOrgTree: () => getUserOrgTree,
|
46
44
|
jumpToSSOLogin: () => jumpToSSOLogin,
|
47
|
-
jumpToSSOLogout: () => jumpToSSOLogout
|
48
|
-
login: () => login,
|
49
|
-
logout: () => logout,
|
50
|
-
queryOrgCompanies: () => queryOrgCompanies,
|
51
|
-
queryOrgCustom: () => queryOrgCustom,
|
52
|
-
queryResource: () => queryResource,
|
53
|
-
superLogin: () => superLogin
|
45
|
+
jumpToSSOLogout: () => jumpToSSOLogout
|
54
46
|
});
|
55
47
|
module.exports = __toCommonJS(index_exports);
|
56
48
|
|
57
49
|
// src/utils/storage.ts
|
58
50
|
var Storage = class {
|
59
|
-
constructor() {
|
60
|
-
this.currentVersion = "1.0.0";
|
61
|
-
}
|
62
|
-
setSystemId(systemId) {
|
51
|
+
constructor(systemId, currentVersion) {
|
63
52
|
this.systemId = systemId;
|
64
|
-
|
65
|
-
/**
|
66
|
-
* Set the current version for new data
|
67
|
-
* If version changes, all existing data for this systemId will be cleared
|
68
|
-
*/
|
69
|
-
setVersion(version) {
|
70
|
-
if (this.currentVersion !== version) {
|
71
|
-
this.clear();
|
72
|
-
this.currentVersion = version;
|
73
|
-
} else {
|
74
|
-
this.currentVersion = version;
|
75
|
-
}
|
76
|
-
}
|
77
|
-
/**
|
78
|
-
* Get the current version
|
79
|
-
*/
|
80
|
-
getVersion() {
|
81
|
-
return this.currentVersion;
|
53
|
+
this.currentVersion = currentVersion;
|
82
54
|
}
|
83
55
|
prefixKey(key) {
|
84
56
|
return this.systemId !== void 0 ? `systemId-${this.systemId}-${key}` : key;
|
@@ -166,7 +138,6 @@ var Storage = class {
|
|
166
138
|
};
|
167
139
|
}
|
168
140
|
};
|
169
|
-
var storage = new Storage();
|
170
141
|
|
171
142
|
// src/utils/dataHandler.ts
|
172
143
|
var getCompletePath = (item, hasSubApp) => {
|
@@ -317,9 +288,6 @@ function handlePermissionTree(data, key) {
|
|
317
288
|
};
|
318
289
|
}
|
319
290
|
|
320
|
-
// src/api.ts
|
321
|
-
var import_axios = __toESM(require("axios"));
|
322
|
-
|
323
291
|
// src/config.ts
|
324
292
|
var USER_INFO_KEY = "opms_user_info";
|
325
293
|
var RESOURCE_KEY = "opms_resources";
|
@@ -327,98 +295,6 @@ var TOKEN_KEY = "opms_authorization";
|
|
327
295
|
var USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
328
296
|
var USER_ORG_KEY = "opms_user_orgs";
|
329
297
|
|
330
|
-
// src/api.ts
|
331
|
-
var axiosClient = import_axios.default.create();
|
332
|
-
axiosClient.interceptors.request.use((config) => {
|
333
|
-
const token = storage.getItem(TOKEN_KEY);
|
334
|
-
if (token) {
|
335
|
-
config.headers.Authorization = token;
|
336
|
-
}
|
337
|
-
return config;
|
338
|
-
});
|
339
|
-
axiosClient.interceptors.response.use(
|
340
|
-
(response) => {
|
341
|
-
const res = response.data;
|
342
|
-
const { success, code, msg } = res;
|
343
|
-
if (success === false) {
|
344
|
-
return Promise.reject({
|
345
|
-
code,
|
346
|
-
msg
|
347
|
-
});
|
348
|
-
}
|
349
|
-
return res;
|
350
|
-
},
|
351
|
-
(error) => {
|
352
|
-
return Promise.reject(error);
|
353
|
-
}
|
354
|
-
);
|
355
|
-
var EnumOrgQueryMode = /* @__PURE__ */ ((EnumOrgQueryMode2) => {
|
356
|
-
EnumOrgQueryMode2["BY_ROLES"] = "BY_ROLES";
|
357
|
-
EnumOrgQueryMode2["BY_DEPT"] = "BY_DEPT";
|
358
|
-
return EnumOrgQueryMode2;
|
359
|
-
})(EnumOrgQueryMode || {});
|
360
|
-
var EnumOrgQueryScope = /* @__PURE__ */ ((EnumOrgQueryScope2) => {
|
361
|
-
EnumOrgQueryScope2["ONLY_BRANCH"] = "ONLY_BRANCH";
|
362
|
-
EnumOrgQueryScope2["STEWARD_UNIT"] = "STEWARD_UNIT";
|
363
|
-
EnumOrgQueryScope2["WITH_DEPARTMENT"] = "WITH_DEPARTMENT";
|
364
|
-
return EnumOrgQueryScope2;
|
365
|
-
})(EnumOrgQueryScope || {});
|
366
|
-
async function login(baseUrl, authorizationCode) {
|
367
|
-
return await axiosClient.get(
|
368
|
-
`${baseUrl}/opmsDefaultAuth/oauthLogin`,
|
369
|
-
{
|
370
|
-
params: { authorizationCode }
|
371
|
-
}
|
372
|
-
);
|
373
|
-
}
|
374
|
-
async function superLogin(baseUrl, params) {
|
375
|
-
return await axiosClient.post(
|
376
|
-
`${baseUrl}/opmsDefaultAuth/superLogin`,
|
377
|
-
params
|
378
|
-
);
|
379
|
-
}
|
380
|
-
async function logout(baseUrl) {
|
381
|
-
return await axiosClient.post(
|
382
|
-
`${baseUrl}/opmsDefaultAuth/logout`
|
383
|
-
);
|
384
|
-
}
|
385
|
-
async function getUserInfo(baseUrl) {
|
386
|
-
return await axiosClient.post(
|
387
|
-
`${baseUrl}/opmsDefaultUser/userInfo`,
|
388
|
-
{}
|
389
|
-
);
|
390
|
-
}
|
391
|
-
async function queryResource(baseUrl, params) {
|
392
|
-
return await axiosClient.post(
|
393
|
-
`${baseUrl}/opmsDefaultUser/userResource`,
|
394
|
-
params
|
395
|
-
);
|
396
|
-
}
|
397
|
-
async function getOrgTree(baseUrl, params) {
|
398
|
-
return await axiosClient.post(
|
399
|
-
`${baseUrl}/opmsDefaultUser/orgTree`,
|
400
|
-
params
|
401
|
-
);
|
402
|
-
}
|
403
|
-
async function getUserOrgTree(baseUrl, params) {
|
404
|
-
return await axiosClient.post(
|
405
|
-
`${baseUrl}/opmsDefaultUser/userOrgTree`,
|
406
|
-
params
|
407
|
-
);
|
408
|
-
}
|
409
|
-
async function queryOrgCompanies(baseUrl, params) {
|
410
|
-
return await axiosClient.post(
|
411
|
-
`${baseUrl}/opmsDefaultUser/branches`,
|
412
|
-
params
|
413
|
-
);
|
414
|
-
}
|
415
|
-
function queryOrgCustom(baseUrl, params) {
|
416
|
-
return import_axios.default.post(
|
417
|
-
`${baseUrl}/opmsDefaultUser/queryOrgCustom`,
|
418
|
-
params
|
419
|
-
);
|
420
|
-
}
|
421
|
-
|
422
298
|
// src/utils/eventEmitter.ts
|
423
299
|
var EventEmitter = class {
|
424
300
|
constructor(allowedEvents) {
|
@@ -517,6 +393,98 @@ var EventEmitter = class {
|
|
517
393
|
}
|
518
394
|
};
|
519
395
|
|
396
|
+
// src/api.ts
|
397
|
+
var import_axios = __toESM(require("axios"));
|
398
|
+
var ApiClient = class {
|
399
|
+
constructor(baseUrl, storage) {
|
400
|
+
this.baseUrl = baseUrl;
|
401
|
+
this.storage = storage;
|
402
|
+
this.axiosClient = import_axios.default.create();
|
403
|
+
this.axiosClient.interceptors.request.use((config) => {
|
404
|
+
const token = this.storage.getItem(TOKEN_KEY);
|
405
|
+
if (token) {
|
406
|
+
config.headers.Authorization = token;
|
407
|
+
}
|
408
|
+
return config;
|
409
|
+
});
|
410
|
+
this.axiosClient.interceptors.response.use(
|
411
|
+
(response) => {
|
412
|
+
const res = response.data;
|
413
|
+
const { success, code, msg } = res;
|
414
|
+
if (success === false) {
|
415
|
+
return Promise.reject({ code, msg });
|
416
|
+
}
|
417
|
+
return res;
|
418
|
+
},
|
419
|
+
(error) => Promise.reject(error)
|
420
|
+
);
|
421
|
+
}
|
422
|
+
async login(authorizationCode) {
|
423
|
+
return await this.axiosClient.get(
|
424
|
+
`${this.baseUrl}/opmsDefaultAuth/oauthLogin`,
|
425
|
+
{ params: { authorizationCode } }
|
426
|
+
);
|
427
|
+
}
|
428
|
+
async superLogin(params) {
|
429
|
+
return await this.axiosClient.post(
|
430
|
+
`${this.baseUrl}/opmsDefaultAuth/superLogin`,
|
431
|
+
params
|
432
|
+
);
|
433
|
+
}
|
434
|
+
async logout() {
|
435
|
+
return await this.axiosClient.post(
|
436
|
+
`${this.baseUrl}/opmsDefaultAuth/logout`
|
437
|
+
);
|
438
|
+
}
|
439
|
+
async getUserInfo() {
|
440
|
+
return await this.axiosClient.post(
|
441
|
+
`${this.baseUrl}/opmsDefaultUser/userInfo`,
|
442
|
+
{}
|
443
|
+
);
|
444
|
+
}
|
445
|
+
async queryResource(params) {
|
446
|
+
return await this.axiosClient.post(
|
447
|
+
`${this.baseUrl}/opmsDefaultUser/userResource`,
|
448
|
+
params
|
449
|
+
);
|
450
|
+
}
|
451
|
+
async getOrgTree(params) {
|
452
|
+
return await this.axiosClient.post(
|
453
|
+
`${this.baseUrl}/opmsDefaultUser/orgTree`,
|
454
|
+
params
|
455
|
+
);
|
456
|
+
}
|
457
|
+
async getUserOrgTree(params) {
|
458
|
+
return await this.axiosClient.post(
|
459
|
+
`${this.baseUrl}/opmsDefaultUser/userOrgTree`,
|
460
|
+
params
|
461
|
+
);
|
462
|
+
}
|
463
|
+
async queryOrgCompanies(params) {
|
464
|
+
return await this.axiosClient.post(
|
465
|
+
`${this.baseUrl}/opmsDefaultUser/branches`,
|
466
|
+
params
|
467
|
+
);
|
468
|
+
}
|
469
|
+
async queryOrgCustom(params) {
|
470
|
+
return import_axios.default.post(
|
471
|
+
`${this.baseUrl}/opmsDefaultUser/queryOrgCustom`,
|
472
|
+
params
|
473
|
+
);
|
474
|
+
}
|
475
|
+
};
|
476
|
+
var EnumOrgQueryMode = /* @__PURE__ */ ((EnumOrgQueryMode2) => {
|
477
|
+
EnumOrgQueryMode2["BY_ROLES"] = "BY_ROLES";
|
478
|
+
EnumOrgQueryMode2["BY_DEPT"] = "BY_DEPT";
|
479
|
+
return EnumOrgQueryMode2;
|
480
|
+
})(EnumOrgQueryMode || {});
|
481
|
+
var EnumOrgQueryScope = /* @__PURE__ */ ((EnumOrgQueryScope2) => {
|
482
|
+
EnumOrgQueryScope2["ONLY_BRANCH"] = "ONLY_BRANCH";
|
483
|
+
EnumOrgQueryScope2["STEWARD_UNIT"] = "STEWARD_UNIT";
|
484
|
+
EnumOrgQueryScope2["WITH_DEPARTMENT"] = "WITH_DEPARTMENT";
|
485
|
+
return EnumOrgQueryScope2;
|
486
|
+
})(EnumOrgQueryScope || {});
|
487
|
+
|
520
488
|
// src/permission.ts
|
521
489
|
var DataHandler = {
|
522
490
|
iterateOrgTree(orgTree) {
|
@@ -592,9 +560,8 @@ var Permission = class {
|
|
592
560
|
this.baseUrl = options.baseUrl;
|
593
561
|
this.systemId = options.systemId;
|
594
562
|
this.hasSubApp = options.hasSubApp ?? false;
|
595
|
-
this.storage = new Storage();
|
596
|
-
this.
|
597
|
-
this.storage.setVersion("1.0.0");
|
563
|
+
this.storage = new Storage(this.systemId, "1.0.0");
|
564
|
+
this.api = new ApiClient(this.baseUrl, this.storage);
|
598
565
|
}
|
599
566
|
/**
|
600
567
|
* Add event listener
|
@@ -644,7 +611,7 @@ var Permission = class {
|
|
644
611
|
}
|
645
612
|
async superLogin(userName, password) {
|
646
613
|
this.clear();
|
647
|
-
const { obj, msg, code } = await superLogin(
|
614
|
+
const { obj, msg, code } = await this.api.superLogin({
|
648
615
|
userName,
|
649
616
|
password
|
650
617
|
});
|
@@ -675,7 +642,7 @@ var Permission = class {
|
|
675
642
|
obj,
|
676
643
|
msg,
|
677
644
|
code: loginCode
|
678
|
-
} = await login(
|
645
|
+
} = await this.api.login(authCode);
|
679
646
|
if (loginCode !== 200) {
|
680
647
|
return Promise.reject({
|
681
648
|
code: loginCode,
|
@@ -692,7 +659,7 @@ var Permission = class {
|
|
692
659
|
* Logout and clear userInfo
|
693
660
|
*/
|
694
661
|
async logout(clearData = true) {
|
695
|
-
await logout(
|
662
|
+
await this.api.logout();
|
696
663
|
clearData && this.clear();
|
697
664
|
}
|
698
665
|
clear() {
|
@@ -700,17 +667,22 @@ var Permission = class {
|
|
700
667
|
this.emit("tokenChange", "");
|
701
668
|
}
|
702
669
|
async getUserInfo() {
|
703
|
-
const data = await getUserInfo(
|
670
|
+
const data = await this.api.getUserInfo();
|
704
671
|
const { obj, success, msg, code } = data;
|
672
|
+
this.storage.setItem(USER_INFO_KEY, obj);
|
705
673
|
return obj;
|
706
674
|
}
|
675
|
+
isSameUser(account) {
|
676
|
+
const userInfo = this.storage.getItem(USER_INFO_KEY);
|
677
|
+
return userInfo?.account === account;
|
678
|
+
}
|
707
679
|
/**
|
708
680
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
709
681
|
*/
|
710
682
|
async getResources() {
|
711
683
|
let resources = this.storage.getItem(RESOURCE_KEY) || null;
|
712
684
|
if (!resources) {
|
713
|
-
const { obj, success, msg, code } = await queryResource(
|
685
|
+
const { obj, success, msg, code } = await this.api.queryResource({
|
714
686
|
systemId: this.systemId
|
715
687
|
});
|
716
688
|
if (!success) {
|
@@ -768,7 +740,7 @@ var Permission = class {
|
|
768
740
|
orgTreeData = this.storage.getItem(cacheKey) || null;
|
769
741
|
}
|
770
742
|
if (!orgTreeData) {
|
771
|
-
const res = await getUserOrgTree(
|
743
|
+
const res = await this.api.getUserOrgTree(params);
|
772
744
|
const { obj } = res;
|
773
745
|
orgTreeData = iterateNestedArray(obj, (item) => {
|
774
746
|
return {
|
@@ -790,8 +762,6 @@ var Permission = class {
|
|
790
762
|
const { tree } = data;
|
791
763
|
return {
|
792
764
|
orgTree: tree
|
793
|
-
// orgNoAuthMap: noAuthMap,
|
794
|
-
// authOrgTree: tree,
|
795
765
|
};
|
796
766
|
} catch (error) {
|
797
767
|
console.log(error);
|
@@ -808,7 +778,7 @@ var Permission = class {
|
|
808
778
|
orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
|
809
779
|
}
|
810
780
|
if (!orgCompanyList) {
|
811
|
-
const { obj } = await queryOrgCustom(
|
781
|
+
const { obj } = await this.api.queryOrgCustom({
|
812
782
|
resultView: "LIST",
|
813
783
|
orgCodeSource: "COS",
|
814
784
|
direction: "FROM_SELF_TO_LEAF",
|
@@ -846,24 +816,6 @@ var Permission = class {
|
|
846
816
|
this.storage.setItem(TOKEN_KEY, token);
|
847
817
|
this.emit("tokenChange", token);
|
848
818
|
}
|
849
|
-
// --- Getters ---
|
850
|
-
// get userInfo(): UserInfo | null {
|
851
|
-
// if (!this._userInfo) {
|
852
|
-
// this._userInfo = storage.getItem(USER_INFO_KEY);
|
853
|
-
// }
|
854
|
-
// if (!this._userInfo) return null;
|
855
|
-
// const { account, name, ehrId, crewCode, crewId } = this._userInfo;
|
856
|
-
// return { account, name, ehrId, crewCode, crewId };
|
857
|
-
// }
|
858
|
-
// get hasRootAuth() {
|
859
|
-
// const orgs = this._userInfo?.organizations || [];
|
860
|
-
// const first = orgs[0];
|
861
|
-
// if (!first) return false;
|
862
|
-
// return first.searchPath === '#1';
|
863
|
-
// }
|
864
|
-
// get userOrganizations(): UserOrganization[] {
|
865
|
-
// return this._userInfo?.userOrganizations || [];
|
866
|
-
// }
|
867
819
|
/**
|
868
820
|
* Get storage information for debugging and monitoring
|
869
821
|
*/
|
@@ -894,7 +846,7 @@ var Permission = class {
|
|
894
846
|
* Get current storage version
|
895
847
|
*/
|
896
848
|
getStorageVersion() {
|
897
|
-
return this.storage.
|
849
|
+
return this.storage.currentVersion;
|
898
850
|
}
|
899
851
|
/**
|
900
852
|
* Clear all storage data for this system
|
@@ -975,6 +927,7 @@ function jumpToSSOLogout({
|
|
975
927
|
}
|
976
928
|
// Annotate the CommonJS export names for ESM import in node:
|
977
929
|
0 && (module.exports = {
|
930
|
+
ApiClient,
|
978
931
|
DataHandler,
|
979
932
|
EnumOrgQueryMode,
|
980
933
|
EnumOrgQueryScope,
|
@@ -985,15 +938,6 @@ function jumpToSSOLogout({
|
|
985
938
|
USER_INFO_KEY,
|
986
939
|
USER_ORG_KEY,
|
987
940
|
USER_TOTAL_COMPANY_KEY,
|
988
|
-
getOrgTree,
|
989
|
-
getUserInfo,
|
990
|
-
getUserOrgTree,
|
991
941
|
jumpToSSOLogin,
|
992
|
-
jumpToSSOLogout
|
993
|
-
login,
|
994
|
-
logout,
|
995
|
-
queryOrgCompanies,
|
996
|
-
queryOrgCustom,
|
997
|
-
queryResource,
|
998
|
-
superLogin
|
942
|
+
jumpToSSOLogout
|
999
943
|
});
|
package/dist/index.d.mts
CHANGED
@@ -1,3 +1,73 @@
|
|
1
|
+
declare class Storage {
|
2
|
+
private systemId;
|
3
|
+
private currentVersion;
|
4
|
+
constructor(systemId: number | string, currentVersion: string);
|
5
|
+
private prefixKey;
|
6
|
+
/**
|
7
|
+
* Set an item in localStorage, with optional expiration in minutes
|
8
|
+
*/
|
9
|
+
setItem<T>(key: string, value: T, expireMinutes?: number): void;
|
10
|
+
/**
|
11
|
+
* Get an item from localStorage, returns undefined if expired or not found
|
12
|
+
* Automatically expires data if version is different
|
13
|
+
*/
|
14
|
+
getItem<T>(key: string): T | undefined;
|
15
|
+
/**
|
16
|
+
* Remove an item from localStorage
|
17
|
+
*/
|
18
|
+
removeItem(key: string): void;
|
19
|
+
/**
|
20
|
+
* Clear all data for the current systemId
|
21
|
+
*/
|
22
|
+
clear(): void;
|
23
|
+
/**
|
24
|
+
* Get all keys for the current systemId
|
25
|
+
*/
|
26
|
+
getKeys(): string[];
|
27
|
+
/**
|
28
|
+
* Check if a key exists
|
29
|
+
*/
|
30
|
+
hasKey(key: string): boolean;
|
31
|
+
/**
|
32
|
+
* Get storage info for debugging
|
33
|
+
*/
|
34
|
+
getStorageInfo(): {
|
35
|
+
systemId: number | string | undefined;
|
36
|
+
currentVersion: string;
|
37
|
+
totalKeys: number;
|
38
|
+
systemKeys: number;
|
39
|
+
};
|
40
|
+
}
|
41
|
+
|
42
|
+
declare class ApiClient {
|
43
|
+
private axiosClient;
|
44
|
+
private baseUrl;
|
45
|
+
private storage;
|
46
|
+
constructor(baseUrl: string, storage: Storage);
|
47
|
+
login(authorizationCode: string): Promise<ApiResponse<{
|
48
|
+
token: string;
|
49
|
+
}>>;
|
50
|
+
superLogin(params: {
|
51
|
+
userName: string;
|
52
|
+
password: string;
|
53
|
+
}): Promise<ApiResponse<{
|
54
|
+
token: string;
|
55
|
+
}>>;
|
56
|
+
logout(): Promise<ApiResponse<void>>;
|
57
|
+
getUserInfo(): Promise<ApiResponse<UserInfo$1>>;
|
58
|
+
queryResource(params: {
|
59
|
+
systemId: string;
|
60
|
+
}): Promise<ApiResponse<Resource[]>>;
|
61
|
+
getOrgTree(params: {
|
62
|
+
systemId: string;
|
63
|
+
name: CodeSourceType;
|
64
|
+
}): Promise<ApiResponse<OrgRecord$1>>;
|
65
|
+
getUserOrgTree(params: UserOrgTreeParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
66
|
+
queryOrgCompanies(params: {
|
67
|
+
queryAllBranches?: boolean;
|
68
|
+
}): Promise<ApiResponse<OrgRecord$1[]>>;
|
69
|
+
queryOrgCustom(params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
70
|
+
}
|
1
71
|
interface ApiResponse<T> {
|
2
72
|
obj: T;
|
3
73
|
success: boolean;
|
@@ -98,28 +168,6 @@ interface UserOrgTreeParams {
|
|
98
168
|
stewardUnitLevel?: number;
|
99
169
|
keepHead?: boolean;
|
100
170
|
}
|
101
|
-
declare function login(baseUrl: string, authorizationCode: string): Promise<ApiResponse<{
|
102
|
-
token: string;
|
103
|
-
}>>;
|
104
|
-
declare function superLogin(baseUrl: string, params: {
|
105
|
-
userName: string;
|
106
|
-
password: string;
|
107
|
-
}): Promise<ApiResponse<{
|
108
|
-
token: string;
|
109
|
-
}>>;
|
110
|
-
declare function logout(baseUrl: string): Promise<ApiResponse<void>>;
|
111
|
-
declare function getUserInfo(baseUrl: string): Promise<ApiResponse<UserInfo$1>>;
|
112
|
-
declare function queryResource(baseUrl: string, params: {
|
113
|
-
systemId: string;
|
114
|
-
}): Promise<ApiResponse<Resource[]>>;
|
115
|
-
declare function getOrgTree(baseUrl: string, params: {
|
116
|
-
systemId: string;
|
117
|
-
name: CodeSourceType;
|
118
|
-
}): Promise<ApiResponse<OrgRecord$1>>;
|
119
|
-
declare function getUserOrgTree(baseUrl: string, params: UserOrgTreeParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
120
|
-
declare function queryOrgCompanies(baseUrl: string, params: {
|
121
|
-
queryAllBranches?: boolean;
|
122
|
-
}): Promise<ApiResponse<OrgRecord$1[]>>;
|
123
171
|
type ResultViewType = 'LIST' | 'TREE' | 'FOREST';
|
124
172
|
type OrgDirectionType = 'NONE' | 'FROM_SELF_TO_ROOT' | 'FROM_SELF_TO_LEAF' | 'TWO_WAY';
|
125
173
|
type OrgType = 'HEAD' | 'BRANCH' | 'DEPARTMENT';
|
@@ -131,60 +179,6 @@ interface QueryOrgCustomParams {
|
|
131
179
|
maxDepth?: number;
|
132
180
|
orgTypes?: OrgType[];
|
133
181
|
}
|
134
|
-
/**
|
135
|
-
* 根据查询条件自定义组织机构查询
|
136
|
-
*/
|
137
|
-
declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
138
|
-
|
139
|
-
declare class Storage {
|
140
|
-
private systemId?;
|
141
|
-
private currentVersion;
|
142
|
-
setSystemId(systemId: number | string): void;
|
143
|
-
/**
|
144
|
-
* Set the current version for new data
|
145
|
-
* If version changes, all existing data for this systemId will be cleared
|
146
|
-
*/
|
147
|
-
setVersion(version: string): void;
|
148
|
-
/**
|
149
|
-
* Get the current version
|
150
|
-
*/
|
151
|
-
getVersion(): string;
|
152
|
-
private prefixKey;
|
153
|
-
/**
|
154
|
-
* Set an item in localStorage, with optional expiration in minutes
|
155
|
-
*/
|
156
|
-
setItem<T>(key: string, value: T, expireMinutes?: number): void;
|
157
|
-
/**
|
158
|
-
* Get an item from localStorage, returns undefined if expired or not found
|
159
|
-
* Automatically expires data if version is different
|
160
|
-
*/
|
161
|
-
getItem<T>(key: string): T | undefined;
|
162
|
-
/**
|
163
|
-
* Remove an item from localStorage
|
164
|
-
*/
|
165
|
-
removeItem(key: string): void;
|
166
|
-
/**
|
167
|
-
* Clear all data for the current systemId
|
168
|
-
*/
|
169
|
-
clear(): void;
|
170
|
-
/**
|
171
|
-
* Get all keys for the current systemId
|
172
|
-
*/
|
173
|
-
getKeys(): string[];
|
174
|
-
/**
|
175
|
-
* Check if a key exists
|
176
|
-
*/
|
177
|
-
hasKey(key: string): boolean;
|
178
|
-
/**
|
179
|
-
* Get storage info for debugging
|
180
|
-
*/
|
181
|
-
getStorageInfo(): {
|
182
|
-
systemId: number | string | undefined;
|
183
|
-
currentVersion: string;
|
184
|
-
totalKeys: number;
|
185
|
-
systemKeys: number;
|
186
|
-
};
|
187
|
-
}
|
188
182
|
|
189
183
|
declare const USER_INFO_KEY = "opms_user_info";
|
190
184
|
declare const RESOURCE_KEY = "opms_resources";
|
@@ -374,6 +368,7 @@ declare class Permission {
|
|
374
368
|
};
|
375
369
|
hasSubApp: boolean;
|
376
370
|
storage: Storage;
|
371
|
+
private api;
|
377
372
|
private eventEmitter;
|
378
373
|
constructor(options: PermissionOptions);
|
379
374
|
/**
|
@@ -411,6 +406,7 @@ declare class Permission {
|
|
411
406
|
logout(clearData?: boolean): Promise<void>;
|
412
407
|
clear(): void;
|
413
408
|
getUserInfo(): Promise<UserInfo$1>;
|
409
|
+
isSameUser(account: string): boolean;
|
414
410
|
/**
|
415
411
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
416
412
|
*/
|
@@ -507,4 +503,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
507
503
|
clientId?: string;
|
508
504
|
}): void;
|
509
505
|
|
510
|
-
export { type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole,
|
506
|
+
export { ApiClient, type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, jumpToSSOLogin, jumpToSSOLogout };
|
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,73 @@
|
|
1
|
+
declare class Storage {
|
2
|
+
private systemId;
|
3
|
+
private currentVersion;
|
4
|
+
constructor(systemId: number | string, currentVersion: string);
|
5
|
+
private prefixKey;
|
6
|
+
/**
|
7
|
+
* Set an item in localStorage, with optional expiration in minutes
|
8
|
+
*/
|
9
|
+
setItem<T>(key: string, value: T, expireMinutes?: number): void;
|
10
|
+
/**
|
11
|
+
* Get an item from localStorage, returns undefined if expired or not found
|
12
|
+
* Automatically expires data if version is different
|
13
|
+
*/
|
14
|
+
getItem<T>(key: string): T | undefined;
|
15
|
+
/**
|
16
|
+
* Remove an item from localStorage
|
17
|
+
*/
|
18
|
+
removeItem(key: string): void;
|
19
|
+
/**
|
20
|
+
* Clear all data for the current systemId
|
21
|
+
*/
|
22
|
+
clear(): void;
|
23
|
+
/**
|
24
|
+
* Get all keys for the current systemId
|
25
|
+
*/
|
26
|
+
getKeys(): string[];
|
27
|
+
/**
|
28
|
+
* Check if a key exists
|
29
|
+
*/
|
30
|
+
hasKey(key: string): boolean;
|
31
|
+
/**
|
32
|
+
* Get storage info for debugging
|
33
|
+
*/
|
34
|
+
getStorageInfo(): {
|
35
|
+
systemId: number | string | undefined;
|
36
|
+
currentVersion: string;
|
37
|
+
totalKeys: number;
|
38
|
+
systemKeys: number;
|
39
|
+
};
|
40
|
+
}
|
41
|
+
|
42
|
+
declare class ApiClient {
|
43
|
+
private axiosClient;
|
44
|
+
private baseUrl;
|
45
|
+
private storage;
|
46
|
+
constructor(baseUrl: string, storage: Storage);
|
47
|
+
login(authorizationCode: string): Promise<ApiResponse<{
|
48
|
+
token: string;
|
49
|
+
}>>;
|
50
|
+
superLogin(params: {
|
51
|
+
userName: string;
|
52
|
+
password: string;
|
53
|
+
}): Promise<ApiResponse<{
|
54
|
+
token: string;
|
55
|
+
}>>;
|
56
|
+
logout(): Promise<ApiResponse<void>>;
|
57
|
+
getUserInfo(): Promise<ApiResponse<UserInfo$1>>;
|
58
|
+
queryResource(params: {
|
59
|
+
systemId: string;
|
60
|
+
}): Promise<ApiResponse<Resource[]>>;
|
61
|
+
getOrgTree(params: {
|
62
|
+
systemId: string;
|
63
|
+
name: CodeSourceType;
|
64
|
+
}): Promise<ApiResponse<OrgRecord$1>>;
|
65
|
+
getUserOrgTree(params: UserOrgTreeParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
66
|
+
queryOrgCompanies(params: {
|
67
|
+
queryAllBranches?: boolean;
|
68
|
+
}): Promise<ApiResponse<OrgRecord$1[]>>;
|
69
|
+
queryOrgCustom(params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
70
|
+
}
|
1
71
|
interface ApiResponse<T> {
|
2
72
|
obj: T;
|
3
73
|
success: boolean;
|
@@ -98,28 +168,6 @@ interface UserOrgTreeParams {
|
|
98
168
|
stewardUnitLevel?: number;
|
99
169
|
keepHead?: boolean;
|
100
170
|
}
|
101
|
-
declare function login(baseUrl: string, authorizationCode: string): Promise<ApiResponse<{
|
102
|
-
token: string;
|
103
|
-
}>>;
|
104
|
-
declare function superLogin(baseUrl: string, params: {
|
105
|
-
userName: string;
|
106
|
-
password: string;
|
107
|
-
}): Promise<ApiResponse<{
|
108
|
-
token: string;
|
109
|
-
}>>;
|
110
|
-
declare function logout(baseUrl: string): Promise<ApiResponse<void>>;
|
111
|
-
declare function getUserInfo(baseUrl: string): Promise<ApiResponse<UserInfo$1>>;
|
112
|
-
declare function queryResource(baseUrl: string, params: {
|
113
|
-
systemId: string;
|
114
|
-
}): Promise<ApiResponse<Resource[]>>;
|
115
|
-
declare function getOrgTree(baseUrl: string, params: {
|
116
|
-
systemId: string;
|
117
|
-
name: CodeSourceType;
|
118
|
-
}): Promise<ApiResponse<OrgRecord$1>>;
|
119
|
-
declare function getUserOrgTree(baseUrl: string, params: UserOrgTreeParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
120
|
-
declare function queryOrgCompanies(baseUrl: string, params: {
|
121
|
-
queryAllBranches?: boolean;
|
122
|
-
}): Promise<ApiResponse<OrgRecord$1[]>>;
|
123
171
|
type ResultViewType = 'LIST' | 'TREE' | 'FOREST';
|
124
172
|
type OrgDirectionType = 'NONE' | 'FROM_SELF_TO_ROOT' | 'FROM_SELF_TO_LEAF' | 'TWO_WAY';
|
125
173
|
type OrgType = 'HEAD' | 'BRANCH' | 'DEPARTMENT';
|
@@ -131,60 +179,6 @@ interface QueryOrgCustomParams {
|
|
131
179
|
maxDepth?: number;
|
132
180
|
orgTypes?: OrgType[];
|
133
181
|
}
|
134
|
-
/**
|
135
|
-
* 根据查询条件自定义组织机构查询
|
136
|
-
*/
|
137
|
-
declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
138
|
-
|
139
|
-
declare class Storage {
|
140
|
-
private systemId?;
|
141
|
-
private currentVersion;
|
142
|
-
setSystemId(systemId: number | string): void;
|
143
|
-
/**
|
144
|
-
* Set the current version for new data
|
145
|
-
* If version changes, all existing data for this systemId will be cleared
|
146
|
-
*/
|
147
|
-
setVersion(version: string): void;
|
148
|
-
/**
|
149
|
-
* Get the current version
|
150
|
-
*/
|
151
|
-
getVersion(): string;
|
152
|
-
private prefixKey;
|
153
|
-
/**
|
154
|
-
* Set an item in localStorage, with optional expiration in minutes
|
155
|
-
*/
|
156
|
-
setItem<T>(key: string, value: T, expireMinutes?: number): void;
|
157
|
-
/**
|
158
|
-
* Get an item from localStorage, returns undefined if expired or not found
|
159
|
-
* Automatically expires data if version is different
|
160
|
-
*/
|
161
|
-
getItem<T>(key: string): T | undefined;
|
162
|
-
/**
|
163
|
-
* Remove an item from localStorage
|
164
|
-
*/
|
165
|
-
removeItem(key: string): void;
|
166
|
-
/**
|
167
|
-
* Clear all data for the current systemId
|
168
|
-
*/
|
169
|
-
clear(): void;
|
170
|
-
/**
|
171
|
-
* Get all keys for the current systemId
|
172
|
-
*/
|
173
|
-
getKeys(): string[];
|
174
|
-
/**
|
175
|
-
* Check if a key exists
|
176
|
-
*/
|
177
|
-
hasKey(key: string): boolean;
|
178
|
-
/**
|
179
|
-
* Get storage info for debugging
|
180
|
-
*/
|
181
|
-
getStorageInfo(): {
|
182
|
-
systemId: number | string | undefined;
|
183
|
-
currentVersion: string;
|
184
|
-
totalKeys: number;
|
185
|
-
systemKeys: number;
|
186
|
-
};
|
187
|
-
}
|
188
182
|
|
189
183
|
declare const USER_INFO_KEY = "opms_user_info";
|
190
184
|
declare const RESOURCE_KEY = "opms_resources";
|
@@ -374,6 +368,7 @@ declare class Permission {
|
|
374
368
|
};
|
375
369
|
hasSubApp: boolean;
|
376
370
|
storage: Storage;
|
371
|
+
private api;
|
377
372
|
private eventEmitter;
|
378
373
|
constructor(options: PermissionOptions);
|
379
374
|
/**
|
@@ -411,6 +406,7 @@ declare class Permission {
|
|
411
406
|
logout(clearData?: boolean): Promise<void>;
|
412
407
|
clear(): void;
|
413
408
|
getUserInfo(): Promise<UserInfo$1>;
|
409
|
+
isSameUser(account: string): boolean;
|
414
410
|
/**
|
415
411
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
416
412
|
*/
|
@@ -507,4 +503,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
507
503
|
clientId?: string;
|
508
504
|
}): void;
|
509
505
|
|
510
|
-
export { type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole,
|
506
|
+
export { ApiClient, type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgDirectionType, type OrgRecord, type OrgTreeItem, type OrgType, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type QueryOrgCustomParams, RESOURCE_KEY, type Resource, type ResourceType, type ResultViewType, TOKEN_KEY, USER_INFO_KEY, USER_ORG_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, jumpToSSOLogin, jumpToSSOLogout };
|
package/dist/index.mjs
CHANGED
@@ -1,28 +1,8 @@
|
|
1
1
|
// src/utils/storage.ts
|
2
2
|
var Storage = class {
|
3
|
-
constructor() {
|
4
|
-
this.currentVersion = "1.0.0";
|
5
|
-
}
|
6
|
-
setSystemId(systemId) {
|
3
|
+
constructor(systemId, currentVersion) {
|
7
4
|
this.systemId = systemId;
|
8
|
-
|
9
|
-
/**
|
10
|
-
* Set the current version for new data
|
11
|
-
* If version changes, all existing data for this systemId will be cleared
|
12
|
-
*/
|
13
|
-
setVersion(version) {
|
14
|
-
if (this.currentVersion !== version) {
|
15
|
-
this.clear();
|
16
|
-
this.currentVersion = version;
|
17
|
-
} else {
|
18
|
-
this.currentVersion = version;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
/**
|
22
|
-
* Get the current version
|
23
|
-
*/
|
24
|
-
getVersion() {
|
25
|
-
return this.currentVersion;
|
5
|
+
this.currentVersion = currentVersion;
|
26
6
|
}
|
27
7
|
prefixKey(key) {
|
28
8
|
return this.systemId !== void 0 ? `systemId-${this.systemId}-${key}` : key;
|
@@ -110,7 +90,6 @@ var Storage = class {
|
|
110
90
|
};
|
111
91
|
}
|
112
92
|
};
|
113
|
-
var storage = new Storage();
|
114
93
|
|
115
94
|
// src/utils/dataHandler.ts
|
116
95
|
var getCompletePath = (item, hasSubApp) => {
|
@@ -261,9 +240,6 @@ function handlePermissionTree(data, key) {
|
|
261
240
|
};
|
262
241
|
}
|
263
242
|
|
264
|
-
// src/api.ts
|
265
|
-
import axios from "axios";
|
266
|
-
|
267
243
|
// src/config.ts
|
268
244
|
var USER_INFO_KEY = "opms_user_info";
|
269
245
|
var RESOURCE_KEY = "opms_resources";
|
@@ -271,98 +247,6 @@ var TOKEN_KEY = "opms_authorization";
|
|
271
247
|
var USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
272
248
|
var USER_ORG_KEY = "opms_user_orgs";
|
273
249
|
|
274
|
-
// src/api.ts
|
275
|
-
var axiosClient = axios.create();
|
276
|
-
axiosClient.interceptors.request.use((config) => {
|
277
|
-
const token = storage.getItem(TOKEN_KEY);
|
278
|
-
if (token) {
|
279
|
-
config.headers.Authorization = token;
|
280
|
-
}
|
281
|
-
return config;
|
282
|
-
});
|
283
|
-
axiosClient.interceptors.response.use(
|
284
|
-
(response) => {
|
285
|
-
const res = response.data;
|
286
|
-
const { success, code, msg } = res;
|
287
|
-
if (success === false) {
|
288
|
-
return Promise.reject({
|
289
|
-
code,
|
290
|
-
msg
|
291
|
-
});
|
292
|
-
}
|
293
|
-
return res;
|
294
|
-
},
|
295
|
-
(error) => {
|
296
|
-
return Promise.reject(error);
|
297
|
-
}
|
298
|
-
);
|
299
|
-
var EnumOrgQueryMode = /* @__PURE__ */ ((EnumOrgQueryMode2) => {
|
300
|
-
EnumOrgQueryMode2["BY_ROLES"] = "BY_ROLES";
|
301
|
-
EnumOrgQueryMode2["BY_DEPT"] = "BY_DEPT";
|
302
|
-
return EnumOrgQueryMode2;
|
303
|
-
})(EnumOrgQueryMode || {});
|
304
|
-
var EnumOrgQueryScope = /* @__PURE__ */ ((EnumOrgQueryScope2) => {
|
305
|
-
EnumOrgQueryScope2["ONLY_BRANCH"] = "ONLY_BRANCH";
|
306
|
-
EnumOrgQueryScope2["STEWARD_UNIT"] = "STEWARD_UNIT";
|
307
|
-
EnumOrgQueryScope2["WITH_DEPARTMENT"] = "WITH_DEPARTMENT";
|
308
|
-
return EnumOrgQueryScope2;
|
309
|
-
})(EnumOrgQueryScope || {});
|
310
|
-
async function login(baseUrl, authorizationCode) {
|
311
|
-
return await axiosClient.get(
|
312
|
-
`${baseUrl}/opmsDefaultAuth/oauthLogin`,
|
313
|
-
{
|
314
|
-
params: { authorizationCode }
|
315
|
-
}
|
316
|
-
);
|
317
|
-
}
|
318
|
-
async function superLogin(baseUrl, params) {
|
319
|
-
return await axiosClient.post(
|
320
|
-
`${baseUrl}/opmsDefaultAuth/superLogin`,
|
321
|
-
params
|
322
|
-
);
|
323
|
-
}
|
324
|
-
async function logout(baseUrl) {
|
325
|
-
return await axiosClient.post(
|
326
|
-
`${baseUrl}/opmsDefaultAuth/logout`
|
327
|
-
);
|
328
|
-
}
|
329
|
-
async function getUserInfo(baseUrl) {
|
330
|
-
return await axiosClient.post(
|
331
|
-
`${baseUrl}/opmsDefaultUser/userInfo`,
|
332
|
-
{}
|
333
|
-
);
|
334
|
-
}
|
335
|
-
async function queryResource(baseUrl, params) {
|
336
|
-
return await axiosClient.post(
|
337
|
-
`${baseUrl}/opmsDefaultUser/userResource`,
|
338
|
-
params
|
339
|
-
);
|
340
|
-
}
|
341
|
-
async function getOrgTree(baseUrl, params) {
|
342
|
-
return await axiosClient.post(
|
343
|
-
`${baseUrl}/opmsDefaultUser/orgTree`,
|
344
|
-
params
|
345
|
-
);
|
346
|
-
}
|
347
|
-
async function getUserOrgTree(baseUrl, params) {
|
348
|
-
return await axiosClient.post(
|
349
|
-
`${baseUrl}/opmsDefaultUser/userOrgTree`,
|
350
|
-
params
|
351
|
-
);
|
352
|
-
}
|
353
|
-
async function queryOrgCompanies(baseUrl, params) {
|
354
|
-
return await axiosClient.post(
|
355
|
-
`${baseUrl}/opmsDefaultUser/branches`,
|
356
|
-
params
|
357
|
-
);
|
358
|
-
}
|
359
|
-
function queryOrgCustom(baseUrl, params) {
|
360
|
-
return axios.post(
|
361
|
-
`${baseUrl}/opmsDefaultUser/queryOrgCustom`,
|
362
|
-
params
|
363
|
-
);
|
364
|
-
}
|
365
|
-
|
366
250
|
// src/utils/eventEmitter.ts
|
367
251
|
var EventEmitter = class {
|
368
252
|
constructor(allowedEvents) {
|
@@ -461,6 +345,98 @@ var EventEmitter = class {
|
|
461
345
|
}
|
462
346
|
};
|
463
347
|
|
348
|
+
// src/api.ts
|
349
|
+
import axios from "axios";
|
350
|
+
var ApiClient = class {
|
351
|
+
constructor(baseUrl, storage) {
|
352
|
+
this.baseUrl = baseUrl;
|
353
|
+
this.storage = storage;
|
354
|
+
this.axiosClient = axios.create();
|
355
|
+
this.axiosClient.interceptors.request.use((config) => {
|
356
|
+
const token = this.storage.getItem(TOKEN_KEY);
|
357
|
+
if (token) {
|
358
|
+
config.headers.Authorization = token;
|
359
|
+
}
|
360
|
+
return config;
|
361
|
+
});
|
362
|
+
this.axiosClient.interceptors.response.use(
|
363
|
+
(response) => {
|
364
|
+
const res = response.data;
|
365
|
+
const { success, code, msg } = res;
|
366
|
+
if (success === false) {
|
367
|
+
return Promise.reject({ code, msg });
|
368
|
+
}
|
369
|
+
return res;
|
370
|
+
},
|
371
|
+
(error) => Promise.reject(error)
|
372
|
+
);
|
373
|
+
}
|
374
|
+
async login(authorizationCode) {
|
375
|
+
return await this.axiosClient.get(
|
376
|
+
`${this.baseUrl}/opmsDefaultAuth/oauthLogin`,
|
377
|
+
{ params: { authorizationCode } }
|
378
|
+
);
|
379
|
+
}
|
380
|
+
async superLogin(params) {
|
381
|
+
return await this.axiosClient.post(
|
382
|
+
`${this.baseUrl}/opmsDefaultAuth/superLogin`,
|
383
|
+
params
|
384
|
+
);
|
385
|
+
}
|
386
|
+
async logout() {
|
387
|
+
return await this.axiosClient.post(
|
388
|
+
`${this.baseUrl}/opmsDefaultAuth/logout`
|
389
|
+
);
|
390
|
+
}
|
391
|
+
async getUserInfo() {
|
392
|
+
return await this.axiosClient.post(
|
393
|
+
`${this.baseUrl}/opmsDefaultUser/userInfo`,
|
394
|
+
{}
|
395
|
+
);
|
396
|
+
}
|
397
|
+
async queryResource(params) {
|
398
|
+
return await this.axiosClient.post(
|
399
|
+
`${this.baseUrl}/opmsDefaultUser/userResource`,
|
400
|
+
params
|
401
|
+
);
|
402
|
+
}
|
403
|
+
async getOrgTree(params) {
|
404
|
+
return await this.axiosClient.post(
|
405
|
+
`${this.baseUrl}/opmsDefaultUser/orgTree`,
|
406
|
+
params
|
407
|
+
);
|
408
|
+
}
|
409
|
+
async getUserOrgTree(params) {
|
410
|
+
return await this.axiosClient.post(
|
411
|
+
`${this.baseUrl}/opmsDefaultUser/userOrgTree`,
|
412
|
+
params
|
413
|
+
);
|
414
|
+
}
|
415
|
+
async queryOrgCompanies(params) {
|
416
|
+
return await this.axiosClient.post(
|
417
|
+
`${this.baseUrl}/opmsDefaultUser/branches`,
|
418
|
+
params
|
419
|
+
);
|
420
|
+
}
|
421
|
+
async queryOrgCustom(params) {
|
422
|
+
return axios.post(
|
423
|
+
`${this.baseUrl}/opmsDefaultUser/queryOrgCustom`,
|
424
|
+
params
|
425
|
+
);
|
426
|
+
}
|
427
|
+
};
|
428
|
+
var EnumOrgQueryMode = /* @__PURE__ */ ((EnumOrgQueryMode2) => {
|
429
|
+
EnumOrgQueryMode2["BY_ROLES"] = "BY_ROLES";
|
430
|
+
EnumOrgQueryMode2["BY_DEPT"] = "BY_DEPT";
|
431
|
+
return EnumOrgQueryMode2;
|
432
|
+
})(EnumOrgQueryMode || {});
|
433
|
+
var EnumOrgQueryScope = /* @__PURE__ */ ((EnumOrgQueryScope2) => {
|
434
|
+
EnumOrgQueryScope2["ONLY_BRANCH"] = "ONLY_BRANCH";
|
435
|
+
EnumOrgQueryScope2["STEWARD_UNIT"] = "STEWARD_UNIT";
|
436
|
+
EnumOrgQueryScope2["WITH_DEPARTMENT"] = "WITH_DEPARTMENT";
|
437
|
+
return EnumOrgQueryScope2;
|
438
|
+
})(EnumOrgQueryScope || {});
|
439
|
+
|
464
440
|
// src/permission.ts
|
465
441
|
var DataHandler = {
|
466
442
|
iterateOrgTree(orgTree) {
|
@@ -536,9 +512,8 @@ var Permission = class {
|
|
536
512
|
this.baseUrl = options.baseUrl;
|
537
513
|
this.systemId = options.systemId;
|
538
514
|
this.hasSubApp = options.hasSubApp ?? false;
|
539
|
-
this.storage = new Storage();
|
540
|
-
this.
|
541
|
-
this.storage.setVersion("1.0.0");
|
515
|
+
this.storage = new Storage(this.systemId, "1.0.0");
|
516
|
+
this.api = new ApiClient(this.baseUrl, this.storage);
|
542
517
|
}
|
543
518
|
/**
|
544
519
|
* Add event listener
|
@@ -588,7 +563,7 @@ var Permission = class {
|
|
588
563
|
}
|
589
564
|
async superLogin(userName, password) {
|
590
565
|
this.clear();
|
591
|
-
const { obj, msg, code } = await superLogin(
|
566
|
+
const { obj, msg, code } = await this.api.superLogin({
|
592
567
|
userName,
|
593
568
|
password
|
594
569
|
});
|
@@ -619,7 +594,7 @@ var Permission = class {
|
|
619
594
|
obj,
|
620
595
|
msg,
|
621
596
|
code: loginCode
|
622
|
-
} = await login(
|
597
|
+
} = await this.api.login(authCode);
|
623
598
|
if (loginCode !== 200) {
|
624
599
|
return Promise.reject({
|
625
600
|
code: loginCode,
|
@@ -636,7 +611,7 @@ var Permission = class {
|
|
636
611
|
* Logout and clear userInfo
|
637
612
|
*/
|
638
613
|
async logout(clearData = true) {
|
639
|
-
await logout(
|
614
|
+
await this.api.logout();
|
640
615
|
clearData && this.clear();
|
641
616
|
}
|
642
617
|
clear() {
|
@@ -644,17 +619,22 @@ var Permission = class {
|
|
644
619
|
this.emit("tokenChange", "");
|
645
620
|
}
|
646
621
|
async getUserInfo() {
|
647
|
-
const data = await getUserInfo(
|
622
|
+
const data = await this.api.getUserInfo();
|
648
623
|
const { obj, success, msg, code } = data;
|
624
|
+
this.storage.setItem(USER_INFO_KEY, obj);
|
649
625
|
return obj;
|
650
626
|
}
|
627
|
+
isSameUser(account) {
|
628
|
+
const userInfo = this.storage.getItem(USER_INFO_KEY);
|
629
|
+
return userInfo?.account === account;
|
630
|
+
}
|
651
631
|
/**
|
652
632
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
653
633
|
*/
|
654
634
|
async getResources() {
|
655
635
|
let resources = this.storage.getItem(RESOURCE_KEY) || null;
|
656
636
|
if (!resources) {
|
657
|
-
const { obj, success, msg, code } = await queryResource(
|
637
|
+
const { obj, success, msg, code } = await this.api.queryResource({
|
658
638
|
systemId: this.systemId
|
659
639
|
});
|
660
640
|
if (!success) {
|
@@ -712,7 +692,7 @@ var Permission = class {
|
|
712
692
|
orgTreeData = this.storage.getItem(cacheKey) || null;
|
713
693
|
}
|
714
694
|
if (!orgTreeData) {
|
715
|
-
const res = await getUserOrgTree(
|
695
|
+
const res = await this.api.getUserOrgTree(params);
|
716
696
|
const { obj } = res;
|
717
697
|
orgTreeData = iterateNestedArray(obj, (item) => {
|
718
698
|
return {
|
@@ -734,8 +714,6 @@ var Permission = class {
|
|
734
714
|
const { tree } = data;
|
735
715
|
return {
|
736
716
|
orgTree: tree
|
737
|
-
// orgNoAuthMap: noAuthMap,
|
738
|
-
// authOrgTree: tree,
|
739
717
|
};
|
740
718
|
} catch (error) {
|
741
719
|
console.log(error);
|
@@ -752,7 +730,7 @@ var Permission = class {
|
|
752
730
|
orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
|
753
731
|
}
|
754
732
|
if (!orgCompanyList) {
|
755
|
-
const { obj } = await queryOrgCustom(
|
733
|
+
const { obj } = await this.api.queryOrgCustom({
|
756
734
|
resultView: "LIST",
|
757
735
|
orgCodeSource: "COS",
|
758
736
|
direction: "FROM_SELF_TO_LEAF",
|
@@ -790,24 +768,6 @@ var Permission = class {
|
|
790
768
|
this.storage.setItem(TOKEN_KEY, token);
|
791
769
|
this.emit("tokenChange", token);
|
792
770
|
}
|
793
|
-
// --- Getters ---
|
794
|
-
// get userInfo(): UserInfo | null {
|
795
|
-
// if (!this._userInfo) {
|
796
|
-
// this._userInfo = storage.getItem(USER_INFO_KEY);
|
797
|
-
// }
|
798
|
-
// if (!this._userInfo) return null;
|
799
|
-
// const { account, name, ehrId, crewCode, crewId } = this._userInfo;
|
800
|
-
// return { account, name, ehrId, crewCode, crewId };
|
801
|
-
// }
|
802
|
-
// get hasRootAuth() {
|
803
|
-
// const orgs = this._userInfo?.organizations || [];
|
804
|
-
// const first = orgs[0];
|
805
|
-
// if (!first) return false;
|
806
|
-
// return first.searchPath === '#1';
|
807
|
-
// }
|
808
|
-
// get userOrganizations(): UserOrganization[] {
|
809
|
-
// return this._userInfo?.userOrganizations || [];
|
810
|
-
// }
|
811
771
|
/**
|
812
772
|
* Get storage information for debugging and monitoring
|
813
773
|
*/
|
@@ -838,7 +798,7 @@ var Permission = class {
|
|
838
798
|
* Get current storage version
|
839
799
|
*/
|
840
800
|
getStorageVersion() {
|
841
|
-
return this.storage.
|
801
|
+
return this.storage.currentVersion;
|
842
802
|
}
|
843
803
|
/**
|
844
804
|
* Clear all storage data for this system
|
@@ -918,6 +878,7 @@ function jumpToSSOLogout({
|
|
918
878
|
window.location.href = logoutUrl.toString();
|
919
879
|
}
|
920
880
|
export {
|
881
|
+
ApiClient,
|
921
882
|
DataHandler,
|
922
883
|
EnumOrgQueryMode,
|
923
884
|
EnumOrgQueryScope,
|
@@ -928,15 +889,6 @@ export {
|
|
928
889
|
USER_INFO_KEY,
|
929
890
|
USER_ORG_KEY,
|
930
891
|
USER_TOTAL_COMPANY_KEY,
|
931
|
-
getOrgTree,
|
932
|
-
getUserInfo,
|
933
|
-
getUserOrgTree,
|
934
892
|
jumpToSSOLogin,
|
935
|
-
jumpToSSOLogout
|
936
|
-
login,
|
937
|
-
logout,
|
938
|
-
queryOrgCompanies,
|
939
|
-
queryOrgCustom,
|
940
|
-
queryResource,
|
941
|
-
superLogin
|
893
|
+
jumpToSSOLogout
|
942
894
|
};
|