@ibiz-template/core 0.0.1-beta.1 → 0.0.1-beta.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/system/index.system.js +1 -1
- package/out/constant/core/core.d.ts +9 -0
- package/out/constant/core/core.d.ts.map +1 -1
- package/out/constant/core/core.js +9 -0
- package/out/context/index.d.ts +63 -4
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +73 -3
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +6 -0
- package/out/error/http-error/http-error.d.ts.map +1 -1
- package/out/error/http-error/http-error.js +0 -4
- package/out/interface/click-outside/click-outside.d.ts +1 -1
- package/out/interface/click-outside/click-outside.d.ts.map +1 -1
- package/out/interface/i-environment/i-environment.d.ts +44 -0
- package/out/interface/i-environment/i-environment.d.ts.map +1 -1
- package/out/types.d.ts +31 -0
- package/out/types.d.ts.map +1 -1
- package/out/utils/data-type/data-types.d.ts +47 -0
- package/out/utils/data-type/data-types.d.ts.map +1 -0
- package/out/utils/data-type/data-types.js +96 -0
- package/out/utils/download-file/download-file.d.ts +10 -0
- package/out/utils/download-file/download-file.d.ts.map +1 -1
- package/out/utils/download-file/download-file.js +20 -0
- package/out/utils/index.d.ts +6 -0
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +6 -0
- package/out/utils/interceptor/core-interceptor.d.ts +1 -2
- package/out/utils/interceptor/core-interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/core-interceptor.js +12 -7
- package/out/utils/interceptor/interceptor.d.ts +6 -6
- package/out/utils/interceptor/interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/interceptor.js +2 -2
- package/out/utils/logger/logger.d.ts +1 -1
- package/out/utils/logger/logger.d.ts.map +1 -1
- package/out/utils/logger/logger.js +1 -1
- package/out/utils/net/http-response.d.ts +1 -3
- package/out/utils/net/http-response.d.ts.map +1 -1
- package/out/utils/net/net.d.ts +30 -13
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/net/net.js +37 -11
- package/out/utils/plural/plural.d.ts.map +1 -1
- package/out/utils/plural/plural.js +2 -0
- package/out/utils/string-util/string-util.d.ts +46 -0
- package/out/utils/string-util/string-util.d.ts.map +1 -0
- package/out/utils/string-util/string-util.js +71 -0
- package/out/utils/sync/await-timeout.d.ts +14 -0
- package/out/utils/sync/await-timeout.d.ts.map +1 -0
- package/out/utils/sync/await-timeout.js +23 -0
- package/out/utils/sync/count-latch.d.ts +60 -0
- package/out/utils/sync/count-latch.d.ts.map +1 -0
- package/out/utils/sync/count-latch.js +90 -0
- package/out/utils/sync/index.d.ts +3 -0
- package/out/utils/sync/index.d.ts.map +1 -0
- package/out/utils/sync/index.js +2 -0
- package/out/utils/upload/select-file.d.ts +53 -0
- package/out/utils/upload/select-file.d.ts.map +1 -0
- package/out/utils/upload/select-file.js +47 -0
- package/out/utils/upload/upload-file.d.ts +46 -0
- package/out/utils/upload/upload-file.d.ts.map +1 -0
- package/out/utils/upload/upload-file.js +151 -0
- package/out/utils/util/ie-helper.d.ts +12 -0
- package/out/utils/util/ie-helper.d.ts.map +1 -0
- package/out/utils/util/ie-helper.js +20 -0
- package/package.json +13 -11
- package/src/constant/core/core.ts +10 -0
- package/src/context/index.ts +115 -5
- package/src/environment/environment.ts +6 -0
- package/src/error/http-error/http-error.ts +0 -4
- package/src/interface/i-environment/i-environment.ts +50 -0
- package/src/types.ts +35 -0
- package/src/utils/data-type/data-types.ts +99 -0
- package/src/utils/download-file/download-file.ts +21 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/interceptor/core-interceptor.ts +16 -11
- package/src/utils/interceptor/interceptor.ts +7 -9
- package/src/utils/logger/logger.ts +1 -1
- package/src/utils/net/http-response.ts +1 -5
- package/src/utils/net/net.ts +45 -22
- package/src/utils/plural/plural.ts +3 -0
- package/src/utils/string-util/string-util.ts +75 -0
- package/src/utils/sync/await-timeout.ts +27 -0
- package/src/utils/sync/count-latch.ts +96 -0
- package/src/utils/sync/index.ts +2 -0
- package/src/utils/upload/select-file.ts +86 -0
- package/src/utils/upload/upload-file.ts +207 -0
- package/src/utils/util/ie-helper.ts +42 -0
- package/LICENSE +0 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download-file.d.ts","sourceRoot":"","sources":["../../../src/utils/download-file/download-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"download-file.d.ts","sourceRoot":"","sources":["../../../src/utils/download-file/download-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,UAmDlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAOjD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAmBhE"}
|
|
@@ -51,11 +51,31 @@ export function calcMimeByFileName(fileName) {
|
|
|
51
51
|
case '.tar':
|
|
52
52
|
mime = 'application/x-tar';
|
|
53
53
|
break;
|
|
54
|
+
case '.xlsx':
|
|
55
|
+
mime = 'application/vnd.ms-excel';
|
|
56
|
+
break;
|
|
54
57
|
default:
|
|
55
58
|
mime = '';
|
|
56
59
|
}
|
|
57
60
|
return mime;
|
|
58
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* 判断是否是图片格式
|
|
64
|
+
*
|
|
65
|
+
* @author lxm
|
|
66
|
+
* @date 2022-11-21 13:11:23
|
|
67
|
+
* @export
|
|
68
|
+
* @param {string} fileName
|
|
69
|
+
* @returns {*} {boolean}
|
|
70
|
+
*/
|
|
71
|
+
export function isImage(fileName) {
|
|
72
|
+
const ext = fileName.split('.').pop();
|
|
73
|
+
if (!ext) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const imageTypes = ['.jpeg', 'jpg', 'gif', 'png', 'bmp', 'svg'];
|
|
77
|
+
return imageTypes.includes(ext);
|
|
78
|
+
}
|
|
59
79
|
/**
|
|
60
80
|
* 纯JS触发下载文件
|
|
61
81
|
*
|
package/out/utils/index.d.ts
CHANGED
|
@@ -5,9 +5,15 @@ export { IHttpResponse, HttpResponse } from './net/http-response';
|
|
|
5
5
|
export { Net } from './net/net';
|
|
6
6
|
export { plural, pluralLower } from './plural/plural';
|
|
7
7
|
export * from './util/util';
|
|
8
|
+
export * from './util/ie-helper';
|
|
8
9
|
export * from './url-helper/url-helper';
|
|
9
10
|
export * from './event/event';
|
|
10
11
|
export * from './click-outside/click-outside';
|
|
11
12
|
export * from './color/color';
|
|
12
13
|
export * from './download-file/download-file';
|
|
14
|
+
export * from './upload/select-file';
|
|
15
|
+
export * from './upload/upload-file';
|
|
16
|
+
export * from './sync';
|
|
17
|
+
export { StringUtil } from './string-util/string-util';
|
|
18
|
+
export { DataTypes } from './data-type/data-types';
|
|
13
19
|
//# sourceMappingURL=index.d.ts.map
|
package/out/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC"}
|
package/out/utils/index.js
CHANGED
|
@@ -5,8 +5,14 @@ export { HttpResponse } from './net/http-response';
|
|
|
5
5
|
export { Net } from './net/net';
|
|
6
6
|
export { plural, pluralLower } from './plural/plural';
|
|
7
7
|
export * from './util/util';
|
|
8
|
+
export * from './util/ie-helper';
|
|
8
9
|
export * from './url-helper/url-helper';
|
|
9
10
|
export * from './event/event';
|
|
10
11
|
export * from './click-outside/click-outside';
|
|
11
12
|
export * from './color/color';
|
|
12
13
|
export * from './download-file/download-file';
|
|
14
|
+
export * from './upload/select-file';
|
|
15
|
+
export * from './upload/upload-file';
|
|
16
|
+
export * from './sync';
|
|
17
|
+
export { StringUtil } from './string-util/string-util';
|
|
18
|
+
export { DataTypes } from './data-type/data-types';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
1
|
import { Interceptor } from './interceptor';
|
|
3
2
|
/**
|
|
4
3
|
* 核心包拦截器
|
|
@@ -10,6 +9,6 @@ import { Interceptor } from './interceptor';
|
|
|
10
9
|
* @extends {Interceptor}
|
|
11
10
|
*/
|
|
12
11
|
export declare class CoreInterceptor extends Interceptor {
|
|
13
|
-
protected onBeforeRequest(config:
|
|
12
|
+
protected onBeforeRequest(config: IData): Promise<IData>;
|
|
14
13
|
}
|
|
15
14
|
//# sourceMappingURL=core-interceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/core-interceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core-interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/core-interceptor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,WAAW;cAC9B,eAAe,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;CA0B/D"}
|
|
@@ -11,20 +11,25 @@ import { Interceptor } from './interceptor';
|
|
|
11
11
|
*/
|
|
12
12
|
export class CoreInterceptor extends Interceptor {
|
|
13
13
|
async onBeforeRequest(config) {
|
|
14
|
-
await super.onBeforeRequest(config);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
14
|
+
config = await super.onBeforeRequest(config);
|
|
15
|
+
const { headers } = config;
|
|
16
|
+
// Set the access token.
|
|
17
|
+
// headers.set('Authorization', `Bearer ${getToken()}`);
|
|
18
|
+
headers.Authorization = `Bearer ${getToken()}`;
|
|
19
|
+
// Set the system ID.
|
|
20
|
+
let systemId = ibiz.env.dcSystem;
|
|
19
21
|
const { orgData } = ibiz;
|
|
20
22
|
if (orgData) {
|
|
21
23
|
if (orgData.systemid) {
|
|
22
|
-
|
|
24
|
+
systemId = orgData.systemid;
|
|
23
25
|
}
|
|
24
26
|
if (orgData.orgid) {
|
|
25
|
-
|
|
27
|
+
// headers.set('srforgid', orgData.orgid);
|
|
28
|
+
headers.srforgid = orgData.orgid;
|
|
26
29
|
}
|
|
27
30
|
}
|
|
31
|
+
// headers.set('srfsystemid', systemId);
|
|
32
|
+
headers.srfsystemid = systemId;
|
|
28
33
|
return config;
|
|
29
34
|
}
|
|
30
35
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxiosInstance,
|
|
1
|
+
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
2
|
/**
|
|
3
3
|
* 拦截器基类
|
|
4
4
|
*
|
|
@@ -32,10 +32,10 @@ export declare class Interceptor {
|
|
|
32
32
|
* @author lxm
|
|
33
33
|
* @date 2022-10-27 17:10:41
|
|
34
34
|
* @protected
|
|
35
|
-
* @param {
|
|
36
|
-
* @returns {*} {Promise<
|
|
35
|
+
* @param {InternalAxiosRequestConfig} config
|
|
36
|
+
* @returns {*} {Promise<InternalAxiosRequestConfig>}
|
|
37
37
|
*/
|
|
38
|
-
protected onBeforeRequest(config:
|
|
38
|
+
protected onBeforeRequest(config: IData): Promise<IData>;
|
|
39
39
|
/**
|
|
40
40
|
* 请求失败之后处理
|
|
41
41
|
*
|
|
@@ -44,7 +44,7 @@ export declare class Interceptor {
|
|
|
44
44
|
* @protected
|
|
45
45
|
* @param {*} error
|
|
46
46
|
*/
|
|
47
|
-
protected onRequestError(error:
|
|
47
|
+
protected onRequestError(error: Error): Promise<never>;
|
|
48
48
|
/**
|
|
49
49
|
* 响应成功之后处理
|
|
50
50
|
*
|
|
@@ -63,7 +63,7 @@ export declare class Interceptor {
|
|
|
63
63
|
* @protected
|
|
64
64
|
* @param {*} _error
|
|
65
65
|
*/
|
|
66
|
-
protected onResponseError(error:
|
|
66
|
+
protected onResponseError(error: Error): Promise<never>;
|
|
67
67
|
/**
|
|
68
68
|
* 使用拦截器
|
|
69
69
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/interceptor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/interceptor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAErD;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU,CAAC,CAAS;IAE5B;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW,CAAC,CAAS;IAE7B;;;;;;;;OAQG;cACa,eAAe,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAI9D;;;;;;;OAOG;IACH,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAKtD;;;;;;;;OAQG;cACa,iBAAiB,CAC/B,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAKvD;;;;;;OAMG;IACH,GAAG,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IAWlC;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;CAQrC"}
|
|
@@ -13,8 +13,8 @@ export class Interceptor {
|
|
|
13
13
|
* @author lxm
|
|
14
14
|
* @date 2022-10-27 17:10:41
|
|
15
15
|
* @protected
|
|
16
|
-
* @param {
|
|
17
|
-
* @returns {*} {Promise<
|
|
16
|
+
* @param {InternalAxiosRequestConfig} config
|
|
17
|
+
* @returns {*} {Promise<InternalAxiosRequestConfig>}
|
|
18
18
|
*/
|
|
19
19
|
async onBeforeRequest(config) {
|
|
20
20
|
return config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Logger from 'loglevel';
|
|
2
2
|
export { Logger };
|
|
@@ -64,9 +64,7 @@ export declare class HttpResponse<T = IData> implements IHttpResponse<T> {
|
|
|
64
64
|
data: T;
|
|
65
65
|
status: number;
|
|
66
66
|
statusText: string;
|
|
67
|
-
headers: AxiosResponseHeaders
|
|
68
|
-
'set-cookie'?: string[] | undefined;
|
|
69
|
-
}>;
|
|
67
|
+
headers: AxiosResponseHeaders;
|
|
70
68
|
/**
|
|
71
69
|
* AxiosResponse 本地仿造时值为空
|
|
72
70
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-response.d.ts","sourceRoot":"","sources":["../../../src/utils/net/http-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,KAAK,CAAE,SAAQ,aAAa;IAC7D;;;;;;;OAOG;IACH,EAAE,EAAE,OAAO,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf,IAAI,EAAE,CAAC,CAAC;IAER;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,qBAAa,YAAY,CAAC,CAAC,GAAG,KAAK,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAC9D;;;;;OAKG;IACH,KAAK,UAAQ;IAEb,EAAE,UAAS;IAEX,IAAI,EAAE,CAAC,CAAC;IAER,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB,OAAO,
|
|
1
|
+
{"version":3,"file":"http-response.d.ts","sourceRoot":"","sources":["../../../src/utils/net/http-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,KAAK,CAAE,SAAQ,aAAa;IAC7D;;;;;;;OAOG;IACH,EAAE,EAAE,OAAO,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf,IAAI,EAAE,CAAC,CAAC;IAER;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,qBAAa,YAAY,CAAC,CAAC,GAAG,KAAK,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAC9D;;;;;OAKG;IACH,KAAK,UAAQ;IAEb,EAAE,UAAS;IAEX,IAAI,EAAE,CAAC,CAAC;IAER,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB,OAAO,EAAE,oBAAoB,CAAM;IAEnC;;;;;;OAMG;IACH,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAM;IAEvC;;;;;;;;OAQG;gBACS,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAQjE"}
|
package/out/utils/net/net.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
2
2
|
import { Interceptor } from '../interceptor/interceptor';
|
|
3
3
|
import { IHttpResponse } from './http-response';
|
|
4
4
|
/**
|
|
@@ -19,13 +19,21 @@ export declare class Net {
|
|
|
19
19
|
* @type {AxiosInstance}
|
|
20
20
|
*/
|
|
21
21
|
protected instance: AxiosInstance;
|
|
22
|
+
/**
|
|
23
|
+
* 是否为 http || https 开头
|
|
24
|
+
*
|
|
25
|
+
* @author chitanda
|
|
26
|
+
* @date 2022-11-07 14:11:28
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
protected urlReg: RegExp;
|
|
22
30
|
/**
|
|
23
31
|
* Creates an instance of Net.
|
|
24
32
|
* @author lxm
|
|
25
33
|
* @date 2022-10-27 16:10:05
|
|
26
|
-
* @param {
|
|
34
|
+
* @param {IData} [config] 创建实例用的默认配置
|
|
27
35
|
*/
|
|
28
|
-
constructor(config?:
|
|
36
|
+
constructor(config?: IData);
|
|
29
37
|
/**
|
|
30
38
|
* 注册的拦截器
|
|
31
39
|
*
|
|
@@ -79,10 +87,10 @@ export declare class Net {
|
|
|
79
87
|
* @param {string} url
|
|
80
88
|
* @param {IData} data
|
|
81
89
|
* @param {IParams} [params={}]
|
|
82
|
-
* @param {
|
|
90
|
+
* @param {IData} [headers={}]
|
|
83
91
|
* @return {*} {Promise<IHttpResponse>}
|
|
84
92
|
*/
|
|
85
|
-
post(url: string, data: IData, params?: IParams, headers?:
|
|
93
|
+
post(url: string, data: IData, params?: IParams, headers?: IData): Promise<IHttpResponse>;
|
|
86
94
|
/**
|
|
87
95
|
* Get 请求
|
|
88
96
|
*
|
|
@@ -90,11 +98,11 @@ export declare class Net {
|
|
|
90
98
|
* @date 2022-10-19 11:10:24
|
|
91
99
|
* @param {string} url
|
|
92
100
|
* @param {IParams} [params={}]
|
|
93
|
-
* @param {
|
|
101
|
+
* @param {IData} [headers={}]
|
|
94
102
|
* @param {IParams} [option={}]
|
|
95
103
|
* @return {*} {Promise<IHttpResponse>}
|
|
96
104
|
*/
|
|
97
|
-
get(url: string, params?: IParams, headers?:
|
|
105
|
+
get(url: string, params?: IParams, headers?: IData, option?: AxiosRequestConfig): Promise<IHttpResponse>;
|
|
98
106
|
/**
|
|
99
107
|
* Delete 请求
|
|
100
108
|
*
|
|
@@ -102,10 +110,10 @@ export declare class Net {
|
|
|
102
110
|
* @date 2022-10-19 11:10:17
|
|
103
111
|
* @param {string} url
|
|
104
112
|
* @param {IParams} [params]
|
|
105
|
-
* @param {
|
|
113
|
+
* @param {IData} [headers={}]
|
|
106
114
|
* @return {*} {Promise<IHttpResponse>}
|
|
107
115
|
*/
|
|
108
|
-
delete(url: string, params?: IParams, headers?:
|
|
116
|
+
delete(url: string, params?: IParams, headers?: IData): Promise<IHttpResponse>;
|
|
109
117
|
/**
|
|
110
118
|
* Put 请求
|
|
111
119
|
*
|
|
@@ -114,20 +122,20 @@ export declare class Net {
|
|
|
114
122
|
* @param {string} url
|
|
115
123
|
* @param {IData} data
|
|
116
124
|
* @param {IParams} [params={}]
|
|
117
|
-
* @param {
|
|
125
|
+
* @param {IData} [headers={}]
|
|
118
126
|
* @return {*} {Promise<IHttpResponse>}
|
|
119
127
|
*/
|
|
120
|
-
put(url: string, data: IData, params?: IParams, headers?:
|
|
128
|
+
put(url: string, data: IData, params?: IParams, headers?: IData): Promise<IHttpResponse>;
|
|
121
129
|
/**
|
|
122
130
|
* 获取模型数据
|
|
123
131
|
*
|
|
124
132
|
* @author chitanda
|
|
125
133
|
* @date 2022-07-14 15:07:15
|
|
126
134
|
* @param {string} url
|
|
127
|
-
* @param {
|
|
135
|
+
* @param {IData} [headers={}]
|
|
128
136
|
* @return {*} {Promise<IHttpResponse>}
|
|
129
137
|
*/
|
|
130
|
-
getModel(url: string, headers?:
|
|
138
|
+
getModel(url: string, headers?: IData): Promise<IHttpResponse>;
|
|
131
139
|
/**
|
|
132
140
|
* 基础请求方法,会合并预置配置
|
|
133
141
|
*
|
|
@@ -138,6 +146,15 @@ export declare class Net {
|
|
|
138
146
|
* @returns {*} {Promise<IHttpResponse>}
|
|
139
147
|
*/
|
|
140
148
|
request(url: string, config?: AxiosRequestConfig): Promise<IHttpResponse>;
|
|
149
|
+
/**
|
|
150
|
+
* 创建标准 axios 请求
|
|
151
|
+
*
|
|
152
|
+
* @author chitanda
|
|
153
|
+
* @date 2023-01-30 15:01:27
|
|
154
|
+
* @param {AxiosRequestConfig<IData>} config
|
|
155
|
+
* @return {*}
|
|
156
|
+
*/
|
|
157
|
+
axios(config: AxiosRequestConfig<IData>): import("axios").AxiosPromise<any>;
|
|
141
158
|
/**
|
|
142
159
|
* 统一处理请求返回
|
|
143
160
|
*
|
|
@@ -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,EAGZ,kBAAkB,EAClB,aAAa,EACd,MAAM,OAAO,CAAC;AAMf,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;GAOG;AACH,qBAAa,GAAG;IACd;;;;;;;OAOG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC;IAElC;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,SAA0B;IAE1C;;;;;OAKG;gBACS,MAAM,CAAC,EAAE,KAAK;IAK1B;;;;;;OAMG;IACH,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAa;IAEnD;;;;;;;OAOG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW;IAKrD;;;;;;OAMG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM;IAQ9B;;;;;;;;OAQG;IACH,SAAS,KAAK,YAAY,IAAI,kBAAkB,CAS/C;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,WAAW,CAAC,GAAG,OAAO,EAAE,kBAAkB,EAAE;IAYtD;;;;;;;;;;OAUG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,KAAU,GAClB,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;;;OAUG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,KAAU,EACnB,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC;IAiBzB;;;;;;;;;OASG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,KAAU,GAClB,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;;;OAUG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,KAAU,GAClB,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;OAQG;IACG,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,KAAU,GAAG,OAAO,CAAC,aAAa,CAAC;IAWxE;;;;;;;;OAQG;IACG,OAAO,CACX,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC;IAIvC;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;CAevB"}
|
package/out/utils/net/net.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { merge } from 'lodash-es';
|
|
3
|
-
import
|
|
3
|
+
import qs from 'qs';
|
|
4
4
|
import { notNilEmpty } from 'qx-util';
|
|
5
5
|
import { HttpError } from '../../error';
|
|
6
|
+
import { CoreInterceptor } from '../interceptor';
|
|
6
7
|
/**
|
|
7
8
|
* 全局请求工具类
|
|
8
9
|
*
|
|
@@ -16,9 +17,17 @@ export class Net {
|
|
|
16
17
|
* Creates an instance of Net.
|
|
17
18
|
* @author lxm
|
|
18
19
|
* @date 2022-10-27 16:10:05
|
|
19
|
-
* @param {
|
|
20
|
+
* @param {IData} [config] 创建实例用的默认配置
|
|
20
21
|
*/
|
|
21
22
|
constructor(config) {
|
|
23
|
+
/**
|
|
24
|
+
* 是否为 http || https 开头
|
|
25
|
+
*
|
|
26
|
+
* @author chitanda
|
|
27
|
+
* @date 2022-11-07 14:11:28
|
|
28
|
+
* @protected
|
|
29
|
+
*/
|
|
30
|
+
this.urlReg = /^http[s]?:\/\/[^\s]*/;
|
|
22
31
|
/**
|
|
23
32
|
* 注册的拦截器
|
|
24
33
|
*
|
|
@@ -28,6 +37,7 @@ export class Net {
|
|
|
28
37
|
*/
|
|
29
38
|
this.interceptors = new Map();
|
|
30
39
|
this.instance = axios.create(config);
|
|
40
|
+
this.addInterceptor('Default', new CoreInterceptor());
|
|
31
41
|
}
|
|
32
42
|
/**
|
|
33
43
|
* 添加拦截器
|
|
@@ -67,7 +77,7 @@ export class Net {
|
|
|
67
77
|
get presetConfig() {
|
|
68
78
|
return {
|
|
69
79
|
// 请求前缀路径
|
|
70
|
-
baseURL:
|
|
80
|
+
baseURL: ibiz.env.baseUrl,
|
|
71
81
|
headers: {
|
|
72
82
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
73
83
|
Accept: 'application/json',
|
|
@@ -84,10 +94,15 @@ export class Net {
|
|
|
84
94
|
* @returns {*}
|
|
85
95
|
*/
|
|
86
96
|
mergeConfig(...configs) {
|
|
97
|
+
const config = this.presetConfig;
|
|
87
98
|
if (configs.length === 0) {
|
|
88
|
-
return
|
|
99
|
+
return config;
|
|
89
100
|
}
|
|
90
|
-
|
|
101
|
+
const { url } = configs[0];
|
|
102
|
+
if (url && this.urlReg.test(url)) {
|
|
103
|
+
delete config.baseURL;
|
|
104
|
+
}
|
|
105
|
+
return merge(config, ...configs);
|
|
91
106
|
}
|
|
92
107
|
/**
|
|
93
108
|
* Post 请求
|
|
@@ -97,7 +112,7 @@ export class Net {
|
|
|
97
112
|
* @param {string} url
|
|
98
113
|
* @param {IData} data
|
|
99
114
|
* @param {IParams} [params={}]
|
|
100
|
-
* @param {
|
|
115
|
+
* @param {IData} [headers={}]
|
|
101
116
|
* @return {*} {Promise<IHttpResponse>}
|
|
102
117
|
*/
|
|
103
118
|
async post(url, data, params = {}, headers = {}) {
|
|
@@ -121,7 +136,7 @@ export class Net {
|
|
|
121
136
|
* @date 2022-10-19 11:10:24
|
|
122
137
|
* @param {string} url
|
|
123
138
|
* @param {IParams} [params={}]
|
|
124
|
-
* @param {
|
|
139
|
+
* @param {IData} [headers={}]
|
|
125
140
|
* @param {IParams} [option={}]
|
|
126
141
|
* @return {*} {Promise<IHttpResponse>}
|
|
127
142
|
*/
|
|
@@ -146,7 +161,7 @@ export class Net {
|
|
|
146
161
|
* @date 2022-10-19 11:10:17
|
|
147
162
|
* @param {string} url
|
|
148
163
|
* @param {IParams} [params]
|
|
149
|
-
* @param {
|
|
164
|
+
* @param {IData} [headers={}]
|
|
150
165
|
* @return {*} {Promise<IHttpResponse>}
|
|
151
166
|
*/
|
|
152
167
|
async delete(url, params, headers = {}) {
|
|
@@ -167,7 +182,7 @@ export class Net {
|
|
|
167
182
|
* @param {string} url
|
|
168
183
|
* @param {IData} data
|
|
169
184
|
* @param {IParams} [params={}]
|
|
170
|
-
* @param {
|
|
185
|
+
* @param {IData} [headers={}]
|
|
171
186
|
* @return {*} {Promise<IHttpResponse>}
|
|
172
187
|
*/
|
|
173
188
|
async put(url, data, params = {}, headers = {}) {
|
|
@@ -190,7 +205,7 @@ export class Net {
|
|
|
190
205
|
* @author chitanda
|
|
191
206
|
* @date 2022-07-14 15:07:15
|
|
192
207
|
* @param {string} url
|
|
193
|
-
* @param {
|
|
208
|
+
* @param {IData} [headers={}]
|
|
194
209
|
* @return {*} {Promise<IHttpResponse>}
|
|
195
210
|
*/
|
|
196
211
|
async getModel(url, headers = {}) {
|
|
@@ -222,6 +237,17 @@ export class Net {
|
|
|
222
237
|
throw new HttpError(error);
|
|
223
238
|
}
|
|
224
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* 创建标准 axios 请求
|
|
242
|
+
*
|
|
243
|
+
* @author chitanda
|
|
244
|
+
* @date 2023-01-30 15:01:27
|
|
245
|
+
* @param {AxiosRequestConfig<IData>} config
|
|
246
|
+
* @return {*}
|
|
247
|
+
*/
|
|
248
|
+
axios(config) {
|
|
249
|
+
return axios(config);
|
|
250
|
+
}
|
|
225
251
|
/**
|
|
226
252
|
* 统一处理请求返回
|
|
227
253
|
*
|
|
@@ -272,7 +298,7 @@ export class Net {
|
|
|
272
298
|
* @return {*} {string}
|
|
273
299
|
*/
|
|
274
300
|
attachUrlParam(url, params) {
|
|
275
|
-
const strParams = stringify(params);
|
|
301
|
+
const strParams = qs.stringify(params);
|
|
276
302
|
if (notNilEmpty(strParams)) {
|
|
277
303
|
if (url.endsWith('?')) {
|
|
278
304
|
url = `${url}${strParams}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../src/utils/plural/plural.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../src/utils/plural/plural.ts"],"names":[],"mappings":"AAKA;;;;;;;;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,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 字符串工具类
|
|
3
|
+
*
|
|
4
|
+
* @author chitanda
|
|
5
|
+
* @date 2021-04-23 20:04:27
|
|
6
|
+
* @export
|
|
7
|
+
* @class StringUtil
|
|
8
|
+
*/
|
|
9
|
+
export declare class StringUtil {
|
|
10
|
+
/**
|
|
11
|
+
* 上下文替换正则
|
|
12
|
+
*
|
|
13
|
+
* @author chitanda
|
|
14
|
+
* @date 2021-04-23 20:04:01
|
|
15
|
+
* @static
|
|
16
|
+
*/
|
|
17
|
+
static contextReg: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* 数据替换正则
|
|
20
|
+
*
|
|
21
|
+
* @author chitanda
|
|
22
|
+
* @date 2021-04-23 20:04:09
|
|
23
|
+
* @static
|
|
24
|
+
*/
|
|
25
|
+
static dataReg: RegExp;
|
|
26
|
+
/**
|
|
27
|
+
* 填充字符串中的数据
|
|
28
|
+
*
|
|
29
|
+
* @author chitanda
|
|
30
|
+
* @date 2021-04-23 20:04:17
|
|
31
|
+
* @static
|
|
32
|
+
* @param {string} str
|
|
33
|
+
* @param {*} [context]
|
|
34
|
+
* @param {*} [data]
|
|
35
|
+
* @return {*} {string}
|
|
36
|
+
*/
|
|
37
|
+
static fill(str: string, context?: IContext, data?: IData): string;
|
|
38
|
+
/**
|
|
39
|
+
* 动态匹配${}
|
|
40
|
+
*
|
|
41
|
+
* @param str
|
|
42
|
+
* @param values
|
|
43
|
+
*/
|
|
44
|
+
static dynamicMatch(str: string, values: any): string;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=string-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-util.d.ts","sourceRoot":"","sources":["../../../src/utils/string-util/string-util.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,SAAgD;IAEjE;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,SAA6C;IAE3D;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM;IAoBlE;;;;;OAKG;IAEH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,MAAM;CAOtD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { notNilEmpty } from 'qx-util';
|
|
2
|
+
/**
|
|
3
|
+
* 字符串工具类
|
|
4
|
+
*
|
|
5
|
+
* @author chitanda
|
|
6
|
+
* @date 2021-04-23 20:04:27
|
|
7
|
+
* @export
|
|
8
|
+
* @class StringUtil
|
|
9
|
+
*/
|
|
10
|
+
export class StringUtil {
|
|
11
|
+
/**
|
|
12
|
+
* 填充字符串中的数据
|
|
13
|
+
*
|
|
14
|
+
* @author chitanda
|
|
15
|
+
* @date 2021-04-23 20:04:17
|
|
16
|
+
* @static
|
|
17
|
+
* @param {string} str
|
|
18
|
+
* @param {*} [context]
|
|
19
|
+
* @param {*} [data]
|
|
20
|
+
* @return {*} {string}
|
|
21
|
+
*/
|
|
22
|
+
static fill(str, context, data) {
|
|
23
|
+
if (notNilEmpty(str)) {
|
|
24
|
+
if (notNilEmpty(context)) {
|
|
25
|
+
const strArr = str.match(this.contextReg);
|
|
26
|
+
strArr === null || strArr === void 0 ? void 0 : strArr.forEach(_key => {
|
|
27
|
+
const key = _key.slice(10, _key.length - 1);
|
|
28
|
+
str = str.replace(`\${context.${key}}`, context[key] || '');
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (notNilEmpty(data)) {
|
|
32
|
+
const strArr = str.match(this.dataReg);
|
|
33
|
+
strArr === null || strArr === void 0 ? void 0 : strArr.forEach(_key => {
|
|
34
|
+
const key = _key.slice(7, _key.length - 1);
|
|
35
|
+
str = str.replace(`\${data.${key}}`, data[key] || '');
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return str;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 动态匹配${}
|
|
43
|
+
*
|
|
44
|
+
* @param str
|
|
45
|
+
* @param values
|
|
46
|
+
*/
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
static dynamicMatch(str, values) {
|
|
49
|
+
return str.replace(/\${(.*?)}/g, (_, key) => {
|
|
50
|
+
const [objKey, propName] = key.split('.');
|
|
51
|
+
const obj = values[objKey];
|
|
52
|
+
return obj ? obj[propName] : '';
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 上下文替换正则
|
|
58
|
+
*
|
|
59
|
+
* @author chitanda
|
|
60
|
+
* @date 2021-04-23 20:04:01
|
|
61
|
+
* @static
|
|
62
|
+
*/
|
|
63
|
+
StringUtil.contextReg = /\$\{context.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
|
|
64
|
+
/**
|
|
65
|
+
* 数据替换正则
|
|
66
|
+
*
|
|
67
|
+
* @author chitanda
|
|
68
|
+
* @date 2021-04-23 20:04:09
|
|
69
|
+
* @static
|
|
70
|
+
*/
|
|
71
|
+
StringUtil.dataReg = /\$\{data.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 设置延迟wait毫米后执行fun方法,返回fun的返回值
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2023-03-06 08:20:57
|
|
6
|
+
* @export
|
|
7
|
+
* @template T
|
|
8
|
+
* @param {number} wait
|
|
9
|
+
* @param {T} fun
|
|
10
|
+
* @param {any[]} params
|
|
11
|
+
* @returns {*} {Promise<ReturnType<T>>}
|
|
12
|
+
*/
|
|
13
|
+
export declare function awaitTimeout<T extends (...args: any) => any>(wait: number, fun?: T, params?: any[]): Promise<ReturnType<T> | undefined>;
|
|
14
|
+
//# sourceMappingURL=await-timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"await-timeout.d.ts","sourceRoot":"","sources":["../../../src/utils/sync/await-timeout.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,EAChE,IAAI,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,CAAC,EACP,MAAM,CAAC,EAAE,GAAG,EAAE,GACb,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CASpC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/**
|
|
3
|
+
* 设置延迟wait毫米后执行fun方法,返回fun的返回值
|
|
4
|
+
*
|
|
5
|
+
* @author lxm
|
|
6
|
+
* @date 2023-03-06 08:20:57
|
|
7
|
+
* @export
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {number} wait
|
|
10
|
+
* @param {T} fun
|
|
11
|
+
* @param {any[]} params
|
|
12
|
+
* @returns {*} {Promise<ReturnType<T>>}
|
|
13
|
+
*/
|
|
14
|
+
export async function awaitTimeout(wait, fun, params) {
|
|
15
|
+
await new Promise(resolve => {
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
resolve(true);
|
|
18
|
+
}, wait);
|
|
19
|
+
});
|
|
20
|
+
if (fun) {
|
|
21
|
+
return fun(...(params || []));
|
|
22
|
+
}
|
|
23
|
+
}
|