@mu-cabin/opms-permission 0.9.12 → 0.9.14
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 +153 -170
- package/dist/index.d.mts +46 -39
- package/dist/index.d.ts +46 -39
- package/dist/index.mjs +150 -160
- 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,
|
@@ -39,46 +40,18 @@ __export(index_exports, {
|
|
39
40
|
TOKEN_KEY: () => TOKEN_KEY,
|
40
41
|
USER_INFO_KEY: () => USER_INFO_KEY,
|
41
42
|
USER_ORG_KEY: () => USER_ORG_KEY,
|
43
|
+
USER_ORG_NO_AUTH_KEY: () => USER_ORG_NO_AUTH_KEY,
|
42
44
|
USER_TOTAL_COMPANY_KEY: () => USER_TOTAL_COMPANY_KEY,
|
43
|
-
getOrgTree: () => getOrgTree,
|
44
|
-
getUserInfo: () => getUserInfo,
|
45
|
-
getUserOrgTree: () => getUserOrgTree,
|
46
45
|
jumpToSSOLogin: () => jumpToSSOLogin,
|
47
|
-
jumpToSSOLogout: () => jumpToSSOLogout
|
48
|
-
login: () => login,
|
49
|
-
logout: () => logout,
|
50
|
-
queryOrgCompanies: () => queryOrgCompanies,
|
51
|
-
queryOrgCustom: () => queryOrgCustom,
|
52
|
-
queryResource: () => queryResource,
|
53
|
-
superLogin: () => superLogin
|
46
|
+
jumpToSSOLogout: () => jumpToSSOLogout
|
54
47
|
});
|
55
48
|
module.exports = __toCommonJS(index_exports);
|
56
49
|
|
57
50
|
// src/utils/storage.ts
|
58
51
|
var Storage = class {
|
59
|
-
constructor() {
|
60
|
-
this.currentVersion = "1.0.0";
|
61
|
-
}
|
62
|
-
setSystemId(systemId) {
|
52
|
+
constructor(systemId, currentVersion) {
|
63
53
|
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;
|
54
|
+
this.currentVersion = currentVersion;
|
82
55
|
}
|
83
56
|
prefixKey(key) {
|
84
57
|
return this.systemId !== void 0 ? `systemId-${this.systemId}-${key}` : key;
|
@@ -166,7 +139,6 @@ var Storage = class {
|
|
166
139
|
};
|
167
140
|
}
|
168
141
|
};
|
169
|
-
var storage = new Storage();
|
170
142
|
|
171
143
|
// src/utils/dataHandler.ts
|
172
144
|
var getCompletePath = (item, hasSubApp) => {
|
@@ -317,107 +289,13 @@ function handlePermissionTree(data, key) {
|
|
317
289
|
};
|
318
290
|
}
|
319
291
|
|
320
|
-
// src/api.ts
|
321
|
-
var import_axios = __toESM(require("axios"));
|
322
|
-
|
323
292
|
// src/config.ts
|
324
293
|
var USER_INFO_KEY = "opms_user_info";
|
325
294
|
var RESOURCE_KEY = "opms_resources";
|
326
295
|
var TOKEN_KEY = "opms_authorization";
|
327
296
|
var USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
328
297
|
var USER_ORG_KEY = "opms_user_orgs";
|
329
|
-
|
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
|
-
}
|
298
|
+
var USER_ORG_NO_AUTH_KEY = "opms_user_org_no_auth";
|
421
299
|
|
422
300
|
// src/utils/eventEmitter.ts
|
423
301
|
var EventEmitter = class {
|
@@ -517,6 +395,98 @@ var EventEmitter = class {
|
|
517
395
|
}
|
518
396
|
};
|
519
397
|
|
398
|
+
// src/api.ts
|
399
|
+
var import_axios = __toESM(require("axios"));
|
400
|
+
var ApiClient = class {
|
401
|
+
constructor(baseUrl, storage) {
|
402
|
+
this.baseUrl = baseUrl;
|
403
|
+
this.storage = storage;
|
404
|
+
this.axiosClient = import_axios.default.create();
|
405
|
+
this.axiosClient.interceptors.request.use((config) => {
|
406
|
+
const token = this.storage.getItem(TOKEN_KEY);
|
407
|
+
if (token) {
|
408
|
+
config.headers.Authorization = token;
|
409
|
+
}
|
410
|
+
return config;
|
411
|
+
});
|
412
|
+
this.axiosClient.interceptors.response.use(
|
413
|
+
(response) => {
|
414
|
+
const res = response.data;
|
415
|
+
const { success, code, msg } = res;
|
416
|
+
if (success === false) {
|
417
|
+
return Promise.reject({ code, msg });
|
418
|
+
}
|
419
|
+
return res;
|
420
|
+
},
|
421
|
+
(error) => Promise.reject(error)
|
422
|
+
);
|
423
|
+
}
|
424
|
+
async login(authorizationCode) {
|
425
|
+
return await this.axiosClient.get(
|
426
|
+
`${this.baseUrl}/opmsDefaultAuth/oauthLogin`,
|
427
|
+
{ params: { authorizationCode } }
|
428
|
+
);
|
429
|
+
}
|
430
|
+
async superLogin(params) {
|
431
|
+
return await this.axiosClient.post(
|
432
|
+
`${this.baseUrl}/opmsDefaultAuth/superLogin`,
|
433
|
+
params
|
434
|
+
);
|
435
|
+
}
|
436
|
+
async logout() {
|
437
|
+
return await this.axiosClient.post(
|
438
|
+
`${this.baseUrl}/opmsDefaultAuth/logout`
|
439
|
+
);
|
440
|
+
}
|
441
|
+
async getUserInfo() {
|
442
|
+
return await this.axiosClient.post(
|
443
|
+
`${this.baseUrl}/opmsDefaultUser/userInfo`,
|
444
|
+
{}
|
445
|
+
);
|
446
|
+
}
|
447
|
+
async queryResource(params) {
|
448
|
+
return await this.axiosClient.post(
|
449
|
+
`${this.baseUrl}/opmsDefaultUser/userResource`,
|
450
|
+
params
|
451
|
+
);
|
452
|
+
}
|
453
|
+
async getOrgTree(params) {
|
454
|
+
return await this.axiosClient.post(
|
455
|
+
`${this.baseUrl}/opmsDefaultUser/orgTree`,
|
456
|
+
params
|
457
|
+
);
|
458
|
+
}
|
459
|
+
async getUserOrgTree(params) {
|
460
|
+
return await this.axiosClient.post(
|
461
|
+
`${this.baseUrl}/opmsDefaultUser/userOrgTree`,
|
462
|
+
params
|
463
|
+
);
|
464
|
+
}
|
465
|
+
async queryOrgCompanies(params) {
|
466
|
+
return await this.axiosClient.post(
|
467
|
+
`${this.baseUrl}/opmsDefaultUser/branches`,
|
468
|
+
params
|
469
|
+
);
|
470
|
+
}
|
471
|
+
async queryOrgCustom(params) {
|
472
|
+
return import_axios.default.post(
|
473
|
+
`${this.baseUrl}/opmsDefaultUser/queryOrgCustom`,
|
474
|
+
params
|
475
|
+
);
|
476
|
+
}
|
477
|
+
};
|
478
|
+
var EnumOrgQueryMode = /* @__PURE__ */ ((EnumOrgQueryMode2) => {
|
479
|
+
EnumOrgQueryMode2["BY_ROLES"] = "BY_ROLES";
|
480
|
+
EnumOrgQueryMode2["BY_DEPT"] = "BY_DEPT";
|
481
|
+
return EnumOrgQueryMode2;
|
482
|
+
})(EnumOrgQueryMode || {});
|
483
|
+
var EnumOrgQueryScope = /* @__PURE__ */ ((EnumOrgQueryScope2) => {
|
484
|
+
EnumOrgQueryScope2["ONLY_BRANCH"] = "ONLY_BRANCH";
|
485
|
+
EnumOrgQueryScope2["STEWARD_UNIT"] = "STEWARD_UNIT";
|
486
|
+
EnumOrgQueryScope2["WITH_DEPARTMENT"] = "WITH_DEPARTMENT";
|
487
|
+
return EnumOrgQueryScope2;
|
488
|
+
})(EnumOrgQueryScope || {});
|
489
|
+
|
520
490
|
// src/permission.ts
|
521
491
|
var DataHandler = {
|
522
492
|
iterateOrgTree(orgTree) {
|
@@ -592,9 +562,8 @@ var Permission = class {
|
|
592
562
|
this.baseUrl = options.baseUrl;
|
593
563
|
this.systemId = options.systemId;
|
594
564
|
this.hasSubApp = options.hasSubApp ?? false;
|
595
|
-
this.storage = new Storage();
|
596
|
-
this.
|
597
|
-
this.storage.setVersion("1.0.0");
|
565
|
+
this.storage = new Storage(this.systemId, "1.0.0");
|
566
|
+
this.api = new ApiClient(this.baseUrl, this.storage);
|
598
567
|
}
|
599
568
|
/**
|
600
569
|
* Add event listener
|
@@ -644,7 +613,7 @@ var Permission = class {
|
|
644
613
|
}
|
645
614
|
async superLogin(userName, password) {
|
646
615
|
this.clear();
|
647
|
-
const { obj, msg, code } = await superLogin(
|
616
|
+
const { obj, msg, code } = await this.api.superLogin({
|
648
617
|
userName,
|
649
618
|
password
|
650
619
|
});
|
@@ -675,7 +644,7 @@ var Permission = class {
|
|
675
644
|
obj,
|
676
645
|
msg,
|
677
646
|
code: loginCode
|
678
|
-
} = await login(
|
647
|
+
} = await this.api.login(authCode);
|
679
648
|
if (loginCode !== 200) {
|
680
649
|
return Promise.reject({
|
681
650
|
code: loginCode,
|
@@ -692,7 +661,7 @@ var Permission = class {
|
|
692
661
|
* Logout and clear userInfo
|
693
662
|
*/
|
694
663
|
async logout(clearData = true) {
|
695
|
-
await logout(
|
664
|
+
await this.api.logout();
|
696
665
|
clearData && this.clear();
|
697
666
|
}
|
698
667
|
clear() {
|
@@ -700,7 +669,7 @@ var Permission = class {
|
|
700
669
|
this.emit("tokenChange", "");
|
701
670
|
}
|
702
671
|
async getUserInfo() {
|
703
|
-
const data = await getUserInfo(
|
672
|
+
const data = await this.api.getUserInfo();
|
704
673
|
const { obj, success, msg, code } = data;
|
705
674
|
this.storage.setItem(USER_INFO_KEY, obj);
|
706
675
|
return obj;
|
@@ -715,7 +684,7 @@ var Permission = class {
|
|
715
684
|
async getResources() {
|
716
685
|
let resources = this.storage.getItem(RESOURCE_KEY) || null;
|
717
686
|
if (!resources) {
|
718
|
-
const { obj, success, msg, code } = await queryResource(
|
687
|
+
const { obj, success, msg, code } = await this.api.queryResource({
|
719
688
|
systemId: this.systemId
|
720
689
|
});
|
721
690
|
if (!success) {
|
@@ -773,7 +742,7 @@ var Permission = class {
|
|
773
742
|
orgTreeData = this.storage.getItem(cacheKey) || null;
|
774
743
|
}
|
775
744
|
if (!orgTreeData) {
|
776
|
-
const res = await getUserOrgTree(
|
745
|
+
const res = await this.api.getUserOrgTree(params);
|
777
746
|
const { obj } = res;
|
778
747
|
orgTreeData = iterateNestedArray(obj, (item) => {
|
779
748
|
return {
|
@@ -795,8 +764,6 @@ var Permission = class {
|
|
795
764
|
const { tree } = data;
|
796
765
|
return {
|
797
766
|
orgTree: tree
|
798
|
-
// orgNoAuthMap: noAuthMap,
|
799
|
-
// authOrgTree: tree,
|
800
767
|
};
|
801
768
|
} catch (error) {
|
802
769
|
console.log(error);
|
@@ -813,7 +780,7 @@ var Permission = class {
|
|
813
780
|
orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
|
814
781
|
}
|
815
782
|
if (!orgCompanyList) {
|
816
|
-
const { obj } = await queryOrgCustom(
|
783
|
+
const { obj } = await this.api.queryOrgCustom({
|
817
784
|
resultView: "LIST",
|
818
785
|
orgCodeSource: "COS",
|
819
786
|
direction: "FROM_SELF_TO_LEAF",
|
@@ -851,24 +818,6 @@ var Permission = class {
|
|
851
818
|
this.storage.setItem(TOKEN_KEY, token);
|
852
819
|
this.emit("tokenChange", token);
|
853
820
|
}
|
854
|
-
// --- Getters ---
|
855
|
-
// get userInfo(): UserInfo | null {
|
856
|
-
// if (!this._userInfo) {
|
857
|
-
// this._userInfo = storage.getItem(USER_INFO_KEY);
|
858
|
-
// }
|
859
|
-
// if (!this._userInfo) return null;
|
860
|
-
// const { account, name, ehrId, crewCode, crewId } = this._userInfo;
|
861
|
-
// return { account, name, ehrId, crewCode, crewId };
|
862
|
-
// }
|
863
|
-
// get hasRootAuth() {
|
864
|
-
// const orgs = this._userInfo?.organizations || [];
|
865
|
-
// const first = orgs[0];
|
866
|
-
// if (!first) return false;
|
867
|
-
// return first.searchPath === '#1';
|
868
|
-
// }
|
869
|
-
// get userOrganizations(): UserOrganization[] {
|
870
|
-
// return this._userInfo?.userOrganizations || [];
|
871
|
-
// }
|
872
821
|
/**
|
873
822
|
* Get storage information for debugging and monitoring
|
874
823
|
*/
|
@@ -895,11 +844,52 @@ var Permission = class {
|
|
895
844
|
}
|
896
845
|
};
|
897
846
|
}
|
847
|
+
/**
|
848
|
+
* Get organization map by codes with caching
|
849
|
+
* Checks localStorage first, then fetches missing orgs from API
|
850
|
+
*/
|
851
|
+
async getOrgMapByCodes(orgCodes, config = {
|
852
|
+
force: false,
|
853
|
+
cacheTimeout: 60 * 24
|
854
|
+
// 24 hours default
|
855
|
+
}) {
|
856
|
+
const { force, cacheTimeout = 60 * 24 } = config;
|
857
|
+
const result = {};
|
858
|
+
const missingOrgCodes = [];
|
859
|
+
let cachedOrgMap = {};
|
860
|
+
if (!force) {
|
861
|
+
cachedOrgMap = this.storage.getItem(USER_ORG_NO_AUTH_KEY) || {};
|
862
|
+
}
|
863
|
+
for (const orgCode of orgCodes) {
|
864
|
+
if (cachedOrgMap[orgCode]) {
|
865
|
+
result[orgCode] = cachedOrgMap[orgCode];
|
866
|
+
} else {
|
867
|
+
missingOrgCodes.push(orgCode);
|
868
|
+
}
|
869
|
+
}
|
870
|
+
if (missingOrgCodes.length > 0) {
|
871
|
+
try {
|
872
|
+
const { obj } = await this.api.queryOrgCustom({
|
873
|
+
orgCodes: missingOrgCodes
|
874
|
+
});
|
875
|
+
for (const org of obj) {
|
876
|
+
const orgCode = org.orgCode;
|
877
|
+
result[orgCode] = org;
|
878
|
+
cachedOrgMap[orgCode] = org;
|
879
|
+
}
|
880
|
+
this.storage.setItem(USER_ORG_NO_AUTH_KEY, cachedOrgMap, cacheTimeout);
|
881
|
+
} catch (error) {
|
882
|
+
console.error("Error fetching org data:", error);
|
883
|
+
throw error;
|
884
|
+
}
|
885
|
+
}
|
886
|
+
return result;
|
887
|
+
}
|
898
888
|
/**
|
899
889
|
* Get current storage version
|
900
890
|
*/
|
901
891
|
getStorageVersion() {
|
902
|
-
return this.storage.
|
892
|
+
return this.storage.currentVersion;
|
903
893
|
}
|
904
894
|
/**
|
905
895
|
* Clear all storage data for this system
|
@@ -929,7 +919,7 @@ var Permission = class {
|
|
929
919
|
clearUserCache() {
|
930
920
|
const keys = this.storage.getKeys();
|
931
921
|
keys.forEach((key) => {
|
932
|
-
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY)) {
|
922
|
+
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY) || key.startsWith(USER_ORG_NO_AUTH_KEY)) {
|
933
923
|
this.storage.removeItem(key);
|
934
924
|
}
|
935
925
|
});
|
@@ -980,6 +970,7 @@ function jumpToSSOLogout({
|
|
980
970
|
}
|
981
971
|
// Annotate the CommonJS export names for ESM import in node:
|
982
972
|
0 && (module.exports = {
|
973
|
+
ApiClient,
|
983
974
|
DataHandler,
|
984
975
|
EnumOrgQueryMode,
|
985
976
|
EnumOrgQueryScope,
|
@@ -989,16 +980,8 @@ function jumpToSSOLogout({
|
|
989
980
|
TOKEN_KEY,
|
990
981
|
USER_INFO_KEY,
|
991
982
|
USER_ORG_KEY,
|
983
|
+
USER_ORG_NO_AUTH_KEY,
|
992
984
|
USER_TOTAL_COMPANY_KEY,
|
993
|
-
getOrgTree,
|
994
|
-
getUserInfo,
|
995
|
-
getUserOrgTree,
|
996
985
|
jumpToSSOLogin,
|
997
|
-
jumpToSSOLogout
|
998
|
-
login,
|
999
|
-
logout,
|
1000
|
-
queryOrgCompanies,
|
1001
|
-
queryOrgCustom,
|
1002
|
-
queryResource,
|
1003
|
-
superLogin
|
986
|
+
jumpToSSOLogout
|
1004
987
|
});
|
package/dist/index.d.mts
CHANGED
@@ -1,16 +1,7 @@
|
|
1
1
|
declare class Storage {
|
2
|
-
private systemId
|
2
|
+
private systemId;
|
3
3
|
private currentVersion;
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Set the current version for new data
|
7
|
-
* If version changes, all existing data for this systemId will be cleared
|
8
|
-
*/
|
9
|
-
setVersion(version: string): void;
|
10
|
-
/**
|
11
|
-
* Get the current version
|
12
|
-
*/
|
13
|
-
getVersion(): string;
|
4
|
+
constructor(systemId: number | string, currentVersion: string);
|
14
5
|
private prefixKey;
|
15
6
|
/**
|
16
7
|
* Set an item in localStorage, with optional expiration in minutes
|
@@ -48,6 +39,35 @@ declare class Storage {
|
|
48
39
|
};
|
49
40
|
}
|
50
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
|
+
}
|
51
71
|
interface ApiResponse<T> {
|
52
72
|
obj: T;
|
53
73
|
success: boolean;
|
@@ -148,49 +168,25 @@ interface UserOrgTreeParams {
|
|
148
168
|
stewardUnitLevel?: number;
|
149
169
|
keepHead?: boolean;
|
150
170
|
}
|
151
|
-
declare function login(baseUrl: string, authorizationCode: string): Promise<ApiResponse<{
|
152
|
-
token: string;
|
153
|
-
}>>;
|
154
|
-
declare function superLogin(baseUrl: string, params: {
|
155
|
-
userName: string;
|
156
|
-
password: string;
|
157
|
-
}): Promise<ApiResponse<{
|
158
|
-
token: string;
|
159
|
-
}>>;
|
160
|
-
declare function logout(baseUrl: string): Promise<ApiResponse<void>>;
|
161
|
-
declare function getUserInfo(baseUrl: string): Promise<ApiResponse<UserInfo$1>>;
|
162
|
-
declare function queryResource(baseUrl: string, params: {
|
163
|
-
systemId: string;
|
164
|
-
}): Promise<ApiResponse<Resource[]>>;
|
165
|
-
declare function getOrgTree(baseUrl: string, params: {
|
166
|
-
systemId: string;
|
167
|
-
name: CodeSourceType;
|
168
|
-
}): Promise<ApiResponse<OrgRecord$1>>;
|
169
|
-
declare function getUserOrgTree(baseUrl: string, params: UserOrgTreeParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
170
|
-
declare function queryOrgCompanies(baseUrl: string, params: {
|
171
|
-
queryAllBranches?: boolean;
|
172
|
-
}): Promise<ApiResponse<OrgRecord$1[]>>;
|
173
171
|
type ResultViewType = 'LIST' | 'TREE' | 'FOREST';
|
174
172
|
type OrgDirectionType = 'NONE' | 'FROM_SELF_TO_ROOT' | 'FROM_SELF_TO_LEAF' | 'TWO_WAY';
|
175
173
|
type OrgType = 'HEAD' | 'BRANCH' | 'DEPARTMENT';
|
176
174
|
interface QueryOrgCustomParams {
|
177
175
|
resultView?: ResultViewType;
|
178
|
-
orgCodeSource
|
176
|
+
orgCodeSource?: CodeSourceType;
|
179
177
|
ids?: number[];
|
180
178
|
direction?: OrgDirectionType;
|
181
179
|
maxDepth?: number;
|
182
180
|
orgTypes?: OrgType[];
|
181
|
+
orgCodes?: string[];
|
183
182
|
}
|
184
|
-
/**
|
185
|
-
* 根据查询条件自定义组织机构查询
|
186
|
-
*/
|
187
|
-
declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
188
183
|
|
189
184
|
declare const USER_INFO_KEY = "opms_user_info";
|
190
185
|
declare const RESOURCE_KEY = "opms_resources";
|
191
186
|
declare const TOKEN_KEY = "opms_authorization";
|
192
187
|
declare const USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
193
188
|
declare const USER_ORG_KEY = "opms_user_orgs";
|
189
|
+
declare const USER_ORG_NO_AUTH_KEY = "opms_user_org_no_auth";
|
194
190
|
|
195
191
|
interface MenuItem {
|
196
192
|
icon?: string;
|
@@ -374,6 +370,7 @@ declare class Permission {
|
|
374
370
|
};
|
375
371
|
hasSubApp: boolean;
|
376
372
|
storage: Storage;
|
373
|
+
private api;
|
377
374
|
private eventEmitter;
|
378
375
|
constructor(options: PermissionOptions);
|
379
376
|
/**
|
@@ -469,6 +466,16 @@ declare class Permission {
|
|
469
466
|
totalKeys: number;
|
470
467
|
systemKeys: number;
|
471
468
|
};
|
469
|
+
/**
|
470
|
+
* Get organization map by codes with caching
|
471
|
+
* Checks localStorage first, then fetches missing orgs from API
|
472
|
+
*/
|
473
|
+
getOrgMapByCodes(orgCodes: string[], config?: {
|
474
|
+
force?: boolean;
|
475
|
+
cacheTimeout?: number;
|
476
|
+
}): Promise<{
|
477
|
+
[orgCode: string]: OrgRecord$1;
|
478
|
+
}>;
|
472
479
|
/**
|
473
480
|
* Get current storage version
|
474
481
|
*/
|
@@ -508,4 +515,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
508
515
|
clientId?: string;
|
509
516
|
}): void;
|
510
517
|
|
511
|
-
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,
|
518
|
+
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_ORG_NO_AUTH_KEY, USER_TOTAL_COMPANY_KEY, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, jumpToSSOLogin, jumpToSSOLogout };
|
package/dist/index.d.ts
CHANGED
@@ -1,16 +1,7 @@
|
|
1
1
|
declare class Storage {
|
2
|
-
private systemId
|
2
|
+
private systemId;
|
3
3
|
private currentVersion;
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Set the current version for new data
|
7
|
-
* If version changes, all existing data for this systemId will be cleared
|
8
|
-
*/
|
9
|
-
setVersion(version: string): void;
|
10
|
-
/**
|
11
|
-
* Get the current version
|
12
|
-
*/
|
13
|
-
getVersion(): string;
|
4
|
+
constructor(systemId: number | string, currentVersion: string);
|
14
5
|
private prefixKey;
|
15
6
|
/**
|
16
7
|
* Set an item in localStorage, with optional expiration in minutes
|
@@ -48,6 +39,35 @@ declare class Storage {
|
|
48
39
|
};
|
49
40
|
}
|
50
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
|
+
}
|
51
71
|
interface ApiResponse<T> {
|
52
72
|
obj: T;
|
53
73
|
success: boolean;
|
@@ -148,49 +168,25 @@ interface UserOrgTreeParams {
|
|
148
168
|
stewardUnitLevel?: number;
|
149
169
|
keepHead?: boolean;
|
150
170
|
}
|
151
|
-
declare function login(baseUrl: string, authorizationCode: string): Promise<ApiResponse<{
|
152
|
-
token: string;
|
153
|
-
}>>;
|
154
|
-
declare function superLogin(baseUrl: string, params: {
|
155
|
-
userName: string;
|
156
|
-
password: string;
|
157
|
-
}): Promise<ApiResponse<{
|
158
|
-
token: string;
|
159
|
-
}>>;
|
160
|
-
declare function logout(baseUrl: string): Promise<ApiResponse<void>>;
|
161
|
-
declare function getUserInfo(baseUrl: string): Promise<ApiResponse<UserInfo$1>>;
|
162
|
-
declare function queryResource(baseUrl: string, params: {
|
163
|
-
systemId: string;
|
164
|
-
}): Promise<ApiResponse<Resource[]>>;
|
165
|
-
declare function getOrgTree(baseUrl: string, params: {
|
166
|
-
systemId: string;
|
167
|
-
name: CodeSourceType;
|
168
|
-
}): Promise<ApiResponse<OrgRecord$1>>;
|
169
|
-
declare function getUserOrgTree(baseUrl: string, params: UserOrgTreeParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
170
|
-
declare function queryOrgCompanies(baseUrl: string, params: {
|
171
|
-
queryAllBranches?: boolean;
|
172
|
-
}): Promise<ApiResponse<OrgRecord$1[]>>;
|
173
171
|
type ResultViewType = 'LIST' | 'TREE' | 'FOREST';
|
174
172
|
type OrgDirectionType = 'NONE' | 'FROM_SELF_TO_ROOT' | 'FROM_SELF_TO_LEAF' | 'TWO_WAY';
|
175
173
|
type OrgType = 'HEAD' | 'BRANCH' | 'DEPARTMENT';
|
176
174
|
interface QueryOrgCustomParams {
|
177
175
|
resultView?: ResultViewType;
|
178
|
-
orgCodeSource
|
176
|
+
orgCodeSource?: CodeSourceType;
|
179
177
|
ids?: number[];
|
180
178
|
direction?: OrgDirectionType;
|
181
179
|
maxDepth?: number;
|
182
180
|
orgTypes?: OrgType[];
|
181
|
+
orgCodes?: string[];
|
183
182
|
}
|
184
|
-
/**
|
185
|
-
* 根据查询条件自定义组织机构查询
|
186
|
-
*/
|
187
|
-
declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
188
183
|
|
189
184
|
declare const USER_INFO_KEY = "opms_user_info";
|
190
185
|
declare const RESOURCE_KEY = "opms_resources";
|
191
186
|
declare const TOKEN_KEY = "opms_authorization";
|
192
187
|
declare const USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
193
188
|
declare const USER_ORG_KEY = "opms_user_orgs";
|
189
|
+
declare const USER_ORG_NO_AUTH_KEY = "opms_user_org_no_auth";
|
194
190
|
|
195
191
|
interface MenuItem {
|
196
192
|
icon?: string;
|
@@ -374,6 +370,7 @@ declare class Permission {
|
|
374
370
|
};
|
375
371
|
hasSubApp: boolean;
|
376
372
|
storage: Storage;
|
373
|
+
private api;
|
377
374
|
private eventEmitter;
|
378
375
|
constructor(options: PermissionOptions);
|
379
376
|
/**
|
@@ -469,6 +466,16 @@ declare class Permission {
|
|
469
466
|
totalKeys: number;
|
470
467
|
systemKeys: number;
|
471
468
|
};
|
469
|
+
/**
|
470
|
+
* Get organization map by codes with caching
|
471
|
+
* Checks localStorage first, then fetches missing orgs from API
|
472
|
+
*/
|
473
|
+
getOrgMapByCodes(orgCodes: string[], config?: {
|
474
|
+
force?: boolean;
|
475
|
+
cacheTimeout?: number;
|
476
|
+
}): Promise<{
|
477
|
+
[orgCode: string]: OrgRecord$1;
|
478
|
+
}>;
|
472
479
|
/**
|
473
480
|
* Get current storage version
|
474
481
|
*/
|
@@ -508,4 +515,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
508
515
|
clientId?: string;
|
509
516
|
}): void;
|
510
517
|
|
511
|
-
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,
|
518
|
+
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_ORG_NO_AUTH_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,107 +240,13 @@ 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";
|
270
246
|
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
|
-
|
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
|
-
}
|
249
|
+
var USER_ORG_NO_AUTH_KEY = "opms_user_org_no_auth";
|
365
250
|
|
366
251
|
// src/utils/eventEmitter.ts
|
367
252
|
var EventEmitter = class {
|
@@ -461,6 +346,98 @@ var EventEmitter = class {
|
|
461
346
|
}
|
462
347
|
};
|
463
348
|
|
349
|
+
// src/api.ts
|
350
|
+
import axios from "axios";
|
351
|
+
var ApiClient = class {
|
352
|
+
constructor(baseUrl, storage) {
|
353
|
+
this.baseUrl = baseUrl;
|
354
|
+
this.storage = storage;
|
355
|
+
this.axiosClient = axios.create();
|
356
|
+
this.axiosClient.interceptors.request.use((config) => {
|
357
|
+
const token = this.storage.getItem(TOKEN_KEY);
|
358
|
+
if (token) {
|
359
|
+
config.headers.Authorization = token;
|
360
|
+
}
|
361
|
+
return config;
|
362
|
+
});
|
363
|
+
this.axiosClient.interceptors.response.use(
|
364
|
+
(response) => {
|
365
|
+
const res = response.data;
|
366
|
+
const { success, code, msg } = res;
|
367
|
+
if (success === false) {
|
368
|
+
return Promise.reject({ code, msg });
|
369
|
+
}
|
370
|
+
return res;
|
371
|
+
},
|
372
|
+
(error) => Promise.reject(error)
|
373
|
+
);
|
374
|
+
}
|
375
|
+
async login(authorizationCode) {
|
376
|
+
return await this.axiosClient.get(
|
377
|
+
`${this.baseUrl}/opmsDefaultAuth/oauthLogin`,
|
378
|
+
{ params: { authorizationCode } }
|
379
|
+
);
|
380
|
+
}
|
381
|
+
async superLogin(params) {
|
382
|
+
return await this.axiosClient.post(
|
383
|
+
`${this.baseUrl}/opmsDefaultAuth/superLogin`,
|
384
|
+
params
|
385
|
+
);
|
386
|
+
}
|
387
|
+
async logout() {
|
388
|
+
return await this.axiosClient.post(
|
389
|
+
`${this.baseUrl}/opmsDefaultAuth/logout`
|
390
|
+
);
|
391
|
+
}
|
392
|
+
async getUserInfo() {
|
393
|
+
return await this.axiosClient.post(
|
394
|
+
`${this.baseUrl}/opmsDefaultUser/userInfo`,
|
395
|
+
{}
|
396
|
+
);
|
397
|
+
}
|
398
|
+
async queryResource(params) {
|
399
|
+
return await this.axiosClient.post(
|
400
|
+
`${this.baseUrl}/opmsDefaultUser/userResource`,
|
401
|
+
params
|
402
|
+
);
|
403
|
+
}
|
404
|
+
async getOrgTree(params) {
|
405
|
+
return await this.axiosClient.post(
|
406
|
+
`${this.baseUrl}/opmsDefaultUser/orgTree`,
|
407
|
+
params
|
408
|
+
);
|
409
|
+
}
|
410
|
+
async getUserOrgTree(params) {
|
411
|
+
return await this.axiosClient.post(
|
412
|
+
`${this.baseUrl}/opmsDefaultUser/userOrgTree`,
|
413
|
+
params
|
414
|
+
);
|
415
|
+
}
|
416
|
+
async queryOrgCompanies(params) {
|
417
|
+
return await this.axiosClient.post(
|
418
|
+
`${this.baseUrl}/opmsDefaultUser/branches`,
|
419
|
+
params
|
420
|
+
);
|
421
|
+
}
|
422
|
+
async queryOrgCustom(params) {
|
423
|
+
return axios.post(
|
424
|
+
`${this.baseUrl}/opmsDefaultUser/queryOrgCustom`,
|
425
|
+
params
|
426
|
+
);
|
427
|
+
}
|
428
|
+
};
|
429
|
+
var EnumOrgQueryMode = /* @__PURE__ */ ((EnumOrgQueryMode2) => {
|
430
|
+
EnumOrgQueryMode2["BY_ROLES"] = "BY_ROLES";
|
431
|
+
EnumOrgQueryMode2["BY_DEPT"] = "BY_DEPT";
|
432
|
+
return EnumOrgQueryMode2;
|
433
|
+
})(EnumOrgQueryMode || {});
|
434
|
+
var EnumOrgQueryScope = /* @__PURE__ */ ((EnumOrgQueryScope2) => {
|
435
|
+
EnumOrgQueryScope2["ONLY_BRANCH"] = "ONLY_BRANCH";
|
436
|
+
EnumOrgQueryScope2["STEWARD_UNIT"] = "STEWARD_UNIT";
|
437
|
+
EnumOrgQueryScope2["WITH_DEPARTMENT"] = "WITH_DEPARTMENT";
|
438
|
+
return EnumOrgQueryScope2;
|
439
|
+
})(EnumOrgQueryScope || {});
|
440
|
+
|
464
441
|
// src/permission.ts
|
465
442
|
var DataHandler = {
|
466
443
|
iterateOrgTree(orgTree) {
|
@@ -536,9 +513,8 @@ var Permission = class {
|
|
536
513
|
this.baseUrl = options.baseUrl;
|
537
514
|
this.systemId = options.systemId;
|
538
515
|
this.hasSubApp = options.hasSubApp ?? false;
|
539
|
-
this.storage = new Storage();
|
540
|
-
this.
|
541
|
-
this.storage.setVersion("1.0.0");
|
516
|
+
this.storage = new Storage(this.systemId, "1.0.0");
|
517
|
+
this.api = new ApiClient(this.baseUrl, this.storage);
|
542
518
|
}
|
543
519
|
/**
|
544
520
|
* Add event listener
|
@@ -588,7 +564,7 @@ var Permission = class {
|
|
588
564
|
}
|
589
565
|
async superLogin(userName, password) {
|
590
566
|
this.clear();
|
591
|
-
const { obj, msg, code } = await superLogin(
|
567
|
+
const { obj, msg, code } = await this.api.superLogin({
|
592
568
|
userName,
|
593
569
|
password
|
594
570
|
});
|
@@ -619,7 +595,7 @@ var Permission = class {
|
|
619
595
|
obj,
|
620
596
|
msg,
|
621
597
|
code: loginCode
|
622
|
-
} = await login(
|
598
|
+
} = await this.api.login(authCode);
|
623
599
|
if (loginCode !== 200) {
|
624
600
|
return Promise.reject({
|
625
601
|
code: loginCode,
|
@@ -636,7 +612,7 @@ var Permission = class {
|
|
636
612
|
* Logout and clear userInfo
|
637
613
|
*/
|
638
614
|
async logout(clearData = true) {
|
639
|
-
await logout(
|
615
|
+
await this.api.logout();
|
640
616
|
clearData && this.clear();
|
641
617
|
}
|
642
618
|
clear() {
|
@@ -644,7 +620,7 @@ var Permission = class {
|
|
644
620
|
this.emit("tokenChange", "");
|
645
621
|
}
|
646
622
|
async getUserInfo() {
|
647
|
-
const data = await getUserInfo(
|
623
|
+
const data = await this.api.getUserInfo();
|
648
624
|
const { obj, success, msg, code } = data;
|
649
625
|
this.storage.setItem(USER_INFO_KEY, obj);
|
650
626
|
return obj;
|
@@ -659,7 +635,7 @@ var Permission = class {
|
|
659
635
|
async getResources() {
|
660
636
|
let resources = this.storage.getItem(RESOURCE_KEY) || null;
|
661
637
|
if (!resources) {
|
662
|
-
const { obj, success, msg, code } = await queryResource(
|
638
|
+
const { obj, success, msg, code } = await this.api.queryResource({
|
663
639
|
systemId: this.systemId
|
664
640
|
});
|
665
641
|
if (!success) {
|
@@ -717,7 +693,7 @@ var Permission = class {
|
|
717
693
|
orgTreeData = this.storage.getItem(cacheKey) || null;
|
718
694
|
}
|
719
695
|
if (!orgTreeData) {
|
720
|
-
const res = await getUserOrgTree(
|
696
|
+
const res = await this.api.getUserOrgTree(params);
|
721
697
|
const { obj } = res;
|
722
698
|
orgTreeData = iterateNestedArray(obj, (item) => {
|
723
699
|
return {
|
@@ -739,8 +715,6 @@ var Permission = class {
|
|
739
715
|
const { tree } = data;
|
740
716
|
return {
|
741
717
|
orgTree: tree
|
742
|
-
// orgNoAuthMap: noAuthMap,
|
743
|
-
// authOrgTree: tree,
|
744
718
|
};
|
745
719
|
} catch (error) {
|
746
720
|
console.log(error);
|
@@ -757,7 +731,7 @@ var Permission = class {
|
|
757
731
|
orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
|
758
732
|
}
|
759
733
|
if (!orgCompanyList) {
|
760
|
-
const { obj } = await queryOrgCustom(
|
734
|
+
const { obj } = await this.api.queryOrgCustom({
|
761
735
|
resultView: "LIST",
|
762
736
|
orgCodeSource: "COS",
|
763
737
|
direction: "FROM_SELF_TO_LEAF",
|
@@ -795,24 +769,6 @@ var Permission = class {
|
|
795
769
|
this.storage.setItem(TOKEN_KEY, token);
|
796
770
|
this.emit("tokenChange", token);
|
797
771
|
}
|
798
|
-
// --- Getters ---
|
799
|
-
// get userInfo(): UserInfo | null {
|
800
|
-
// if (!this._userInfo) {
|
801
|
-
// this._userInfo = storage.getItem(USER_INFO_KEY);
|
802
|
-
// }
|
803
|
-
// if (!this._userInfo) return null;
|
804
|
-
// const { account, name, ehrId, crewCode, crewId } = this._userInfo;
|
805
|
-
// return { account, name, ehrId, crewCode, crewId };
|
806
|
-
// }
|
807
|
-
// get hasRootAuth() {
|
808
|
-
// const orgs = this._userInfo?.organizations || [];
|
809
|
-
// const first = orgs[0];
|
810
|
-
// if (!first) return false;
|
811
|
-
// return first.searchPath === '#1';
|
812
|
-
// }
|
813
|
-
// get userOrganizations(): UserOrganization[] {
|
814
|
-
// return this._userInfo?.userOrganizations || [];
|
815
|
-
// }
|
816
772
|
/**
|
817
773
|
* Get storage information for debugging and monitoring
|
818
774
|
*/
|
@@ -839,11 +795,52 @@ var Permission = class {
|
|
839
795
|
}
|
840
796
|
};
|
841
797
|
}
|
798
|
+
/**
|
799
|
+
* Get organization map by codes with caching
|
800
|
+
* Checks localStorage first, then fetches missing orgs from API
|
801
|
+
*/
|
802
|
+
async getOrgMapByCodes(orgCodes, config = {
|
803
|
+
force: false,
|
804
|
+
cacheTimeout: 60 * 24
|
805
|
+
// 24 hours default
|
806
|
+
}) {
|
807
|
+
const { force, cacheTimeout = 60 * 24 } = config;
|
808
|
+
const result = {};
|
809
|
+
const missingOrgCodes = [];
|
810
|
+
let cachedOrgMap = {};
|
811
|
+
if (!force) {
|
812
|
+
cachedOrgMap = this.storage.getItem(USER_ORG_NO_AUTH_KEY) || {};
|
813
|
+
}
|
814
|
+
for (const orgCode of orgCodes) {
|
815
|
+
if (cachedOrgMap[orgCode]) {
|
816
|
+
result[orgCode] = cachedOrgMap[orgCode];
|
817
|
+
} else {
|
818
|
+
missingOrgCodes.push(orgCode);
|
819
|
+
}
|
820
|
+
}
|
821
|
+
if (missingOrgCodes.length > 0) {
|
822
|
+
try {
|
823
|
+
const { obj } = await this.api.queryOrgCustom({
|
824
|
+
orgCodes: missingOrgCodes
|
825
|
+
});
|
826
|
+
for (const org of obj) {
|
827
|
+
const orgCode = org.orgCode;
|
828
|
+
result[orgCode] = org;
|
829
|
+
cachedOrgMap[orgCode] = org;
|
830
|
+
}
|
831
|
+
this.storage.setItem(USER_ORG_NO_AUTH_KEY, cachedOrgMap, cacheTimeout);
|
832
|
+
} catch (error) {
|
833
|
+
console.error("Error fetching org data:", error);
|
834
|
+
throw error;
|
835
|
+
}
|
836
|
+
}
|
837
|
+
return result;
|
838
|
+
}
|
842
839
|
/**
|
843
840
|
* Get current storage version
|
844
841
|
*/
|
845
842
|
getStorageVersion() {
|
846
|
-
return this.storage.
|
843
|
+
return this.storage.currentVersion;
|
847
844
|
}
|
848
845
|
/**
|
849
846
|
* Clear all storage data for this system
|
@@ -873,7 +870,7 @@ var Permission = class {
|
|
873
870
|
clearUserCache() {
|
874
871
|
const keys = this.storage.getKeys();
|
875
872
|
keys.forEach((key) => {
|
876
|
-
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY)) {
|
873
|
+
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY) || key.startsWith(USER_ORG_NO_AUTH_KEY)) {
|
877
874
|
this.storage.removeItem(key);
|
878
875
|
}
|
879
876
|
});
|
@@ -923,6 +920,7 @@ function jumpToSSOLogout({
|
|
923
920
|
window.location.href = logoutUrl.toString();
|
924
921
|
}
|
925
922
|
export {
|
923
|
+
ApiClient,
|
926
924
|
DataHandler,
|
927
925
|
EnumOrgQueryMode,
|
928
926
|
EnumOrgQueryScope,
|
@@ -932,16 +930,8 @@ export {
|
|
932
930
|
TOKEN_KEY,
|
933
931
|
USER_INFO_KEY,
|
934
932
|
USER_ORG_KEY,
|
933
|
+
USER_ORG_NO_AUTH_KEY,
|
935
934
|
USER_TOTAL_COMPANY_KEY,
|
936
|
-
getOrgTree,
|
937
|
-
getUserInfo,
|
938
|
-
getUserOrgTree,
|
939
935
|
jumpToSSOLogin,
|
940
|
-
jumpToSSOLogout
|
941
|
-
login,
|
942
|
-
logout,
|
943
|
-
queryOrgCompanies,
|
944
|
-
queryOrgCustom,
|
945
|
-
queryResource,
|
946
|
-
superLogin
|
936
|
+
jumpToSSOLogout
|
947
937
|
};
|