@ibiz-template/core 0.6.0 → 0.6.1-alpha.3
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/index.esm.js +27 -21
- package/dist/index.system.min.js +1 -1
- package/out/interface/i-devtool-config/i-devtool-config.d.ts +7 -0
- package/out/interface/i-devtool-config/i-devtool-config.d.ts.map +1 -1
- package/out/utils/bit-mask/bit-mask.d.ts +27 -0
- package/out/utils/bit-mask/bit-mask.d.ts.map +1 -1
- package/out/utils/bit-mask/bit-mask.js +27 -0
- package/out/utils/color/color.d.ts.map +1 -1
- package/out/utils/color/color.js +8 -4
- package/out/utils/download-file/download-file.js +17 -17
- package/out/utils/string-util/string-util.d.ts +6 -0
- package/out/utils/string-util/string-util.d.ts.map +1 -1
- package/out/utils/string-util/string-util.js +6 -0
- package/out/utils/sync/await-timeout.d.ts +6 -0
- package/out/utils/sync/await-timeout.d.ts.map +1 -1
- package/out/utils/sync/await-timeout.js +6 -0
- package/out/utils/types/types.d.ts +3 -1
- package/out/utils/types/types.d.ts.map +1 -1
- package/out/utils/util/util.d.ts +137 -0
- package/out/utils/util/util.d.ts.map +1 -1
- package/out/utils/util/util.js +137 -0
- package/package.json +4 -5
- package/src/command/command-register.ts +0 -135
- package/src/command/command.ts +0 -79
- package/src/command/index.ts +0 -11
- package/src/command/interface/command/command-option.ts +0 -22
- package/src/command/interface/command/command.ts +0 -86
- package/src/command/interface/disposable/disposable.ts +0 -3
- package/src/command/interface/index.ts +0 -9
- package/src/command/utils/index.ts +0 -2
- package/src/command/utils/linked-list.ts +0 -136
- package/src/command/utils/util.ts +0 -95
- package/src/constant/core/core.ts +0 -63
- package/src/constant/http-status-message/http-status-message.ts +0 -20
- package/src/constant/index.ts +0 -5
- package/src/constant/login-mode/login-mode.ts +0 -23
- package/src/constant/menu-permission-mode/menu-permission-mode.ts +0 -23
- package/src/constant/util/util.ts +0 -5
- package/src/context/index.ts +0 -231
- package/src/environment/environment.ts +0 -39
- package/src/error/http-error/http-error.ts +0 -45
- package/src/error/index.ts +0 -5
- package/src/error/model-error/model-error.ts +0 -26
- package/src/error/notice-error/notice-error.ts +0 -19
- package/src/error/runtime-error/runtime-error.ts +0 -16
- package/src/error/runtime-model-error/runtime-model-error.ts +0 -27
- package/src/ibizsys.ts +0 -78
- package/src/index.ts +0 -14
- package/src/install.ts +0 -15
- package/src/interface/click-outside/click-outside.ts +0 -71
- package/src/interface/i-18n/i-18n.ts +0 -68
- package/src/interface/i-chat-message/i-chat-message.ts +0 -83
- package/src/interface/i-devtool-config/i-devtool-config.ts +0 -16
- package/src/interface/i-environment/i-environment.ts +0 -289
- package/src/interface/i-internal-message/i-internal-message.ts +0 -151
- package/src/interface/i-mark-open-data/i-mark-open-data.ts +0 -39
- package/src/interface/i-portal-async-action/i-portal-async-action.ts +0 -177
- package/src/interface/i-portal-message/i-portal-message.ts +0 -84
- package/src/interface/index.ts +0 -14
- package/src/interface/org-data/org-data.ts +0 -42
- package/src/params/params.ts +0 -134
- package/src/types.ts +0 -110
- package/src/utils/bit-mask/bit-mask.ts +0 -85
- package/src/utils/click-outside/click-outside.ts +0 -110
- package/src/utils/clone/clone.ts +0 -43
- package/src/utils/color/color.ts +0 -84
- package/src/utils/data-type/data-types.ts +0 -99
- package/src/utils/download-file/download-file.ts +0 -109
- package/src/utils/event/event.ts +0 -77
- package/src/utils/history-list/history-item.ts +0 -45
- package/src/utils/history-list/history-list.ts +0 -151
- package/src/utils/index.ts +0 -24
- package/src/utils/interceptor/core-interceptor.ts +0 -40
- package/src/utils/interceptor/index.ts +0 -2
- package/src/utils/interceptor/interceptor.ts +0 -126
- package/src/utils/logger/logger.ts +0 -10
- package/src/utils/message-center/base/message-all.ts +0 -12
- package/src/utils/message-center/base/message-base.ts +0 -86
- package/src/utils/message-center/command/async-action/command-async-action.ts +0 -24
- package/src/utils/message-center/command/change/command-change.ts +0 -12
- package/src/utils/message-center/command/command-base/command-base.ts +0 -30
- package/src/utils/message-center/command/create/command-create.ts +0 -24
- package/src/utils/message-center/command/internal-message/command-internal-message.ts +0 -24
- package/src/utils/message-center/command/mark-open-data/command-mark-open-data.ts +0 -24
- package/src/utils/message-center/command/message-command.ts +0 -158
- package/src/utils/message-center/command/remove/command-remove.ts +0 -24
- package/src/utils/message-center/command/update/command-update.ts +0 -24
- package/src/utils/message-center/console/message-console.ts +0 -31
- package/src/utils/message-center/index.ts +0 -1
- package/src/utils/message-center/interface/i-app-data-entity.ts +0 -19
- package/src/utils/message-center/interface/index.ts +0 -1
- package/src/utils/message-center/message-center.ts +0 -82
- package/src/utils/namespace/namespace.ts +0 -247
- package/src/utils/net/http-response.ts +0 -106
- package/src/utils/net/net.ts +0 -469
- package/src/utils/recursive/find-recursive-child.ts +0 -133
- package/src/utils/string-util/string-util.ts +0 -60
- package/src/utils/style/remote-style.ts +0 -20
- package/src/utils/sync/await-timeout.ts +0 -27
- package/src/utils/sync/count-latch.ts +0 -95
- package/src/utils/sync/index.ts +0 -2
- package/src/utils/types/types.ts +0 -22
- package/src/utils/upload/select-file.ts +0 -86
- package/src/utils/upload/upload-file.ts +0 -208
- package/src/utils/url-helper/url-helper.ts +0 -63
- package/src/utils/util/util.ts +0 -376
package/src/utils/net/net.ts
DELETED
|
@@ -1,469 +0,0 @@
|
|
|
1
|
-
import axios, {
|
|
2
|
-
AxiosError,
|
|
3
|
-
RawAxiosRequestHeaders,
|
|
4
|
-
AxiosResponse,
|
|
5
|
-
AxiosRequestConfig,
|
|
6
|
-
AxiosInstance,
|
|
7
|
-
CreateAxiosDefaults,
|
|
8
|
-
} from 'axios';
|
|
9
|
-
import {
|
|
10
|
-
FetchEventSourceInit,
|
|
11
|
-
fetchEventSource,
|
|
12
|
-
} from '@microsoft/fetch-event-source';
|
|
13
|
-
import { merge } from 'lodash-es';
|
|
14
|
-
import qs from 'qs';
|
|
15
|
-
import { notNilEmpty } from 'qx-util';
|
|
16
|
-
import { mergeDeepRight } from 'ramda';
|
|
17
|
-
import { HttpError } from '../../error';
|
|
18
|
-
import { CoreInterceptor } from '../interceptor';
|
|
19
|
-
import { Interceptor } from '../interceptor/interceptor';
|
|
20
|
-
import { IHttpResponse } from './http-response';
|
|
21
|
-
import { getToken } from '../util/util';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 全局请求工具类
|
|
25
|
-
*
|
|
26
|
-
* @author chitanda
|
|
27
|
-
* @date 2022-07-14 15:07:42
|
|
28
|
-
* @export
|
|
29
|
-
* @class Net
|
|
30
|
-
*/
|
|
31
|
-
export class Net {
|
|
32
|
-
/**
|
|
33
|
-
* axios实例
|
|
34
|
-
*
|
|
35
|
-
* @author lxm
|
|
36
|
-
* @date 2022-10-27 17:10:18
|
|
37
|
-
* @protected
|
|
38
|
-
* @type {AxiosInstance}
|
|
39
|
-
*/
|
|
40
|
-
protected instance: AxiosInstance;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 是否为 http || https 开头
|
|
44
|
-
*
|
|
45
|
-
* @author chitanda
|
|
46
|
-
* @date 2022-11-07 14:11:28
|
|
47
|
-
* @protected
|
|
48
|
-
*/
|
|
49
|
-
protected urlReg = /^http[s]?:\/\/[^\s]*/;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 请求等待队列,防止重复请求。当有完全相同请求参数的请求时,会等待上一个请求完成后把结果返回给当前请求,不会重复请求
|
|
53
|
-
* key: 由请求的 config 生成的字符串,用于唯一标识请求
|
|
54
|
-
* value: 当前正在请求的 Promise
|
|
55
|
-
*
|
|
56
|
-
* @author chitanda
|
|
57
|
-
* @date 2023-06-07 14:06:19
|
|
58
|
-
* @protected
|
|
59
|
-
*/
|
|
60
|
-
protected waitRequest = new Map<string, Promise<AxiosResponse>>();
|
|
61
|
-
|
|
62
|
-
protected get baseUrl(): string {
|
|
63
|
-
return (
|
|
64
|
-
this.instance.defaults.baseURL || `${ibiz.env.baseUrl}/${ibiz.env.appId}`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Creates an instance of Net.
|
|
70
|
-
* @author lxm
|
|
71
|
-
* @date 2022-10-27 16:10:05
|
|
72
|
-
* @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
|
|
73
|
-
*/
|
|
74
|
-
constructor(config?: CreateAxiosDefaults) {
|
|
75
|
-
this.instance = axios.create(config);
|
|
76
|
-
this.addInterceptor('Default', new CoreInterceptor());
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 注册的拦截器
|
|
81
|
-
*
|
|
82
|
-
* @author lxm
|
|
83
|
-
* @date 2022-10-27 17:10:18
|
|
84
|
-
* @type {Map<string, Interceptor>}
|
|
85
|
-
*/
|
|
86
|
-
interceptors: Map<string, Interceptor> = new Map();
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 添加拦截器
|
|
90
|
-
*
|
|
91
|
-
* @author lxm
|
|
92
|
-
* @date 2022-10-27 17:10:42
|
|
93
|
-
* @param {string} name 唯一标识
|
|
94
|
-
* @param {Interceptor} interceptor 拦截器
|
|
95
|
-
*/
|
|
96
|
-
addInterceptor(name: string, interceptor: Interceptor): void {
|
|
97
|
-
interceptor.use(this.instance);
|
|
98
|
-
this.interceptors.set(name, interceptor);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 删除拦截器
|
|
103
|
-
*
|
|
104
|
-
* @author lxm
|
|
105
|
-
* @date 2022-10-27 17:10:27
|
|
106
|
-
* @param {string} name 唯一标识
|
|
107
|
-
*/
|
|
108
|
-
removeInterceptor(name: string): void {
|
|
109
|
-
const interceptor = this.interceptors.get(name);
|
|
110
|
-
if (interceptor) {
|
|
111
|
-
interceptor.eject(this.instance);
|
|
112
|
-
this.interceptors.delete(name);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 预置config,绑定动态的配置
|
|
118
|
-
*
|
|
119
|
-
* @author lxm
|
|
120
|
-
* @date 2022-10-27 16:10:48
|
|
121
|
-
* @readonly
|
|
122
|
-
* @protected
|
|
123
|
-
* @type {AxiosRequestConfig}
|
|
124
|
-
*/
|
|
125
|
-
protected get presetConfig(): AxiosRequestConfig {
|
|
126
|
-
return {
|
|
127
|
-
// 请求前缀路径
|
|
128
|
-
baseURL: this.baseUrl,
|
|
129
|
-
headers: {
|
|
130
|
-
'Content-Type': 'application/json;charset=UTF-8',
|
|
131
|
-
Accept: 'application/json',
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* 从左到右递归合并配置参数(内置第一个合并的预置参数)
|
|
138
|
-
*
|
|
139
|
-
* @author lxm
|
|
140
|
-
* @date 2022-10-27 16:10:09
|
|
141
|
-
* @protected
|
|
142
|
-
* @param {...AxiosRequestConfig[]} configs
|
|
143
|
-
* @returns {*}
|
|
144
|
-
*/
|
|
145
|
-
protected mergeConfig(...configs: AxiosRequestConfig[]): AxiosRequestConfig {
|
|
146
|
-
const config = this.presetConfig;
|
|
147
|
-
if (configs.length === 0) {
|
|
148
|
-
return config;
|
|
149
|
-
}
|
|
150
|
-
const { url } = configs[0];
|
|
151
|
-
if (url && this.urlReg.test(url)) {
|
|
152
|
-
delete config.baseURL;
|
|
153
|
-
}
|
|
154
|
-
return merge(config, ...configs);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Post 请求
|
|
159
|
-
*
|
|
160
|
-
* @author chitanda
|
|
161
|
-
* @date 2022-10-19 11:10:30
|
|
162
|
-
* @param {string} url
|
|
163
|
-
* @param {IData} data
|
|
164
|
-
* @param {IParams} [params={}]
|
|
165
|
-
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
166
|
-
* @return {*} {Promise<IHttpResponse>}
|
|
167
|
-
*/
|
|
168
|
-
async post(
|
|
169
|
-
url: string,
|
|
170
|
-
data: IData,
|
|
171
|
-
params: IParams = {},
|
|
172
|
-
headers: RawAxiosRequestHeaders = {},
|
|
173
|
-
): Promise<IHttpResponse> {
|
|
174
|
-
url = this.handleAppPresetParam(url, params);
|
|
175
|
-
try {
|
|
176
|
-
const response = await this.request(url, {
|
|
177
|
-
method: 'post',
|
|
178
|
-
data,
|
|
179
|
-
headers,
|
|
180
|
-
});
|
|
181
|
-
return this.doResponseResult(response);
|
|
182
|
-
} catch (error) {
|
|
183
|
-
throw new HttpError(error as AxiosError);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Get 请求
|
|
189
|
-
*
|
|
190
|
-
* @author chitanda
|
|
191
|
-
* @date 2022-10-19 11:10:24
|
|
192
|
-
* @param {string} url
|
|
193
|
-
* @param {IParams} [params={}]
|
|
194
|
-
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
195
|
-
* @param {IParams} [option={}]
|
|
196
|
-
* @return {*} {Promise<IHttpResponse>}
|
|
197
|
-
*/
|
|
198
|
-
async get(
|
|
199
|
-
url: string,
|
|
200
|
-
params: IParams = {},
|
|
201
|
-
headers: RawAxiosRequestHeaders = {},
|
|
202
|
-
option: AxiosRequestConfig = {},
|
|
203
|
-
): Promise<IHttpResponse> {
|
|
204
|
-
url = this.attachUrlParam(url, params);
|
|
205
|
-
try {
|
|
206
|
-
const response = await this.request(
|
|
207
|
-
url,
|
|
208
|
-
merge({ method: 'get', headers }, option),
|
|
209
|
-
);
|
|
210
|
-
return this.doResponseResult(response);
|
|
211
|
-
} catch (error) {
|
|
212
|
-
throw new HttpError(error as AxiosError);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Delete 请求
|
|
218
|
-
*
|
|
219
|
-
* @author chitanda
|
|
220
|
-
* @date 2022-10-19 11:10:17
|
|
221
|
-
* @param {string} url
|
|
222
|
-
* @param {IParams} [params]
|
|
223
|
-
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
224
|
-
* @return {*} {Promise<IHttpResponse>}
|
|
225
|
-
*/
|
|
226
|
-
async delete(
|
|
227
|
-
url: string,
|
|
228
|
-
params?: IParams,
|
|
229
|
-
headers: RawAxiosRequestHeaders = {},
|
|
230
|
-
): Promise<IHttpResponse> {
|
|
231
|
-
url = this.handleAppPresetParam(url, params);
|
|
232
|
-
try {
|
|
233
|
-
const response = await this.request(url, { method: 'delete', headers });
|
|
234
|
-
return this.doResponseResult(response);
|
|
235
|
-
} catch (error) {
|
|
236
|
-
throw new HttpError(error as AxiosError);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Put 请求
|
|
242
|
-
*
|
|
243
|
-
* @author chitanda
|
|
244
|
-
* @date 2022-10-19 11:10:11
|
|
245
|
-
* @param {string} url
|
|
246
|
-
* @param {IData} data
|
|
247
|
-
* @param {IParams} [params={}]
|
|
248
|
-
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
249
|
-
* @return {*} {Promise<IHttpResponse>}
|
|
250
|
-
*/
|
|
251
|
-
async put(
|
|
252
|
-
url: string,
|
|
253
|
-
data: IData,
|
|
254
|
-
params: IParams = {},
|
|
255
|
-
headers: RawAxiosRequestHeaders = {},
|
|
256
|
-
): Promise<IHttpResponse> {
|
|
257
|
-
url = this.handleAppPresetParam(url, params);
|
|
258
|
-
try {
|
|
259
|
-
const response = await this.request(url, {
|
|
260
|
-
method: 'put',
|
|
261
|
-
data,
|
|
262
|
-
headers,
|
|
263
|
-
});
|
|
264
|
-
return this.doResponseResult(response);
|
|
265
|
-
} catch (error) {
|
|
266
|
-
throw new HttpError(error as AxiosError);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* 获取模型数据
|
|
272
|
-
*
|
|
273
|
-
* @author chitanda
|
|
274
|
-
* @date 2022-07-14 15:07:15
|
|
275
|
-
* @param {string} url
|
|
276
|
-
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
277
|
-
* @return {*} {Promise<IHttpResponse>}
|
|
278
|
-
*/
|
|
279
|
-
async getModel(
|
|
280
|
-
url: string,
|
|
281
|
-
headers: RawAxiosRequestHeaders = {},
|
|
282
|
-
): Promise<IHttpResponse> {
|
|
283
|
-
try {
|
|
284
|
-
const response = await this.instance.get(url, {
|
|
285
|
-
headers,
|
|
286
|
-
});
|
|
287
|
-
return this.doResponseResult(response);
|
|
288
|
-
} catch (error) {
|
|
289
|
-
throw new HttpError(error as AxiosError);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* 基础请求方法,会合并预置配置
|
|
295
|
-
*
|
|
296
|
-
* @author lxm
|
|
297
|
-
* @date 2022-10-27 14:10:06
|
|
298
|
-
* @param {string} url
|
|
299
|
-
* @param {AxiosRequestConfig} [config={}]
|
|
300
|
-
* @returns {*} {Promise<IHttpResponse>}
|
|
301
|
-
*/
|
|
302
|
-
async request(
|
|
303
|
-
url: string,
|
|
304
|
-
config: AxiosRequestConfig = {},
|
|
305
|
-
): Promise<IHttpResponse> {
|
|
306
|
-
// axios 请求参数配置
|
|
307
|
-
const cfg = this.mergeConfig({ url }, config);
|
|
308
|
-
// 当前请求的唯一标识
|
|
309
|
-
const key = JSON.stringify(cfg);
|
|
310
|
-
try {
|
|
311
|
-
let requestPromise: Promise<AxiosResponse> | null = null;
|
|
312
|
-
if (!this.waitRequest.has(key)) {
|
|
313
|
-
requestPromise = this.instance.request(cfg);
|
|
314
|
-
this.waitRequest.set(key, requestPromise);
|
|
315
|
-
} else {
|
|
316
|
-
requestPromise = this.waitRequest.get(key)!;
|
|
317
|
-
}
|
|
318
|
-
const response = await requestPromise;
|
|
319
|
-
// 当第一个请求完成后就删除等待队列中的请求
|
|
320
|
-
if (this.waitRequest.has(key)) {
|
|
321
|
-
this.waitRequest.delete(key);
|
|
322
|
-
}
|
|
323
|
-
return this.doResponseResult(response);
|
|
324
|
-
} catch (error) {
|
|
325
|
-
// 请求异常删除等待队列中的请求体
|
|
326
|
-
if (this.waitRequest.has(key)) {
|
|
327
|
-
this.waitRequest.delete(key);
|
|
328
|
-
}
|
|
329
|
-
throw new HttpError(error as AxiosError);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* 创建标准 axios 请求
|
|
335
|
-
*
|
|
336
|
-
* @author chitanda
|
|
337
|
-
* @date 2023-01-30 15:01:27
|
|
338
|
-
* @param {AxiosRequestConfig<IData>} config
|
|
339
|
-
* @return {*}
|
|
340
|
-
*/
|
|
341
|
-
axios(config: AxiosRequestConfig<IData>): Promise<AxiosResponse> {
|
|
342
|
-
return axios(config);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* 触发 sse 请求
|
|
347
|
-
*
|
|
348
|
-
* @author chitanda
|
|
349
|
-
* @date 2023-10-10 16:10:08
|
|
350
|
-
* @param {string} url
|
|
351
|
-
* @param {IParams} params
|
|
352
|
-
* @param {FetchEventSourceInit} [options={}]
|
|
353
|
-
* @return {*} {Promise<void>}
|
|
354
|
-
*/
|
|
355
|
-
async sse(
|
|
356
|
-
url: string,
|
|
357
|
-
params: IParams,
|
|
358
|
-
options: FetchEventSourceInit = {},
|
|
359
|
-
): Promise<void> {
|
|
360
|
-
url = this.attachUrlParam(this.baseUrl + url, params);
|
|
361
|
-
if (!options.headers) {
|
|
362
|
-
options.headers = {};
|
|
363
|
-
}
|
|
364
|
-
const headers = options.headers!;
|
|
365
|
-
// 补充基本认证信息
|
|
366
|
-
{
|
|
367
|
-
headers.Authorization = `Bearer ${getToken()}`;
|
|
368
|
-
let systemId = ibiz.env.dcSystem;
|
|
369
|
-
const { orgData } = ibiz;
|
|
370
|
-
if (orgData) {
|
|
371
|
-
if (orgData.systemid) {
|
|
372
|
-
systemId = orgData.systemid;
|
|
373
|
-
}
|
|
374
|
-
if (orgData.orgid) {
|
|
375
|
-
headers.srforgid = orgData.orgid;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
headers.srfsystemid = systemId;
|
|
379
|
-
}
|
|
380
|
-
const config = mergeDeepRight(
|
|
381
|
-
{
|
|
382
|
-
openWhenHidden: true,
|
|
383
|
-
method: 'POST',
|
|
384
|
-
},
|
|
385
|
-
options,
|
|
386
|
-
);
|
|
387
|
-
await fetchEventSource(url, config);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* 统一处理请求返回
|
|
392
|
-
*
|
|
393
|
-
* @author chitanda
|
|
394
|
-
* @date 2022-07-14 16:07:23
|
|
395
|
-
* @private
|
|
396
|
-
* @param {AxiosResponse} response
|
|
397
|
-
* @return {*} {IHttpResponse}
|
|
398
|
-
*/
|
|
399
|
-
private doResponseResult(response: AxiosResponse): IHttpResponse {
|
|
400
|
-
const res = response as IHttpResponse;
|
|
401
|
-
if (res.status >= 200 && res.status <= 299) {
|
|
402
|
-
res.ok = true;
|
|
403
|
-
const resData = res.data as unknown;
|
|
404
|
-
if (resData === '' || resData === null) {
|
|
405
|
-
res.data = undefined as unknown as IData;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return res;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* 处理平台预定义参数
|
|
413
|
-
*
|
|
414
|
-
* @author chitanda
|
|
415
|
-
* @date 2022-07-14 15:07:12
|
|
416
|
-
* @private
|
|
417
|
-
* @param {string} url
|
|
418
|
-
* @param {IParams} [params]
|
|
419
|
-
* @return {*} {string}
|
|
420
|
-
*/
|
|
421
|
-
private handleAppPresetParam(url: string, params?: IParams): string {
|
|
422
|
-
if (params) {
|
|
423
|
-
// const keys = Object.keys(params);
|
|
424
|
-
// const tempParam: IParams = {};
|
|
425
|
-
// keys.forEach((item: string) => {
|
|
426
|
-
// if (item.startsWith('srf') && notNilEmpty(params[item])) {
|
|
427
|
-
// tempParam[item] = params[item];
|
|
428
|
-
// }
|
|
429
|
-
// });
|
|
430
|
-
return this.attachUrlParam(url, params);
|
|
431
|
-
}
|
|
432
|
-
return url;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* url 附加请求参数,并处理路径的字符转换 encode
|
|
437
|
-
*
|
|
438
|
-
* @author chitanda
|
|
439
|
-
* @date 2022-07-14 15:07:34
|
|
440
|
-
* @private
|
|
441
|
-
* @param {string} url
|
|
442
|
-
* @param {IParams} params
|
|
443
|
-
* @return {*} {string}
|
|
444
|
-
*/
|
|
445
|
-
private attachUrlParam(url: string, params: IParams): string {
|
|
446
|
-
{
|
|
447
|
-
// url 转码
|
|
448
|
-
const urlSplit = url.split('?');
|
|
449
|
-
urlSplit[0] = urlSplit[0]
|
|
450
|
-
.split('/')
|
|
451
|
-
.map(item => encodeURIComponent(item))
|
|
452
|
-
.join('/');
|
|
453
|
-
url = urlSplit.length > 1 ? urlSplit.join('?') : urlSplit[0];
|
|
454
|
-
}
|
|
455
|
-
const strParams: string = qs.stringify(params);
|
|
456
|
-
if (notNilEmpty(strParams)) {
|
|
457
|
-
if (url.endsWith('?')) {
|
|
458
|
-
url = `${url}${strParams}`;
|
|
459
|
-
} else if (url.indexOf('?') !== -1 && url.endsWith('&')) {
|
|
460
|
-
url = `${url}${strParams}`;
|
|
461
|
-
} else if (url.indexOf('?') !== -1 && !url.endsWith('&')) {
|
|
462
|
-
url = `${url}&${strParams}`;
|
|
463
|
-
} else {
|
|
464
|
-
url = `${url}?${strParams}`;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
return url;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { mergeDeepRight } from 'ramda';
|
|
3
|
-
|
|
4
|
-
/** 默认配置参数 */
|
|
5
|
-
const IterateOpts = {
|
|
6
|
-
/** 子集合属性数组 */
|
|
7
|
-
childrenFields: ['children'],
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const BreakError = new Error('中断操作');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 获取子属性集合
|
|
14
|
-
* @author lxm
|
|
15
|
-
* @date 2023-04-20 08:54:32
|
|
16
|
-
* @param {IData} parent
|
|
17
|
-
* @param {string[]} fields 子集合可能的属性名称
|
|
18
|
-
* @return {*} {(IData[] | undefined)}
|
|
19
|
-
*/
|
|
20
|
-
function getChildField(parent: IData, fields: string[]): IData[] | undefined {
|
|
21
|
-
for (const field of fields) {
|
|
22
|
-
if (parent[field]?.length) {
|
|
23
|
-
return parent[field];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _recursiveIterate(
|
|
29
|
-
parent: IData,
|
|
30
|
-
callback: (item: any) => boolean | void,
|
|
31
|
-
opts?: Partial<typeof IterateOpts>,
|
|
32
|
-
): void {
|
|
33
|
-
const { childrenFields } = mergeDeepRight(IterateOpts, opts || {});
|
|
34
|
-
const children = getChildField(parent, childrenFields);
|
|
35
|
-
if (children?.length) {
|
|
36
|
-
for (const child of children) {
|
|
37
|
-
// 递归自身的子成员
|
|
38
|
-
const isBreak = callback(child);
|
|
39
|
-
// 如果回调返回true则退出
|
|
40
|
-
if (isBreak) {
|
|
41
|
-
throw BreakError;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 递归孙的成员
|
|
45
|
-
recursiveIterate(child, callback, opts);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 递归遍历子元素
|
|
52
|
-
* @author lxm
|
|
53
|
-
* @date 2023-04-23 09:07:06
|
|
54
|
-
* @export
|
|
55
|
-
* @param {IData} parent 父元素
|
|
56
|
-
* @param {(item: any) => boolean} callback 每一个子元素的回调
|
|
57
|
-
* @param {Partial<typeof IterateOpts>} [opts]
|
|
58
|
-
*/
|
|
59
|
-
export function recursiveIterate(
|
|
60
|
-
parent: IData,
|
|
61
|
-
callback: (item: any) => boolean | void,
|
|
62
|
-
opts?: Partial<typeof IterateOpts>,
|
|
63
|
-
): void {
|
|
64
|
-
try {
|
|
65
|
-
_recursiveIterate(parent, callback, opts);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
if (error !== BreakError) {
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** 默认配置参数 */
|
|
74
|
-
const CompareOpts = {
|
|
75
|
-
...IterateOpts,
|
|
76
|
-
/** 比较的属性 */
|
|
77
|
-
compareField: 'name',
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
type ICompareOpts = Partial<typeof CompareOpts> & {
|
|
81
|
-
/**
|
|
82
|
-
* 自定义比较回调
|
|
83
|
-
* @author lxm
|
|
84
|
-
* @date 2023-04-23 09:06:42
|
|
85
|
-
*/
|
|
86
|
-
compareCallback?: (
|
|
87
|
-
child: IData,
|
|
88
|
-
key: string,
|
|
89
|
-
compareField: string,
|
|
90
|
-
) => boolean;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 递归查找子元素
|
|
95
|
-
* @author lxm
|
|
96
|
-
* @date 2023-04-20 08:53:35
|
|
97
|
-
* @export
|
|
98
|
-
* @param {IData} parent 父对象
|
|
99
|
-
* @param {string} key 子元素的比较属性的值
|
|
100
|
-
* @param {ICompareOpts} [opts]
|
|
101
|
-
* @return {*} {(IData | undefined)}
|
|
102
|
-
*/
|
|
103
|
-
export function findRecursiveChild(
|
|
104
|
-
parent: IData,
|
|
105
|
-
key: string,
|
|
106
|
-
opts?: ICompareOpts,
|
|
107
|
-
): IData | undefined {
|
|
108
|
-
const { compareField, compareCallback } = mergeDeepRight(
|
|
109
|
-
CompareOpts,
|
|
110
|
-
opts || {},
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// 默认比较方法
|
|
114
|
-
const _compareCallback =
|
|
115
|
-
compareCallback ||
|
|
116
|
-
((child: IData): boolean => {
|
|
117
|
-
return child[compareField] === key;
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// 递归遍历,找到后中断遍历,返回找到项
|
|
121
|
-
let find;
|
|
122
|
-
recursiveIterate(
|
|
123
|
-
parent,
|
|
124
|
-
item => {
|
|
125
|
-
if (_compareCallback(item, key, compareField)) {
|
|
126
|
-
find = item;
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
opts,
|
|
131
|
-
);
|
|
132
|
-
return find;
|
|
133
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { notNilEmpty } from 'qx-util';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 字符串工具类
|
|
5
|
-
*
|
|
6
|
-
* @author chitanda
|
|
7
|
-
* @date 2021-04-23 20:04:27
|
|
8
|
-
* @export
|
|
9
|
-
* @class StringUtil
|
|
10
|
-
*/
|
|
11
|
-
export class StringUtil {
|
|
12
|
-
/**
|
|
13
|
-
* 上下文替换正则
|
|
14
|
-
*
|
|
15
|
-
* @author chitanda
|
|
16
|
-
* @date 2021-04-23 20:04:01
|
|
17
|
-
* @static
|
|
18
|
-
*/
|
|
19
|
-
static contextReg = /\$\{context.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 数据替换正则
|
|
23
|
-
*
|
|
24
|
-
* @author chitanda
|
|
25
|
-
* @date 2021-04-23 20:04:09
|
|
26
|
-
* @static
|
|
27
|
-
*/
|
|
28
|
-
static dataReg = /\$\{data.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 填充字符串中的数据
|
|
32
|
-
*
|
|
33
|
-
* @author chitanda
|
|
34
|
-
* @date 2021-04-23 20:04:17
|
|
35
|
-
* @static
|
|
36
|
-
* @param {string} str
|
|
37
|
-
* @param {*} [context]
|
|
38
|
-
* @param {*} [data]
|
|
39
|
-
* @return {*} {string}
|
|
40
|
-
*/
|
|
41
|
-
static fill(str: string, context?: IContext, data?: IData): string {
|
|
42
|
-
if (notNilEmpty(str)) {
|
|
43
|
-
if (notNilEmpty(context)) {
|
|
44
|
-
const strArr = str.match(this.contextReg);
|
|
45
|
-
strArr?.forEach(_key => {
|
|
46
|
-
const key = _key.slice(10, _key.length - 1);
|
|
47
|
-
str = str.replace(`\${context.${key}}`, context![key] || '');
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
if (notNilEmpty(data)) {
|
|
51
|
-
const strArr = str.match(this.dataReg);
|
|
52
|
-
strArr?.forEach(_key => {
|
|
53
|
-
const key = _key.slice(7, _key.length - 1);
|
|
54
|
-
str = str.replace(`\${data.${key}}`, data![key] || '');
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return str;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 设置远程样式表
|
|
3
|
-
*
|
|
4
|
-
* @author lxm
|
|
5
|
-
* @date 2023-02-09 05:46:49
|
|
6
|
-
* @export
|
|
7
|
-
* @param {string} url
|
|
8
|
-
* @returns {*} {Promise<void>}
|
|
9
|
-
*/
|
|
10
|
-
export async function setRemoteStyle(url: string): Promise<void> {
|
|
11
|
-
try {
|
|
12
|
-
const res = await ibiz.net.get(url);
|
|
13
|
-
const styleDom = document.createElement('style');
|
|
14
|
-
styleDom.setAttribute('title', 'app-style-css');
|
|
15
|
-
styleDom.innerText = res.data as unknown as string;
|
|
16
|
-
document.head.appendChild(styleDom);
|
|
17
|
-
} catch (error) {
|
|
18
|
-
ibiz.log.debug('加载远程样式表失败', url);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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<T extends (...args: any) => any>(
|
|
15
|
-
wait: number,
|
|
16
|
-
fun?: T,
|
|
17
|
-
params?: any[],
|
|
18
|
-
): Promise<ReturnType<T> | undefined> {
|
|
19
|
-
await new Promise(resolve => {
|
|
20
|
-
setTimeout(() => {
|
|
21
|
-
resolve(true);
|
|
22
|
-
}, wait);
|
|
23
|
-
});
|
|
24
|
-
if (fun) {
|
|
25
|
-
return fun(...(params || []));
|
|
26
|
-
}
|
|
27
|
-
}
|