react-base-client 1.0.151 → 1.1.0

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.
Files changed (33) hide show
  1. package/package.json +2 -3
  2. package/src/.umi/core/EmptyRoute.tsx +9 -0
  3. package/src/.umi/core/defineApp.ts +18 -0
  4. package/src/.umi/core/history.ts +64 -0
  5. package/src/.umi/core/plugin.ts +52 -0
  6. package/src/.umi/core/pluginConfig.d.ts +327 -0
  7. package/src/.umi/core/polyfill.ts +163 -0
  8. package/src/.umi/core/route.tsx +13 -0
  9. package/src/.umi/core/terminal.ts +38 -0
  10. package/src/.umi/exports.ts +19 -0
  11. package/src/.umi/plugin-access/context.ts +5 -0
  12. package/src/.umi/plugin-access/index.tsx +87 -0
  13. package/src/.umi/plugin-access/runtime.tsx +23 -0
  14. package/src/.umi/plugin-initialState/@@initialState.ts +50 -0
  15. package/src/.umi/plugin-initialState/Provider.tsx +19 -0
  16. package/src/.umi/plugin-initialState/runtime.tsx +8 -0
  17. package/src/.umi/plugin-initialState/runtimeConfig.d.ts +5 -0
  18. package/src/.umi/plugin-model/index.tsx +181 -0
  19. package/src/.umi/plugin-model/model.ts +8 -0
  20. package/src/.umi/plugin-model/runtime.tsx +20 -0
  21. package/src/.umi/plugin-request/index.ts +9 -0
  22. package/src/.umi/plugin-request/request.ts +265 -0
  23. package/src/.umi/plugin-request/runtimeConfig.d.ts +6 -0
  24. package/src/.umi/plugin-request/types.d.ts +10 -0
  25. package/src/.umi/testBrowser.tsx +88 -0
  26. package/src/.umi/tsconfig.json +35 -0
  27. package/src/.umi/typings.d.ts +136 -0
  28. package/src/.umi/umi.ts +74 -0
  29. package/src/components/AMap/index.tsx +90 -32
  30. package/src/components/AMap/typing.d.ts +41 -36
  31. package/src/components/SubmitForm/index.tsx +138 -133
  32. package/src/components/XAMap/index.tsx +167 -0
  33. package/tsconfig.json +0 -29
@@ -20,7 +20,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
20
20
  const mapLayers = props.mapLayers || (wmsJSON?.layers || []);
21
21
  const realTime = props.realTime || undefined;
22
22
  const showLayersPanel = props.showLayersPanel || false
23
- const [getMap, setMap] = useState<any>();
23
+ const mapRef = useRef<any>(null);
24
24
 
25
25
  const [getAMap, setAMap] = useState<any>();
26
26
 
@@ -32,7 +32,13 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
32
32
 
33
33
  const [intervalId, setIntervalId] = useState<NodeJS.Timeout | null>(null);
34
34
 
35
- const [layers, setLayers] = useState({});
35
+ const [layers, setLayers] = useState<Record<string, any>>({});
36
+
37
+ // 新增:持久化 layers 的 ref
38
+ const layersRef = useRef(layers);
39
+ useEffect(() => {
40
+ layersRef.current = layers;
41
+ }, [layers]);
36
42
 
37
43
  const [isCollapsed, setIsCollapsed] = useState(true);
38
44
 
@@ -99,7 +105,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
99
105
 
100
106
  const handleLocationClick = () => {
101
107
  console.log('>>>> 用户点击定位按钮,当前 followUserLocation:', followUserLocation);
102
- initMapCenter(getMap, true);
108
+ initMapCenter(mapRef.current, true);
103
109
  setFollowUserLocation(true);
104
110
  console.log('>>>> 已设置 followUserLocation 为 true');
105
111
  };
@@ -127,8 +133,8 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
127
133
  _lng: string | number,
128
134
  _lat: string | number,
129
135
  ) {
130
- getMap?.setZoomAndCenter?.(_grade, [_lng, _lat]);
131
- getMap?.getCenter?.();
136
+ mapRef.current?.setZoomAndCenter?.(_grade, [_lng, _lat]);
137
+ mapRef.current?.getCenter?.();
132
138
  }
133
139
  /**
134
140
  * 添加回调事件
@@ -207,7 +213,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
207
213
  */
208
214
  const upMapOnData = () => {
209
215
  for (const layerItem of getLayerAll) {
210
- getMap?.remove(layerItem);
216
+ mapRef.current?.remove(layerItem);
211
217
  }
212
218
  const labelsLayer = new AMap.LabelsLayer({
213
219
  zooms: [3, 20],
@@ -224,7 +230,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
224
230
  rowItem.f_latitude
225
231
  ) {
226
232
  setZommAndCenterView(
227
- getMap,
233
+ mapRef.current,
228
234
  15,
229
235
  rowItem.f_longitude,
230
236
  rowItem.f_latitude,
@@ -239,7 +245,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
239
245
  rowItem.f_latitude
240
246
  ) {
241
247
  setZommAndCenterView(
242
- getMap,
248
+ mapRef.current,
243
249
  15,
244
250
  rowItem.f_longitude,
245
251
  rowItem.f_latitude,
@@ -304,11 +310,11 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
304
310
  });
305
311
  marker.setMap(getMap);
306
312
  initSimpleInfoWdw(getAMap, rowItem, marker, getMap, i === props.rowData.length - 1);*/
307
- initSimpleInfoWdw(getAMap, rowItem, labelsMarker, getMap);
313
+ initSimpleInfoWdw(getAMap, rowItem, labelsMarker, mapRef.current);
308
314
  }
309
315
  }
310
316
  setLayerAll([labelsLayer, ...getLayerAll]);
311
- getMap.add(labelsLayer);
317
+ mapRef.current?.add(labelsLayer);
312
318
  };
313
319
  /**
314
320
  * 初始化地图
@@ -328,7 +334,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
328
334
  LAYERS: layer,
329
335
  VERSION: wmsJSON.wms.version,
330
336
  SRS: wmsJSON.wms.srs
331
- }
337
+ } as any
332
338
  });
333
339
  }
334
340
 
@@ -373,7 +379,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
373
379
  });
374
380
  } else {
375
381
  getLayerAll.forEach(layer => {
376
- layer.setMap(getMap);
382
+ layer.setMap(mapRef.current);
377
383
  });
378
384
  }
379
385
  return;
@@ -387,7 +393,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
387
393
  layer.wms.setMap(null);
388
394
  layer.isShow = false;
389
395
  } else {
390
- layer.wms.setMap(getMap);
396
+ layer.wms.setMap(mapRef.current);
391
397
  layer.isShow = true;
392
398
  }
393
399
  }
@@ -398,13 +404,13 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
398
404
  const [isMapSatellite, setIsMapSatellite] = useState(false);
399
405
  // 添加切换地图类型的函数
400
406
  const toggleMapType = () => {
401
- if (getMap) {
407
+ if (mapRef.current) {
402
408
  if (isMapSatellite) {
403
409
  // 切换回矢量地图
404
- getMap.setLayers([new AMap.TileLayer()]);
410
+ mapRef.current.setLayers([new AMap.TileLayer()]);
405
411
  } else {
406
412
  // 切换到卫星地图
407
- getMap.setLayers([
413
+ mapRef.current.setLayers([
408
414
  new AMap.TileLayer.Satellite(),
409
415
  new AMap.TileLayer.RoadNet()
410
416
  ]);
@@ -412,29 +418,81 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
412
418
  // 重新添加之前显示的 WMS 图层
413
419
  Object.values(layers).forEach((layer: any) => {
414
420
  if (layer.isShow) {
415
- layer.wms.setMap(getMap);
421
+ layer.wms.setMap(mapRef.current);
416
422
  }
417
423
  });
418
424
 
419
425
  setIsMapSatellite(!isMapSatellite);
420
426
  }
421
427
  };
422
- // 修改setupMapEvents函数,使用正确的事件名称并添加日志
428
+ // 新增: 获取WMS图层feature属性
429
+ const handleMapClickForWMS = async (e: any) => {
430
+ if (!props.wmsJSON || !props.onWmsFeatureClick) return;
431
+ const wms = props.wmsJSON.wms;
432
+ if (!wms) return;
433
+ const map = mapRef.current;
434
+ if (!map) return;
435
+ const size = map.getSize();
436
+ const bounds = map.getBounds();
437
+ const sw = bounds.getSouthWest();
438
+ const ne = bounds.getNorthEast();
439
+ const bbox = [sw.lng, sw.lat, ne.lng, ne.lat].join(',');
440
+ const xy = map.lngLatToContainer([e.lnglat.lng, e.lnglat.lat]);
441
+ const version = wms.version || '1.1.1';
442
+
443
+ // 修改:始终获取最新的 layers
444
+ const visibleLayers = Object.values(layersRef.current).filter(l => l.isShow);
445
+
446
+ for (let i = 0; i < visibleLayers.length; i++) {
447
+ const layer = visibleLayers[i];
448
+ const params: any = {
449
+ SERVICE: 'WMS',
450
+ VERSION: version,
451
+ REQUEST: 'GetFeatureInfo',
452
+ FORMAT: 'image/png',
453
+ TRANSPARENT: 'true',
454
+ QUERY_LAYERS: layer.layerName,
455
+ LAYERS: layer.layerName,
456
+ TILED: 'true',
457
+ INFO_FORMAT: 'application/json',
458
+ CRS: 'EPSG:4326',
459
+ BBOX: bbox,
460
+ WIDTH: size.getWidth(),
461
+ HEIGHT: size.getHeight(),
462
+ };
463
+ if (version === '1.3.0') {
464
+ params.I = Math.round(xy.x);
465
+ params.J = Math.round(xy.y);
466
+ } else {
467
+ params.X = Math.round(xy.x);
468
+ params.Y = Math.round(xy.y);
469
+ }
470
+ const url = wms.phoneUrl + '?' + Object.keys(params).map(k => `${k}=${encodeURIComponent(params[k])}`).join('&');
471
+ try {
472
+ const res = await fetch(url);
473
+ const data = await res.json();
474
+ console.log('>>>> data: ', data);
475
+ if (data && data.features && data.features.length > 0) {
476
+ props.onWmsFeatureClick && props.onWmsFeatureClick(data.features[0].properties, data.features[0].geometry);
477
+ break; // 找到就退出
478
+ }
479
+ } catch (err) {
480
+ // 忽略错误,继续下一个
481
+ }
482
+ }
483
+ };
484
+ // 修改setupMapEvents,增加WMS点击监听
423
485
  const setupMapEvents = (map: any) => {
424
-
425
486
  map.on('dragend', () => {
426
- // >>>> 地图被拖动
427
487
  setFollowUserLocation(false);
428
488
  });
429
-
430
489
  map.on('zoomend', () => {
431
- // >>>> 地图缩放
432
490
  setFollowUserLocation(false);
433
491
  });
434
-
435
- map.on('click', () => {
436
- // >>>> 地图被点击
492
+ map.on('click', (e: any) => {
493
+ console.log('>>>> mapClick:');
437
494
  setFollowUserLocation(false);
495
+ handleMapClickForWMS(e);
438
496
  });
439
497
  };
440
498
 
@@ -456,7 +514,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
456
514
  });
457
515
 
458
516
  setAMap(AMap);
459
- setMap(_map);
517
+ mapRef.current = _map;
460
518
 
461
519
  // 确保地图完全加载后再设置事件监听
462
520
  _map.on('complete', () => {
@@ -475,10 +533,10 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
475
533
 
476
534
  // 管线初始化
477
535
  if (wmsJSON != null) {
478
- const layer = {}
479
- wmsJSON.layers.forEach((item: { layerName: string | number; phoneShow: any; }) => {
536
+ const layer: Record<string, any> = {}
537
+ wmsJSON.layers.forEach((item: { layerName: string | number; phoneShow: any; value?: any; }) => {
480
538
  const wmsTileLayer = getWms(item.layerName, wmsJSON)
481
- layer[item.layerName] = {
539
+ layer[item.layerName as string] = {
482
540
  isShow: item.phoneShow,
483
541
  wms: wmsTileLayer,
484
542
  layerName: item.layerName,
@@ -507,10 +565,10 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
507
565
  }, [props.mapId, props.wmsJSON, realTime]);
508
566
 
509
567
  useEffect(() => {
510
- if (getMap) {
568
+ if (mapRef.current) {
511
569
  upMapOnData();
512
570
  }
513
- }, [props.rowData, getMap]);
571
+ }, [props.rowData, mapRef.current]);
514
572
 
515
573
  useEffect(() => {
516
574
  positionPickerStartAndStop(getPositionPicker);
@@ -594,7 +652,7 @@ const AMapComponent = React.forwardRef<any, AMapType.Props>((props, ref) => {
594
652
  </button>
595
653
 
596
654
  {/* 只在展开状态下显示层按钮 */}
597
- {!isCollapsed && mapLayers && mapLayers.map(layer => (
655
+ {!isCollapsed && mapLayers && mapLayers.map((layer: any) => (
598
656
  <button
599
657
  key={layer.layerName}
600
658
  onClick={() => toggleLayer(layer.layerName, layer)}
@@ -1,36 +1,41 @@
1
- import { CSSProperties } from "react";
2
- declare namespace AMapType {
3
- type RowData = {
4
- f_longitude: number; // 经度
5
- f_latitude: number; // 纬度
6
- f_title?: any; // 显示标题
7
- f_context?: any; // 显示内容
8
- f_icon?: any; // 图标
9
- f_label?: any; // 标题
10
- f_isclose_window?: boolean | undefined; // 是否点击图标按钮打开对应的窗口[true不显示 false显示]
11
- callBack?: (event: any, rowData: any) => void;
12
- windowEventClassAndCallback?: Array<{ class: string, callback: (event: any, rowData: any) => void }>; // 参数1 自定义windw监听的class值 参数2 自定义windw的回调事件
13
- labelStyle?: TextStyle | undefined; // 标题样式
14
- [key: string]: any; //其他扩展内容
15
- }
16
-
17
- type dragMapSettingType = {
18
- mapModel: "dragMarker" | "dragMap" //地图模式 点拖拽和地图拖拽
19
- dragMapSuccessCallBack?: (rowData: any) => void //地图选点成功
20
- dragMapFailCallBack?: (rowData: any) => void //地图选点失败
21
- isGetLocation: boolean //是否获取当前位置信息
22
- getLoactionSuccessCallBack?: (rowData: any) => void // 获取当前位置信息成功
23
- getLoactionFailCallBack?: (rowData: any) => void // 获取当前位置信息失败
24
- }
25
-
26
- type Props = {
27
- realTime?: number | undefined
28
- mapStyle?: CSSProperties | undefined;
29
- mapId?: string | undefined;
30
- rowData: Array<RowData>;
31
- dragMapSetting?: dragMapSettingType;
32
- wmsJSON?: JSON | {}
33
- showLayersPanel?: boolean;
34
- }
35
-
36
- }
1
+ import { CSSProperties } from "react";
2
+ declare namespace AMapType {
3
+ type RowData = {
4
+ f_longitude: number; // 经度
5
+ f_latitude: number; // 纬度
6
+ f_title?: any; // 显示标题
7
+ f_context?: any; // 显示内容
8
+ f_icon?: any; // 图标
9
+ f_label?: any; // 标题
10
+ f_isclose_window?: boolean | undefined; // 是否点击图标按钮打开对应的窗口[true不显示 false显示]
11
+ callBack?: (event: any, rowData: any) => void;
12
+ windowEventClassAndCallback?: Array<{ class: string, callback: (event: any, rowData: any) => void }>; // 参数1 自定义windw监听的class值 参数2 自定义windw的回调事件
13
+ labelStyle?: TextStyle | undefined; // 标题样式
14
+ [key: string]: any; //其他扩展内容
15
+ }
16
+
17
+ type dragMapSettingType = {
18
+ mapModel: "dragMarker" | "dragMap" //地图模式 点拖拽和地图拖拽
19
+ dragMapSuccessCallBack?: (rowData: any) => void //地图选点成功
20
+ dragMapFailCallBack?: (rowData: any) => void //地图选点失败
21
+ isGetLocation: boolean //是否获取当前位置信息
22
+ getLoactionSuccessCallBack?: (rowData: any) => void // 获取当前位置信息成功
23
+ getLoactionFailCallBack?: (rowData: any) => void // 获取当前位置信息失败
24
+ }
25
+
26
+ type Props = {
27
+ realTime?: number | undefined
28
+ mapStyle?: CSSProperties | undefined;
29
+ mapId?: string | undefined;
30
+ rowData: Array<RowData>;
31
+ dragMapSetting?: dragMapSettingType;
32
+ wmsJSON?: any;
33
+ showLayersPanel?: boolean;
34
+ mapLayers?: Array<any>;
35
+ /**
36
+ * 点击 WMS 图层要素时的回调,返回 feature 属性
37
+ */
38
+ onWmsFeatureClick?: (featureProps: any, geometry: any) => void;
39
+ }
40
+
41
+ }
@@ -1,133 +1,138 @@
1
- // @ts-ignore
2
- import {
3
- Button,
4
- Form,
5
- FormItemProps,
6
- FormProps,
7
- Input,
8
- InputProps,
9
- TextArea,
10
- TextAreaProps,
11
- } from 'antd-mobile';
12
- import { FormInstance } from 'rc-field-form/es/interface';
13
- import React, { ReactNode } from 'react';
14
- import './index.less';
15
- import XSelectPicker, { XSelectProps } from '../XSelectPicker';
16
- import XDatePicker, { XDatePickerProps } from '../XDatePicker';
17
- import XLngLatAddress, { XLngLatAddressProps } from '../XLngLatAddress';
18
- import XImageUpload, { XImageUploadProps } from '../XImageUpload';
19
- import XSelectList, { XSelectListProps } from '../XSelectList';
20
- import { generateUUID } from '../../utils/util';
21
- export type RenderFormProps = FormProps & {
22
- items: Array<FormItem>;
23
- title?: ReactNode;
24
- id?: string;
25
- onFinish?: (values: any) => void;
26
- onValuesChange?: (changedValues: any, allValues: any) => void; // 添加这一行
27
- initialValues?: Record<string, any>;
28
- form?: FormInstance<any>;
29
- children?: React.ReactNode;
30
- hiddenSearch?: boolean;
31
- buttonText?: ReactNode;
32
- disabled?: boolean;
33
- };
34
- export type FormItem = FormItemProps & {
35
- type:
36
- | 'input'
37
- | 'select'
38
- | 'textarea'
39
- | 'date'
40
- | 'lnglat'
41
- | 'image'
42
- | 'selectlist';
43
- name: string;
44
- label: string;
45
- props?:
46
- | InputProps
47
- | XSelectProps
48
- | XDatePickerProps
49
- | XLngLatAddressProps
50
- | XImageUploadProps
51
- | TextAreaProps
52
- | XSelectListProps;
53
- };
54
- const RenderForm: React.FC<RenderFormProps> = (props) => {
55
- const {
56
- items,
57
- title,
58
- form,
59
- buttonText,
60
- onFinish,
61
- children,
62
- initialValues,
63
- disabled = false,
64
- hiddenSearch = false,
65
- id = generateUUID(),
66
- } = props;
67
- function wrapperItem(Component: any, item: FormItem, placeholder?: string) {
68
- const { name, label, props } = item;
69
- return (
70
- <div id={id + name} key={id + name}>
71
- <Form.Item {...item}>
72
- <Component {...props} placeholder={placeholder + label}></Component>
73
- </Form.Item>
74
- </div>
75
- );
76
- }
77
- const [newForm] = Form.useForm(form);
78
- return (
79
- <div className="add-render">
80
- <Form
81
- {...props}
82
- form={newForm}
83
- initialValues={initialValues}
84
- onFinish={onFinish}
85
- onValuesChange={props.onValuesChange} // 添加这一行
86
- disabled={disabled}
87
- className={hiddenSearch ? '' : 'add-render-form'}
88
- // {...hiddenConfig}
89
- >
90
- {title && <Form.Header>{title}</Form.Header>}
91
- {items.map((item: FormItem) => {
92
- const { type } = item;
93
- switch (type) {
94
- case 'input':
95
- return wrapperItem(Input, item, '请输入');
96
- case 'select':
97
- return wrapperItem(XSelectPicker, item, '请选择');
98
- case 'textarea':
99
- return wrapperItem(TextArea, item, '请输入');
100
- case 'date':
101
- return wrapperItem(XDatePicker, item, '请选择');
102
- case 'lnglat':
103
- return wrapperItem(XLngLatAddress, item, '请选择');
104
- case 'image':
105
- return wrapperItem(XImageUpload, item);
106
- case 'selectlist':
107
- return wrapperItem(XSelectList, item, '请选择');
108
- default:
109
- return <></>;
110
- }
111
- })}
112
- {children}
113
- </Form>
114
- {hiddenSearch ? (
115
- <></>
116
- ) : (
117
- <div style={{ padding: '15px 10px' }}>
118
- <Button
119
- block
120
- type="submit"
121
- color="primary"
122
- size="middle"
123
- onClick={() => newForm.submit()}
124
- >
125
- {buttonText || '提交'}
126
- </Button>
127
- </div>
128
- )}
129
- </div>
130
- );
131
- };
132
-
133
- export default RenderForm;
1
+ // @ts-ignore
2
+ import {
3
+ Button,
4
+ Form,
5
+ FormItemProps,
6
+ FormProps,
7
+ Input,
8
+ InputProps,
9
+ TextArea,
10
+ TextAreaProps,
11
+ } from 'antd-mobile';
12
+ import { FormInstance } from 'rc-field-form/es/interface';
13
+ import React, { ReactNode } from 'react';
14
+ import './index.less';
15
+ import XSelectPicker, { XSelectProps } from '../XSelectPicker';
16
+ import XDatePicker, { XDatePickerProps } from '../XDatePicker';
17
+ import XLngLatAddress, { XLngLatAddressProps } from '../XLngLatAddress';
18
+ import XImageUpload, { XImageUploadProps } from '../XImageUpload';
19
+ import XSelectList, { XSelectListProps } from '../XSelectList';
20
+ import XAMap, { XAMapProps } from '../XAMap';
21
+ import { generateUUID } from '../../utils/util';
22
+ export type RenderFormProps = FormProps & {
23
+ items: Array<FormItem>;
24
+ title?: ReactNode;
25
+ id?: string;
26
+ onFinish?: (values: any) => void;
27
+ onValuesChange?: (changedValues: any, allValues: any) => void; // 添加这一行
28
+ initialValues?: Record<string, any>;
29
+ form?: FormInstance<any>;
30
+ children?: React.ReactNode;
31
+ hiddenSearch?: boolean;
32
+ buttonText?: ReactNode;
33
+ disabled?: boolean;
34
+ };
35
+ export type FormItem = FormItemProps & {
36
+ type:
37
+ | 'input'
38
+ | 'select'
39
+ | 'textarea'
40
+ | 'date'
41
+ | 'lnglat'
42
+ | 'image'
43
+ | 'selectlist'
44
+ | 'aMap';
45
+ name: string;
46
+ label: string;
47
+ props?:
48
+ | InputProps
49
+ | XSelectProps
50
+ | XDatePickerProps
51
+ | XLngLatAddressProps
52
+ | XImageUploadProps
53
+ | TextAreaProps
54
+ | XSelectListProps
55
+ | XAMapProps;
56
+ };
57
+ const RenderForm: React.FC<RenderFormProps> = (props) => {
58
+ const {
59
+ items,
60
+ title,
61
+ form,
62
+ buttonText,
63
+ onFinish,
64
+ children,
65
+ initialValues,
66
+ disabled = false,
67
+ hiddenSearch = false,
68
+ id = generateUUID(),
69
+ } = props;
70
+ function wrapperItem(Component: any, item: FormItem, placeholder?: string) {
71
+ const { name, label, props } = item;
72
+ return (
73
+ <div id={id + name} key={id + name}>
74
+ <Form.Item {...item}>
75
+ <Component {...props} placeholder={placeholder + label}></Component>
76
+ </Form.Item>
77
+ </div>
78
+ );
79
+ }
80
+ const [newForm] = Form.useForm(form);
81
+ return (
82
+ <div className="add-render">
83
+ <Form
84
+ {...props}
85
+ form={newForm}
86
+ initialValues={initialValues}
87
+ onFinish={onFinish}
88
+ onValuesChange={props.onValuesChange} // 添加这一行
89
+ disabled={disabled}
90
+ className={hiddenSearch ? '' : 'add-render-form'}
91
+ // {...hiddenConfig}
92
+ >
93
+ {title && <Form.Header>{title}</Form.Header>}
94
+ {items.map((item: FormItem) => {
95
+ const { type } = item;
96
+ switch (type) {
97
+ case 'input':
98
+ return wrapperItem(Input, item, '请输入');
99
+ case 'select':
100
+ return wrapperItem(XSelectPicker, item, '请选择');
101
+ case 'textarea':
102
+ return wrapperItem(TextArea, item, '请输入');
103
+ case 'date':
104
+ return wrapperItem(XDatePicker, item, '请选择');
105
+ case 'lnglat':
106
+ return wrapperItem(XLngLatAddress, item, '请选择');
107
+ case 'image':
108
+ return wrapperItem(XImageUpload, item);
109
+ case 'selectlist':
110
+ return wrapperItem(XSelectList, item, '请选择');
111
+ case 'aMap':
112
+ return wrapperItem(XAMap, item, '点击查看');
113
+ default:
114
+ return <></>;
115
+ }
116
+ })}
117
+ {children}
118
+ </Form>
119
+ {hiddenSearch ? (
120
+ <></>
121
+ ) : (
122
+ <div style={{ padding: '15px 10px' }}>
123
+ <Button
124
+ block
125
+ type="submit"
126
+ color="primary"
127
+ size="middle"
128
+ onClick={() => newForm.submit()}
129
+ >
130
+ {buttonText || '提交'}
131
+ </Button>
132
+ </div>
133
+ )}
134
+ </div>
135
+ );
136
+ };
137
+
138
+ export default RenderForm;