@ibiz-template/core 0.0.1-alpha.4 → 0.0.1-alpha.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.
Files changed (45) hide show
  1. package/out/constant/http-status-message/http-status-message.d.ts +5 -0
  2. package/out/constant/http-status-message/http-status-message.d.ts.map +1 -0
  3. package/out/constant/http-status-message/http-status-message.js +20 -0
  4. package/out/constant/index.d.ts +1 -0
  5. package/out/constant/index.d.ts.map +1 -1
  6. package/out/constant/index.js +1 -0
  7. package/out/context/index.d.ts +3 -3
  8. package/out/context/index.d.ts.map +1 -1
  9. package/out/context/index.js +1 -1
  10. package/out/environment/environment.d.ts.map +1 -1
  11. package/out/environment/environment.js +2 -1
  12. package/out/error/http-error/http-error.d.ts +18 -0
  13. package/out/error/http-error/http-error.d.ts.map +1 -0
  14. package/out/error/http-error/http-error.js +36 -0
  15. package/out/error/index.d.ts +3 -0
  16. package/out/error/index.d.ts.map +1 -0
  17. package/out/error/index.js +2 -0
  18. package/out/error/runtime-error/runtime-error.d.ts +15 -0
  19. package/out/error/runtime-error/runtime-error.d.ts.map +1 -0
  20. package/out/error/runtime-error/runtime-error.js +15 -0
  21. package/out/index.d.ts +1 -0
  22. package/out/index.d.ts.map +1 -1
  23. package/out/index.js +1 -0
  24. package/out/interface/i-environment/i-environment.d.ts +8 -0
  25. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  26. package/out/types.d.ts +10 -0
  27. package/out/types.d.ts.map +1 -1
  28. package/out/utils/net/net.d.ts.map +1 -1
  29. package/out/utils/net/net.js +43 -17
  30. package/out/utils/util/util.d.ts +29 -0
  31. package/out/utils/util/util.d.ts.map +1 -1
  32. package/out/utils/util/util.js +50 -0
  33. package/package.json +6 -4
  34. package/src/constant/http-status-message/http-status-message.ts +20 -0
  35. package/src/constant/index.ts +1 -0
  36. package/src/context/index.ts +3 -3
  37. package/src/environment/environment.ts +2 -1
  38. package/src/error/http-error/http-error.ts +43 -0
  39. package/src/error/index.ts +2 -0
  40. package/src/error/runtime-error/runtime-error.ts +14 -0
  41. package/src/index.ts +1 -0
  42. package/src/interface/i-environment/i-environment.ts +9 -0
  43. package/src/types.ts +11 -0
  44. package/src/utils/net/net.ts +43 -22
  45. package/src/utils/util/util.ts +64 -0
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 请求状态码文本
3
+ */
4
+ export declare const HttpStatusMessageConst: Record<number, string>;
5
+ //# sourceMappingURL=http-status-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-status-message.d.ts","sourceRoot":"","sources":["../../../src/constant/http-status-message/http-status-message.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAgBzD,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 请求状态码文本
3
+ */
4
+ export const HttpStatusMessageConst = {
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,2 +1,3 @@
1
1
  export { CoreConst } from './core/core';
2
+ export { HttpStatusMessageConst } from './http-status-message/http-status-message';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC"}
@@ -1 +1,2 @@
1
1
  export { CoreConst } from './core/core';
2
+ export { HttpStatusMessageConst } from './http-status-message/http-status-message';
@@ -29,16 +29,16 @@ export declare class IBizContext implements IContext {
29
29
  * @protected
30
30
  * @type {(IBizContext | null)}
31
31
  */
32
- protected _parent: IBizContext | null;
32
+ protected _parent: IContext | null;
33
33
  /**
34
34
  * Creates an instance of IBizContext.
35
35
  *
36
36
  * @author chitanda
37
37
  * @date 2022-07-14 10:07:15
38
- * @param {IContext} [context={}]
38
+ * @param {IContext} [context={}] 自身的上下文
39
39
  * @param {IBizContext} [parent]
40
40
  */
41
- constructor(context?: IContext, parent?: IBizContext);
41
+ constructor(context?: IContext, parent?: IContext);
42
42
  /**
43
43
  * 创建代理
44
44
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,qBAAa,sBAAuB,YAAW,YAAY,CAAC,WAAW,CAAC;IACtE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO;IAKrE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO;CAa1E;AAED;;;;;;;GAOG;AACH,qBAAa,WAAY,YAAW,QAAQ;IAsBvB,OAAO,EAAE,QAAQ;IApBpC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;IAE5B;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAQ;IAE7C;;;;;;;OAOG;gBACgB,OAAO,GAAE,QAAa,EAAE,MAAM,CAAC,EAAE,WAAW;IAO/D;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,IAAI,WAAW;IAIpC;;;;;OAKG;IACH,OAAO,IAAI,IAAI;CAIhB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,qBAAa,sBAAuB,YAAW,YAAY,CAAC,WAAW,CAAC;IACtE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO;IAKrE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO;CAa1E;AAED;;;;;;;GAOG;AACH,qBAAa,WAAY,YAAW,QAAQ;IAsBvB,OAAO,EAAE,QAAQ;IApBpC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;IAE5B;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAQ;IAE1C;;;;;;;OAOG;gBACgB,OAAO,GAAE,QAAa,EAAE,MAAM,CAAC,EAAE,QAAQ;IAO5D;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,IAAI,WAAW;IAIpC;;;;;OAKG;IACH,OAAO,IAAI,IAAI;CAIhB"}
@@ -43,7 +43,7 @@ export class IBizContext {
43
43
  *
44
44
  * @author chitanda
45
45
  * @date 2022-07-14 10:07:15
46
- * @param {IContext} [context={}]
46
+ * @param {IContext} [context={}] 自身的上下文
47
47
  * @param {IBizContext} [parent]
48
48
  */
49
49
  constructor(context = {}, parent) {
@@ -1 +1 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/environment/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,YAMzB,CAAC"}
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/environment/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,YAOzB,CAAC"}
@@ -3,7 +3,8 @@
3
3
  */
4
4
  export const Environment = {
5
5
  baseUrl: '',
6
- assetsUrl: './assets/',
6
+ remoteModelUrl: '/remotemodel',
7
+ assetsUrl: './assets',
7
8
  dcSystem: '',
8
9
  ExportFile: '/ibizutil/download',
9
10
  UploadFile: '/ibizutil/upload',
@@ -0,0 +1,18 @@
1
+ import { AxiosError, AxiosResponse } from 'axios';
2
+ /**
3
+ * 请求异常
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-09-18 17:09:10
7
+ * @export
8
+ * @class HttpError
9
+ * @implements {Error}
10
+ */
11
+ export declare class HttpError implements Error {
12
+ name: string;
13
+ message: string;
14
+ status: number;
15
+ response?: AxiosResponse;
16
+ constructor(err: AxiosError);
17
+ }
18
+ //# sourceMappingURL=http-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../../src/error/http-error/http-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlD;;;;;;;;GAQG;AACH,qBAAa,SAAU,YAAW,KAAK;IACrC,IAAI,EAAE,MAAM,CAAe;IAE3B,OAAO,EAAE,MAAM,CAAC;IAEhB,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,CAAC,EAAE,aAAa,CAAC;gBAEb,GAAG,EAAE,UAAU;CAqB5B"}
@@ -0,0 +1,36 @@
1
+ import { HttpStatusMessageConst } from '../../constant';
2
+ /**
3
+ * 请求异常
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-09-18 17:09:10
7
+ * @export
8
+ * @class HttpError
9
+ * @implements {Error}
10
+ */
11
+ export class HttpError {
12
+ constructor(err) {
13
+ this.name = 'HttpError';
14
+ const res = err.response;
15
+ this.response = err.response;
16
+ if (res) {
17
+ if (res.data) {
18
+ this.message = res.data.message;
19
+ }
20
+ else {
21
+ this.message = res.statusText;
22
+ }
23
+ if (!this.message) {
24
+ this.message = HttpStatusMessageConst[res.status];
25
+ }
26
+ if (!this.message) {
27
+ this.message = '网络异常,请稍后重试!';
28
+ }
29
+ this.status = res.status;
30
+ }
31
+ else {
32
+ this.message = err.message;
33
+ this.status = 500;
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,3 @@
1
+ export { HttpError } from './http-error/http-error';
2
+ export { RuntimeError } from './runtime-error/runtime-error';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { HttpError } from './http-error/http-error';
2
+ export { RuntimeError } from './runtime-error/runtime-error';
@@ -0,0 +1,15 @@
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 declare class RuntimeError implements Error {
11
+ message: string;
12
+ name: string;
13
+ constructor(message: string);
14
+ }
15
+ //# sourceMappingURL=runtime-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-error.d.ts","sourceRoot":"","sources":["../../../src/error/runtime-error/runtime-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,YAAa,YAAW,KAAK;IAGrB,OAAO,EAAE,MAAM;IAFlC,IAAI,EAAE,MAAM,CAAmB;gBAEZ,OAAO,EAAE,MAAM;CACnC"}
@@ -0,0 +1,15 @@
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 {
11
+ constructor(message) {
12
+ this.message = message;
13
+ this.name = 'Runtime Error';
14
+ }
15
+ }
package/out/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import './types';
2
2
  export * from './constant';
3
3
  export { IBizContext, IBizContextProxyHandle } from './context';
4
4
  export { Environment } from './environment/environment';
5
+ export * from './error';
5
6
  export * from './interface';
6
7
  export * from './utils';
7
8
  export { IBizSys } from './ibizsys';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;AAEjB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;AAEjB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
package/out/index.js CHANGED
@@ -2,6 +2,7 @@ import './types';
2
2
  export * from './constant';
3
3
  export { IBizContext, IBizContextProxyHandle } from './context';
4
4
  export { Environment } from './environment/environment';
5
+ export * from './error';
5
6
  export * from './interface';
6
7
  export * from './utils';
7
8
  export { IBizSys } from './ibizsys';
@@ -23,6 +23,14 @@ export interface IEnvironment {
23
23
  * @type {string}
24
24
  */
25
25
  baseUrl: string;
26
+ /**
27
+ * 远程模型路径
28
+ *
29
+ * @author chitanda
30
+ * @date 2022-09-22 18:09:25
31
+ * @type {string}
32
+ */
33
+ remoteModelUrl: string;
26
34
  /**
27
35
  * 资源文件根路径
28
36
  *
@@ -1 +1 @@
1
- {"version":3,"file":"i-environment.d.ts","sourceRoot":"","sources":["../../../src/interface/i-environment/i-environment.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB"}
1
+ {"version":3,"file":"i-environment.d.ts","sourceRoot":"","sources":["../../../src/interface/i-environment/i-environment.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB"}
package/out/types.d.ts CHANGED
@@ -34,5 +34,15 @@ declare global {
34
34
  interface IData {
35
35
  [key: string | symbol]: any;
36
36
  }
37
+ /**
38
+ * 任意对象结构
39
+ *
40
+ * @author chitanda
41
+ * @date 2022-09-21 15:09:30
42
+ * @interface IObject
43
+ */
44
+ interface IObject {
45
+ [key: string | symbol]: any;
46
+ }
37
47
  }
38
48
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,IAAI,EAAE,OAAO,CAAC;IAEpB,UAAU,MAAM;QACd,IAAI,EAAE,OAAO,CAAC;KACf;IAED;;;;;;OAMG;IACH,UAAU,QAAQ;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,OAAO;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,KAAK;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;CACF"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,IAAI,EAAE,OAAO,CAAC;IAEpB,UAAU,MAAM;QACd,IAAI,EAAE,OAAO,CAAC;KACf;IAED;;;;;;OAMG;IACH,UAAU,QAAQ;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,OAAO;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,KAAK;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,OAAO;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/utils/net/net.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,mBAAmB,EAAiB,MAAM,OAAO,CAAC;AAGlE,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;IAezB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,EACjC,MAAM,GAAE,OAAY,GACnB,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;OAQG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAMzB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAMzB;;;;;;;;OAQG;IACG,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAOzB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;CAGlB"}
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"}
@@ -1,6 +1,7 @@
1
1
  import axios from 'axios';
2
2
  import { stringify } from 'qs';
3
3
  import { notNilEmpty } from 'qx-util';
4
+ import { HttpError } from '../../error';
4
5
  /**
5
6
  * 全局请求工具类
6
7
  *
@@ -45,13 +46,18 @@ export class Net {
45
46
  */
46
47
  async post(url, data, params = {}, headers = {}) {
47
48
  url = this.handleAppPresetParam(url, params);
48
- const response = await axios({
49
- method: 'post',
50
- url,
51
- data,
52
- headers: Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', Accept: 'application/json' }, headers),
53
- });
54
- return this.doResponseResult(response);
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
+ }
55
61
  }
56
62
  /**
57
63
  * Get 请求
@@ -68,8 +74,13 @@ export class Net {
68
74
  // delete params.srfparentdata;
69
75
  // }
70
76
  url = this.attachUrlParam(url, params);
71
- const response = await axios.get(url, Object.assign({ headers }, option));
72
- return this.doResponseResult(response);
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
+ }
73
84
  }
74
85
  /**
75
86
  * Delete 请求
@@ -82,8 +93,13 @@ export class Net {
82
93
  */
83
94
  async delete(url, params, headers = {}) {
84
95
  url = this.handleAppPresetParam(url, params);
85
- const response = await axios.delete(url, { headers });
86
- return this.doResponseResult(response);
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
+ }
87
103
  }
88
104
  /**
89
105
  * Put 请求
@@ -96,8 +112,13 @@ export class Net {
96
112
  */
97
113
  async put(url, data, params = {}, headers = {}) {
98
114
  url = this.handleAppPresetParam(url, params);
99
- const response = await axios.put(url, data, { headers });
100
- return this.doResponseResult(response);
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
+ }
101
122
  }
102
123
  /**
103
124
  * 获取模型数据
@@ -109,10 +130,15 @@ export class Net {
109
130
  * @return {*} {Promise<IHttpResponse>}
110
131
  */
111
132
  async getModel(url, headers = {}) {
112
- const response = await axios.get(url, {
113
- headers,
114
- });
115
- return this.doResponseResult(response);
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
+ }
116
142
  }
117
143
  /**
118
144
  * 统一处理请求返回
@@ -1,3 +1,4 @@
1
+ import { DebounceSettings } from 'lodash-es';
1
2
  /**
2
3
  * 获取认证令牌
3
4
  *
@@ -7,4 +8,32 @@
7
8
  * @return {*} {(string | null)}
8
9
  */
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;
10
39
  //# 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":"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"}
@@ -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,51 @@ 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
+ * @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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiz-template/core",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-alpha.6",
4
4
  "description": "核心包",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",
@@ -28,10 +28,12 @@
28
28
  "devDependencies": {
29
29
  "@types/pluralize": "^0.0.29",
30
30
  "@types/qs": "^6.9.7",
31
- "qx-util": "^0.4.0"
31
+ "lodash-es": "^4.17.21",
32
+ "qx-util": "^0.4.1"
32
33
  },
33
34
  "peerDependencies": {
34
- "qx-util": "^0.4.0"
35
+ "lodash-es": "^4.17.21",
36
+ "qx-util": "^0.4.1"
35
37
  },
36
- "gitHead": "e21190e748f8e9ccdcda19ce09bc21c8e0ad7e87"
38
+ "gitHead": "0af61790674d0f38ffcf2697fc8b2d2324507ce7"
37
39
  }
@@ -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,2 @@
1
1
  export { CoreConst } from './core/core';
2
+ export { HttpStatusMessageConst } from './http-status-message/http-status-message';
@@ -51,17 +51,17 @@ export class IBizContext implements IContext {
51
51
  * @protected
52
52
  * @type {(IBizContext | null)}
53
53
  */
54
- protected _parent: IBizContext | null = null;
54
+ protected _parent: IContext | null = null;
55
55
 
56
56
  /**
57
57
  * Creates an instance of IBizContext.
58
58
  *
59
59
  * @author chitanda
60
60
  * @date 2022-07-14 10:07:15
61
- * @param {IContext} [context={}]
61
+ * @param {IContext} [context={}] 自身的上下文
62
62
  * @param {IBizContext} [parent]
63
63
  */
64
- constructor(public context: IContext = {}, parent?: IBizContext) {
64
+ constructor(public context: IContext = {}, parent?: IContext) {
65
65
  if (parent) {
66
66
  this._parent = parent;
67
67
  }
@@ -5,7 +5,8 @@ import { IEnvironment } from '../interface';
5
5
  */
6
6
  export const Environment: IEnvironment = {
7
7
  baseUrl: '',
8
- assetsUrl: './assets/',
8
+ remoteModelUrl: '/remotemodel',
9
+ assetsUrl: './assets',
9
10
  dcSystem: '',
10
11
  ExportFile: '/ibizutil/download',
11
12
  UploadFile: '/ibizutil/upload',
@@ -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
+ }
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import './types';
3
3
  export * from './constant';
4
4
  export { IBizContext, IBizContextProxyHandle } 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';
@@ -25,6 +25,15 @@ export interface IEnvironment {
25
25
  */
26
26
  baseUrl: string;
27
27
 
28
+ /**
29
+ * 远程模型路径
30
+ *
31
+ * @author chitanda
32
+ * @date 2022-09-22 18:09:25
33
+ * @type {string}
34
+ */
35
+ remoteModelUrl: string;
36
+
28
37
  /**
29
38
  * 资源文件根路径
30
39
  *
package/src/types.ts CHANGED
@@ -40,4 +40,15 @@ declare global {
40
40
  interface IData {
41
41
  [key: string | symbol]: any;
42
42
  }
43
+
44
+ /**
45
+ * 任意对象结构
46
+ *
47
+ * @author chitanda
48
+ * @date 2022-09-21 15:09:30
49
+ * @interface IObject
50
+ */
51
+ interface IObject {
52
+ [key: string | symbol]: any;
53
+ }
43
54
  }
@@ -1,6 +1,7 @@
1
- import axios, { AxiosRequestHeaders, AxiosResponse } from 'axios';
1
+ import axios, { AxiosError, AxiosRequestHeaders, AxiosResponse } from 'axios';
2
2
  import { stringify } from 'qs';
3
3
  import { notNilEmpty } from 'qx-util';
4
+ import { HttpError } from '../../error';
4
5
  import { IHttpResponse } from './http-response';
5
6
 
6
7
  /**
@@ -55,17 +56,21 @@ export class Net {
55
56
  headers: AxiosRequestHeaders = {},
56
57
  ): Promise<IHttpResponse> {
57
58
  url = this.handleAppPresetParam(url, params);
58
- const response = await axios({
59
- method: 'post',
60
- url,
61
- data,
62
- headers: {
63
- 'Content-Type': 'application/json;charset=UTF-8',
64
- Accept: 'application/json',
65
- ...headers,
66
- },
67
- });
68
- return this.doResponseResult(response);
59
+ try {
60
+ const response = await axios({
61
+ method: 'post',
62
+ url,
63
+ data,
64
+ headers: {
65
+ 'Content-Type': 'application/json;charset=UTF-8',
66
+ Accept: 'application/json',
67
+ ...headers,
68
+ },
69
+ });
70
+ return this.doResponseResult(response);
71
+ } catch (error) {
72
+ throw new HttpError(error as AxiosError);
73
+ }
69
74
  }
70
75
 
71
76
  /**
@@ -88,8 +93,12 @@ export class Net {
88
93
  // delete params.srfparentdata;
89
94
  // }
90
95
  url = this.attachUrlParam(url, params);
91
- const response = await axios.get(url, { headers, ...option });
92
- return this.doResponseResult(response);
96
+ try {
97
+ const response = await axios.get(url, { headers, ...option });
98
+ return this.doResponseResult(response);
99
+ } catch (error) {
100
+ throw new HttpError(error as AxiosError);
101
+ }
93
102
  }
94
103
 
95
104
  /**
@@ -107,8 +116,12 @@ export class Net {
107
116
  headers: AxiosRequestHeaders = {},
108
117
  ): Promise<IHttpResponse> {
109
118
  url = this.handleAppPresetParam(url, params);
110
- const response = await axios.delete(url, { headers });
111
- return this.doResponseResult(response);
119
+ try {
120
+ const response = await axios.delete(url, { headers });
121
+ return this.doResponseResult(response);
122
+ } catch (error) {
123
+ throw new HttpError(error as AxiosError);
124
+ }
112
125
  }
113
126
 
114
127
  /**
@@ -127,8 +140,12 @@ export class Net {
127
140
  headers: AxiosRequestHeaders = {},
128
141
  ): Promise<IHttpResponse> {
129
142
  url = this.handleAppPresetParam(url, params);
130
- const response = await axios.put(url, data, { headers });
131
- return this.doResponseResult(response);
143
+ try {
144
+ const response = await axios.put(url, data, { headers });
145
+ return this.doResponseResult(response);
146
+ } catch (error) {
147
+ throw new HttpError(error as AxiosError);
148
+ }
132
149
  }
133
150
 
134
151
  /**
@@ -144,10 +161,14 @@ export class Net {
144
161
  url: string,
145
162
  headers: AxiosRequestHeaders = {},
146
163
  ): Promise<IHttpResponse> {
147
- const response = await axios.get(url, {
148
- headers,
149
- });
150
- return this.doResponseResult(response);
164
+ try {
165
+ const response = await axios.get(url, {
166
+ headers,
167
+ });
168
+ return this.doResponseResult(response);
169
+ } catch (error) {
170
+ throw new HttpError(error as AxiosError);
171
+ }
151
172
  }
152
173
 
153
174
  /**
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { debounce, DebounceSettings } from 'lodash-es';
1
3
  import { getCookie } from 'qx-util';
2
4
  import { CoreConst } from '../../constant';
3
5
 
@@ -12,3 +14,65 @@ import { CoreConst } from '../../constant';
12
14
  export function getToken(): string | null {
13
15
  return getCookie(CoreConst.TOKEN);
14
16
  }
17
+
18
+ /**
19
+ * 判断两个数组是否有相同的元素
20
+ *
21
+ * @author lxm
22
+ * @date 2022-09-20 19:09:29
23
+ * @export
24
+ * @param {any[]} arr1
25
+ * @param {any[]} arr2
26
+ * @returns {*} {boolean}
27
+ */
28
+ export function isOverlap(arr1: any[], arr2: any[]): boolean {
29
+ const newArr = Array.from(new Set([...arr1, ...arr2]));
30
+ return newArr.length === arr1.length + arr2.length;
31
+ }
32
+
33
+ /**
34
+ * 防抖并合并每次的参数
35
+ *
36
+ * @author lxm
37
+ * @date 2022-09-20 21:09:53
38
+ * @export
39
+ * @template T
40
+ * @param {T} func 要防抖的函数
41
+ * @param {(
42
+ * oldParams: Parameters<T>,
43
+ * newParams: Parameters<T>,
44
+ * ) => Parameters<T>} mergeFunc 合并的回调函数
45
+ * @param {number} [wait] 防抖的延迟毫秒数
46
+ * @param {DebounceSettings} [options] 防抖函数的额外参数
47
+ * @returns {*}
48
+ */
49
+ export function debounceAndMerge<T extends (...args: any[]) => any>(
50
+ func: T,
51
+ mergeFunc: (
52
+ oldParams: Parameters<T>,
53
+ newParams: Parameters<T>,
54
+ ) => Parameters<T>,
55
+ wait?: number,
56
+ options?: DebounceSettings,
57
+ ) {
58
+ // 缓存上一次的函数参数
59
+ let oldParams: Parameters<T> | undefined;
60
+ const debounceFunc = debounce(
61
+ (...params: Parameters<T>) => {
62
+ // 防抖函数执行的时候清空缓存参数
63
+ oldParams = undefined;
64
+ return func(...params);
65
+ },
66
+ wait,
67
+ options,
68
+ );
69
+ return (...args: Parameters<T>) => {
70
+ // 合并参数,并把参数缓存到oldParams里,用新参数调用防抖函数
71
+ let newParams = args;
72
+ if (oldParams) {
73
+ newParams = mergeFunc(oldParams, newParams);
74
+ }
75
+ oldParams = newParams;
76
+ return debounceFunc(...newParams);
77
+ };
78
+ }