@mu-cabin/opms-permission 0.9.4 → 0.9.6
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 +65 -22
- package/dist/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.mjs +64 -22
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
43
43
|
login: () => login,
|
44
44
|
logout: () => logout,
|
45
45
|
queryOrgCompanies: () => queryOrgCompanies,
|
46
|
+
queryOrgCustom: () => queryOrgCustom,
|
46
47
|
queryResource: () => queryResource
|
47
48
|
});
|
48
49
|
module.exports = __toCommonJS(index_exports);
|
@@ -316,7 +317,9 @@ var import_axios = __toESM(require("axios"));
|
|
316
317
|
// src/config.ts
|
317
318
|
var USER_INFO_KEY = "opms_user_info";
|
318
319
|
var RESOURCE_KEY = "opms_resources";
|
319
|
-
var TOKEN_KEY = "
|
320
|
+
var TOKEN_KEY = "opms_authorization";
|
321
|
+
var USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
322
|
+
var USER_ORG_KEY = "opms_user_orgs";
|
320
323
|
|
321
324
|
// src/api.ts
|
322
325
|
var axiosClient = import_axios.default.create();
|
@@ -397,6 +400,12 @@ async function queryOrgCompanies(baseUrl, params) {
|
|
397
400
|
params
|
398
401
|
);
|
399
402
|
}
|
403
|
+
function queryOrgCustom(params) {
|
404
|
+
return import_axios.default.post(
|
405
|
+
"/api/opmsDefaultUser/queryOrgCustom",
|
406
|
+
params
|
407
|
+
);
|
408
|
+
}
|
400
409
|
|
401
410
|
// src/utils/eventEmitter.ts
|
402
411
|
var EventEmitter = class {
|
@@ -688,7 +697,10 @@ var Permission = class {
|
|
688
697
|
// 12 hours
|
689
698
|
);
|
690
699
|
}
|
691
|
-
const { resourceMap, widgetMap } = createResourceMap(
|
700
|
+
const { resourceMap, widgetMap } = createResourceMap(
|
701
|
+
resources,
|
702
|
+
this.hasSubApp
|
703
|
+
);
|
692
704
|
const { menuList, menuMap } = createMenuList(resources, this.hasSubApp);
|
693
705
|
return {
|
694
706
|
resources,
|
@@ -702,16 +714,22 @@ var Permission = class {
|
|
702
714
|
* Generate cache key for user orgs query
|
703
715
|
*/
|
704
716
|
generateUserOrgsCacheKey(params) {
|
705
|
-
const sortedParams = Object.keys(params).sort().reduce(
|
706
|
-
acc
|
707
|
-
|
708
|
-
|
709
|
-
|
717
|
+
const sortedParams = Object.keys(params).sort().reduce(
|
718
|
+
(acc, key) => {
|
719
|
+
acc[key] = params[key];
|
720
|
+
return acc;
|
721
|
+
},
|
722
|
+
{}
|
723
|
+
);
|
724
|
+
return `${USER_ORG_KEY}_${JSON.stringify(sortedParams)}`;
|
710
725
|
}
|
711
726
|
/**
|
712
727
|
* Query and process organization tree with caching
|
713
728
|
*/
|
714
|
-
async queryUserOrgs(params, config = {
|
729
|
+
async queryUserOrgs(params, config = {
|
730
|
+
force: false,
|
731
|
+
cacheTimeout: 2
|
732
|
+
}) {
|
715
733
|
try {
|
716
734
|
const { force, cacheTimeout = 2 } = config;
|
717
735
|
let orgTreeData = null;
|
@@ -750,18 +768,40 @@ var Permission = class {
|
|
750
768
|
return null;
|
751
769
|
}
|
752
770
|
}
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
771
|
+
async queryCompanies(config = {
|
772
|
+
force: false,
|
773
|
+
cacheTimeout: 2
|
774
|
+
}) {
|
775
|
+
const { force, cacheTimeout = 2 } = config;
|
776
|
+
let orgCompanyList;
|
777
|
+
if (!force) {
|
778
|
+
orgCompanyList = storage.getItem(USER_TOTAL_COMPANY_KEY);
|
779
|
+
}
|
780
|
+
if (!orgCompanyList) {
|
781
|
+
const { obj } = await queryOrgCustom({
|
782
|
+
resultView: "TREE",
|
783
|
+
orgCodeSource: "COS",
|
784
|
+
direction: "FROM_SELF_TO_LEAF",
|
785
|
+
orgTypes: ["HEAD", "BRANCH"],
|
786
|
+
maxDepth: 100
|
787
|
+
});
|
788
|
+
orgCompanyList = iterateNestedArray(obj, (item) => {
|
789
|
+
return {
|
790
|
+
label: item.orgShortName,
|
791
|
+
value: item.orgCode,
|
792
|
+
title: item.orgShortName,
|
793
|
+
key: item.orgCode,
|
794
|
+
nodeLevel: item.nodeLevel,
|
795
|
+
children: item.children,
|
796
|
+
disabled: !item.hasPermission,
|
797
|
+
orgType: item.orgType,
|
798
|
+
orgId: item.orgId
|
799
|
+
};
|
800
|
+
});
|
801
|
+
storage.setItem(USER_TOTAL_COMPANY_KEY, orgCompanyList, cacheTimeout);
|
802
|
+
}
|
803
|
+
return orgCompanyList;
|
804
|
+
}
|
765
805
|
isLogin() {
|
766
806
|
return !!storage.getItem(TOKEN_KEY);
|
767
807
|
}
|
@@ -795,7 +835,9 @@ var Permission = class {
|
|
795
835
|
*/
|
796
836
|
getStorageInfo() {
|
797
837
|
const keys = storage.getKeys();
|
798
|
-
const userOrgsCacheKeys = keys.filter(
|
838
|
+
const userOrgsCacheKeys = keys.filter(
|
839
|
+
(key) => key.startsWith(USER_ORG_KEY)
|
840
|
+
);
|
799
841
|
return {
|
800
842
|
...storage.getStorageInfo(),
|
801
843
|
permissionKeys: {
|
@@ -836,7 +878,7 @@ var Permission = class {
|
|
836
878
|
} else {
|
837
879
|
const keys = storage.getKeys();
|
838
880
|
keys.forEach((key) => {
|
839
|
-
if (key.startsWith(
|
881
|
+
if (key.startsWith(USER_ORG_KEY)) {
|
840
882
|
storage.removeItem(key);
|
841
883
|
}
|
842
884
|
});
|
@@ -893,5 +935,6 @@ function jumpToSSOLogout({
|
|
893
935
|
login,
|
894
936
|
logout,
|
895
937
|
queryOrgCompanies,
|
938
|
+
queryOrgCustom,
|
896
939
|
queryResource
|
897
940
|
});
|
package/dist/index.d.mts
CHANGED
@@ -27,7 +27,6 @@ interface Resource {
|
|
27
27
|
icon?: string;
|
28
28
|
openIndicator: OpenIndicatorType;
|
29
29
|
orgQueryMode: EnumOrgQueryMode;
|
30
|
-
orgQueryScope: EnumOrgQueryScope;
|
31
30
|
}
|
32
31
|
type CodeSourceType = 'FLY_NET' | 'COS' | 'CSM';
|
33
32
|
interface OrgRecord$1 {
|
@@ -115,6 +114,21 @@ declare function getUserOrgTree(baseUrl: string, params: UserOrgTreeParams): Pro
|
|
115
114
|
declare function queryOrgCompanies(baseUrl: string, params: {
|
116
115
|
queryAllBranches?: boolean;
|
117
116
|
}): Promise<ApiResponse<OrgRecord$1[]>>;
|
117
|
+
type ResultViewType = 'LIST' | 'TREE' | 'FOREST';
|
118
|
+
type OrgDirectionType = 'NONE' | 'FROM_SELF_TO_ROOT' | 'FROM_SELF_TO_LEAF' | 'TWO_WAY';
|
119
|
+
type OrgType = 'HEAD' | 'BRANCH' | 'DEPARTMENT';
|
120
|
+
interface QueryOrgCustomParams {
|
121
|
+
resultView?: ResultViewType;
|
122
|
+
orgCodeSource: CodeSourceType;
|
123
|
+
ids?: number[];
|
124
|
+
direction?: OrgDirectionType;
|
125
|
+
maxDepth?: number;
|
126
|
+
orgTypes?: OrgType[];
|
127
|
+
}
|
128
|
+
/**
|
129
|
+
* 根据查询条件自定义组织机构查询
|
130
|
+
*/
|
131
|
+
declare function queryOrgCustom(params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
118
132
|
|
119
133
|
interface MenuItem {
|
120
134
|
icon?: string;
|
@@ -122,7 +136,7 @@ interface MenuItem {
|
|
122
136
|
name: string;
|
123
137
|
children: MenuItem[];
|
124
138
|
resourceId: number;
|
125
|
-
openIndicator:
|
139
|
+
openIndicator: OpenIndicatorType;
|
126
140
|
}
|
127
141
|
interface UserInfo {
|
128
142
|
account: string;
|
@@ -360,6 +374,10 @@ declare class Permission {
|
|
360
374
|
}): Promise<{
|
361
375
|
orgTree: OrgTreeItem[];
|
362
376
|
} | null>;
|
377
|
+
queryCompanies(config?: {
|
378
|
+
force?: boolean;
|
379
|
+
cacheTimeout?: number;
|
380
|
+
}): Promise<OrgRecord$1[]>;
|
363
381
|
isLogin(): boolean;
|
364
382
|
getToken(): string | null;
|
365
383
|
setToken(token: string): void;
|
@@ -422,4 +440,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
422
440
|
clientId?: string;
|
423
441
|
}): void;
|
424
442
|
|
425
|
-
export { type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgRecord, type OrgTreeItem, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type Resource, type ResourceType, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryResource };
|
443
|
+
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 };
|
package/dist/index.d.ts
CHANGED
@@ -27,7 +27,6 @@ interface Resource {
|
|
27
27
|
icon?: string;
|
28
28
|
openIndicator: OpenIndicatorType;
|
29
29
|
orgQueryMode: EnumOrgQueryMode;
|
30
|
-
orgQueryScope: EnumOrgQueryScope;
|
31
30
|
}
|
32
31
|
type CodeSourceType = 'FLY_NET' | 'COS' | 'CSM';
|
33
32
|
interface OrgRecord$1 {
|
@@ -115,6 +114,21 @@ declare function getUserOrgTree(baseUrl: string, params: UserOrgTreeParams): Pro
|
|
115
114
|
declare function queryOrgCompanies(baseUrl: string, params: {
|
116
115
|
queryAllBranches?: boolean;
|
117
116
|
}): Promise<ApiResponse<OrgRecord$1[]>>;
|
117
|
+
type ResultViewType = 'LIST' | 'TREE' | 'FOREST';
|
118
|
+
type OrgDirectionType = 'NONE' | 'FROM_SELF_TO_ROOT' | 'FROM_SELF_TO_LEAF' | 'TWO_WAY';
|
119
|
+
type OrgType = 'HEAD' | 'BRANCH' | 'DEPARTMENT';
|
120
|
+
interface QueryOrgCustomParams {
|
121
|
+
resultView?: ResultViewType;
|
122
|
+
orgCodeSource: CodeSourceType;
|
123
|
+
ids?: number[];
|
124
|
+
direction?: OrgDirectionType;
|
125
|
+
maxDepth?: number;
|
126
|
+
orgTypes?: OrgType[];
|
127
|
+
}
|
128
|
+
/**
|
129
|
+
* 根据查询条件自定义组织机构查询
|
130
|
+
*/
|
131
|
+
declare function queryOrgCustom(params: QueryOrgCustomParams): Promise<ApiResponse<OrgRecord$1[]>>;
|
118
132
|
|
119
133
|
interface MenuItem {
|
120
134
|
icon?: string;
|
@@ -122,7 +136,7 @@ interface MenuItem {
|
|
122
136
|
name: string;
|
123
137
|
children: MenuItem[];
|
124
138
|
resourceId: number;
|
125
|
-
openIndicator:
|
139
|
+
openIndicator: OpenIndicatorType;
|
126
140
|
}
|
127
141
|
interface UserInfo {
|
128
142
|
account: string;
|
@@ -360,6 +374,10 @@ declare class Permission {
|
|
360
374
|
}): Promise<{
|
361
375
|
orgTree: OrgTreeItem[];
|
362
376
|
} | null>;
|
377
|
+
queryCompanies(config?: {
|
378
|
+
force?: boolean;
|
379
|
+
cacheTimeout?: number;
|
380
|
+
}): Promise<OrgRecord$1[]>;
|
363
381
|
isLogin(): boolean;
|
364
382
|
getToken(): string | null;
|
365
383
|
setToken(token: string): void;
|
@@ -422,4 +440,4 @@ declare function jumpToSSOLogout({ baseUrl, redirectToUrl, clientId, }: {
|
|
422
440
|
clientId?: string;
|
423
441
|
}): void;
|
424
442
|
|
425
|
-
export { type ApiResponse, type ChildOrganization, type CodeSourceType, DataHandler, EnumOrgQueryMode, EnumOrgQueryScope, EventEmitter, type MenuItem, type OpenIndicatorType, Permission as OpmsPermission, type Option, type OrgRecord, type OrgTreeItem, type PermissionEventListener, type PermissionEventMap, type PermissionEventType, type Resource, type ResourceType, type UserInfo, type UserOrgTreeParams, type UserOrganization, type UserRole, getOrgTree, getUserInfo, getUserOrgTree, jumpToSSOLogin, jumpToSSOLogout, login, logout, queryOrgCompanies, queryResource };
|
443
|
+
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 };
|
package/dist/index.mjs
CHANGED
@@ -267,7 +267,9 @@ import axios from "axios";
|
|
267
267
|
// src/config.ts
|
268
268
|
var USER_INFO_KEY = "opms_user_info";
|
269
269
|
var RESOURCE_KEY = "opms_resources";
|
270
|
-
var TOKEN_KEY = "
|
270
|
+
var TOKEN_KEY = "opms_authorization";
|
271
|
+
var USER_TOTAL_COMPANY_KEY = "opms_user_total_company";
|
272
|
+
var USER_ORG_KEY = "opms_user_orgs";
|
271
273
|
|
272
274
|
// src/api.ts
|
273
275
|
var axiosClient = axios.create();
|
@@ -348,6 +350,12 @@ async function queryOrgCompanies(baseUrl, params) {
|
|
348
350
|
params
|
349
351
|
);
|
350
352
|
}
|
353
|
+
function queryOrgCustom(params) {
|
354
|
+
return axios.post(
|
355
|
+
"/api/opmsDefaultUser/queryOrgCustom",
|
356
|
+
params
|
357
|
+
);
|
358
|
+
}
|
351
359
|
|
352
360
|
// src/utils/eventEmitter.ts
|
353
361
|
var EventEmitter = class {
|
@@ -639,7 +647,10 @@ var Permission = class {
|
|
639
647
|
// 12 hours
|
640
648
|
);
|
641
649
|
}
|
642
|
-
const { resourceMap, widgetMap } = createResourceMap(
|
650
|
+
const { resourceMap, widgetMap } = createResourceMap(
|
651
|
+
resources,
|
652
|
+
this.hasSubApp
|
653
|
+
);
|
643
654
|
const { menuList, menuMap } = createMenuList(resources, this.hasSubApp);
|
644
655
|
return {
|
645
656
|
resources,
|
@@ -653,16 +664,22 @@ var Permission = class {
|
|
653
664
|
* Generate cache key for user orgs query
|
654
665
|
*/
|
655
666
|
generateUserOrgsCacheKey(params) {
|
656
|
-
const sortedParams = Object.keys(params).sort().reduce(
|
657
|
-
acc
|
658
|
-
|
659
|
-
|
660
|
-
|
667
|
+
const sortedParams = Object.keys(params).sort().reduce(
|
668
|
+
(acc, key) => {
|
669
|
+
acc[key] = params[key];
|
670
|
+
return acc;
|
671
|
+
},
|
672
|
+
{}
|
673
|
+
);
|
674
|
+
return `${USER_ORG_KEY}_${JSON.stringify(sortedParams)}`;
|
661
675
|
}
|
662
676
|
/**
|
663
677
|
* Query and process organization tree with caching
|
664
678
|
*/
|
665
|
-
async queryUserOrgs(params, config = {
|
679
|
+
async queryUserOrgs(params, config = {
|
680
|
+
force: false,
|
681
|
+
cacheTimeout: 2
|
682
|
+
}) {
|
666
683
|
try {
|
667
684
|
const { force, cacheTimeout = 2 } = config;
|
668
685
|
let orgTreeData = null;
|
@@ -701,18 +718,40 @@ var Permission = class {
|
|
701
718
|
return null;
|
702
719
|
}
|
703
720
|
}
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
721
|
+
async queryCompanies(config = {
|
722
|
+
force: false,
|
723
|
+
cacheTimeout: 2
|
724
|
+
}) {
|
725
|
+
const { force, cacheTimeout = 2 } = config;
|
726
|
+
let orgCompanyList;
|
727
|
+
if (!force) {
|
728
|
+
orgCompanyList = storage.getItem(USER_TOTAL_COMPANY_KEY);
|
729
|
+
}
|
730
|
+
if (!orgCompanyList) {
|
731
|
+
const { obj } = await queryOrgCustom({
|
732
|
+
resultView: "TREE",
|
733
|
+
orgCodeSource: "COS",
|
734
|
+
direction: "FROM_SELF_TO_LEAF",
|
735
|
+
orgTypes: ["HEAD", "BRANCH"],
|
736
|
+
maxDepth: 100
|
737
|
+
});
|
738
|
+
orgCompanyList = iterateNestedArray(obj, (item) => {
|
739
|
+
return {
|
740
|
+
label: item.orgShortName,
|
741
|
+
value: item.orgCode,
|
742
|
+
title: item.orgShortName,
|
743
|
+
key: item.orgCode,
|
744
|
+
nodeLevel: item.nodeLevel,
|
745
|
+
children: item.children,
|
746
|
+
disabled: !item.hasPermission,
|
747
|
+
orgType: item.orgType,
|
748
|
+
orgId: item.orgId
|
749
|
+
};
|
750
|
+
});
|
751
|
+
storage.setItem(USER_TOTAL_COMPANY_KEY, orgCompanyList, cacheTimeout);
|
752
|
+
}
|
753
|
+
return orgCompanyList;
|
754
|
+
}
|
716
755
|
isLogin() {
|
717
756
|
return !!storage.getItem(TOKEN_KEY);
|
718
757
|
}
|
@@ -746,7 +785,9 @@ var Permission = class {
|
|
746
785
|
*/
|
747
786
|
getStorageInfo() {
|
748
787
|
const keys = storage.getKeys();
|
749
|
-
const userOrgsCacheKeys = keys.filter(
|
788
|
+
const userOrgsCacheKeys = keys.filter(
|
789
|
+
(key) => key.startsWith(USER_ORG_KEY)
|
790
|
+
);
|
750
791
|
return {
|
751
792
|
...storage.getStorageInfo(),
|
752
793
|
permissionKeys: {
|
@@ -787,7 +828,7 @@ var Permission = class {
|
|
787
828
|
} else {
|
788
829
|
const keys = storage.getKeys();
|
789
830
|
keys.forEach((key) => {
|
790
|
-
if (key.startsWith(
|
831
|
+
if (key.startsWith(USER_ORG_KEY)) {
|
791
832
|
storage.removeItem(key);
|
792
833
|
}
|
793
834
|
});
|
@@ -843,5 +884,6 @@ export {
|
|
843
884
|
login,
|
844
885
|
logout,
|
845
886
|
queryOrgCompanies,
|
887
|
+
queryOrgCustom,
|
846
888
|
queryResource
|
847
889
|
};
|