@hzab/form-render 0.3.0 → 0.4.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 (36) hide show
  1. package/lib/index.js +1 -1
  2. package/lib/static/imgs/marker-icon_ab8bbcc8cb.svg +4 -0
  3. package/lib/static/imgs/picker-icon_24d725ef02.svg +5 -0
  4. package/lib/static/imgs/position-icon_5bcb8a742e.svg +6 -0
  5. package/lib/static/imgs/reset-icon_9edad62306.svg +5 -0
  6. package/package.json +4 -3
  7. package/src/common/location-utils.ts +21 -0
  8. package/src/components/DatePicker/index.tsx +89 -0
  9. package/src/components/LocationPicker/Map/AMap/common/loader.ts +59 -0
  10. package/src/components/LocationPicker/Map/AMap/common/utils.ts +137 -0
  11. package/src/components/LocationPicker/Map/AMap/index.jsx +44 -0
  12. package/src/components/LocationPicker/Map/AMap/index.less +4 -0
  13. package/src/components/LocationPicker/README.md +35 -0
  14. package/src/components/LocationPicker/assets/marker-icon.svg +4 -0
  15. package/src/components/LocationPicker/assets/picker-icon.svg +5 -0
  16. package/src/components/LocationPicker/assets/position-icon.svg +6 -0
  17. package/src/components/LocationPicker/assets/reset-icon.svg +5 -0
  18. package/src/components/LocationPicker/common/utils.ts +45 -0
  19. package/src/components/LocationPicker/components/MapSearch/index.jsx +61 -0
  20. package/src/components/LocationPicker/components/MapSearch/index.less +10 -0
  21. package/src/components/LocationPicker/components/ModalContent/index.less +81 -0
  22. package/src/components/LocationPicker/components/ModalContent/index.tsx +258 -0
  23. package/src/components/LocationPicker/components/Notice/index.tsx +14 -0
  24. package/src/components/LocationPicker/components/PickerInfo/index.less +21 -0
  25. package/src/components/LocationPicker/components/PickerInfo/index.tsx +100 -0
  26. package/src/components/LocationPicker/components/ResInfo/index.less +25 -0
  27. package/src/components/LocationPicker/components/ResInfo/index.tsx +58 -0
  28. package/src/components/LocationPicker/components/ResInfo/picker-icon.svg +5 -0
  29. package/src/components/LocationPicker/index.less +17 -0
  30. package/src/components/LocationPicker/index.tsx +199 -0
  31. package/src/components/LocationPicker/marker-icon.png +0 -0
  32. package/src/components/LocationPicker/servers/index.ts +121 -0
  33. package/src/components/TreeCheckbox/common/utils.ts +29 -40
  34. package/src/components/TreeCheckbox/index.tsx +13 -3
  35. package/src/components/UserSelect/index.tsx +1 -1
  36. package/src/components/index.tsx +3 -0
@@ -0,0 +1,258 @@
1
+ import { useEffect, useMemo, useRef, useState } from "react";
2
+ import { Spin, message } from "antd";
3
+ import { useField } from "@formily/react";
4
+ import { debounce } from "lodash";
5
+
6
+ import PickerInfo from "../PickerInfo";
7
+ import AMapCom from "../../Map/AMap";
8
+ import Notice from "../Notice";
9
+ import MapSearch from "../MapSearch";
10
+
11
+ import { getCurrentPosition } from "../../../../common/location-utils";
12
+ import { MapUtils } from "../../Map/AMap/common/utils";
13
+ import { getAddress } from "../../servers";
14
+ import { getPropsValue } from "../../common/utils";
15
+
16
+ import MarkerIcon from "../../assets/marker-icon.svg";
17
+ import PositionIcon from "../../assets/position-icon.svg";
18
+ import ResetIcon from "../../assets/reset-icon.svg";
19
+
20
+ import "./index.less";
21
+
22
+ export const ModalContent = (props) => {
23
+ const {
24
+ mode,
25
+ /**
26
+ * 选择器和地图的布局
27
+ * 水平 输入框在前 hor
28
+ * 垂直 输入框在前 ver
29
+ * 水平 输入框在后 hor-reverse
30
+ * 垂直 输入框在后 ver-reverse
31
+ */
32
+ layout = "ver",
33
+ // 是否允许搜索
34
+ hasSearch = true,
35
+ /**
36
+ *
37
+ isObjectRes
38
+ true: 把所有数据存放在一个对象中(该对象和其他表单项平级),对象 key 为当前项的 name
39
+ false: 所有数据打平放到当前的 data 中,和其他表单项平级
40
+ */
41
+ isObjectRes = true,
42
+ /**
43
+ * 打开地图时是否根据经纬度自动修正已填的地址
44
+ */
45
+ isAutoFixAddr = false,
46
+ /**
47
+ * 改变经纬度等数据的触发模式
48
+ * 移动地图:move
49
+ * 点击地图:click
50
+ */
51
+ changeMode = "click",
52
+ lonKey = "longitude",
53
+ latKey = "latitude",
54
+ addrKey = "address",
55
+ value,
56
+ // 搜索框是否自动搜索
57
+ isAutoSearch = true,
58
+ //
59
+ visible,
60
+ defaultLocation,
61
+ disabled,
62
+ readOnly,
63
+ } = props;
64
+
65
+ const field: any = useField();
66
+
67
+ const mapUtilsRef = useRef<MapUtils>();
68
+
69
+ // 数据格式转为内部格式,方便存取
70
+ const formatVal = useMemo(
71
+ () =>
72
+ getPropsValue(value, field, {
73
+ isObjectRes,
74
+ lonKey,
75
+ latKey,
76
+ addrKey,
77
+ }),
78
+ [isObjectRes, lonKey, latKey, addrKey, value, field.data],
79
+ );
80
+ const [loading, setLoading] = useState(false);
81
+ const [addrLoading, setAddrLoading] = useState(false);
82
+ // 地图选点组件选中的值
83
+ const [pickInfo, setPickInfo] = useState(formatVal);
84
+
85
+ useEffect(() => {
86
+ if (visible) {
87
+ let _lon = defaultLocation.lon;
88
+ let _lat = defaultLocation.lat;
89
+ if (formatVal.lon && formatVal.lat) {
90
+ _lon = formatVal.lon;
91
+ _lat = formatVal.lat;
92
+ }
93
+ // 解决关闭弹窗之后点位不居中的问题
94
+ if (window.AMap && window.AMap.LngLat) {
95
+ setMapCenter(_lon, _lat);
96
+ }
97
+ setPickPoint(_lon, _lat, { isAutoFixAddr: false });
98
+ }
99
+ }, [visible, formatVal, changeMode]);
100
+
101
+ function mapInit({ map, mapUtils }) {
102
+ mapUtilsRef.current = mapUtils;
103
+ let _lon = defaultLocation.lon;
104
+ let _lat = defaultLocation.lat;
105
+ if (pickInfo.lon && pickInfo.lat) {
106
+ _lon = pickInfo.lon;
107
+ _lat = pickInfo.lat;
108
+ }
109
+ setPickPoint(_lon, _lat, { isAutoFixAddr });
110
+
111
+ setMapCenter(_lon, _lat);
112
+ setLoading(false);
113
+ if (!(disabled || readOnly)) {
114
+ if (changeMode === "click") {
115
+ mapUtilsRef.current?.setPickerMarker(_lon, _lat);
116
+ // 点击选中点位的情况
117
+ mapUtilsRef.current.on("click", function (ev) {
118
+ const { lng: evLon, lat: evLat } = ev.lnglat || {};
119
+ setPickPoint(evLon, evLat, { changeCenter: true });
120
+ });
121
+ } else {
122
+ // 移动地图
123
+ mapUtilsRef.current.on(
124
+ "mouseup",
125
+ debounce(function (ev) {
126
+ let currentCenter = mapUtilsRef.current?.getCenter();
127
+ const { lng: centerLon, lat: centerLat } = currentCenter || {};
128
+ // 移动选中点位的情况
129
+ let _lon = centerLon;
130
+ let _lat = centerLat;
131
+ setPickPoint(_lon, _lat);
132
+ }, 1000),
133
+ );
134
+ }
135
+ } else {
136
+ // 禁用、只读情况使用 marker 展示点位
137
+ mapUtilsRef.current?.setPickerMarker(_lon, _lat);
138
+ }
139
+ }
140
+
141
+ /**
142
+ * 设置地图中心点
143
+ * @param lon
144
+ * @param lat
145
+ */
146
+ function setMapCenter(lon = pickInfo.lon, lat = pickInfo.lat) {
147
+ mapUtilsRef.current?.setCenter(lon, lat);
148
+ }
149
+
150
+ async function setPickPoint(_lon, _lat, opt?: any) {
151
+ const { isAutoFixAddr: _isAutoFixAddr = isAutoFixAddr || true, changeCenter } = opt || {};
152
+ const lon = _lon || pickInfo.lon;
153
+ const lat = _lat || pickInfo.lat;
154
+ // 禁用、只读情况使用 marker 展示点位
155
+ if (changeMode === "click" || disabled || readOnly) {
156
+ mapUtilsRef.current?.setPickerMarker(_lon, _lat);
157
+ }
158
+ if (changeCenter) {
159
+ setMapCenter(_lon, _lat);
160
+ }
161
+ const addr = _isAutoFixAddr || !pickInfo.addr ? await getAddr(lon, lat) : pickInfo.addr;
162
+ const res = { ...pickInfo, lon, lat, addr };
163
+ setPickInfo(res);
164
+ props.setPickInfo && props.setPickInfo(res);
165
+ }
166
+
167
+ function getAddr(_lng, _lat) {
168
+ return new Promise((resolve, reject) => {
169
+ if (!window.AMap) {
170
+ reject();
171
+ return new Error("window.AMap is not defined");
172
+ }
173
+
174
+ setAddrLoading(true);
175
+ getAddress(_lng, _lat)
176
+ .then((addr) => {
177
+ setAddrLoading(false);
178
+ setPickInfo((_p) => ({ ..._p, addr }));
179
+ resolve(addr);
180
+ })
181
+ .catch((err) => {
182
+ reject(err);
183
+ message.error(err);
184
+ setAddrLoading(false);
185
+ });
186
+ });
187
+ }
188
+
189
+ function resetCenter() {
190
+ setMapCenter();
191
+ }
192
+
193
+ function getPosition() {
194
+ setLoading(true);
195
+ // 获取当前经纬度
196
+ getCurrentPosition()
197
+ .then((res) => {
198
+ const { coords = {} } = res;
199
+ setPickPoint(coords.longitude, coords.latitude, { changeCenter: true });
200
+ setLoading(false);
201
+ })
202
+ .catch((e) => {
203
+ setLoading(false);
204
+ message.error("定位获取失败");
205
+ console.warn("Error getCurrentPosition e: ", e);
206
+ });
207
+ }
208
+
209
+ // 展示已选点位恢复居中按钮:changeMode !== 'move' 或 禁用、只读模式。用于详情等只读情况恢复点位居中
210
+ const showResetCenter = changeMode !== "move" || disabled || readOnly;
211
+ // 展示获取当前定位按钮 props.showGetPositionBtn !== false 且非禁用、只读模式
212
+ const showGetPositionBtn = props.showGetPositionBtn !== false && !(disabled || readOnly);
213
+
214
+ const pickInfoRender = function () {
215
+ /* 点击/移动 地图选中的数据 */
216
+ return (
217
+ <PickerInfo
218
+ pickInfo={pickInfo}
219
+ setPickInfo={setPickInfo}
220
+ setPoint={setPickPoint}
221
+ addrLoading={addrLoading}
222
+ defaultLocation={defaultLocation}
223
+ disabled={disabled}
224
+ readOnly={readOnly}
225
+ />
226
+ );
227
+ };
228
+
229
+ return (
230
+ <div className={`location-picker-modal-content location-mode-${mode} location-modal-content-layout-${layout}`}>
231
+ {pickInfoRender()}
232
+ <div className="location-picker-map-wrap">
233
+ <div className="location-picker-map">
234
+ {/* 关闭弹窗之后清除搜索内容 */}
235
+ {hasSearch && visible ? <MapSearch setPoint={setPickPoint} isAutoSearch={isAutoSearch} /> : null}
236
+ <AMapCom init={mapInit} loading={loading} style={{ height: "500px" }} />
237
+ <div className="set-map-actions">
238
+ {/* 已选的点位居中 */}
239
+ {showResetCenter ? <img className="reset-icon" src={ResetIcon} onClick={resetCenter} /> : null}
240
+ {/* 获取当前经纬度 */}
241
+ {showGetPositionBtn ? <img className="center-icon" src={PositionIcon} onClick={getPosition} /> : null}
242
+ </div>
243
+ {changeMode !== "click" && !(disabled || readOnly) && (
244
+ <img className="location-picker-center-icon" src={MarkerIcon} />
245
+ )}
246
+ </div>
247
+ <Notice changeMode={changeMode} />
248
+ </div>
249
+ {loading && (
250
+ <div className="spin-loading-wrap">
251
+ <Spin className="spin-loading" />
252
+ </div>
253
+ )}
254
+ </div>
255
+ );
256
+ };
257
+
258
+ export default ModalContent;
@@ -0,0 +1,14 @@
1
+ import { Alert } from "antd";
2
+
3
+ export const Notice = (props) => {
4
+ return (
5
+ <Alert
6
+ className="location-picker-notice-bar"
7
+ message={props.changeMode === "click" ? "点击地图上的位置,选择目标地址" : "拖拽移动地图,中心标点为目标地址"}
8
+ type="info"
9
+ showIcon
10
+ />
11
+ );
12
+ };
13
+
14
+ export default Notice;
@@ -0,0 +1,21 @@
1
+ .location-picker-info {
2
+ padding: 12px;
3
+ .picker-info-lon,
4
+ .picker-info-lat,
5
+ .picker-info-addr {
6
+ display: flex;
7
+ margin-bottom: 8px;
8
+ .picker-info-label {
9
+ white-space: nowrap;
10
+ }
11
+ }
12
+ .picker-info-input {
13
+ min-width: 300px;
14
+ }
15
+ .picker-info-lon {
16
+ }
17
+ .picker-info-lat {
18
+ }
19
+ .picker-info-addr {
20
+ }
21
+ }
@@ -0,0 +1,100 @@
1
+ import { InputNumber, Spin } from "antd";
2
+
3
+ import "./index.less";
4
+
5
+ export const PickerInfo = (props) => {
6
+ const { pickInfo, setPickInfo, setPoint, addrLoading, defaultLocation, disabled, readOnly } = props;
7
+
8
+ function onPILonChange(e) {
9
+ const val = e?.target?.value ?? e;
10
+ let res = null;
11
+ setPickInfo((info) => {
12
+ res = {
13
+ ...info,
14
+ lon: val,
15
+ };
16
+ return res;
17
+ });
18
+ return res;
19
+ }
20
+
21
+ function onPILatChange(e) {
22
+ const val = e?.target?.value ?? e;
23
+ let res = null;
24
+ setPickInfo((info) => {
25
+ res = {
26
+ ...info,
27
+ lat: val,
28
+ };
29
+ return res;
30
+ });
31
+ return res;
32
+ }
33
+
34
+ /**
35
+ * 失去焦点之后,地图居中
36
+ * @param e
37
+ */
38
+ function onPILonBlur(e) {
39
+ const res = onPILonChange(e);
40
+ setPoint && setPoint(res.lon || defaultLocation.lon, res.lat || defaultLocation.lat, { changeCenter: true });
41
+ }
42
+
43
+ /**
44
+ * 失去焦点之后,地图居中
45
+ * @param e
46
+ */
47
+ function onPILatBlur(e) {
48
+ const res = onPILatChange(e);
49
+ setPoint && setPoint(res.lon || defaultLocation.lon, res.lat || defaultLocation.lat, { changeCenter: true });
50
+ }
51
+
52
+ return (
53
+ <div className="location-picker-info">
54
+ <div className="picker-info-position">
55
+ <div className="picker-info-lon">
56
+ <div className="picker-info-label">经度:</div>
57
+ {readOnly ? (
58
+ pickInfo.lon
59
+ ) : (
60
+ <InputNumber
61
+ className="picker-info-input"
62
+ disabled={disabled || addrLoading}
63
+ max={180}
64
+ min={-180}
65
+ controls={false}
66
+ value={pickInfo.lon}
67
+ onChange={onPILonChange}
68
+ onBlur={onPILonBlur}
69
+ onPressEnter={onPILonBlur}
70
+ />
71
+ )}
72
+ </div>
73
+ <div className="picker-info-lat">
74
+ <div className="picker-info-label">纬度:</div>
75
+ {readOnly ? (
76
+ pickInfo.lat
77
+ ) : (
78
+ <InputNumber
79
+ className="picker-info-input"
80
+ disabled={disabled || addrLoading}
81
+ max={90}
82
+ min={-90}
83
+ controls={false}
84
+ value={pickInfo.lat}
85
+ onChange={onPILatChange}
86
+ onBlur={onPILatBlur}
87
+ onPressEnter={onPILatBlur}
88
+ />
89
+ )}
90
+ </div>
91
+ </div>
92
+ <div className="picker-info-addr">
93
+ <div className="picker-info-label">地址:</div>
94
+ {addrLoading ? <Spin size="small" /> : pickInfo.addr}
95
+ </div>
96
+ </div>
97
+ );
98
+ };
99
+
100
+ export default PickerInfo;
@@ -0,0 +1,25 @@
1
+ .location-value-box {
2
+ .location-value-head-box {
3
+ display: flex;
4
+ .location-lon-lat {
5
+ flex: 1;
6
+ }
7
+ }
8
+
9
+ .location-btn {
10
+ padding: 4px 0;
11
+ padding-left: 5px;
12
+ line-height: 1;
13
+ &:focus {
14
+ background: transparent;
15
+ }
16
+ .location-picker-icon {
17
+ width: 16px;
18
+ margin-right: 4px;
19
+ }
20
+ .location-picker-text {
21
+ display: inline-block;
22
+ vertical-align: middle;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,58 @@
1
+ import { useMemo } from "react";
2
+ import { Button } from "antd";
3
+ import { useField } from "@formily/react";
4
+
5
+ import pickerIconDefault from "./picker-icon.svg";
6
+ import { getPropsValue } from "../../common/utils";
7
+
8
+ import "./index.less";
9
+
10
+ /**
11
+ * 展示 form 表单当前项的数据
12
+ * @param props
13
+ * @returns
14
+ */
15
+ export const ResInfo = (props) => {
16
+ const {
17
+ onShow,
18
+ isObjectRes,
19
+ lonKey,
20
+ latKey,
21
+ addrKey,
22
+ value,
23
+ pickerText = "选点",
24
+ pickerIcon,
25
+ pickerIconUrl,
26
+ } = props || {};
27
+ const field: any = useField();
28
+
29
+ // 数据格式转为内部格式,方便存取
30
+ const formatVal = useMemo(
31
+ () =>
32
+ getPropsValue(value, field, {
33
+ isObjectRes,
34
+ lonKey,
35
+ latKey,
36
+ addrKey,
37
+ }),
38
+ [isObjectRes, lonKey, latKey, addrKey, value, field.data],
39
+ );
40
+
41
+ return (
42
+ <div className="location-value-box">
43
+ <div className="location-value-head-box">
44
+ <div className="location-lon-lat">
45
+ <div>经度:{formatVal.lon} </div>
46
+ <div>纬度:{formatVal.lat}</div>
47
+ </div>
48
+ <Button className="location-btn" color="primary" type="text" onClick={onShow}>
49
+ {pickerIcon ? pickerIcon : <img className="location-picker-icon" src={pickerIconUrl || pickerIconDefault} />}
50
+ <span className="location-picker-text">{pickerText}</span>
51
+ </Button>
52
+ </div>
53
+ <div>地址:{formatVal.addr}</div>
54
+ </div>
55
+ );
56
+ };
57
+
58
+ export default ResInfo;
@@ -0,0 +1,5 @@
1
+ <svg t="1708305242338" class="icon" viewBox="0 0 1088 1024" version="1.1"
2
+ xmlns="http://www.w3.org/2000/svg" p-id="1494" width="200" height="200">
3
+ <path d="M812.224 416a288 288 0 1 0-576 0c0 118.144 94.528 272.128 288 456.576 193.472-184.448 288-338.432 288-456.576z m-288 544c-234.688-213.312-352-394.688-352-544a352 352 0 1 1 704 0c0 149.312-117.312 330.688-352 544z" fill="#1677ff" p-id="1495"></path>
4
+ <path d="M524.224 448a64 64 0 1 0 0-128 64 64 0 0 0 0 128z m0 64a128 128 0 1 1 0-256 128 128 0 0 1 0 256z m345.6 192l102.4 256h-288v-64h-320v64h-288l102.4-256h691.2z m-68.928 0H247.552l-76.8 192h706.944l-76.8-192z" fill="#1677ff" p-id="1496"></path>
5
+ </svg>
@@ -0,0 +1,17 @@
1
+ .location-picker {
2
+ .location-value-box {
3
+ .location-value-head-box {
4
+ display: flex;
5
+ .location-lon-lat {
6
+ flex: 1;
7
+ }
8
+ }
9
+ }
10
+ }
11
+
12
+ .location-picker-modal {
13
+ .ant-modal-body {
14
+ display: flex;
15
+ flex-direction: column;
16
+ }
17
+ }
@@ -0,0 +1,199 @@
1
+ import { useEffect, useMemo, useRef, useState } from "react";
2
+ import { Modal } from "antd";
3
+ import { useField, useFieldSchema } from "@formily/react";
4
+
5
+ import ResInfo from "./components/ResInfo";
6
+ import ModalContent from "./components/ModalContent";
7
+
8
+ import { MapUtils } from "./Map/AMap/common/utils";
9
+ import { getCurrentPosition } from "../../common/location-utils";
10
+
11
+ import { getParentValue } from "./common/utils";
12
+
13
+ import "./index.less";
14
+
15
+ const defaultLocation = {
16
+ lon: 120.168893,
17
+ lat: 30.225404,
18
+ addr: "浙江省杭州市上城区南星街道杭州西湖风景名胜区",
19
+ };
20
+
21
+ // 获取当前经纬度
22
+ getCurrentPosition()
23
+ .then((res) => {
24
+ const { coords = {} } = res;
25
+ defaultLocation.lon = coords.longitude;
26
+ defaultLocation.lat = coords.latitude;
27
+ })
28
+ .catch((e) => {
29
+ console.warn("Error getCurrentPosition e: ", e);
30
+ });
31
+
32
+ export function LocationPicker(props) {
33
+ const {
34
+ /**
35
+ * 地图显示类型:
36
+ * 弹窗 dialog
37
+ * 直接显示 show
38
+ */
39
+ mode = "dialog",
40
+ /**
41
+ * 选择器和地图的布局
42
+ * 水平 hor
43
+ * 垂直 ver
44
+ */
45
+ layout = "ver",
46
+ // 是否允许搜索
47
+ hasSearch = true,
48
+ /**
49
+ *
50
+ isObjectRes
51
+ true: 把所有数据存放在一个对象中(该对象和其他表单项平级),对象 key 为当前项的 name
52
+ false: 所有数据打平放到当前的 data 中,和其他表单项平级
53
+ */
54
+ isObjectRes = true,
55
+ /**
56
+ * 打开地图时是否根据经纬度自动修正已填的地址
57
+ */
58
+ isAutoFixAddr = false,
59
+ /**
60
+ * 改变经纬度等数据的触发模式
61
+ * 移动地图 move
62
+ * 点击地图 click
63
+ */
64
+ changeMode = "click",
65
+ lonKey = "longitude",
66
+ latKey = "latitude",
67
+ addrKey = "address",
68
+ value,
69
+ // 搜索框是否自动搜索
70
+ isAutoSearch = true,
71
+ modalConf = {},
72
+ } = props;
73
+ const field: any = useField();
74
+ const fieldSchema = useFieldSchema();
75
+
76
+ const mapUtilsRef = useRef<MapUtils>();
77
+ const pickInfoRef = useRef(defaultLocation);
78
+
79
+ const [visible, setVisible] = useState(false);
80
+
81
+ function onShow() {
82
+ // 等待地图加载完毕
83
+ !mapUtilsRef.current && setVisible(true);
84
+ setVisible(true);
85
+ }
86
+
87
+ function onClose() {
88
+ setVisible(false);
89
+ }
90
+
91
+ function onChange(res = pickInfoRef.current) {
92
+ const info = res || pickInfoRef.current;
93
+ const _res = {
94
+ [lonKey]: info.lon,
95
+ [latKey]: info.lat,
96
+ [addrKey]: info.addr,
97
+ };
98
+ props.onChange && props.onChange(_res);
99
+ if (isObjectRes === false) {
100
+ // 只有一层的情况
101
+ if (!field.parent) {
102
+ field.form.setValues(_res);
103
+ } else if (field.parent && fieldSchema.parent) {
104
+ // 嵌套在 ArrayBase: ArrayTable ArrayCard 等 里面的情况
105
+ const parentVal = getParentValue(field);
106
+ Object.keys(_res).forEach((key) => {
107
+ parentVal[key] = _res[key];
108
+ });
109
+ }
110
+ }
111
+ }
112
+
113
+ function onOk() {
114
+ onChange();
115
+ onClose();
116
+ }
117
+
118
+ function setResInfo(res) {
119
+ setPickInfo(res);
120
+ onChange(res);
121
+ }
122
+
123
+ function setPickInfo(res) {
124
+ pickInfoRef.current = res;
125
+ }
126
+
127
+ const isHor = layout === "hor" || layout === "hor-reverse";
128
+ const _props = {
129
+ disabled: props.disabled,
130
+ readOnly: props.readOnly,
131
+ /**
132
+ * 地图显示类型:
133
+ * 弹窗 dialog
134
+ * 直接显示 show
135
+ */
136
+ mode: mode ?? "dialog",
137
+ layout: layout ?? "ver",
138
+ /**
139
+ * 是否是水平布局
140
+ */
141
+ isHor,
142
+ // 是否允许搜索
143
+ hasSearch: hasSearch ?? true,
144
+ /**
145
+ *
146
+ isObjectRes
147
+ true: 把所有数据存放在一个对象中(该对象和其他表单项平级),对象 key 为当前项的 name
148
+ false: 所有数据打平放到当前的 data 中,和其他表单项平级
149
+ */
150
+ isObjectRes: isObjectRes ?? true,
151
+ /**
152
+ * 打开地图时是否根据经纬度自动修正已填的地址
153
+ */
154
+ isAutoFixAddr: isAutoFixAddr ?? false,
155
+ /**
156
+ * 改变经纬度等数据的触发模式
157
+ * 移动地图:move
158
+ * 点击地图:click
159
+ */
160
+ changeMode: changeMode ?? "click",
161
+ lonKey: lonKey ?? "longitude",
162
+ latKey: latKey ?? "latitude",
163
+ addrKey: addrKey ?? "address",
164
+ value,
165
+ // 搜索框是否自动搜索
166
+ isAutoSearch: isAutoSearch ?? true,
167
+ defaultLocation,
168
+ // 地图选点按钮的 icon 元素
169
+ pickerIcon: props.pickerIcon,
170
+ // 地图选点按钮的 icon img 的地址
171
+ pickerIconUrl: props.pickerIconUrl,
172
+ };
173
+
174
+ return (
175
+ <div className="location-picker">
176
+ {mode === "show" ? (
177
+ <ModalContent {..._props} visible={visible} setPickInfo={setResInfo} layout={layout} />
178
+ ) : (
179
+ <>
180
+ {/* 弹窗 */}
181
+ {/* 有弹窗时,显示表单选中的结果 */}
182
+ <ResInfo {..._props} onShow={onShow} />
183
+ <Modal
184
+ className="location-picker-modal"
185
+ title="地图选点"
186
+ onCancel={onClose}
187
+ onOk={onOk}
188
+ visible={visible}
189
+ width={modalConf?.width || isHor ? "1024px" : "720px"}
190
+ >
191
+ <ModalContent {..._props} visible={visible} setPickInfo={setPickInfo} layout={layout} />
192
+ </Modal>
193
+ </>
194
+ )}
195
+ </div>
196
+ );
197
+ }
198
+
199
+ export default LocationPicker;