@ibiz-template/core 0.0.1-alpha.6 → 0.0.1-beta.130
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 -0
- 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/constant/index.d.ts +3 -0
- package/out/constant/index.d.ts.map +1 -1
- package/out/constant/index.js +3 -0
- package/out/constant/login-mode/login-mode.d.ts +23 -0
- package/out/constant/login-mode/login-mode.d.ts.map +1 -0
- package/out/constant/login-mode/login-mode.js +24 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
- package/out/constant/util/util.d.ts +5 -0
- package/out/constant/util/util.d.ts.map +1 -0
- package/out/constant/util/util.js +5 -0
- package/out/context/index.d.ts +49 -27
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +94 -55
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +16 -2
- package/out/error/http-error/http-error.d.ts.map +1 -1
- package/out/error/http-error/http-error.js +0 -4
- package/out/factory-center.d.ts +11 -0
- package/out/factory-center.d.ts.map +1 -0
- package/out/factory-center.js +10 -0
- package/out/ibizsys.d.ts +8 -1
- package/out/ibizsys.d.ts.map +1 -1
- package/out/ibizsys.js +8 -1
- package/out/index.d.ts +2 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/install.d.ts.map +1 -1
- package/out/install.js +4 -2
- package/out/interface/click-outside/click-outside.d.ts +70 -0
- package/out/interface/click-outside/click-outside.d.ts.map +1 -0
- package/out/interface/click-outside/click-outside.js +1 -0
- package/out/interface/i-environment/i-environment.d.ts +108 -4
- package/out/interface/i-environment/i-environment.d.ts.map +1 -1
- package/out/interface/index.d.ts +1 -0
- package/out/interface/index.d.ts.map +1 -1
- package/out/interface/index.js +1 -1
- package/out/types.d.ts +41 -0
- package/out/types.d.ts.map +1 -1
- package/out/utils/click-outside/click-outside.d.ts +14 -0
- package/out/utils/click-outside/click-outside.d.ts.map +1 -0
- package/out/utils/click-outside/click-outside.js +85 -0
- package/out/utils/color/color.d.ts +13 -0
- package/out/utils/color/color.d.ts.map +1 -0
- package/out/utils/color/color.js +76 -0
- package/out/utils/download-file/download-file.d.ts +31 -0
- package/out/utils/download-file/download-file.d.ts.map +1 -0
- package/out/utils/download-file/download-file.js +107 -0
- package/out/utils/event/event.d.ts +34 -0
- package/out/utils/event/event.d.ts.map +1 -0
- package/out/utils/event/event.js +60 -0
- package/out/utils/index.d.ts +11 -1
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +11 -1
- package/out/utils/interceptor/core-interceptor.d.ts +15 -0
- package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
- package/out/utils/interceptor/core-interceptor.js +30 -0
- package/out/utils/interceptor/index.d.ts +3 -0
- package/out/utils/interceptor/index.d.ts.map +1 -0
- package/out/utils/interceptor/index.js +2 -0
- package/out/utils/interceptor/interceptor.d.ts +74 -3
- package/out/utils/interceptor/interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/interceptor.js +73 -22
- package/out/utils/logger/logger.d.ts +3 -0
- package/out/utils/logger/logger.d.ts.map +1 -0
- package/out/utils/logger/logger.js +2 -0
- package/out/utils/net/http-response.d.ts +4 -9
- package/out/utils/net/http-response.d.ts.map +1 -1
- package/out/utils/net/http-response.js +0 -7
- package/out/utils/net/net.d.ts +98 -30
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/net/net.js +133 -38
- 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 +150 -0
- package/out/utils/url-helper/url-helper.d.ts +51 -0
- package/out/utils/url-helper/url-helper.d.ts.map +1 -0
- package/out/utils/url-helper/url-helper.js +59 -0
- package/out/utils/util/util.d.ts +20 -4
- package/out/utils/util/util.d.ts.map +1 -1
- package/out/utils/util/util.js +59 -5
- package/package.json +21 -10
- package/src/constant/core/core.ts +10 -0
- package/src/constant/index.ts +3 -0
- package/src/constant/login-mode/login-mode.ts +23 -0
- package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
- package/src/constant/util/util.ts +5 -0
- package/src/context/index.ts +127 -51
- package/src/environment/environment.ts +16 -2
- package/src/error/http-error/http-error.ts +0 -4
- package/src/factory-center.ts +9 -0
- package/src/ibizsys.ts +9 -1
- package/src/index.ts +2 -1
- package/src/install.ts +4 -2
- package/src/interface/click-outside/click-outside.ts +71 -0
- package/src/interface/i-environment/i-environment.ts +122 -4
- package/src/interface/index.ts +1 -0
- package/src/types.ts +45 -0
- package/src/utils/click-outside/click-outside.ts +110 -0
- package/src/utils/color/color.ts +84 -0
- package/src/utils/download-file/download-file.ts +109 -0
- package/src/utils/event/event.ts +77 -0
- package/src/utils/index.ts +11 -1
- package/src/utils/interceptor/core-interceptor.ts +35 -0
- package/src/utils/interceptor/index.ts +2 -0
- package/src/utils/interceptor/interceptor.ts +109 -22
- package/src/utils/logger/logger.ts +3 -0
- package/src/utils/net/http-response.ts +6 -9
- package/src/utils/net/net.ts +171 -50
- 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 +206 -0
- package/src/utils/url-helper/url-helper.ts +62 -0
- package/src/utils/util/util.ts +72 -14
- package/LICENSE +0 -21
package/out/utils/net/net.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RawAxiosRequestHeaders, AxiosResponse, AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults } from 'axios';
|
|
2
|
+
import { Interceptor } from '../interceptor/interceptor';
|
|
2
3
|
import { IHttpResponse } from './http-response';
|
|
3
4
|
/**
|
|
4
5
|
* 全局请求工具类
|
|
@@ -10,73 +11,150 @@ import { IHttpResponse } from './http-response';
|
|
|
10
11
|
*/
|
|
11
12
|
export declare class Net {
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
+
* axios实例
|
|
15
|
+
*
|
|
16
|
+
* @author lxm
|
|
17
|
+
* @date 2022-10-27 17:10:18
|
|
18
|
+
* @protected
|
|
19
|
+
* @type {AxiosInstance}
|
|
20
|
+
*/
|
|
21
|
+
protected instance: AxiosInstance;
|
|
22
|
+
/**
|
|
23
|
+
* 是否为 http || https 开头
|
|
14
24
|
*
|
|
15
25
|
* @author chitanda
|
|
16
|
-
* @date 2022-07
|
|
26
|
+
* @date 2022-11-07 14:11:28
|
|
17
27
|
* @protected
|
|
18
|
-
* @type {string}
|
|
19
28
|
*/
|
|
20
|
-
protected
|
|
21
|
-
get prefix(): string;
|
|
29
|
+
protected urlReg: RegExp;
|
|
22
30
|
/**
|
|
23
31
|
* Creates an instance of Net.
|
|
32
|
+
* @author lxm
|
|
33
|
+
* @date 2022-10-27 16:10:05
|
|
34
|
+
* @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
|
|
35
|
+
*/
|
|
36
|
+
constructor(config?: CreateAxiosDefaults);
|
|
37
|
+
/**
|
|
38
|
+
* 注册的拦截器
|
|
24
39
|
*
|
|
25
|
-
* @author
|
|
26
|
-
* @date 2022-
|
|
27
|
-
* @
|
|
40
|
+
* @author lxm
|
|
41
|
+
* @date 2022-10-27 17:10:18
|
|
42
|
+
* @type {Map<string, Interceptor>}
|
|
43
|
+
*/
|
|
44
|
+
interceptors: Map<string, Interceptor>;
|
|
45
|
+
/**
|
|
46
|
+
* 添加拦截器
|
|
47
|
+
*
|
|
48
|
+
* @author lxm
|
|
49
|
+
* @date 2022-10-27 17:10:42
|
|
50
|
+
* @param {string} name 唯一标识
|
|
51
|
+
* @param {Interceptor} interceptor 拦截器
|
|
52
|
+
*/
|
|
53
|
+
addInterceptor(name: string, interceptor: Interceptor): void;
|
|
54
|
+
/**
|
|
55
|
+
* 删除拦截器
|
|
56
|
+
*
|
|
57
|
+
* @author lxm
|
|
58
|
+
* @date 2022-10-27 17:10:27
|
|
59
|
+
* @param {string} name 唯一标识
|
|
60
|
+
*/
|
|
61
|
+
removeInterceptor(name: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* 预置config,绑定动态的配置
|
|
64
|
+
*
|
|
65
|
+
* @author lxm
|
|
66
|
+
* @date 2022-10-27 16:10:48
|
|
67
|
+
* @readonly
|
|
68
|
+
* @protected
|
|
69
|
+
* @type {AxiosRequestConfig}
|
|
70
|
+
*/
|
|
71
|
+
protected get presetConfig(): AxiosRequestConfig;
|
|
72
|
+
/**
|
|
73
|
+
* 从左到右递归合并配置参数(内置第一个合并的预置参数)
|
|
74
|
+
*
|
|
75
|
+
* @author lxm
|
|
76
|
+
* @date 2022-10-27 16:10:09
|
|
77
|
+
* @protected
|
|
78
|
+
* @param {...AxiosRequestConfig[]} configs
|
|
79
|
+
* @returns {*}
|
|
28
80
|
*/
|
|
29
|
-
|
|
81
|
+
protected mergeConfig(...configs: AxiosRequestConfig[]): any;
|
|
30
82
|
/**
|
|
31
83
|
* Post 请求
|
|
32
84
|
*
|
|
33
85
|
* @author chitanda
|
|
34
|
-
* @date 2022-
|
|
86
|
+
* @date 2022-10-19 11:10:30
|
|
35
87
|
* @param {string} url
|
|
88
|
+
* @param {IData} data
|
|
36
89
|
* @param {IParams} [params={}]
|
|
90
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
37
91
|
* @return {*} {Promise<IHttpResponse>}
|
|
38
92
|
*/
|
|
39
|
-
post(url: string, data: IData, params?: IParams, headers?:
|
|
93
|
+
post(url: string, data: IData, params?: IParams, headers?: RawAxiosRequestHeaders): Promise<IHttpResponse>;
|
|
40
94
|
/**
|
|
41
95
|
* Get 请求
|
|
42
96
|
*
|
|
43
97
|
* @author chitanda
|
|
44
|
-
* @date 2022-
|
|
98
|
+
* @date 2022-10-19 11:10:24
|
|
45
99
|
* @param {string} url
|
|
46
100
|
* @param {IParams} [params={}]
|
|
101
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
102
|
+
* @param {IParams} [option={}]
|
|
47
103
|
* @return {*} {Promise<IHttpResponse>}
|
|
48
104
|
*/
|
|
49
|
-
get(url: string, params?: IParams, headers?:
|
|
105
|
+
get(url: string, params?: IParams, headers?: RawAxiosRequestHeaders, option?: AxiosRequestConfig): Promise<IHttpResponse>;
|
|
50
106
|
/**
|
|
51
107
|
* Delete 请求
|
|
52
108
|
*
|
|
53
109
|
* @author chitanda
|
|
54
|
-
* @date 2022-
|
|
110
|
+
* @date 2022-10-19 11:10:17
|
|
55
111
|
* @param {string} url
|
|
56
112
|
* @param {IParams} [params]
|
|
113
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
57
114
|
* @return {*} {Promise<IHttpResponse>}
|
|
58
115
|
*/
|
|
59
|
-
delete(url: string, params?: IParams, headers?:
|
|
116
|
+
delete(url: string, params?: IParams, headers?: RawAxiosRequestHeaders): Promise<IHttpResponse>;
|
|
60
117
|
/**
|
|
61
118
|
* Put 请求
|
|
62
119
|
*
|
|
63
120
|
* @author chitanda
|
|
64
|
-
* @date 2022-
|
|
121
|
+
* @date 2022-10-19 11:10:11
|
|
65
122
|
* @param {string} url
|
|
66
123
|
* @param {IData} data
|
|
124
|
+
* @param {IParams} [params={}]
|
|
125
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
67
126
|
* @return {*} {Promise<IHttpResponse>}
|
|
68
127
|
*/
|
|
69
|
-
put(url: string, data: IData, params?: IParams, headers?:
|
|
128
|
+
put(url: string, data: IData, params?: IParams, headers?: RawAxiosRequestHeaders): Promise<IHttpResponse>;
|
|
70
129
|
/**
|
|
71
130
|
* 获取模型数据
|
|
72
131
|
*
|
|
73
132
|
* @author chitanda
|
|
74
133
|
* @date 2022-07-14 15:07:15
|
|
75
134
|
* @param {string} url
|
|
76
|
-
* @param {
|
|
135
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
77
136
|
* @return {*} {Promise<IHttpResponse>}
|
|
78
137
|
*/
|
|
79
|
-
getModel(url: string, headers?:
|
|
138
|
+
getModel(url: string, headers?: RawAxiosRequestHeaders): Promise<IHttpResponse>;
|
|
139
|
+
/**
|
|
140
|
+
* 基础请求方法,会合并预置配置
|
|
141
|
+
*
|
|
142
|
+
* @author lxm
|
|
143
|
+
* @date 2022-10-27 14:10:06
|
|
144
|
+
* @param {string} url
|
|
145
|
+
* @param {AxiosRequestConfig} [config={}]
|
|
146
|
+
* @returns {*} {Promise<IHttpResponse>}
|
|
147
|
+
*/
|
|
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>): Promise<AxiosResponse<any, any>>;
|
|
80
158
|
/**
|
|
81
159
|
* 统一处理请求返回
|
|
82
160
|
*
|
|
@@ -109,15 +187,5 @@ export declare class Net {
|
|
|
109
187
|
* @return {*} {string}
|
|
110
188
|
*/
|
|
111
189
|
private attachUrlParam;
|
|
112
|
-
/**
|
|
113
|
-
* 处理 url 参数
|
|
114
|
-
*
|
|
115
|
-
* @author chitanda
|
|
116
|
-
* @date 2022-07-20 20:07:17
|
|
117
|
-
* @private
|
|
118
|
-
* @param {string} url
|
|
119
|
-
* @return {*} {string}
|
|
120
|
-
*/
|
|
121
|
-
private attachUrl;
|
|
122
190
|
}
|
|
123
191
|
//# sourceMappingURL=net.d.ts.map
|
|
@@ -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,EAEZ,sBAAsB,EACtB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACpB,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,mBAAmB;IAKxC;;;;;;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,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;;;OAUG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,sBAA2B,EACpC,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC;IAiBzB;;;;;;;;;OASG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;;;OAUG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;OAQG;IACG,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;;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,7 +1,9 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
2
3
|
import { stringify } from 'qs';
|
|
3
4
|
import { notNilEmpty } from 'qx-util';
|
|
4
5
|
import { HttpError } from '../../error';
|
|
6
|
+
import { CoreInterceptor } from '../interceptor';
|
|
5
7
|
/**
|
|
6
8
|
* 全局请求工具类
|
|
7
9
|
*
|
|
@@ -13,45 +15,113 @@ import { HttpError } from '../../error';
|
|
|
13
15
|
export class Net {
|
|
14
16
|
/**
|
|
15
17
|
* Creates an instance of Net.
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
19
|
-
* @param {string} [prefix] 请求前缀
|
|
18
|
+
* @author lxm
|
|
19
|
+
* @date 2022-10-27 16:10:05
|
|
20
|
+
* @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
|
|
20
21
|
*/
|
|
21
|
-
constructor(
|
|
22
|
+
constructor(config) {
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
+
* 是否为 http || https 开头
|
|
24
25
|
*
|
|
25
26
|
* @author chitanda
|
|
26
|
-
* @date 2022-07
|
|
27
|
+
* @date 2022-11-07 14:11:28
|
|
27
28
|
* @protected
|
|
28
|
-
* @type {string}
|
|
29
29
|
*/
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
this.urlReg = /^http[s]?:\/\/[^\s]*/;
|
|
31
|
+
/**
|
|
32
|
+
* 注册的拦截器
|
|
33
|
+
*
|
|
34
|
+
* @author lxm
|
|
35
|
+
* @date 2022-10-27 17:10:18
|
|
36
|
+
* @type {Map<string, Interceptor>}
|
|
37
|
+
*/
|
|
38
|
+
this.interceptors = new Map();
|
|
39
|
+
this.instance = axios.create(config);
|
|
40
|
+
this.addInterceptor('Default', new CoreInterceptor());
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 添加拦截器
|
|
44
|
+
*
|
|
45
|
+
* @author lxm
|
|
46
|
+
* @date 2022-10-27 17:10:42
|
|
47
|
+
* @param {string} name 唯一标识
|
|
48
|
+
* @param {Interceptor} interceptor 拦截器
|
|
49
|
+
*/
|
|
50
|
+
addInterceptor(name, interceptor) {
|
|
51
|
+
interceptor.use(this.instance);
|
|
52
|
+
this.interceptors.set(name, interceptor);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 删除拦截器
|
|
56
|
+
*
|
|
57
|
+
* @author lxm
|
|
58
|
+
* @date 2022-10-27 17:10:27
|
|
59
|
+
* @param {string} name 唯一标识
|
|
60
|
+
*/
|
|
61
|
+
removeInterceptor(name) {
|
|
62
|
+
const interceptor = this.interceptors.get(name);
|
|
63
|
+
if (interceptor) {
|
|
64
|
+
interceptor.eject(this.instance);
|
|
65
|
+
this.interceptors.delete(name);
|
|
33
66
|
}
|
|
34
67
|
}
|
|
35
|
-
|
|
36
|
-
|
|
68
|
+
/**
|
|
69
|
+
* 预置config,绑定动态的配置
|
|
70
|
+
*
|
|
71
|
+
* @author lxm
|
|
72
|
+
* @date 2022-10-27 16:10:48
|
|
73
|
+
* @readonly
|
|
74
|
+
* @protected
|
|
75
|
+
* @type {AxiosRequestConfig}
|
|
76
|
+
*/
|
|
77
|
+
get presetConfig() {
|
|
78
|
+
return {
|
|
79
|
+
// 请求前缀路径
|
|
80
|
+
baseURL: ibiz.env.baseUrl,
|
|
81
|
+
headers: {
|
|
82
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
83
|
+
Accept: 'application/json',
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 从左到右递归合并配置参数(内置第一个合并的预置参数)
|
|
89
|
+
*
|
|
90
|
+
* @author lxm
|
|
91
|
+
* @date 2022-10-27 16:10:09
|
|
92
|
+
* @protected
|
|
93
|
+
* @param {...AxiosRequestConfig[]} configs
|
|
94
|
+
* @returns {*}
|
|
95
|
+
*/
|
|
96
|
+
mergeConfig(...configs) {
|
|
97
|
+
const config = this.presetConfig;
|
|
98
|
+
if (configs.length === 0) {
|
|
99
|
+
return config;
|
|
100
|
+
}
|
|
101
|
+
const { url } = configs[0];
|
|
102
|
+
if (url && this.urlReg.test(url)) {
|
|
103
|
+
delete config.baseURL;
|
|
104
|
+
}
|
|
105
|
+
return merge(config, ...configs);
|
|
37
106
|
}
|
|
38
107
|
/**
|
|
39
108
|
* Post 请求
|
|
40
109
|
*
|
|
41
110
|
* @author chitanda
|
|
42
|
-
* @date 2022-
|
|
111
|
+
* @date 2022-10-19 11:10:30
|
|
43
112
|
* @param {string} url
|
|
113
|
+
* @param {IData} data
|
|
44
114
|
* @param {IParams} [params={}]
|
|
115
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
45
116
|
* @return {*} {Promise<IHttpResponse>}
|
|
46
117
|
*/
|
|
47
118
|
async post(url, data, params = {}, headers = {}) {
|
|
48
119
|
url = this.handleAppPresetParam(url, params);
|
|
49
120
|
try {
|
|
50
|
-
const response = await
|
|
121
|
+
const response = await this.request(url, {
|
|
51
122
|
method: 'post',
|
|
52
|
-
url,
|
|
53
123
|
data,
|
|
54
|
-
headers
|
|
124
|
+
headers,
|
|
55
125
|
});
|
|
56
126
|
return this.doResponseResult(response);
|
|
57
127
|
}
|
|
@@ -63,9 +133,11 @@ export class Net {
|
|
|
63
133
|
* Get 请求
|
|
64
134
|
*
|
|
65
135
|
* @author chitanda
|
|
66
|
-
* @date 2022-
|
|
136
|
+
* @date 2022-10-19 11:10:24
|
|
67
137
|
* @param {string} url
|
|
68
138
|
* @param {IParams} [params={}]
|
|
139
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
140
|
+
* @param {IParams} [option={}]
|
|
69
141
|
* @return {*} {Promise<IHttpResponse>}
|
|
70
142
|
*/
|
|
71
143
|
async get(url, params = {}, headers = {}, option = {}) {
|
|
@@ -75,7 +147,7 @@ export class Net {
|
|
|
75
147
|
// }
|
|
76
148
|
url = this.attachUrlParam(url, params);
|
|
77
149
|
try {
|
|
78
|
-
const response = await
|
|
150
|
+
const response = await this.request(url, merge({ method: 'get', headers }, option));
|
|
79
151
|
return this.doResponseResult(response);
|
|
80
152
|
}
|
|
81
153
|
catch (error) {
|
|
@@ -86,15 +158,16 @@ export class Net {
|
|
|
86
158
|
* Delete 请求
|
|
87
159
|
*
|
|
88
160
|
* @author chitanda
|
|
89
|
-
* @date 2022-
|
|
161
|
+
* @date 2022-10-19 11:10:17
|
|
90
162
|
* @param {string} url
|
|
91
163
|
* @param {IParams} [params]
|
|
164
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
92
165
|
* @return {*} {Promise<IHttpResponse>}
|
|
93
166
|
*/
|
|
94
167
|
async delete(url, params, headers = {}) {
|
|
95
168
|
url = this.handleAppPresetParam(url, params);
|
|
96
169
|
try {
|
|
97
|
-
const response = await
|
|
170
|
+
const response = await this.request(url, { method: 'delete', headers });
|
|
98
171
|
return this.doResponseResult(response);
|
|
99
172
|
}
|
|
100
173
|
catch (error) {
|
|
@@ -105,15 +178,21 @@ export class Net {
|
|
|
105
178
|
* Put 请求
|
|
106
179
|
*
|
|
107
180
|
* @author chitanda
|
|
108
|
-
* @date 2022-
|
|
181
|
+
* @date 2022-10-19 11:10:11
|
|
109
182
|
* @param {string} url
|
|
110
183
|
* @param {IData} data
|
|
184
|
+
* @param {IParams} [params={}]
|
|
185
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
111
186
|
* @return {*} {Promise<IHttpResponse>}
|
|
112
187
|
*/
|
|
113
188
|
async put(url, data, params = {}, headers = {}) {
|
|
114
189
|
url = this.handleAppPresetParam(url, params);
|
|
115
190
|
try {
|
|
116
|
-
const response = await
|
|
191
|
+
const response = await this.request(url, {
|
|
192
|
+
method: 'put',
|
|
193
|
+
data,
|
|
194
|
+
headers,
|
|
195
|
+
});
|
|
117
196
|
return this.doResponseResult(response);
|
|
118
197
|
}
|
|
119
198
|
catch (error) {
|
|
@@ -126,12 +205,12 @@ export class Net {
|
|
|
126
205
|
* @author chitanda
|
|
127
206
|
* @date 2022-07-14 15:07:15
|
|
128
207
|
* @param {string} url
|
|
129
|
-
* @param {
|
|
208
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
130
209
|
* @return {*} {Promise<IHttpResponse>}
|
|
131
210
|
*/
|
|
132
211
|
async getModel(url, headers = {}) {
|
|
133
212
|
try {
|
|
134
|
-
const response = await
|
|
213
|
+
const response = await this.instance.get(url, {
|
|
135
214
|
headers,
|
|
136
215
|
});
|
|
137
216
|
return this.doResponseResult(response);
|
|
@@ -140,6 +219,35 @@ export class Net {
|
|
|
140
219
|
throw new HttpError(error);
|
|
141
220
|
}
|
|
142
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* 基础请求方法,会合并预置配置
|
|
224
|
+
*
|
|
225
|
+
* @author lxm
|
|
226
|
+
* @date 2022-10-27 14:10:06
|
|
227
|
+
* @param {string} url
|
|
228
|
+
* @param {AxiosRequestConfig} [config={}]
|
|
229
|
+
* @returns {*} {Promise<IHttpResponse>}
|
|
230
|
+
*/
|
|
231
|
+
async request(url, config = {}) {
|
|
232
|
+
try {
|
|
233
|
+
const response = await this.instance.request(this.mergeConfig({ url }, config));
|
|
234
|
+
return this.doResponseResult(response);
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
throw new HttpError(error);
|
|
238
|
+
}
|
|
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
|
+
}
|
|
143
251
|
/**
|
|
144
252
|
* 统一处理请求返回
|
|
145
253
|
*
|
|
@@ -190,7 +298,6 @@ export class Net {
|
|
|
190
298
|
* @return {*} {string}
|
|
191
299
|
*/
|
|
192
300
|
attachUrlParam(url, params) {
|
|
193
|
-
url = this.attachUrl(url);
|
|
194
301
|
const strParams = stringify(params);
|
|
195
302
|
if (notNilEmpty(strParams)) {
|
|
196
303
|
if (url.endsWith('?')) {
|
|
@@ -208,16 +315,4 @@ export class Net {
|
|
|
208
315
|
}
|
|
209
316
|
return url;
|
|
210
317
|
}
|
|
211
|
-
/**
|
|
212
|
-
* 处理 url 参数
|
|
213
|
-
*
|
|
214
|
-
* @author chitanda
|
|
215
|
-
* @date 2022-07-20 20:07:17
|
|
216
|
-
* @private
|
|
217
|
-
* @param {string} url
|
|
218
|
-
* @return {*} {string}
|
|
219
|
-
*/
|
|
220
|
-
attachUrl(url) {
|
|
221
|
-
return `${this.prefix}${url}`;
|
|
222
|
-
}
|
|
223
318
|
}
|
|
@@ -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
|
+
}
|