@mu-cabin/opms-permission 0.9.10 → 0.9.12
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 +63 -24
- package/dist/index.d.mts +62 -1
- package/dist/index.d.ts +62 -1
- package/dist/index.mjs +58 -24
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -35,6 +35,11 @@ __export(index_exports, {
|
|
35
35
|
EnumOrgQueryScope: () => EnumOrgQueryScope,
|
36
36
|
EventEmitter: () => EventEmitter,
|
37
37
|
OpmsPermission: () => Permission,
|
38
|
+
RESOURCE_KEY: () => RESOURCE_KEY,
|
39
|
+
TOKEN_KEY: () => TOKEN_KEY,
|
40
|
+
USER_INFO_KEY: () => USER_INFO_KEY,
|
41
|
+
USER_ORG_KEY: () => USER_ORG_KEY,
|
42
|
+
USER_TOTAL_COMPANY_KEY: () => USER_TOTAL_COMPANY_KEY,
|
38
43
|
getOrgTree: () => getOrgTree,
|
39
44
|
getUserInfo: () => getUserInfo,
|
40
45
|
getUserOrgTree: () => getUserOrgTree,
|
@@ -587,8 +592,9 @@ var Permission = class {
|
|
587
592
|
this.baseUrl = options.baseUrl;
|
588
593
|
this.systemId = options.systemId;
|
589
594
|
this.hasSubApp = options.hasSubApp ?? false;
|
590
|
-
storage
|
591
|
-
storage.
|
595
|
+
this.storage = new Storage();
|
596
|
+
this.storage.setSystemId(this.systemId);
|
597
|
+
this.storage.setVersion("1.0.0");
|
592
598
|
}
|
593
599
|
/**
|
594
600
|
* Add event listener
|
@@ -649,7 +655,7 @@ var Permission = class {
|
|
649
655
|
});
|
650
656
|
}
|
651
657
|
const { token } = obj;
|
652
|
-
storage.setItem(TOKEN_KEY, token);
|
658
|
+
this.storage.setItem(TOKEN_KEY, token);
|
653
659
|
this.emit("tokenChange", token);
|
654
660
|
return token;
|
655
661
|
}
|
@@ -678,7 +684,7 @@ var Permission = class {
|
|
678
684
|
}
|
679
685
|
const { token } = obj;
|
680
686
|
url.searchParams.delete("code");
|
681
|
-
storage.setItem(TOKEN_KEY, token);
|
687
|
+
this.storage.setItem(TOKEN_KEY, token);
|
682
688
|
this.emit("tokenChange", token);
|
683
689
|
return token;
|
684
690
|
}
|
@@ -690,19 +696,24 @@ var Permission = class {
|
|
690
696
|
clearData && this.clear();
|
691
697
|
}
|
692
698
|
clear() {
|
693
|
-
storage.clear();
|
699
|
+
this.storage.clear();
|
694
700
|
this.emit("tokenChange", "");
|
695
701
|
}
|
696
702
|
async getUserInfo() {
|
697
703
|
const data = await getUserInfo(this.baseUrl);
|
698
704
|
const { obj, success, msg, code } = data;
|
705
|
+
this.storage.setItem(USER_INFO_KEY, obj);
|
699
706
|
return obj;
|
700
707
|
}
|
708
|
+
isSameUser(account) {
|
709
|
+
const userInfo = this.storage.getItem(USER_INFO_KEY);
|
710
|
+
return userInfo?.account === account;
|
711
|
+
}
|
701
712
|
/**
|
702
713
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
703
714
|
*/
|
704
715
|
async getResources() {
|
705
|
-
let resources = storage.getItem(RESOURCE_KEY) || null;
|
716
|
+
let resources = this.storage.getItem(RESOURCE_KEY) || null;
|
706
717
|
if (!resources) {
|
707
718
|
const { obj, success, msg, code } = await queryResource(this.baseUrl, {
|
708
719
|
systemId: this.systemId
|
@@ -714,7 +725,7 @@ var Permission = class {
|
|
714
725
|
});
|
715
726
|
}
|
716
727
|
resources = obj;
|
717
|
-
storage.setItem(
|
728
|
+
this.storage.setItem(
|
718
729
|
RESOURCE_KEY,
|
719
730
|
resources,
|
720
731
|
60 * 12
|
@@ -759,7 +770,7 @@ var Permission = class {
|
|
759
770
|
let orgTreeData = null;
|
760
771
|
if (!force) {
|
761
772
|
const cacheKey = this.generateUserOrgsCacheKey(params);
|
762
|
-
orgTreeData = storage.getItem(cacheKey) || null;
|
773
|
+
orgTreeData = this.storage.getItem(cacheKey) || null;
|
763
774
|
}
|
764
775
|
if (!orgTreeData) {
|
765
776
|
const res = await getUserOrgTree(this.baseUrl, params);
|
@@ -778,7 +789,7 @@ var Permission = class {
|
|
778
789
|
};
|
779
790
|
});
|
780
791
|
const cacheKey = this.generateUserOrgsCacheKey(params);
|
781
|
-
storage.setItem(cacheKey, orgTreeData, cacheTimeout);
|
792
|
+
this.storage.setItem(cacheKey, orgTreeData, cacheTimeout);
|
782
793
|
}
|
783
794
|
const data = handlePermissionTree(orgTreeData, "orgId");
|
784
795
|
const { tree } = data;
|
@@ -799,7 +810,7 @@ var Permission = class {
|
|
799
810
|
const { force, cacheTimeout = 2 } = config;
|
800
811
|
let orgCompanyList;
|
801
812
|
if (!force) {
|
802
|
-
orgCompanyList = storage.getItem(USER_TOTAL_COMPANY_KEY);
|
813
|
+
orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
|
803
814
|
}
|
804
815
|
if (!orgCompanyList) {
|
805
816
|
const { obj } = await queryOrgCustom(this.baseUrl, {
|
@@ -822,18 +833,22 @@ var Permission = class {
|
|
822
833
|
orgId: item.orgId
|
823
834
|
};
|
824
835
|
});
|
825
|
-
storage.setItem(
|
836
|
+
this.storage.setItem(
|
837
|
+
USER_TOTAL_COMPANY_KEY,
|
838
|
+
orgCompanyList,
|
839
|
+
cacheTimeout
|
840
|
+
);
|
826
841
|
}
|
827
842
|
return orgCompanyList;
|
828
843
|
}
|
829
844
|
isLogin() {
|
830
|
-
return !!storage.getItem(TOKEN_KEY);
|
845
|
+
return !!this.storage.getItem(TOKEN_KEY);
|
831
846
|
}
|
832
847
|
getToken() {
|
833
|
-
return storage.getItem(TOKEN_KEY);
|
848
|
+
return this.storage.getItem(TOKEN_KEY);
|
834
849
|
}
|
835
850
|
setToken(token) {
|
836
|
-
storage.setItem(TOKEN_KEY, token);
|
851
|
+
this.storage.setItem(TOKEN_KEY, token);
|
837
852
|
this.emit("tokenChange", token);
|
838
853
|
}
|
839
854
|
// --- Getters ---
|
@@ -858,21 +873,21 @@ var Permission = class {
|
|
858
873
|
* Get storage information for debugging and monitoring
|
859
874
|
*/
|
860
875
|
getStorageInfo() {
|
861
|
-
const keys = storage.getKeys();
|
876
|
+
const keys = this.storage.getKeys();
|
862
877
|
const userOrgsCacheKeys = keys.filter(
|
863
878
|
(key) => key.startsWith(USER_ORG_KEY)
|
864
879
|
);
|
865
880
|
return {
|
866
|
-
...storage.getStorageInfo(),
|
881
|
+
...this.storage.getStorageInfo(),
|
867
882
|
permissionKeys: {
|
868
883
|
resourceKey: RESOURCE_KEY,
|
869
884
|
tokenKey: TOKEN_KEY,
|
870
885
|
userInfoKey: USER_INFO_KEY
|
871
886
|
},
|
872
887
|
hasData: {
|
873
|
-
resources: storage.hasKey(RESOURCE_KEY),
|
874
|
-
token: storage.hasKey(TOKEN_KEY),
|
875
|
-
userInfo: storage.hasKey(USER_INFO_KEY)
|
888
|
+
resources: this.storage.hasKey(RESOURCE_KEY),
|
889
|
+
token: this.storage.hasKey(TOKEN_KEY),
|
890
|
+
userInfo: this.storage.hasKey(USER_INFO_KEY)
|
876
891
|
},
|
877
892
|
cacheInfo: {
|
878
893
|
userOrgsCacheCount: userOrgsCacheKeys.length,
|
@@ -884,13 +899,16 @@ var Permission = class {
|
|
884
899
|
* Get current storage version
|
885
900
|
*/
|
886
901
|
getStorageVersion() {
|
887
|
-
return storage.getVersion();
|
902
|
+
return this.storage.getVersion();
|
888
903
|
}
|
889
904
|
/**
|
890
905
|
* Clear all storage data for this system
|
891
906
|
*/
|
892
907
|
clearStorage() {
|
893
|
-
storage.clear();
|
908
|
+
this.storage.clear();
|
909
|
+
}
|
910
|
+
clearAuthCache() {
|
911
|
+
this.storage.removeItem(TOKEN_KEY);
|
894
912
|
}
|
895
913
|
/**
|
896
914
|
* Clear user orgs cache for specific parameters or all
|
@@ -898,16 +916,32 @@ var Permission = class {
|
|
898
916
|
clearUserOrgsCache(params) {
|
899
917
|
if (params) {
|
900
918
|
const cacheKey = this.generateUserOrgsCacheKey(params);
|
901
|
-
storage.removeItem(cacheKey);
|
919
|
+
this.storage.removeItem(cacheKey);
|
902
920
|
} else {
|
903
|
-
const keys = storage.getKeys();
|
921
|
+
const keys = this.storage.getKeys();
|
904
922
|
keys.forEach((key) => {
|
905
923
|
if (key.startsWith(USER_ORG_KEY)) {
|
906
|
-
storage.removeItem(key);
|
924
|
+
this.storage.removeItem(key);
|
907
925
|
}
|
908
926
|
});
|
909
927
|
}
|
910
928
|
}
|
929
|
+
clearUserCache() {
|
930
|
+
const keys = this.storage.getKeys();
|
931
|
+
keys.forEach((key) => {
|
932
|
+
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY)) {
|
933
|
+
this.storage.removeItem(key);
|
934
|
+
}
|
935
|
+
});
|
936
|
+
}
|
937
|
+
clearAppCache() {
|
938
|
+
const keys = this.storage.getKeys();
|
939
|
+
keys.forEach((key) => {
|
940
|
+
if (key.startsWith(RESOURCE_KEY)) {
|
941
|
+
this.storage.removeItem(key);
|
942
|
+
}
|
943
|
+
});
|
944
|
+
}
|
911
945
|
};
|
912
946
|
|
913
947
|
// src/sso.ts
|
@@ -951,6 +985,11 @@ function jumpToSSOLogout({
|
|
951
985
|
EnumOrgQueryScope,
|
952
986
|
EventEmitter,
|
953
987
|
OpmsPermission,
|
988
|
+
RESOURCE_KEY,
|
989
|
+
TOKEN_KEY,
|
990
|
+
USER_INFO_KEY,
|
991
|
+
USER_ORG_KEY,
|
992
|
+
USER_TOTAL_COMPANY_KEY,
|
954
993
|
getOrgTree,
|
955
994
|
getUserInfo,
|
956
995
|
getUserOrgTree,
|
package/dist/index.d.mts
CHANGED
@@ -1,3 +1,53 @@
|
|
1
|
+
declare class Storage {
|
2
|
+
private systemId?;
|
3
|
+
private currentVersion;
|
4
|
+
setSystemId(systemId: number | string): void;
|
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;
|
14
|
+
private prefixKey;
|
15
|
+
/**
|
16
|
+
* Set an item in localStorage, with optional expiration in minutes
|
17
|
+
*/
|
18
|
+
setItem<T>(key: string, value: T, expireMinutes?: number): void;
|
19
|
+
/**
|
20
|
+
* Get an item from localStorage, returns undefined if expired or not found
|
21
|
+
* Automatically expires data if version is different
|
22
|
+
*/
|
23
|
+
getItem<T>(key: string): T | undefined;
|
24
|
+
/**
|
25
|
+
* Remove an item from localStorage
|
26
|
+
*/
|
27
|
+
removeItem(key: string): void;
|
28
|
+
/**
|
29
|
+
* Clear all data for the current systemId
|
30
|
+
*/
|
31
|
+
clear(): void;
|
32
|
+
/**
|
33
|
+
* Get all keys for the current systemId
|
34
|
+
*/
|
35
|
+
getKeys(): string[];
|
36
|
+
/**
|
37
|
+
* Check if a key exists
|
38
|
+
*/
|
39
|
+
hasKey(key: string): boolean;
|
40
|
+
/**
|
41
|
+
* Get storage info for debugging
|
42
|
+
*/
|
43
|
+
getStorageInfo(): {
|
44
|
+
systemId: number | string | undefined;
|
45
|
+
currentVersion: string;
|
46
|
+
totalKeys: number;
|
47
|
+
systemKeys: number;
|
48
|
+
};
|
49
|
+
}
|
50
|
+
|
1
51
|
interface ApiResponse<T> {
|
2
52
|
obj: T;
|
3
53
|
success: boolean;
|
@@ -136,6 +186,12 @@ interface QueryOrgCustomParams {
|
|
136
186
|
*/
|
137
187
|
declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
138
188
|
|
189
|
+
declare const USER_INFO_KEY = "opms_user_info";
|
190
|
+
declare const RESOURCE_KEY = "opms_resources";
|
191
|
+
declare const TOKEN_KEY = "opms_authorization";
|
192
|
+
declare const USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
193
|
+
declare const USER_ORG_KEY = "opms_user_orgs";
|
194
|
+
|
139
195
|
interface MenuItem {
|
140
196
|
icon?: string;
|
141
197
|
path: string;
|
@@ -317,6 +373,7 @@ declare class Permission {
|
|
317
373
|
[path: string]: MenuItem;
|
318
374
|
};
|
319
375
|
hasSubApp: boolean;
|
376
|
+
storage: Storage;
|
320
377
|
private eventEmitter;
|
321
378
|
constructor(options: PermissionOptions);
|
322
379
|
/**
|
@@ -354,6 +411,7 @@ declare class Permission {
|
|
354
411
|
logout(clearData?: boolean): Promise<void>;
|
355
412
|
clear(): void;
|
356
413
|
getUserInfo(): Promise<UserInfo$1>;
|
414
|
+
isSameUser(account: string): boolean;
|
357
415
|
/**
|
358
416
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
359
417
|
*/
|
@@ -419,10 +477,13 @@ declare class Permission {
|
|
419
477
|
* Clear all storage data for this system
|
420
478
|
*/
|
421
479
|
clearStorage(): void;
|
480
|
+
clearAuthCache(): void;
|
422
481
|
/**
|
423
482
|
* Clear user orgs cache for specific parameters or all
|
424
483
|
*/
|
425
484
|
clearUserOrgsCache(params?: UserOrgTreeParams): void;
|
485
|
+
clearUserCache(): void;
|
486
|
+
clearAppCache(): void;
|
426
487
|
}
|
427
488
|
|
428
489
|
/**
|
@@ -447,4 +508,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
447
508
|
clientId?: string;
|
448
509
|
}): void;
|
449
510
|
|
450
|
-
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, type Resource, type ResourceType, type ResultViewType, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryOrgCustom, queryResource, superLogin };
|
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, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryOrgCustom, queryResource, superLogin };
|
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,53 @@
|
|
1
|
+
declare class Storage {
|
2
|
+
private systemId?;
|
3
|
+
private currentVersion;
|
4
|
+
setSystemId(systemId: number | string): void;
|
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;
|
14
|
+
private prefixKey;
|
15
|
+
/**
|
16
|
+
* Set an item in localStorage, with optional expiration in minutes
|
17
|
+
*/
|
18
|
+
setItem<T>(key: string, value: T, expireMinutes?: number): void;
|
19
|
+
/**
|
20
|
+
* Get an item from localStorage, returns undefined if expired or not found
|
21
|
+
* Automatically expires data if version is different
|
22
|
+
*/
|
23
|
+
getItem<T>(key: string): T | undefined;
|
24
|
+
/**
|
25
|
+
* Remove an item from localStorage
|
26
|
+
*/
|
27
|
+
removeItem(key: string): void;
|
28
|
+
/**
|
29
|
+
* Clear all data for the current systemId
|
30
|
+
*/
|
31
|
+
clear(): void;
|
32
|
+
/**
|
33
|
+
* Get all keys for the current systemId
|
34
|
+
*/
|
35
|
+
getKeys(): string[];
|
36
|
+
/**
|
37
|
+
* Check if a key exists
|
38
|
+
*/
|
39
|
+
hasKey(key: string): boolean;
|
40
|
+
/**
|
41
|
+
* Get storage info for debugging
|
42
|
+
*/
|
43
|
+
getStorageInfo(): {
|
44
|
+
systemId: number | string | undefined;
|
45
|
+
currentVersion: string;
|
46
|
+
totalKeys: number;
|
47
|
+
systemKeys: number;
|
48
|
+
};
|
49
|
+
}
|
50
|
+
|
1
51
|
interface ApiResponse<T> {
|
2
52
|
obj: T;
|
3
53
|
success: boolean;
|
@@ -136,6 +186,12 @@ interface QueryOrgCustomParams {
|
|
136
186
|
*/
|
137
187
|
declare function queryOrgCustom(baseUrl: string, params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
138
188
|
|
189
|
+
declare const USER_INFO_KEY = "opms_user_info";
|
190
|
+
declare const RESOURCE_KEY = "opms_resources";
|
191
|
+
declare const TOKEN_KEY = "opms_authorization";
|
192
|
+
declare const USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
193
|
+
declare const USER_ORG_KEY = "opms_user_orgs";
|
194
|
+
|
139
195
|
interface MenuItem {
|
140
196
|
icon?: string;
|
141
197
|
path: string;
|
@@ -317,6 +373,7 @@ declare class Permission {
|
|
317
373
|
[path: string]: MenuItem;
|
318
374
|
};
|
319
375
|
hasSubApp: boolean;
|
376
|
+
storage: Storage;
|
320
377
|
private eventEmitter;
|
321
378
|
constructor(options: PermissionOptions);
|
322
379
|
/**
|
@@ -354,6 +411,7 @@ declare class Permission {
|
|
354
411
|
logout(clearData?: boolean): Promise<void>;
|
355
412
|
clear(): void;
|
356
413
|
getUserInfo(): Promise<UserInfo$1>;
|
414
|
+
isSameUser(account: string): boolean;
|
357
415
|
/**
|
358
416
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
359
417
|
*/
|
@@ -419,10 +477,13 @@ declare class Permission {
|
|
419
477
|
* Clear all storage data for this system
|
420
478
|
*/
|
421
479
|
clearStorage(): void;
|
480
|
+
clearAuthCache(): void;
|
422
481
|
/**
|
423
482
|
* Clear user orgs cache for specific parameters or all
|
424
483
|
*/
|
425
484
|
clearUserOrgsCache(params?: UserOrgTreeParams): void;
|
485
|
+
clearUserCache(): void;
|
486
|
+
clearAppCache(): void;
|
426
487
|
}
|
427
488
|
|
428
489
|
/**
|
@@ -447,4 +508,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
447
508
|
clientId?: string;
|
448
509
|
}): void;
|
449
510
|
|
450
|
-
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, type Resource, type ResourceType, type ResultViewType, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryOrgCustom, queryResource, superLogin };
|
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, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryOrgCustom, queryResource, superLogin };
|
package/dist/index.mjs
CHANGED
@@ -536,8 +536,9 @@ var Permission = class {
|
|
536
536
|
this.baseUrl = options.baseUrl;
|
537
537
|
this.systemId = options.systemId;
|
538
538
|
this.hasSubApp = options.hasSubApp ?? false;
|
539
|
-
storage
|
540
|
-
storage.
|
539
|
+
this.storage = new Storage();
|
540
|
+
this.storage.setSystemId(this.systemId);
|
541
|
+
this.storage.setVersion("1.0.0");
|
541
542
|
}
|
542
543
|
/**
|
543
544
|
* Add event listener
|
@@ -598,7 +599,7 @@ var Permission = class {
|
|
598
599
|
});
|
599
600
|
}
|
600
601
|
const { token } = obj;
|
601
|
-
storage.setItem(TOKEN_KEY, token);
|
602
|
+
this.storage.setItem(TOKEN_KEY, token);
|
602
603
|
this.emit("tokenChange", token);
|
603
604
|
return token;
|
604
605
|
}
|
@@ -627,7 +628,7 @@ var Permission = class {
|
|
627
628
|
}
|
628
629
|
const { token } = obj;
|
629
630
|
url.searchParams.delete("code");
|
630
|
-
storage.setItem(TOKEN_KEY, token);
|
631
|
+
this.storage.setItem(TOKEN_KEY, token);
|
631
632
|
this.emit("tokenChange", token);
|
632
633
|
return token;
|
633
634
|
}
|
@@ -639,19 +640,24 @@ var Permission = class {
|
|
639
640
|
clearData && this.clear();
|
640
641
|
}
|
641
642
|
clear() {
|
642
|
-
storage.clear();
|
643
|
+
this.storage.clear();
|
643
644
|
this.emit("tokenChange", "");
|
644
645
|
}
|
645
646
|
async getUserInfo() {
|
646
647
|
const data = await getUserInfo(this.baseUrl);
|
647
648
|
const { obj, success, msg, code } = data;
|
649
|
+
this.storage.setItem(USER_INFO_KEY, obj);
|
648
650
|
return obj;
|
649
651
|
}
|
652
|
+
isSameUser(account) {
|
653
|
+
const userInfo = this.storage.getItem(USER_INFO_KEY);
|
654
|
+
return userInfo?.account === account;
|
655
|
+
}
|
650
656
|
/**
|
651
657
|
* Get resources and process to menuList, menuMap, widgetMap (matches app store logic)
|
652
658
|
*/
|
653
659
|
async getResources() {
|
654
|
-
let resources = storage.getItem(RESOURCE_KEY) || null;
|
660
|
+
let resources = this.storage.getItem(RESOURCE_KEY) || null;
|
655
661
|
if (!resources) {
|
656
662
|
const { obj, success, msg, code } = await queryResource(this.baseUrl, {
|
657
663
|
systemId: this.systemId
|
@@ -663,7 +669,7 @@ var Permission = class {
|
|
663
669
|
});
|
664
670
|
}
|
665
671
|
resources = obj;
|
666
|
-
storage.setItem(
|
672
|
+
this.storage.setItem(
|
667
673
|
RESOURCE_KEY,
|
668
674
|
resources,
|
669
675
|
60 * 12
|
@@ -708,7 +714,7 @@ var Permission = class {
|
|
708
714
|
let orgTreeData = null;
|
709
715
|
if (!force) {
|
710
716
|
const cacheKey = this.generateUserOrgsCacheKey(params);
|
711
|
-
orgTreeData = storage.getItem(cacheKey) || null;
|
717
|
+
orgTreeData = this.storage.getItem(cacheKey) || null;
|
712
718
|
}
|
713
719
|
if (!orgTreeData) {
|
714
720
|
const res = await getUserOrgTree(this.baseUrl, params);
|
@@ -727,7 +733,7 @@ var Permission = class {
|
|
727
733
|
};
|
728
734
|
});
|
729
735
|
const cacheKey = this.generateUserOrgsCacheKey(params);
|
730
|
-
storage.setItem(cacheKey, orgTreeData, cacheTimeout);
|
736
|
+
this.storage.setItem(cacheKey, orgTreeData, cacheTimeout);
|
731
737
|
}
|
732
738
|
const data = handlePermissionTree(orgTreeData, "orgId");
|
733
739
|
const { tree } = data;
|
@@ -748,7 +754,7 @@ var Permission = class {
|
|
748
754
|
const { force, cacheTimeout = 2 } = config;
|
749
755
|
let orgCompanyList;
|
750
756
|
if (!force) {
|
751
|
-
orgCompanyList = storage.getItem(USER_TOTAL_COMPANY_KEY);
|
757
|
+
orgCompanyList = this.storage.getItem(USER_TOTAL_COMPANY_KEY);
|
752
758
|
}
|
753
759
|
if (!orgCompanyList) {
|
754
760
|
const { obj } = await queryOrgCustom(this.baseUrl, {
|
@@ -771,18 +777,22 @@ var Permission = class {
|
|
771
777
|
orgId: item.orgId
|
772
778
|
};
|
773
779
|
});
|
774
|
-
storage.setItem(
|
780
|
+
this.storage.setItem(
|
781
|
+
USER_TOTAL_COMPANY_KEY,
|
782
|
+
orgCompanyList,
|
783
|
+
cacheTimeout
|
784
|
+
);
|
775
785
|
}
|
776
786
|
return orgCompanyList;
|
777
787
|
}
|
778
788
|
isLogin() {
|
779
|
-
return !!storage.getItem(TOKEN_KEY);
|
789
|
+
return !!this.storage.getItem(TOKEN_KEY);
|
780
790
|
}
|
781
791
|
getToken() {
|
782
|
-
return storage.getItem(TOKEN_KEY);
|
792
|
+
return this.storage.getItem(TOKEN_KEY);
|
783
793
|
}
|
784
794
|
setToken(token) {
|
785
|
-
storage.setItem(TOKEN_KEY, token);
|
795
|
+
this.storage.setItem(TOKEN_KEY, token);
|
786
796
|
this.emit("tokenChange", token);
|
787
797
|
}
|
788
798
|
// --- Getters ---
|
@@ -807,21 +817,21 @@ var Permission = class {
|
|
807
817
|
* Get storage information for debugging and monitoring
|
808
818
|
*/
|
809
819
|
getStorageInfo() {
|
810
|
-
const keys = storage.getKeys();
|
820
|
+
const keys = this.storage.getKeys();
|
811
821
|
const userOrgsCacheKeys = keys.filter(
|
812
822
|
(key) => key.startsWith(USER_ORG_KEY)
|
813
823
|
);
|
814
824
|
return {
|
815
|
-
...storage.getStorageInfo(),
|
825
|
+
...this.storage.getStorageInfo(),
|
816
826
|
permissionKeys: {
|
817
827
|
resourceKey: RESOURCE_KEY,
|
818
828
|
tokenKey: TOKEN_KEY,
|
819
829
|
userInfoKey: USER_INFO_KEY
|
820
830
|
},
|
821
831
|
hasData: {
|
822
|
-
resources: storage.hasKey(RESOURCE_KEY),
|
823
|
-
token: storage.hasKey(TOKEN_KEY),
|
824
|
-
userInfo: storage.hasKey(USER_INFO_KEY)
|
832
|
+
resources: this.storage.hasKey(RESOURCE_KEY),
|
833
|
+
token: this.storage.hasKey(TOKEN_KEY),
|
834
|
+
userInfo: this.storage.hasKey(USER_INFO_KEY)
|
825
835
|
},
|
826
836
|
cacheInfo: {
|
827
837
|
userOrgsCacheCount: userOrgsCacheKeys.length,
|
@@ -833,13 +843,16 @@ var Permission = class {
|
|
833
843
|
* Get current storage version
|
834
844
|
*/
|
835
845
|
getStorageVersion() {
|
836
|
-
return storage.getVersion();
|
846
|
+
return this.storage.getVersion();
|
837
847
|
}
|
838
848
|
/**
|
839
849
|
* Clear all storage data for this system
|
840
850
|
*/
|
841
851
|
clearStorage() {
|
842
|
-
storage.clear();
|
852
|
+
this.storage.clear();
|
853
|
+
}
|
854
|
+
clearAuthCache() {
|
855
|
+
this.storage.removeItem(TOKEN_KEY);
|
843
856
|
}
|
844
857
|
/**
|
845
858
|
* Clear user orgs cache for specific parameters or all
|
@@ -847,16 +860,32 @@ var Permission = class {
|
|
847
860
|
clearUserOrgsCache(params) {
|
848
861
|
if (params) {
|
849
862
|
const cacheKey = this.generateUserOrgsCacheKey(params);
|
850
|
-
storage.removeItem(cacheKey);
|
863
|
+
this.storage.removeItem(cacheKey);
|
851
864
|
} else {
|
852
|
-
const keys = storage.getKeys();
|
865
|
+
const keys = this.storage.getKeys();
|
853
866
|
keys.forEach((key) => {
|
854
867
|
if (key.startsWith(USER_ORG_KEY)) {
|
855
|
-
storage.removeItem(key);
|
868
|
+
this.storage.removeItem(key);
|
856
869
|
}
|
857
870
|
});
|
858
871
|
}
|
859
872
|
}
|
873
|
+
clearUserCache() {
|
874
|
+
const keys = this.storage.getKeys();
|
875
|
+
keys.forEach((key) => {
|
876
|
+
if (key.startsWith(USER_ORG_KEY) || key.startsWith(USER_TOTAL_COMPANY_KEY) || key.startsWith(USER_INFO_KEY)) {
|
877
|
+
this.storage.removeItem(key);
|
878
|
+
}
|
879
|
+
});
|
880
|
+
}
|
881
|
+
clearAppCache() {
|
882
|
+
const keys = this.storage.getKeys();
|
883
|
+
keys.forEach((key) => {
|
884
|
+
if (key.startsWith(RESOURCE_KEY)) {
|
885
|
+
this.storage.removeItem(key);
|
886
|
+
}
|
887
|
+
});
|
888
|
+
}
|
860
889
|
};
|
861
890
|
|
862
891
|
// src/sso.ts
|
@@ -899,6 +928,11 @@ export {
|
|
899
928
|
EnumOrgQueryScope,
|
900
929
|
EventEmitter,
|
901
930
|
Permission as OpmsPermission,
|
931
|
+
RESOURCE_KEY,
|
932
|
+
TOKEN_KEY,
|
933
|
+
USER_INFO_KEY,
|
934
|
+
USER_ORG_KEY,
|
935
|
+
USER_TOTAL_COMPANY_KEY,
|
902
936
|
getOrgTree,
|
903
937
|
getUserInfo,
|
904
938
|
getUserOrgTree,
|