@lingxiteam/ebe-utils 0.0.24 → 0.0.27

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.
@@ -1,6 +1,5 @@
1
1
  import { antPrefix } from '@/components/pcfactory/src/variables';
2
2
  import { CloseCircleFilled } from '@ant-design/icons';
3
- import { LocaleFunction } from '@lingxiteam/types';
4
3
  import {
5
4
  Button,
6
5
  ConfigProvider,
@@ -21,13 +20,9 @@ const openProgressMsg = (
21
20
  fileName: string,
22
21
  percentComplete: number,
23
22
  text: string,
24
- { getLocale = (k, p) => p ?? '' }: { getLocale: LocaleFunction },
25
23
  ) => {
26
24
  message.loading({
27
- icon: getLocale('ProgressComp.progressMsg', `${fileName} 正在${text}:`, {
28
- fileName,
29
- text,
30
- }),
25
+ icon: `${fileName} 正在${text}:`,
31
26
  content: openProgress(percentComplete),
32
27
  key,
33
28
  duration: 0,
@@ -66,12 +61,10 @@ const showProgressNotification = (config: {
66
61
  type?: 'error' | 'success' | 'process';
67
62
  btn: (onCancel: () => void) => any;
68
63
  loadingText?: string;
69
- getLocale: LocaleFunction;
70
64
  }) => {
71
- const getLocale = config.getLocale ?? ((k?: string, l?: string) => l ?? '');
72
65
  const {
73
66
  key,
74
- title = getLocale('derive', '导出'),
67
+ title = '导出',
75
68
  percent,
76
69
  onCancel,
77
70
  message,
@@ -93,17 +86,14 @@ const showProgressNotification = (config: {
93
86
  <ConfigProvider prefixCls={antPrefix} locale={zhCN}>
94
87
  <Popconfirm
95
88
  placement="bottomRight"
96
- title={getLocale(
97
- 'ProgressComp.cancelMessage',
98
- '取消将无法获得下载结果,请确认是否需要取消',
99
- )}
89
+ title={'取消将无法获得下载结果,请确认是否需要取消'}
100
90
  onConfirm={() => {
101
91
  onCancel?.();
102
92
  notification?.close(key);
103
93
  }}
104
94
  overlayClassName="ProgressComp-confirm"
105
95
  >
106
- <Button>{getLocale('cancelText', '取消')}</Button>
96
+ <Button>{'取消'}</Button>
107
97
  </Popconfirm>
108
98
  </ConfigProvider>
109
99
  );
@@ -118,7 +118,8 @@ const useBaseDataSource = <T extends BaseDataSourceType>(
118
118
  } else if (operateType === ARRAY_OPERATE_TYPE.DELETE) {
119
119
  ArrayUtil.remove(data, path, predicate);
120
120
  } else if (operateType === ARRAY_OPERATE_TYPE.REPLACE) {
121
- ArrayUtil.replace(data, path, value);
121
+ // 如果是数组,变化的值是一个 undefined 则应给一个空数组
122
+ ArrayUtil.replace(data, path, value || []);
122
123
  } else if (operateType === ARRAY_OPERATE_TYPE.UPDATE) {
123
124
  ArrayUtil.update(
124
125
  {
@@ -23,6 +23,12 @@ interface ApiType {
23
23
  importInsts: string;
24
24
  // 获取导出进度
25
25
  getImportExportApply: HTTPMehodFn;
26
+ // 根据 serviceCodes 获取内部服务字段
27
+ getSqlQueryColumnsList: HTTPMehodFn;
28
+ // 根据 busiObjectIds 获取业务对象字段
29
+ queryBusiObjectRowColumnsList: HTTPMehodFn;
30
+ // 获取服务编排出参字段
31
+ queryServiceResponseColumnsList: HTTPMehodFn;
26
32
  }
27
33
 
28
34
  const api: ApiType = {
@@ -54,6 +60,19 @@ const api: ApiType = {
54
60
  // 获取导出进度
55
61
  getImportExportApply: (params, appCtx) =>
56
62
  urlHelper.get('app/object/getImportExportApply', params, appCtx),
63
+ // 根据 serviceCodes 获取内部服务字段
64
+ getSqlQueryColumnsList: (params, appCtx) =>
65
+ urlHelper.get('app/sql/getSqlQueryColumnsList', params, appCtx),
66
+ // 根据 busiObjectIds 获取业务对象字段
67
+ queryBusiObjectRowColumnsList: (params, appCtx) =>
68
+ urlHelper.get('app/object/queryBusiObjectRowColumnsList', params, appCtx),
69
+ // 获取服务编排出参字段
70
+ queryServiceResponseColumnsList: (params, appCtx) =>
71
+ urlHelper.get(
72
+ 'app/orchestrationService/queryServiceResponseColumnsList',
73
+ params,
74
+ appCtx,
75
+ ),
57
76
  };
58
77
 
59
78
  export default api;
@@ -19,9 +19,464 @@ export const checkIsContains = (contents: any, containContent: any) => {
19
19
  }
20
20
  return String(contents).indexOf(containContent) !== -1;
21
21
  };
22
+
22
23
  const numberregex = /\d+/g;
23
24
  export const safeNumber = (str: string | number) => {
24
25
  return typeof str === 'string' && numberregex.test(str) && !isNaN(Number(str))
25
26
  ? Number(str)
26
27
  : str;
27
28
  };
29
+
30
+ /**
31
+ * 复制文本
32
+ * @param text 复制内容
33
+ */
34
+ export const copyText = (text: string) => {
35
+ return new Promise<void>((resolve, reject) => {
36
+ const textarea = document.createElement('textarea');
37
+ textarea.value = text;
38
+ textarea.setAttribute('readonly', 'readonly');
39
+ document.body.appendChild(textarea);
40
+ textarea.select();
41
+ if (document.execCommand('copy')) {
42
+ document.execCommand('copy');
43
+ resolve();
44
+ } else {
45
+ reject();
46
+ }
47
+ document.body.removeChild(textarea);
48
+ });
49
+ };
50
+
51
+ interface commonFunc {
52
+ (...args: any): any;
53
+ }
54
+
55
+ // 初始化百度地图
56
+ const initBaiduMap = (mapKey: string) =>
57
+ new Promise((resolve, reject) => {
58
+ if (typeof (window as any).BMap !== 'undefined') {
59
+ resolve((window as any).BMap);
60
+ return;
61
+ }
62
+ (window as any).onBMapCallback = () => {
63
+ // console.log('百度地图脚本初始化成功');
64
+ resolve((window as any).BMap);
65
+ };
66
+ // 将地图注册的信息插入到document中
67
+ const url = `https://api.map.baidu.com/api?v=3.0&ak=${mapKey}&callback=onBMapCallback`;
68
+ const mapScript = document.createElement('script');
69
+ mapScript.type = 'text/javascript';
70
+ mapScript.src = url;
71
+ mapScript.onerror = reject;
72
+ const [head] = document.getElementsByTagName('head') as any;
73
+ head.appendChild(mapScript);
74
+ });
75
+
76
+ const pointBaiduTranslate: commonFunc = (
77
+ convertor,
78
+ ggPoint,
79
+ successCallBack,
80
+ errorCallBask,
81
+ address,
82
+ { getLocale },
83
+ ) => {
84
+ convertor.translate([ggPoint], 5, 3, (data: any) => {
85
+ // console.log('转换后的坐标', data);
86
+ if (data.status === 0) {
87
+ successCallBack([data.points[0], address]);
88
+ } else {
89
+ errorCallBask(getLocale('sysAction.location.transformfail'));
90
+ }
91
+ });
92
+ };
93
+
94
+ const getBaiduCurrentLocation: commonFunc = (
95
+ geolocation,
96
+ geocoder,
97
+ locationAddress,
98
+ type,
99
+ convertor,
100
+ successCallBack,
101
+ errorCallBask,
102
+ timer,
103
+ { getLocale },
104
+ ) => {
105
+ geolocation.getCurrentPosition(
106
+ (r: any) => {
107
+ console.log(geolocation.getStatus());
108
+ console.log((window as any).BMAP_STATUS_SUCCESS);
109
+ if (geolocation.getStatus() === (window as any).BMAP_STATUS_SUCCESS) {
110
+ // console.log('获取定位:', r);
111
+ // 获取详细地址
112
+ if (locationAddress && locationAddress !== '') {
113
+ geocoder.getLocation(r.point, (address: any) => {
114
+ // console.log('定位地址:', address.address);
115
+ switch (type) {
116
+ case 'WGS84': // 大地坐标系 法律规定不支持转换
117
+ // pointTranslate(convertor, r.point, successCallBack, errorCallBask, r.address);
118
+ successCallBack([r.point, address]);
119
+ break;
120
+ case 'GCJ02': // 火星坐标系
121
+ pointBaiduTranslate(
122
+ convertor,
123
+ r.point,
124
+ successCallBack,
125
+ errorCallBask,
126
+ address,
127
+ { getLocale },
128
+ );
129
+ break;
130
+ default:
131
+ // 默认百度坐标系
132
+ successCallBack([r.point, address]);
133
+ break;
134
+ }
135
+ });
136
+ } else {
137
+ switch (type) {
138
+ case 'WGS84': // 大地坐标系 法律规定不支持转换
139
+ // pointTranslate(convertor, r.point, successCallBack, errorCallBask, r.address);
140
+ successCallBack([r.point, r.address]);
141
+ break;
142
+ case 'GCJ02': // 火星坐标系
143
+ pointBaiduTranslate(
144
+ convertor,
145
+ r.point,
146
+ successCallBack,
147
+ errorCallBask,
148
+ r.address,
149
+ { getLocale },
150
+ );
151
+ break;
152
+ default:
153
+ // 默认百度坐标系
154
+ successCallBack([r.point, r.address]);
155
+ break;
156
+ }
157
+ }
158
+ } else {
159
+ // console.log('定位失败:', r);
160
+ clearInterval(timer);
161
+ errorCallBask(getLocale('sysAction.localtion.fail'));
162
+ }
163
+ },
164
+ { enableHighAccuracy: true, maximumAge: 0, SDKLocation: true },
165
+ );
166
+ };
167
+
168
+ const getBaiduLocation: commonFunc = (
169
+ always,
170
+ type,
171
+ locationAddress,
172
+ successCallBack,
173
+ errorCallBask,
174
+ { getLocale },
175
+ ) => {
176
+ const geolocation = new (window as any).BMap.Geolocation();
177
+ const convertor = new (window as any).BMap.Convertor();
178
+ const geocoder = new (window as any).BMap.Geocoder();
179
+
180
+ // /**
181
+ // * 开启辅助定位
182
+ // */
183
+ // geolocation?.enableSDKLocation();
184
+ getBaiduCurrentLocation(
185
+ geolocation,
186
+ geocoder,
187
+ locationAddress,
188
+ type,
189
+ convertor,
190
+ successCallBack,
191
+ errorCallBask,
192
+ null,
193
+ { getLocale },
194
+ );
195
+ if (always && always !== '') {
196
+ // 持续定位 默认定位60次,间隔15秒
197
+ let times = 0;
198
+ const timer = setInterval(() => {
199
+ if (times > 60) {
200
+ clearInterval(timer);
201
+ }
202
+ times += 1;
203
+ getBaiduCurrentLocation(
204
+ geolocation,
205
+ geocoder,
206
+ locationAddress,
207
+ type,
208
+ convertor,
209
+ successCallBack,
210
+ errorCallBask,
211
+ timer,
212
+ { getLocale },
213
+ );
214
+ }, 15000);
215
+ }
216
+ };
217
+
218
+ // 初始化高德地图
219
+ const initGaoDeMap = (securityKey: string | null, mapKey: string) =>
220
+ new Promise((resolve, reject) => {
221
+ if (typeof (window as any).AMap !== 'undefined') {
222
+ resolve((window as any).AMap);
223
+ return;
224
+ }
225
+ (window as any)._AMapSecurityConfig = {
226
+ securityJsCode: securityKey || '',
227
+ };
228
+ (window as any).onAMapLoaded = () => {
229
+ resolve((window as any).AMap);
230
+ };
231
+ // 将地图注册的信息插入到document中
232
+ const url = `https://webapi.amap.com/maps?v=2.0&key=${mapKey}&callback=onAMapLoaded`;
233
+ const mapScript = document.createElement('script');
234
+ mapScript.type = 'text/javascript';
235
+ mapScript.src = url;
236
+ mapScript.onerror = reject;
237
+ const [head] = document.getElementsByTagName('head') as any;
238
+ head.appendChild(mapScript);
239
+ });
240
+
241
+ const pointTranslate: commonFunc = (
242
+ ggPoint,
243
+ successCallBack,
244
+ errorCallBask,
245
+ address,
246
+ { getLocale },
247
+ ) => {
248
+ // 高德转百度坐标
249
+ const xPI = (3.14159265358979324 * 3000.0) / 180.0;
250
+ const bdLng = Number(ggPoint.KL || ggPoint.lng);
251
+ const bdLat = Number(ggPoint.kT || ggPoint.lat);
252
+ const z =
253
+ Math.sqrt(bdLng * bdLng + bdLat * bdLat) + 0.00002 * Math.sin(bdLat * xPI);
254
+ const theTa = Math.atan2(bdLat, bdLng) + 0.000003 * Math.cos(bdLng * xPI);
255
+ const lng = z * Math.cos(theTa) + 0.0065;
256
+ const lat = z * Math.sin(theTa) + 0.006;
257
+ if (lng && lat) {
258
+ successCallBack([{ lng, lat }, address]);
259
+ } else {
260
+ errorCallBask(getLocale('sysAction.location.transformfail'));
261
+ }
262
+ };
263
+
264
+ const getCurrentLocation: commonFunc = (
265
+ geolocation,
266
+ locationAddress,
267
+ type,
268
+ successCallBack,
269
+ errorCallBask,
270
+ timer,
271
+ { getLocale },
272
+ ) => {
273
+ geolocation.getCurrentPosition((status: string, r: any) => {
274
+ if (status === 'complete') {
275
+ // console.log('获取定位:', r, status);
276
+ // 获取详细地址
277
+ if (locationAddress && locationAddress !== '') {
278
+ (window as any).AMap.plugin('AMap.Geocoder', () => {
279
+ const geocoder = new (window as any).AMap.Geocoder({});
280
+ geocoder.getAddress(
281
+ {
282
+ lng: r.position.KL || r.position.lng,
283
+ lat: r.position.kT || r.position.lat,
284
+ noAutofix: false,
285
+ },
286
+ (status: string, result: any) => {
287
+ let address = '获取详细地址失败';
288
+ if (status === 'complete' && result.regeocode) {
289
+ address = result.regeocode.formattedAddress;
290
+ } else {
291
+ address = `${address}: ${result}`;
292
+ }
293
+ switch (type) {
294
+ case 'WGS84': // 大地坐标系 法律规定不支持转换
295
+ // pointTranslate(convertor, r.point, successCallBack, errorCallBask, r.address);
296
+ successCallBack([r.position, address]);
297
+ break;
298
+ case 'GCJ02': // 火星坐标系
299
+ successCallBack([r.position, address]);
300
+ break;
301
+ default:
302
+ // 默认百度坐标系
303
+ pointTranslate(
304
+ r.position,
305
+ successCallBack,
306
+ errorCallBask,
307
+ address,
308
+ { getLocale },
309
+ );
310
+ break;
311
+ }
312
+ },
313
+ );
314
+ });
315
+ } else {
316
+ switch (type) {
317
+ case 'WGS84': // 大地坐标系 法律规定不支持转换
318
+ // pointTranslate(convertor, r.point, successCallBack, errorCallBask, r.address);
319
+ successCallBack([r.position, '']);
320
+ break;
321
+ case 'GCJ02': // 火星坐标系
322
+ successCallBack([r.position, '']);
323
+ break;
324
+ default:
325
+ // 默认百度坐标系
326
+ pointTranslate(r.position, successCallBack, errorCallBask, '', {
327
+ getLocale,
328
+ });
329
+ break;
330
+ }
331
+ }
332
+ } else {
333
+ // console.log('高德定位失败:', r);
334
+ clearInterval(timer);
335
+ errorCallBask(`${getLocale('sysAction.location.fail')}:${status}${r}`);
336
+ }
337
+ });
338
+ };
339
+
340
+ const getGaoDeLocation: commonFunc = (
341
+ always,
342
+ type,
343
+ locationAddress,
344
+ successCallBack,
345
+ errorCallBask,
346
+ { getLocale },
347
+ ) => {
348
+ (window as any).AMap.plugin('AMap.Geolocation', () => {
349
+ const geolocation = new (window as any).AMap.Geolocation({
350
+ timeout: 10000,
351
+ enableHighAccuracy: true,
352
+ });
353
+ // const convertor = new (window as any).AMap.Convertor();
354
+ getCurrentLocation(
355
+ geolocation,
356
+ locationAddress,
357
+ type,
358
+ successCallBack,
359
+ errorCallBask,
360
+ null,
361
+ { getLocale },
362
+ );
363
+ if (always && always !== '') {
364
+ // 持续定位 默认定位60次,间隔15秒
365
+ let times = 0;
366
+ const timer = setInterval(() => {
367
+ if (times > 60) {
368
+ clearInterval(timer);
369
+ }
370
+ times += 1;
371
+ getCurrentLocation(
372
+ geolocation,
373
+ locationAddress,
374
+ type,
375
+ successCallBack,
376
+ errorCallBask,
377
+ timer,
378
+ { getLocale },
379
+ );
380
+ }, 15000);
381
+ }
382
+ });
383
+ };
384
+
385
+ // export default {
386
+ // initBaiduMap,
387
+ // getBaiduLocation,
388
+ // };
389
+ interface LocalLocationParams {
390
+ mapKey: string;
391
+ mapType: string;
392
+ securityKey?: string;
393
+ locationAlways: boolean;
394
+ locationOutputType: string;
395
+ locationAddress: boolean;
396
+ }
397
+ interface LocalLocation {
398
+ longitude: string;
399
+ latitude: string;
400
+ locationInformation: string;
401
+ }
402
+ export const getLocalLocation = ({
403
+ securityKey = '',
404
+ mapType,
405
+ mapKey,
406
+ locationAlways,
407
+ locationOutputType,
408
+ locationAddress,
409
+ }: LocalLocationParams) => {
410
+ return new Promise<LocalLocation>((resolve, reject) => {
411
+ if (mapType === 'baidu') {
412
+ initBaiduMap(mapKey)
413
+ .then(() => {
414
+ // 百度地图注册成功
415
+ getBaiduLocation(
416
+ locationAlways,
417
+ locationOutputType,
418
+ locationAddress,
419
+ (opt: any) => {
420
+ // console.log('定位成功:', opt);
421
+ const [position] = opt;
422
+ const localLocation = {
423
+ longitude: position.lng,
424
+ latitude: position.lat,
425
+ locationInformation: '',
426
+ };
427
+ if (locationAddress) {
428
+ const address = opt[1];
429
+ localLocation.locationInformation = address;
430
+ }
431
+ resolve(localLocation);
432
+ },
433
+ (err: any) => {
434
+ reject(err);
435
+ // console.log('定位失败:', err);
436
+ },
437
+ // FIXME: getLocale
438
+ { getLocale: (a: any) => a },
439
+ );
440
+ })
441
+ .catch((err) => {
442
+ reject(err);
443
+ // 地图注册失败
444
+ // console.log('---注册失败:', err);
445
+ });
446
+ } else {
447
+ initGaoDeMap(securityKey, mapKey)
448
+ .then(() => {
449
+ getGaoDeLocation(
450
+ locationAlways,
451
+ locationOutputType,
452
+ locationAddress,
453
+ (opt: any) => {
454
+ // console.log('定位成功:', opt);
455
+ const [position] = opt;
456
+ const localLocation = {
457
+ longitude: position.KL || position.lng,
458
+ latitude: position.kT || position.lat,
459
+ locationInformation: '',
460
+ };
461
+ if (locationAddress) {
462
+ const address = opt[1];
463
+ localLocation.locationInformation = address;
464
+ }
465
+ resolve(localLocation);
466
+ },
467
+ (err: any) => {
468
+ // console.log('定位失败:', err);
469
+ reject(err);
470
+ },
471
+ // FIXME: getLocale
472
+ { getLocale: (a: any) => a },
473
+ );
474
+ })
475
+ .catch((err) => {
476
+ reject(err);
477
+ // 地图注册失败
478
+ // console.log('---注册失败:', err);
479
+ });
480
+ }
481
+ });
482
+ };
@@ -73,9 +73,12 @@ export const useComponentHoc = (
73
73
  setState({ value: v }),
74
74
  );
75
75
  if (syncComplete) {
76
- if (isFunction(propsTrigger)) {
77
- propsTrigger(v, ...resetProps);
78
- }
76
+ // setState 异步设置值,onChange 中存在同步取值的问题,会导致取到的是上一次的值
77
+ setTimeout(() => {
78
+ if (isFunction(propsTrigger)) {
79
+ propsTrigger(v, ...resetProps);
80
+ }
81
+ }, 10);
79
82
  }
80
83
  }, 20);
81
84
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxiteam/ebe-utils",
3
- "version": "0.0.24",
3
+ "version": "0.0.27",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -17,7 +17,7 @@
17
17
  "@babel/parser": "^7.12.12",
18
18
  "@babel/traverse": "^7.12.12",
19
19
  "@babel/types": "^7.12.12",
20
- "@lingxiteam/ebe": "0.0.24",
20
+ "@lingxiteam/ebe": "0.0.27",
21
21
  "cac": "^6.7.14",
22
22
  "fs-extra": "9.x"
23
23
  },