@ibiz-template/core 0.0.1-alpha.4 → 0.0.1-alpha.5
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/out/context/index.d.ts +3 -3
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +1 -1
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +2 -1
- package/out/error/http-error/http-error.d.ts +18 -0
- package/out/error/http-error/http-error.d.ts.map +1 -0
- package/out/error/http-error/http-error.js +29 -0
- package/out/error/index.d.ts +3 -0
- package/out/error/index.d.ts.map +1 -0
- package/out/error/index.js +2 -0
- package/out/error/runtime-error/runtime-error.d.ts +15 -0
- package/out/error/runtime-error/runtime-error.d.ts.map +1 -0
- package/out/error/runtime-error/runtime-error.js +15 -0
- package/out/index.d.ts +1 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +1 -0
- package/out/interface/i-environment/i-environment.d.ts +8 -0
- package/out/interface/i-environment/i-environment.d.ts.map +1 -1
- package/out/types.d.ts +10 -0
- package/out/types.d.ts.map +1 -1
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/net/net.js +43 -17
- package/out/utils/util/util.d.ts +29 -0
- package/out/utils/util/util.d.ts.map +1 -1
- package/out/utils/util/util.js +50 -0
- package/package.json +4 -4
- package/src/context/index.ts +3 -3
- package/src/environment/environment.ts +2 -1
- package/src/error/http-error/http-error.ts +36 -0
- package/src/error/index.ts +2 -0
- package/src/error/runtime-error/runtime-error.ts +14 -0
- package/src/index.ts +1 -0
- package/src/interface/i-environment/i-environment.ts +9 -0
- package/src/types.ts +11 -0
- package/src/utils/net/net.ts +43 -22
- package/src/utils/util/util.ts +64 -0
package/out/context/index.d.ts
CHANGED
|
@@ -29,16 +29,16 @@ export declare class IBizContext implements IContext {
|
|
|
29
29
|
* @protected
|
|
30
30
|
* @type {(IBizContext | null)}
|
|
31
31
|
*/
|
|
32
|
-
protected _parent:
|
|
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?:
|
|
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,
|
|
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"}
|
package/out/context/index.js
CHANGED
|
@@ -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,
|
|
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"}
|
|
@@ -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;AAElD;;;;;;;;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;CAe5B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 请求异常
|
|
3
|
+
*
|
|
4
|
+
* @author chitanda
|
|
5
|
+
* @date 2022-09-18 17:09:10
|
|
6
|
+
* @export
|
|
7
|
+
* @class HttpError
|
|
8
|
+
* @implements {Error}
|
|
9
|
+
*/
|
|
10
|
+
export class HttpError {
|
|
11
|
+
constructor(err) {
|
|
12
|
+
this.name = 'HttpError';
|
|
13
|
+
const res = err.response;
|
|
14
|
+
this.response = err.response;
|
|
15
|
+
if (res) {
|
|
16
|
+
if (res.data) {
|
|
17
|
+
this.message = res.data.message;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.message = res.statusText;
|
|
21
|
+
}
|
|
22
|
+
this.status = res.status;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.message = err.message;
|
|
26
|
+
this.status = 500;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -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,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';
|
package/out/index.d.ts.map
CHANGED
|
@@ -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';
|
|
@@ -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
|
package/out/types.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/out/utils/net/net.js
CHANGED
|
@@ -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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
* 统一处理请求返回
|
package/out/utils/util/util.d.ts
CHANGED
|
@@ -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":"
|
|
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"}
|
package/out/utils/util/util.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.0.1-alpha.5",
|
|
4
4
|
"description": "核心包",
|
|
5
5
|
"main": "out/index.js",
|
|
6
6
|
"types": "out/index.d.ts",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/pluralize": "^0.0.29",
|
|
30
30
|
"@types/qs": "^6.9.7",
|
|
31
|
-
"qx-util": "^0.4.
|
|
31
|
+
"qx-util": "^0.4.1"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"qx-util": "^0.4.
|
|
34
|
+
"qx-util": "^0.4.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "8c4920248d5047ef434647c7f3707b49cb4d7077"
|
|
37
37
|
}
|
package/src/context/index.ts
CHANGED
|
@@ -51,17 +51,17 @@ export class IBizContext implements IContext {
|
|
|
51
51
|
* @protected
|
|
52
52
|
* @type {(IBizContext | null)}
|
|
53
53
|
*/
|
|
54
|
-
protected _parent:
|
|
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?:
|
|
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
|
-
|
|
8
|
+
remoteModelUrl: '/remotemodel',
|
|
9
|
+
assetsUrl: './assets',
|
|
9
10
|
dcSystem: '',
|
|
10
11
|
ExportFile: '/ibizutil/download',
|
|
11
12
|
UploadFile: '/ibizutil/upload',
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AxiosError, AxiosResponse } from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 请求异常
|
|
5
|
+
*
|
|
6
|
+
* @author chitanda
|
|
7
|
+
* @date 2022-09-18 17:09:10
|
|
8
|
+
* @export
|
|
9
|
+
* @class HttpError
|
|
10
|
+
* @implements {Error}
|
|
11
|
+
*/
|
|
12
|
+
export class HttpError implements Error {
|
|
13
|
+
name: string = 'HttpError';
|
|
14
|
+
|
|
15
|
+
message: string;
|
|
16
|
+
|
|
17
|
+
status: number;
|
|
18
|
+
|
|
19
|
+
response?: AxiosResponse;
|
|
20
|
+
|
|
21
|
+
constructor(err: AxiosError) {
|
|
22
|
+
const res = err.response;
|
|
23
|
+
this.response = err.response;
|
|
24
|
+
if (res) {
|
|
25
|
+
if (res.data) {
|
|
26
|
+
this.message = (res.data as IData).message;
|
|
27
|
+
} else {
|
|
28
|
+
this.message = res.statusText;
|
|
29
|
+
}
|
|
30
|
+
this.status = res.status;
|
|
31
|
+
} else {
|
|
32
|
+
this.message = err.message;
|
|
33
|
+
this.status = 500;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -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';
|
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
|
}
|
package/src/utils/net/net.ts
CHANGED
|
@@ -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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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
|
-
|
|
111
|
-
|
|
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
|
-
|
|
131
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
/**
|
package/src/utils/util/util.ts
CHANGED
|
@@ -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
|
+
}
|