@ibiz-template/core 0.0.1-alpha.4 → 0.0.1-alpha.40

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.
Files changed (114) hide show
  1. package/dist/system/index.system.js +1 -0
  2. package/out/constant/http-status-message/http-status-message.d.ts +5 -0
  3. package/out/constant/http-status-message/http-status-message.d.ts.map +1 -0
  4. package/out/constant/http-status-message/http-status-message.js +20 -0
  5. package/out/constant/index.d.ts +4 -0
  6. package/out/constant/index.d.ts.map +1 -1
  7. package/out/constant/index.js +4 -0
  8. package/out/constant/login-mode/login-mode.d.ts +23 -0
  9. package/out/constant/login-mode/login-mode.d.ts.map +1 -0
  10. package/out/constant/login-mode/login-mode.js +24 -0
  11. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
  12. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
  13. package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
  14. package/out/constant/util/util.d.ts +5 -0
  15. package/out/constant/util/util.d.ts.map +1 -0
  16. package/out/constant/util/util.js +5 -0
  17. package/out/context/index.d.ts +2 -39
  18. package/out/context/index.d.ts.map +1 -1
  19. package/out/context/index.js +34 -65
  20. package/out/environment/environment.d.ts.map +1 -1
  21. package/out/environment/environment.js +11 -1
  22. package/out/error/http-error/http-error.d.ts +18 -0
  23. package/out/error/http-error/http-error.d.ts.map +1 -0
  24. package/out/error/http-error/http-error.js +36 -0
  25. package/out/error/index.d.ts +3 -0
  26. package/out/error/index.d.ts.map +1 -0
  27. package/out/error/index.js +2 -0
  28. package/out/error/runtime-error/runtime-error.d.ts +15 -0
  29. package/out/error/runtime-error/runtime-error.d.ts.map +1 -0
  30. package/out/error/runtime-error/runtime-error.js +15 -0
  31. package/out/factory-center.d.ts +11 -0
  32. package/out/factory-center.d.ts.map +1 -0
  33. package/out/factory-center.js +10 -0
  34. package/out/ibizsys.d.ts +8 -1
  35. package/out/ibizsys.d.ts.map +1 -1
  36. package/out/ibizsys.js +8 -1
  37. package/out/index.d.ts +3 -1
  38. package/out/index.d.ts.map +1 -1
  39. package/out/index.js +3 -1
  40. package/out/install.d.ts.map +1 -1
  41. package/out/install.js +4 -2
  42. package/out/interface/click-outside/click-outside.d.ts +70 -0
  43. package/out/interface/click-outside/click-outside.d.ts.map +1 -0
  44. package/out/interface/click-outside/click-outside.js +1 -0
  45. package/out/interface/i-environment/i-environment.d.ts +76 -0
  46. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  47. package/out/interface/index.d.ts +1 -0
  48. package/out/interface/index.d.ts.map +1 -1
  49. package/out/interface/index.js +1 -1
  50. package/out/types.d.ts +20 -0
  51. package/out/types.d.ts.map +1 -1
  52. package/out/utils/click-outside/click-outside.d.ts +14 -0
  53. package/out/utils/click-outside/click-outside.d.ts.map +1 -0
  54. package/out/utils/click-outside/click-outside.js +85 -0
  55. package/out/utils/event/event.d.ts +34 -0
  56. package/out/utils/event/event.d.ts.map +1 -0
  57. package/out/utils/event/event.js +60 -0
  58. package/out/utils/index.d.ts +5 -1
  59. package/out/utils/index.d.ts.map +1 -1
  60. package/out/utils/index.js +5 -1
  61. package/out/utils/interceptor/core-interceptor.d.ts +15 -0
  62. package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
  63. package/out/utils/interceptor/core-interceptor.js +30 -0
  64. package/out/utils/interceptor/index.d.ts +3 -0
  65. package/out/utils/interceptor/index.d.ts.map +1 -0
  66. package/out/utils/interceptor/index.js +2 -0
  67. package/out/utils/interceptor/interceptor.d.ts +74 -3
  68. package/out/utils/interceptor/interceptor.d.ts.map +1 -1
  69. package/out/utils/interceptor/interceptor.js +73 -22
  70. package/out/utils/logger/logger.d.ts +3 -0
  71. package/out/utils/logger/logger.d.ts.map +1 -0
  72. package/out/utils/logger/logger.js +2 -0
  73. package/out/utils/net/http-response.d.ts +4 -9
  74. package/out/utils/net/http-response.d.ts.map +1 -1
  75. package/out/utils/net/http-response.js +0 -7
  76. package/out/utils/net/net.d.ts +82 -31
  77. package/out/utils/net/net.d.ts.map +1 -1
  78. package/out/utils/net/net.js +145 -50
  79. package/out/utils/url-helper/url-helper.d.ts +51 -0
  80. package/out/utils/url-helper/url-helper.d.ts.map +1 -0
  81. package/out/utils/url-helper/url-helper.js +59 -0
  82. package/out/utils/util/util.d.ts +45 -0
  83. package/out/utils/util/util.d.ts.map +1 -1
  84. package/out/utils/util/util.js +96 -0
  85. package/package.json +18 -7
  86. package/src/constant/http-status-message/http-status-message.ts +20 -0
  87. package/src/constant/index.ts +4 -0
  88. package/src/constant/login-mode/login-mode.ts +23 -0
  89. package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
  90. package/src/constant/util/util.ts +5 -0
  91. package/src/context/index.ts +35 -69
  92. package/src/environment/environment.ts +11 -1
  93. package/src/error/http-error/http-error.ts +43 -0
  94. package/src/error/index.ts +2 -0
  95. package/src/error/runtime-error/runtime-error.ts +14 -0
  96. package/src/factory-center.ts +9 -0
  97. package/src/ibizsys.ts +9 -1
  98. package/src/index.ts +3 -1
  99. package/src/install.ts +4 -2
  100. package/src/interface/click-outside/click-outside.ts +71 -0
  101. package/src/interface/i-environment/i-environment.ts +86 -0
  102. package/src/interface/index.ts +1 -0
  103. package/src/types.ts +21 -0
  104. package/src/utils/click-outside/click-outside.ts +110 -0
  105. package/src/utils/event/event.ts +77 -0
  106. package/src/utils/index.ts +5 -1
  107. package/src/utils/interceptor/core-interceptor.ts +35 -0
  108. package/src/utils/interceptor/index.ts +2 -0
  109. package/src/utils/interceptor/interceptor.ts +109 -22
  110. package/src/utils/logger/logger.ts +3 -0
  111. package/src/utils/net/http-response.ts +6 -9
  112. package/src/utils/net/net.ts +175 -61
  113. package/src/utils/url-helper/url-helper.ts +62 -0
  114. package/src/utils/util/util.ts +115 -0
@@ -0,0 +1,51 @@
1
+ /**
2
+ * 路径解析助手
3
+ *
4
+ * @author lxm
5
+ * @date 2022-10-11 14:10:12
6
+ * @export
7
+ * @class UrlHelper
8
+ */
9
+ export declare class UrlHelper {
10
+ /**
11
+ * 路由路径前面的基础路径
12
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
13
+ * 返回:http://172.16.103.120:30061/portalwebapp/#
14
+ *
15
+ * @author lxm
16
+ * @date 2022-10-11 20:10:29
17
+ * @returns {*}
18
+ */
19
+ static get routeBase(): string;
20
+ /**
21
+ * 应用的的基础路径
22
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
23
+ * 返回:http://172.16.103.120:30061/portalwebapp
24
+ *
25
+ * @author lxm
26
+ * @date 2022-10-11 20:10:29
27
+ * @returns {*}
28
+ */
29
+ static get appBase(): string;
30
+ /**
31
+ * #开始到末尾,即路由地址
32
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
33
+ * 返回:/index/appportalview?params=123
34
+ *
35
+ * @author lxm
36
+ * @date 2022-10-11 16:10:40
37
+ * @returns {*}
38
+ */
39
+ static get routePath(): string;
40
+ /**
41
+ * 当前地址的全路径,包含域名和参数
42
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
43
+ *
44
+ * @author lxm
45
+ * @date 2022-10-11 21:10:39
46
+ * @readonly
47
+ * @static
48
+ */
49
+ static get fullPath(): string;
50
+ }
51
+ //# sourceMappingURL=url-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-helper.d.ts","sourceRoot":"","sources":["../../../src/utils/url-helper/url-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,SAAS;IACpB;;;;;;;;OAQG;IACH,MAAM,KAAK,SAAS,WAEnB;IAED;;;;;;;;OAQG;IACH,MAAM,KAAK,OAAO,WAGjB;IAED;;;;;;;;OAQG;IACH,MAAM,KAAK,SAAS,WAEnB;IAED;;;;;;;;OAQG;IACH,MAAM,KAAK,QAAQ,WAElB;CACF"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * 路径解析助手
3
+ *
4
+ * @author lxm
5
+ * @date 2022-10-11 14:10:12
6
+ * @export
7
+ * @class UrlHelper
8
+ */
9
+ export class UrlHelper {
10
+ /**
11
+ * 路由路径前面的基础路径
12
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
13
+ * 返回:http://172.16.103.120:30061/portalwebapp/#
14
+ *
15
+ * @author lxm
16
+ * @date 2022-10-11 20:10:29
17
+ * @returns {*}
18
+ */
19
+ static get routeBase() {
20
+ return `${this.appBase}/#`;
21
+ }
22
+ /**
23
+ * 应用的的基础路径
24
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
25
+ * 返回:http://172.16.103.120:30061/portalwebapp
26
+ *
27
+ * @author lxm
28
+ * @date 2022-10-11 20:10:29
29
+ * @returns {*}
30
+ */
31
+ static get appBase() {
32
+ const { origin, pathname } = window.location;
33
+ return `${origin}${pathname}`.replace(/\/$/, '');
34
+ }
35
+ /**
36
+ * #开始到末尾,即路由地址
37
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
38
+ * 返回:/index/appportalview?params=123
39
+ *
40
+ * @author lxm
41
+ * @date 2022-10-11 16:10:40
42
+ * @returns {*}
43
+ */
44
+ static get routePath() {
45
+ return window.location.hash.replace('#', '');
46
+ }
47
+ /**
48
+ * 当前地址的全路径,包含域名和参数
49
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
50
+ *
51
+ * @author lxm
52
+ * @date 2022-10-11 21:10:39
53
+ * @readonly
54
+ * @static
55
+ */
56
+ static get fullPath() {
57
+ return window.location.href;
58
+ }
59
+ }
@@ -7,4 +7,49 @@
7
7
  * @return {*} {(string | null)}
8
8
  */
9
9
  export declare function getToken(): string | null;
10
+ /**
11
+ * 判断两个数组是否有相同的元素
12
+ *
13
+ * @author lxm
14
+ * @date 2022-09-20 19:09:29
15
+ * @export
16
+ * @param {any[]} arr1
17
+ * @param {any[]} arr2
18
+ * @returns {*} {boolean}
19
+ */
20
+ export declare function isOverlap(arr1: any[], arr2: any[]): boolean;
21
+ /**
22
+ * 防抖并合并每次的参数,
23
+ * 最后一次才会执行
24
+ *
25
+ * @author lxm
26
+ * @date 2022-09-20 21:09:53
27
+ * @export
28
+ * @template T
29
+ * @param {T} func 要防抖的函数
30
+ * @param {(
31
+ * oldParams: Parameters<T>,
32
+ * newParams: Parameters<T>,
33
+ * ) => Parameters<T>} mergeFunc 合并的回调函数
34
+ * @param {number} [wait] 防抖的延迟毫秒数
35
+ * @returns {*}
36
+ */
37
+ export declare function debounceAndMerge<T extends (...args: any[]) => any>(func: T, mergeFunc: (oldParams: Parameters<T>, newParams: Parameters<T>) => Parameters<T>, wait?: number): (...args: Parameters<T>) => any;
38
+ /**
39
+ * 防抖并合并每次的参数,最后一次才会执行
40
+ * 绑定方法为异步方法,给每次调用返回最终执行那次的结果
41
+ *
42
+ * @author lxm
43
+ * @date 2022-09-20 21:09:53
44
+ * @export
45
+ * @template T
46
+ * @param {T} func 要防抖的函数
47
+ * @param {(
48
+ * oldParams: Parameters<T>,
49
+ * newParams: Parameters<T>,
50
+ * ) => Parameters<T>} mergeFunc 合并的回调函数
51
+ * @param {number} [wait] 防抖的延迟毫秒数
52
+ * @returns {*}
53
+ */
54
+ export declare function debounceAndAsyncMerge<T extends (...args: any[]) => Promise<any>>(func: T, mergeFunc: (oldParams: Parameters<T>, newParams: Parameters<T>) => Parameters<T>, wait?: number): T;
10
55
  //# sourceMappingURL=util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/utils/util/util.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAExC"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/utils/util/util.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAExC;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAG3D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAChE,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,CACT,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EACxB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,KACrB,UAAU,CAAC,CAAC,CAAC,EAClB,IAAI,CAAC,EAAE,MAAM,aASI,WAAW,CAAC,CAAC,SAS/B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAE1C,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,CACT,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EACxB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,KACrB,UAAU,CAAC,CAAC,CAAC,EAClB,IAAI,CAAC,EAAE,MAAM,GACZ,CAAC,CA6BH"}
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { debounce } from 'lodash-es';
1
3
  import { getCookie } from 'qx-util';
2
4
  import { CoreConst } from '../../constant';
3
5
  /**
@@ -11,3 +13,97 @@ import { CoreConst } from '../../constant';
11
13
  export function getToken() {
12
14
  return getCookie(CoreConst.TOKEN);
13
15
  }
16
+ /**
17
+ * 判断两个数组是否有相同的元素
18
+ *
19
+ * @author lxm
20
+ * @date 2022-09-20 19:09:29
21
+ * @export
22
+ * @param {any[]} arr1
23
+ * @param {any[]} arr2
24
+ * @returns {*} {boolean}
25
+ */
26
+ export function isOverlap(arr1, arr2) {
27
+ const newArr = Array.from(new Set([...arr1, ...arr2]));
28
+ return newArr.length !== arr1.length + arr2.length;
29
+ }
30
+ /**
31
+ * 防抖并合并每次的参数,
32
+ * 最后一次才会执行
33
+ *
34
+ * @author lxm
35
+ * @date 2022-09-20 21:09:53
36
+ * @export
37
+ * @template T
38
+ * @param {T} func 要防抖的函数
39
+ * @param {(
40
+ * oldParams: Parameters<T>,
41
+ * newParams: Parameters<T>,
42
+ * ) => Parameters<T>} mergeFunc 合并的回调函数
43
+ * @param {number} [wait] 防抖的延迟毫秒数
44
+ * @returns {*}
45
+ */
46
+ export function debounceAndMerge(func, mergeFunc, wait) {
47
+ // 缓存上一次的函数参数
48
+ let oldParams;
49
+ const debounceFunc = debounce((...params) => {
50
+ // 防抖函数执行的时候清空缓存参数
51
+ oldParams = undefined;
52
+ return func(...params);
53
+ }, wait);
54
+ return (...args) => {
55
+ // 合并参数,并把参数缓存到oldParams里,用新参数调用防抖函数
56
+ let newParams = args;
57
+ if (oldParams) {
58
+ newParams = mergeFunc(oldParams, newParams);
59
+ }
60
+ oldParams = newParams;
61
+ return debounceFunc(...newParams);
62
+ };
63
+ }
64
+ /**
65
+ * 防抖并合并每次的参数,最后一次才会执行
66
+ * 绑定方法为异步方法,给每次调用返回最终执行那次的结果
67
+ *
68
+ * @author lxm
69
+ * @date 2022-09-20 21:09:53
70
+ * @export
71
+ * @template T
72
+ * @param {T} func 要防抖的函数
73
+ * @param {(
74
+ * oldParams: Parameters<T>,
75
+ * newParams: Parameters<T>,
76
+ * ) => Parameters<T>} mergeFunc 合并的回调函数
77
+ * @param {number} [wait] 防抖的延迟毫秒数
78
+ * @returns {*}
79
+ */
80
+ export function debounceAndAsyncMerge(func, mergeFunc, wait) {
81
+ // 缓存上一次的函数参数
82
+ let oldParams;
83
+ let promises = [];
84
+ const debounceFunc = debounce(async (...params) => {
85
+ // 防抖函数执行的时候清空缓存参数
86
+ oldParams = undefined;
87
+ const result = await func(...params);
88
+ promises.forEach(promise => {
89
+ promise.resolve(result);
90
+ });
91
+ promises = [];
92
+ return result;
93
+ }, wait);
94
+ const fun = async (...args) => {
95
+ // 合并参数,并把参数缓存到oldParams里,用新参数调用防抖函数
96
+ let newParams = args;
97
+ if (oldParams) {
98
+ newParams = mergeFunc(oldParams, newParams);
99
+ }
100
+ oldParams = newParams;
101
+ // 执行防抖函数
102
+ debounceFunc(...newParams);
103
+ return new Promise((resolve, reject) => {
104
+ // 阻塞当前调用,当防抖函数被执行后返回
105
+ promises.push({ resolve, reject });
106
+ });
107
+ };
108
+ return fun;
109
+ }
package/package.json CHANGED
@@ -1,19 +1,27 @@
1
1
  {
2
2
  "name": "@ibiz-template/core",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-alpha.40",
4
4
  "description": "核心包",
5
+ "type": "module",
5
6
  "main": "out/index.js",
6
7
  "types": "out/index.d.ts",
8
+ "system": "./dist/system/index.system.js",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://gitee.com/iBizModeling/ibiz-template.git"
12
+ },
7
13
  "files": [
14
+ "dist",
8
15
  "out",
9
16
  "src"
10
17
  ],
11
18
  "scripts": {
12
19
  "dev": "tsc --watch",
13
- "build": "npm run lint && npm run clean && tsc --build",
20
+ "build": "npm run lint && npm run clean && npm run build:rollup && tsc --build",
21
+ "build:rollup": "rollup -c",
14
22
  "lint": "eslint 'src/**/*.ts'",
15
23
  "lint:fix": "eslint --fix 'src/**/*.ts'",
16
- "clean": "rimraf out",
24
+ "clean": "rimraf out dist",
17
25
  "test": "jest",
18
26
  "publish:next": "npm run build && npm publish --access public --tag next",
19
27
  "publish:npm": "npm run build && npm publish --access public"
@@ -21,17 +29,20 @@
21
29
  "author": "chitanda",
22
30
  "license": "MIT",
23
31
  "dependencies": {
24
- "axios": "^0.27.2",
32
+ "axios": "^1.1.3",
33
+ "loglevel": "^1.8.0",
25
34
  "pluralize": "^8.0.0",
26
35
  "qs": "^6.11.0"
27
36
  },
28
37
  "devDependencies": {
29
38
  "@types/pluralize": "^0.0.29",
30
39
  "@types/qs": "^6.9.7",
31
- "qx-util": "^0.4.0"
40
+ "lodash-es": "^4.17.21",
41
+ "qx-util": "^0.4.4"
32
42
  },
33
43
  "peerDependencies": {
34
- "qx-util": "^0.4.0"
44
+ "lodash-es": "^4.17.21",
45
+ "qx-util": "^0.4.4"
35
46
  },
36
- "gitHead": "e21190e748f8e9ccdcda19ce09bc21c8e0ad7e87"
47
+ "gitHead": "be7fae93941fcce8a2c0fa9f4158e9525bcdb55d"
37
48
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 请求状态码文本
3
+ */
4
+ export const HttpStatusMessageConst: Record<number, string> = {
5
+ 200: '服务器成功返回请求的数据。',
6
+ 201: '新建或修改数据成功。',
7
+ 202: '一个请求已经进入后台排队(异步任务)。',
8
+ 204: '删除数据成功。',
9
+ 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
10
+ 401: '用户没有权限(令牌、用户名、密码错误)。',
11
+ 403: '用户得到授权,但是访问是被禁止的。',
12
+ 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
13
+ 406: '请求的格式不可得。',
14
+ 410: '请求的资源被永久删除,且不会再得到的。',
15
+ 422: '当创建一个对象时,发生一个验证错误。',
16
+ 500: '服务器发生错误,请检查服务器。',
17
+ 502: '网关错误。',
18
+ 503: '服务不可用,服务器暂时过载或维护。',
19
+ 504: '网关超时。',
20
+ };
@@ -1 +1,5 @@
1
1
  export { CoreConst } from './core/core';
2
+ export * from './util/util';
3
+ export { HttpStatusMessageConst } from './http-status-message/http-status-message';
4
+ export { LoginMode } from './login-mode/login-mode';
5
+ export { MenuPermissionMode } from './menu-permission-mode/menu-permission-mode';
@@ -0,0 +1,23 @@
1
+ /* eslint-disable no-shadow */
2
+ /**
3
+ * 登录模式
4
+ *
5
+ * @author lxm
6
+ * @date 2022-10-12 14:10:56
7
+ * @export
8
+ * @enum {number}
9
+ */
10
+ export enum LoginMode {
11
+ /**
12
+ * 默认标准登录
13
+ */
14
+ DEFAULT = 'DEFAULT',
15
+ /**
16
+ * 自定义登录
17
+ */
18
+ CUSTOM = 'CUSTOM',
19
+ /**
20
+ * 中央认证登录
21
+ */
22
+ CAS = 'CAS',
23
+ }
@@ -0,0 +1,23 @@
1
+ /* eslint-disable no-shadow */
2
+ /**
3
+ * 菜单权限校验模式
4
+ *
5
+ * @author lxm
6
+ * @date 2022-10-12 14:10:56
7
+ * @export
8
+ * @enum {number}
9
+ */
10
+ export enum MenuPermissionMode {
11
+ /**
12
+ * 混合模式(默认)
13
+ */
14
+ MIXIN = 'MIXIN',
15
+ /**
16
+ * 统一资源模式
17
+ */
18
+ RESOURCE = 'RESOURCE',
19
+ /**
20
+ * RT模式
21
+ */
22
+ RT = 'RT',
23
+ }
@@ -0,0 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-function */
2
+ /**
3
+ * 无操作函数
4
+ */
5
+ export const NOOP = () => {};
@@ -1,36 +1,3 @@
1
- /* eslint-disable no-param-reassign */
2
- /* eslint-disable no-constructor-return */
3
- /* eslint-disable no-underscore-dangle */
4
- /* eslint-disable max-classes-per-file */
5
- /**
6
- * 上下文代理处理
7
- *
8
- * @author chitanda
9
- * @date 2022-07-14 10:07:45
10
- * @class IBizContextProxyHandle
11
- * @implements {ProxyHandler<IBizContext>}
12
- */
13
- export class IBizContextProxyHandle implements ProxyHandler<IBizContext> {
14
- set(target: IBizContext, p: string | symbol, value: unknown): boolean {
15
- target.context[p] = value;
16
- return true;
17
- }
18
-
19
- get(target: IBizContext, p: string | symbol, _receiver: unknown): unknown {
20
- if (target[p] !== undefined) {
21
- return target[p];
22
- }
23
- if (target.context[p] !== undefined) {
24
- return target.context[p];
25
- }
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- if ((target as any)._parent && (target as any)._parent[p] !== undefined) {
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
- return (target as any)._parent[p];
30
- }
31
- }
32
- }
33
-
34
1
  /**
35
2
  * 上下文处理类
36
3
  *
@@ -43,51 +10,50 @@ export class IBizContext implements IContext {
43
10
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
11
  [key: string | symbol]: any;
45
12
 
46
- /**
47
- * 父上下文
48
- *
49
- * @author chitanda
50
- * @date 2022-07-14 10:07:06
51
- * @protected
52
- * @type {(IBizContext | null)}
53
- */
54
- protected _parent: IBizContext | null = null;
13
+ protected _context!: IContext;
55
14
 
56
15
  /**
57
16
  * Creates an instance of IBizContext.
58
17
  *
59
18
  * @author chitanda
60
19
  * @date 2022-07-14 10:07:15
61
- * @param {IContext} [context={}]
20
+ * @param {IContext} [context={}] 自身的上下文
62
21
  * @param {IBizContext} [parent]
63
22
  */
64
- constructor(public context: IContext = {}, parent?: IBizContext) {
23
+ // eslint-disable-next-line default-param-last
24
+ constructor(context: IContext = {}, parent?: IBizContext) {
65
25
  if (parent) {
66
- this._parent = parent;
26
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
27
+ const self = this;
28
+ // 定义私有变量,用于存储父已有上下文,方便覆盖
29
+ Object.defineProperty(this, '_context', {
30
+ enumerable: false,
31
+ value: {},
32
+ });
33
+ // 监控父上下文参数,自身不存在时从父取
34
+ const properties: { [key: string]: PropertyDescriptor } = {};
35
+ const keys = Object.keys(parent);
36
+ keys.forEach(key => {
37
+ properties[key] = {
38
+ enumerable: true,
39
+ set(val: unknown) {
40
+ if (val == null) {
41
+ self._context[key] = null;
42
+ } else {
43
+ self._context[key] = val;
44
+ }
45
+ },
46
+ get() {
47
+ if (self._context[key] !== undefined) {
48
+ return self._context[key];
49
+ }
50
+ return parent[key];
51
+ },
52
+ };
53
+ });
54
+ Object.defineProperties(this, properties);
67
55
  }
68
- return this.createProxy();
69
- }
70
-
71
- /**
72
- * 创建代理
73
- *
74
- * @author chitanda
75
- * @date 2022-07-14 11:07:37
76
- * @protected
77
- * @return {*} {IBizContext}
78
- */
79
- protected createProxy(): IBizContext {
80
- return new Proxy(this, new IBizContextProxyHandle());
81
- }
82
-
83
- /**
84
- * 销毁上下文,避免内存泄漏
85
- *
86
- * @author chitanda
87
- * @date 2022-07-14 11:07:45
88
- */
89
- destroy(): void {
90
- this.context = {};
91
- this._parent = null;
56
+ // 合并给入上下文
57
+ Object.assign(this, context);
92
58
  }
93
59
  }
@@ -1,12 +1,22 @@
1
+ import { LoginMode, MenuPermissionMode } from '../constant';
1
2
  import { IEnvironment } from '../interface';
2
3
 
3
4
  /**
4
5
  * 环境变量
5
6
  */
6
7
  export const Environment: IEnvironment = {
8
+ dev: false,
9
+ logLevel: 'ERROR',
10
+ jsCdn: 'https://cdn.jsdelivr.net',
7
11
  baseUrl: '',
8
- assetsUrl: './assets/',
12
+ pluginBaseUrl: './plugins',
13
+ remoteModelUrl: '/remotemodel',
14
+ assetsUrl: './assets',
9
15
  dcSystem: '',
10
16
  ExportFile: '/ibizutil/download',
11
17
  UploadFile: '/ibizutil/upload',
18
+ casLoginUrl: '',
19
+ loginMode: LoginMode.DEFAULT,
20
+ menuPermissionMode: MenuPermissionMode.MIXIN,
21
+ enablePermission: true,
12
22
  };
@@ -0,0 +1,43 @@
1
+ import { AxiosError, AxiosResponse } from 'axios';
2
+ import { HttpStatusMessageConst } from '../../constant';
3
+
4
+ /**
5
+ * 请求异常
6
+ *
7
+ * @author chitanda
8
+ * @date 2022-09-18 17:09:10
9
+ * @export
10
+ * @class HttpError
11
+ * @implements {Error}
12
+ */
13
+ export class HttpError implements Error {
14
+ name: string = 'HttpError';
15
+
16
+ message: string;
17
+
18
+ status: number;
19
+
20
+ response?: AxiosResponse;
21
+
22
+ constructor(err: AxiosError) {
23
+ const res = err.response;
24
+ this.response = err.response;
25
+ if (res) {
26
+ if (res.data) {
27
+ this.message = (res.data as IData).message;
28
+ } else {
29
+ this.message = res.statusText;
30
+ }
31
+ if (!this.message) {
32
+ this.message = HttpStatusMessageConst[res.status];
33
+ }
34
+ if (!this.message) {
35
+ this.message = '网络异常,请稍后重试!';
36
+ }
37
+ this.status = res.status;
38
+ } else {
39
+ this.message = err.message;
40
+ this.status = 500;
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,2 @@
1
+ export { HttpError } from './http-error/http-error';
2
+ export { RuntimeError } from './runtime-error/runtime-error';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 运行时异常
3
+ *
4
+ * @author lxm
5
+ * @date 2022-09-21 18:09:09
6
+ * @export
7
+ * @class RuntimeError
8
+ * @implements {Error}
9
+ */
10
+ export class RuntimeError implements Error {
11
+ name: string = 'Runtime Error';
12
+
13
+ constructor(public message: string) {}
14
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 工厂类挂载中心,挂载各种解耦用创建工厂
3
+ *
4
+ * @author lxm
5
+ * @date 2022-10-17 15:10:04
6
+ * @export
7
+ * @class FactoryCenter
8
+ */
9
+ export class FactoryCenter {}
package/src/ibizsys.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Environment } from './environment/environment';
2
2
  import { OrgData } from './interface';
3
- import { Net } from './utils';
3
+ import { Logger, Net } from './utils';
4
4
 
5
5
  /**
6
6
  * 全局对象
@@ -19,6 +19,14 @@ export class IBizSys {
19
19
  */
20
20
  env = Environment;
21
21
 
22
+ /**
23
+ * 日志对象
24
+ *
25
+ * @author chitanda
26
+ * @date 2022-10-25 20:10:22
27
+ */
28
+ log = Logger;
29
+
22
30
  /**
23
31
  * 网络请求工具类
24
32
  *
package/src/index.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import './types';
2
2
 
3
3
  export * from './constant';
4
- export { IBizContext, IBizContextProxyHandle } from './context';
4
+ export { IBizContext } from './context';
5
5
  export { Environment } from './environment/environment';
6
+ export * from './error';
6
7
  export * from './interface';
7
8
  export * from './utils';
8
9
  export { IBizSys } from './ibizsys';
10
+ export { FactoryCenter } from './factory-center';
9
11
  export { install } from './install';