@ibiz-template/core 0.0.1-alpha.0 → 0.0.1-alpha.10

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/out/constant/core/core.d.ts +23 -0
  3. package/out/constant/core/core.d.ts.map +1 -0
  4. package/out/constant/core/core.js +22 -0
  5. package/out/constant/http-status-message/http-status-message.d.ts +5 -0
  6. package/out/constant/http-status-message/http-status-message.d.ts.map +1 -0
  7. package/out/constant/http-status-message/http-status-message.js +20 -0
  8. package/out/constant/index.d.ts +3 -0
  9. package/out/constant/index.d.ts.map +1 -0
  10. package/out/constant/index.js +2 -0
  11. package/out/context/index.d.ts +38 -3
  12. package/out/context/index.d.ts.map +1 -1
  13. package/out/context/index.js +53 -6
  14. package/out/environment/environment.d.ts +6 -0
  15. package/out/environment/environment.d.ts.map +1 -0
  16. package/out/environment/environment.js +11 -0
  17. package/out/error/http-error/http-error.d.ts +18 -0
  18. package/out/error/http-error/http-error.d.ts.map +1 -0
  19. package/out/error/http-error/http-error.js +36 -0
  20. package/out/error/index.d.ts +3 -0
  21. package/out/error/index.d.ts.map +1 -0
  22. package/out/error/index.js +2 -0
  23. package/out/error/runtime-error/runtime-error.d.ts +15 -0
  24. package/out/error/runtime-error/runtime-error.d.ts.map +1 -0
  25. package/out/error/runtime-error/runtime-error.js +15 -0
  26. package/out/ibizsys.d.ts +44 -0
  27. package/out/ibizsys.d.ts.map +1 -0
  28. package/out/ibizsys.js +29 -0
  29. package/out/index.d.ts +9 -1
  30. package/out/index.d.ts.map +1 -1
  31. package/out/index.js +9 -8
  32. package/out/install.d.ts +9 -0
  33. package/out/install.d.ts.map +1 -0
  34. package/out/install.js +16 -0
  35. package/out/interface/i-environment/i-environment.d.ts +67 -0
  36. package/out/interface/i-environment/i-environment.d.ts.map +1 -0
  37. package/out/interface/{i-context/i-context.js → i-environment/i-environment.js} +0 -0
  38. package/out/interface/index.d.ts +2 -1
  39. package/out/interface/index.d.ts.map +1 -1
  40. package/out/interface/org-data/org-data.d.ts +43 -0
  41. package/out/interface/org-data/org-data.d.ts.map +1 -0
  42. package/out/interface/org-data/org-data.js +1 -0
  43. package/out/types.d.ts +48 -0
  44. package/out/types.d.ts.map +1 -0
  45. package/out/types.js +1 -0
  46. package/out/utils/index.d.ts +7 -0
  47. package/out/utils/index.d.ts.map +1 -0
  48. package/out/utils/index.js +6 -0
  49. package/out/utils/interceptor/interceptor.d.ts +13 -0
  50. package/out/utils/interceptor/interceptor.d.ts.map +1 -0
  51. package/out/utils/interceptor/interceptor.js +33 -0
  52. package/out/utils/namespace/namespace.d.ts +148 -0
  53. package/out/utils/namespace/namespace.d.ts.map +1 -0
  54. package/out/utils/namespace/namespace.js +216 -0
  55. package/out/utils/net/http-response.d.ts +94 -0
  56. package/out/utils/net/http-response.d.ts.map +1 -0
  57. package/out/utils/net/http-response.js +53 -0
  58. package/out/utils/net/net.d.ts +123 -0
  59. package/out/utils/net/net.d.ts.map +1 -0
  60. package/out/utils/net/net.js +223 -0
  61. package/out/utils/plural/plural.d.ts +21 -0
  62. package/out/utils/plural/plural.d.ts.map +1 -0
  63. package/out/utils/plural/plural.js +25 -0
  64. package/out/utils/util/util.d.ts +39 -0
  65. package/out/utils/util/util.d.ts.map +1 -0
  66. package/out/utils/util/util.js +63 -0
  67. package/package.json +24 -6
  68. package/src/constant/core/core.ts +23 -0
  69. package/src/constant/http-status-message/http-status-message.ts +20 -0
  70. package/src/constant/index.ts +2 -0
  71. package/src/context/index.ts +112 -0
  72. package/src/environment/environment.ts +13 -0
  73. package/src/error/http-error/http-error.ts +43 -0
  74. package/src/error/index.ts +2 -0
  75. package/src/error/runtime-error/runtime-error.ts +14 -0
  76. package/src/ibizsys.ts +48 -0
  77. package/src/index.ts +10 -0
  78. package/src/install.ts +17 -0
  79. package/src/interface/i-environment/i-environment.ts +72 -0
  80. package/src/interface/index.ts +2 -0
  81. package/src/interface/org-data/org-data.ts +42 -0
  82. package/src/types.ts +54 -0
  83. package/src/utils/index.ts +6 -0
  84. package/src/utils/interceptor/interceptor.ts +35 -0
  85. package/src/utils/namespace/namespace.ts +244 -0
  86. package/src/utils/net/http-response.ts +113 -0
  87. package/src/utils/net/net.ts +254 -0
  88. package/src/utils/plural/plural.ts +27 -0
  89. package/src/utils/util/util.ts +78 -0
  90. package/out/interface/i-context/i-context.d.ts +0 -12
  91. package/out/interface/i-context/i-context.d.ts.map +0 -1
@@ -0,0 +1,123 @@
1
+ import { AxiosRequestHeaders } from 'axios';
2
+ import { IHttpResponse } from './http-response';
3
+ /**
4
+ * 全局请求工具类
5
+ *
6
+ * @author chitanda
7
+ * @date 2022-07-14 15:07:42
8
+ * @export
9
+ * @class Net
10
+ */
11
+ export declare class Net {
12
+ /**
13
+ * 标准请求前缀
14
+ *
15
+ * @author chitanda
16
+ * @date 2022-07-21 10:07:48
17
+ * @protected
18
+ * @type {string}
19
+ */
20
+ protected _prefix: string;
21
+ get prefix(): string;
22
+ /**
23
+ * Creates an instance of Net.
24
+ *
25
+ * @author chitanda
26
+ * @date 2022-07-21 10:07:27
27
+ * @param {string} [prefix] 请求前缀
28
+ */
29
+ constructor(prefix?: string);
30
+ /**
31
+ * Post 请求
32
+ *
33
+ * @author chitanda
34
+ * @date 2022-07-14 15:07:01
35
+ * @param {string} url
36
+ * @param {IParams} [params={}]
37
+ * @return {*} {Promise<IHttpResponse>}
38
+ */
39
+ post(url: string, data: IData, params?: IParams, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
40
+ /**
41
+ * Get 请求
42
+ *
43
+ * @author chitanda
44
+ * @date 2022-07-14 15:07:08
45
+ * @param {string} url
46
+ * @param {IParams} [params={}]
47
+ * @return {*} {Promise<IHttpResponse>}
48
+ */
49
+ get(url: string, params?: IParams, headers?: AxiosRequestHeaders, option?: IParams): Promise<IHttpResponse>;
50
+ /**
51
+ * Delete 请求
52
+ *
53
+ * @author chitanda
54
+ * @date 2022-07-14 15:07:43
55
+ * @param {string} url
56
+ * @param {IParams} [params]
57
+ * @return {*} {Promise<IHttpResponse>}
58
+ */
59
+ delete(url: string, params?: IParams, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
60
+ /**
61
+ * Put 请求
62
+ *
63
+ * @author chitanda
64
+ * @date 2022-07-14 15:07:49
65
+ * @param {string} url
66
+ * @param {IData} data
67
+ * @return {*} {Promise<IHttpResponse>}
68
+ */
69
+ put(url: string, data: IData, params?: IParams, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
70
+ /**
71
+ * 获取模型数据
72
+ *
73
+ * @author chitanda
74
+ * @date 2022-07-14 15:07:15
75
+ * @param {string} url
76
+ * @param {AxiosRequestHeaders} [headers={}]
77
+ * @return {*} {Promise<IHttpResponse>}
78
+ */
79
+ getModel(url: string, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
80
+ /**
81
+ * 统一处理请求返回
82
+ *
83
+ * @author chitanda
84
+ * @date 2022-07-14 16:07:23
85
+ * @private
86
+ * @param {AxiosResponse} response
87
+ * @return {*} {IHttpResponse}
88
+ */
89
+ private doResponseResult;
90
+ /**
91
+ * 处理平台预定义参数
92
+ *
93
+ * @author chitanda
94
+ * @date 2022-07-14 15:07:12
95
+ * @private
96
+ * @param {string} url
97
+ * @param {IParams} [params]
98
+ * @return {*} {string}
99
+ */
100
+ private handleAppPresetParam;
101
+ /**
102
+ * url 附加请求参数
103
+ *
104
+ * @author chitanda
105
+ * @date 2022-07-14 15:07:34
106
+ * @private
107
+ * @param {string} url
108
+ * @param {IParams} params
109
+ * @return {*} {string}
110
+ */
111
+ private attachUrlParam;
112
+ /**
113
+ * 处理 url 参数
114
+ *
115
+ * @author chitanda
116
+ * @date 2022-07-20 20:07:17
117
+ * @private
118
+ * @param {string} url
119
+ * @return {*} {string}
120
+ */
121
+ private attachUrl;
122
+ }
123
+ //# sourceMappingURL=net.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/utils/net/net.ts"],"names":[],"mappings":"AAAA,OAAc,EAAc,mBAAmB,EAAiB,MAAM,OAAO,CAAC;AAI9E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;GAOG;AACH,qBAAa,GAAG;IACd;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,CAAM;IAE/B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;;OAMG;gBACS,MAAM,CAAC,EAAE,MAAM;IAM3B;;;;;;;;OAQG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAmBzB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,EACjC,MAAM,GAAE,OAAY,GACnB,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;OAQG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;OAQG;IACG,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;CAGlB"}
@@ -0,0 +1,223 @@
1
+ import axios from 'axios';
2
+ import { stringify } from 'qs';
3
+ import { notNilEmpty } from 'qx-util';
4
+ import { HttpError } from '../../error';
5
+ /**
6
+ * 全局请求工具类
7
+ *
8
+ * @author chitanda
9
+ * @date 2022-07-14 15:07:42
10
+ * @export
11
+ * @class Net
12
+ */
13
+ export class Net {
14
+ /**
15
+ * Creates an instance of Net.
16
+ *
17
+ * @author chitanda
18
+ * @date 2022-07-21 10:07:27
19
+ * @param {string} [prefix] 请求前缀
20
+ */
21
+ constructor(prefix) {
22
+ /**
23
+ * 标准请求前缀
24
+ *
25
+ * @author chitanda
26
+ * @date 2022-07-21 10:07:48
27
+ * @protected
28
+ * @type {string}
29
+ */
30
+ this._prefix = '';
31
+ if (prefix) {
32
+ this._prefix = prefix;
33
+ }
34
+ }
35
+ get prefix() {
36
+ return this._prefix || ibiz.env.baseUrl;
37
+ }
38
+ /**
39
+ * Post 请求
40
+ *
41
+ * @author chitanda
42
+ * @date 2022-07-14 15:07:01
43
+ * @param {string} url
44
+ * @param {IParams} [params={}]
45
+ * @return {*} {Promise<IHttpResponse>}
46
+ */
47
+ async post(url, data, params = {}, headers = {}) {
48
+ url = this.handleAppPresetParam(url, params);
49
+ try {
50
+ const response = await axios({
51
+ method: 'post',
52
+ url,
53
+ data,
54
+ headers: Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', Accept: 'application/json' }, headers),
55
+ });
56
+ return this.doResponseResult(response);
57
+ }
58
+ catch (error) {
59
+ throw new HttpError(error);
60
+ }
61
+ }
62
+ /**
63
+ * Get 请求
64
+ *
65
+ * @author chitanda
66
+ * @date 2022-07-14 15:07:08
67
+ * @param {string} url
68
+ * @param {IParams} [params={}]
69
+ * @return {*} {Promise<IHttpResponse>}
70
+ */
71
+ async get(url, params = {}, headers = {}, option = {}) {
72
+ // if (params.srfparentdata) {
73
+ // Object.assign(params, params.srfparentdata);
74
+ // delete params.srfparentdata;
75
+ // }
76
+ url = this.attachUrlParam(url, params);
77
+ try {
78
+ const response = await axios.get(url, Object.assign({ headers }, option));
79
+ return this.doResponseResult(response);
80
+ }
81
+ catch (error) {
82
+ throw new HttpError(error);
83
+ }
84
+ }
85
+ /**
86
+ * Delete 请求
87
+ *
88
+ * @author chitanda
89
+ * @date 2022-07-14 15:07:43
90
+ * @param {string} url
91
+ * @param {IParams} [params]
92
+ * @return {*} {Promise<IHttpResponse>}
93
+ */
94
+ async delete(url, params, headers = {}) {
95
+ url = this.handleAppPresetParam(url, params);
96
+ try {
97
+ const response = await axios.delete(url, { headers });
98
+ return this.doResponseResult(response);
99
+ }
100
+ catch (error) {
101
+ throw new HttpError(error);
102
+ }
103
+ }
104
+ /**
105
+ * Put 请求
106
+ *
107
+ * @author chitanda
108
+ * @date 2022-07-14 15:07:49
109
+ * @param {string} url
110
+ * @param {IData} data
111
+ * @return {*} {Promise<IHttpResponse>}
112
+ */
113
+ async put(url, data, params = {}, headers = {}) {
114
+ url = this.handleAppPresetParam(url, params);
115
+ try {
116
+ const response = await axios.put(url, data, { headers });
117
+ return this.doResponseResult(response);
118
+ }
119
+ catch (error) {
120
+ throw new HttpError(error);
121
+ }
122
+ }
123
+ /**
124
+ * 获取模型数据
125
+ *
126
+ * @author chitanda
127
+ * @date 2022-07-14 15:07:15
128
+ * @param {string} url
129
+ * @param {AxiosRequestHeaders} [headers={}]
130
+ * @return {*} {Promise<IHttpResponse>}
131
+ */
132
+ async getModel(url, headers = {}) {
133
+ try {
134
+ const response = await axios.get(url, {
135
+ headers,
136
+ });
137
+ return this.doResponseResult(response);
138
+ }
139
+ catch (error) {
140
+ throw new HttpError(error);
141
+ }
142
+ }
143
+ /**
144
+ * 统一处理请求返回
145
+ *
146
+ * @author chitanda
147
+ * @date 2022-07-14 16:07:23
148
+ * @private
149
+ * @param {AxiosResponse} response
150
+ * @return {*} {IHttpResponse}
151
+ */
152
+ doResponseResult(response) {
153
+ const res = response;
154
+ if (res.status >= 200 && res.status <= 299) {
155
+ res.ok = true;
156
+ }
157
+ return res;
158
+ }
159
+ /**
160
+ * 处理平台预定义参数
161
+ *
162
+ * @author chitanda
163
+ * @date 2022-07-14 15:07:12
164
+ * @private
165
+ * @param {string} url
166
+ * @param {IParams} [params]
167
+ * @return {*} {string}
168
+ */
169
+ handleAppPresetParam(url, params) {
170
+ if (params) {
171
+ const keys = Object.keys(params);
172
+ const tempParam = {};
173
+ keys.forEach((item) => {
174
+ if (item.startsWith('srf') && notNilEmpty(params[item])) {
175
+ tempParam[item] = params[item];
176
+ }
177
+ });
178
+ return this.attachUrlParam(url, params);
179
+ }
180
+ return url;
181
+ }
182
+ /**
183
+ * url 附加请求参数
184
+ *
185
+ * @author chitanda
186
+ * @date 2022-07-14 15:07:34
187
+ * @private
188
+ * @param {string} url
189
+ * @param {IParams} params
190
+ * @return {*} {string}
191
+ */
192
+ attachUrlParam(url, params) {
193
+ url = this.attachUrl(url);
194
+ const strParams = stringify(params);
195
+ if (notNilEmpty(strParams)) {
196
+ if (url.endsWith('?')) {
197
+ url = `${url}${strParams}`;
198
+ }
199
+ else if (url.indexOf('?') !== -1 && url.endsWith('&')) {
200
+ url = `${url}${strParams}`;
201
+ }
202
+ else if (url.indexOf('?') !== -1 && !url.endsWith('&')) {
203
+ url = `${url}&${strParams}`;
204
+ }
205
+ else {
206
+ url = `${url}?${strParams}`;
207
+ }
208
+ }
209
+ return url;
210
+ }
211
+ /**
212
+ * 处理 url 参数
213
+ *
214
+ * @author chitanda
215
+ * @date 2022-07-20 20:07:17
216
+ * @private
217
+ * @param {string} url
218
+ * @return {*} {string}
219
+ */
220
+ attachUrl(url) {
221
+ return `${this.prefix}${url}`;
222
+ }
223
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 英文转复数写法
3
+ *
4
+ * @author chitanda
5
+ * @date 2022-08-25 18:08:41
6
+ * @export
7
+ * @param {string} key
8
+ * @return {*} {string}
9
+ */
10
+ export declare function plural(key: string): string;
11
+ /**
12
+ * 英文转复数写法并转全小写
13
+ *
14
+ * @author chitanda
15
+ * @date 2022-08-25 18:08:23
16
+ * @export
17
+ * @param {string} key
18
+ * @return {*} {string}
19
+ */
20
+ export declare function pluralLower(key: string): string;
21
+ //# sourceMappingURL=plural.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../src/utils/plural/plural.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C"}
@@ -0,0 +1,25 @@
1
+ import pluralize from 'pluralize';
2
+ /**
3
+ * 英文转复数写法
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-08-25 18:08:41
7
+ * @export
8
+ * @param {string} key
9
+ * @return {*} {string}
10
+ */
11
+ export function plural(key) {
12
+ return pluralize(key);
13
+ }
14
+ /**
15
+ * 英文转复数写法并转全小写
16
+ *
17
+ * @author chitanda
18
+ * @date 2022-08-25 18:08:23
19
+ * @export
20
+ * @param {string} key
21
+ * @return {*} {string}
22
+ */
23
+ export function pluralLower(key) {
24
+ return plural(key).toLowerCase();
25
+ }
@@ -0,0 +1,39 @@
1
+ import { DebounceSettings } from 'lodash-es';
2
+ /**
3
+ * 获取认证令牌
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-07-20 18:07:39
7
+ * @export
8
+ * @return {*} {(string | null)}
9
+ */
10
+ export declare function getToken(): string | null;
11
+ /**
12
+ * 判断两个数组是否有相同的元素
13
+ *
14
+ * @author lxm
15
+ * @date 2022-09-20 19:09:29
16
+ * @export
17
+ * @param {any[]} arr1
18
+ * @param {any[]} arr2
19
+ * @returns {*} {boolean}
20
+ */
21
+ export declare function isOverlap(arr1: any[], arr2: any[]): boolean;
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
+ * @param {DebounceSettings} [options] 防抖函数的额外参数
36
+ * @returns {*}
37
+ */
38
+ export declare function debounceAndMerge<T extends (...args: any[]) => any>(func: T, mergeFunc: (oldParams: Parameters<T>, newParams: Parameters<T>) => Parameters<T>, wait?: number, options?: DebounceSettings): (...args: Parameters<T>) => any;
39
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/utils/util/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAIvD;;;;;;;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,EACb,OAAO,CAAC,EAAE,gBAAgB,aAaT,WAAW,CAAC,CAAC,SAS/B"}
@@ -0,0 +1,63 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { debounce } from 'lodash-es';
3
+ import { getCookie } from 'qx-util';
4
+ import { CoreConst } from '../../constant';
5
+ /**
6
+ * 获取认证令牌
7
+ *
8
+ * @author chitanda
9
+ * @date 2022-07-20 18:07:39
10
+ * @export
11
+ * @return {*} {(string | null)}
12
+ */
13
+ export function getToken() {
14
+ return getCookie(CoreConst.TOKEN);
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
+ * @author lxm
34
+ * @date 2022-09-20 21:09:53
35
+ * @export
36
+ * @template T
37
+ * @param {T} func 要防抖的函数
38
+ * @param {(
39
+ * oldParams: Parameters<T>,
40
+ * newParams: Parameters<T>,
41
+ * ) => Parameters<T>} mergeFunc 合并的回调函数
42
+ * @param {number} [wait] 防抖的延迟毫秒数
43
+ * @param {DebounceSettings} [options] 防抖函数的额外参数
44
+ * @returns {*}
45
+ */
46
+ export function debounceAndMerge(func, mergeFunc, wait, options) {
47
+ // 缓存上一次的函数参数
48
+ let oldParams;
49
+ const debounceFunc = debounce((...params) => {
50
+ // 防抖函数执行的时候清空缓存参数
51
+ oldParams = undefined;
52
+ return func(...params);
53
+ }, wait, options);
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
+ }
package/package.json CHANGED
@@ -1,21 +1,39 @@
1
1
  {
2
2
  "name": "@ibiz-template/core",
3
- "version": "0.0.1-alpha.0",
4
- "description": "核心逻辑包",
3
+ "version": "0.0.1-alpha.10",
4
+ "description": "核心包",
5
5
  "main": "out/index.js",
6
- "types": "out/types/index.d.ts",
6
+ "types": "out/index.d.ts",
7
7
  "files": [
8
- "out"
8
+ "out",
9
+ "src"
9
10
  ],
10
11
  "scripts": {
11
12
  "dev": "tsc --watch",
12
13
  "build": "npm run lint && npm run clean && tsc --build",
13
- "lint": "eslint src/**/*.ts",
14
+ "lint": "eslint 'src/**/*.ts'",
15
+ "lint:fix": "eslint --fix 'src/**/*.ts'",
14
16
  "clean": "rimraf out",
17
+ "test": "jest",
15
18
  "publish:next": "npm run build && npm publish --access public --tag next",
16
19
  "publish:npm": "npm run build && npm publish --access public"
17
20
  },
18
21
  "author": "chitanda",
19
22
  "license": "MIT",
20
- "dependencies": {}
23
+ "dependencies": {
24
+ "axios": "^0.27.2",
25
+ "pluralize": "^8.0.0",
26
+ "qs": "^6.11.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/pluralize": "^0.0.29",
30
+ "@types/qs": "^6.9.7",
31
+ "lodash-es": "^4.17.21",
32
+ "qx-util": "^0.4.1"
33
+ },
34
+ "peerDependencies": {
35
+ "lodash-es": "^4.17.21",
36
+ "qx-util": "^0.4.1"
37
+ },
38
+ "gitHead": "ce2eaad242ee290ab9bec6b8293e7ae920cfc2f0"
21
39
  }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 核心全局静态变量
3
+ *
4
+ * @author chitanda
5
+ * @date 2022-07-14 17:07:25
6
+ * @export
7
+ * @enum {number}
8
+ */
9
+ export class CoreConst {
10
+ /**
11
+ * 默认模型服务标识
12
+ */
13
+ static readonly DEFAULT_MODEL_SERVICE_TAG = 'default';
14
+
15
+ /**
16
+ * 访问令牌标识
17
+ *
18
+ * @author chitanda
19
+ * @date 2022-07-20 15:07:28
20
+ * @static
21
+ */
22
+ static readonly TOKEN = 'access_token';
23
+ }
@@ -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
+ };
@@ -0,0 +1,2 @@
1
+ export { CoreConst } from './core/core';
2
+ export { HttpStatusMessageConst } from './http-status-message/http-status-message';