@hzab/form-render 0.4.2 → 0.5.1
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/lib/index.js +1 -1
- package/package.json +1 -1
- package/src/common/date-utils.ts +18 -0
- package/src/common/formily-utils.ts +13 -0
- package/src/components/DatePicker/index.tsx +74 -60
- package/src/components/LocationPicker/Map/AMap/common/loader.ts +1 -1
- package/src/components/LocationPicker/Map/AMap/common/utils.ts +14 -4
- package/src/components/LocationPicker/Map/AMap/index.jsx +3 -2
- package/src/components/LocationPicker/README.md +29 -21
- package/src/components/LocationPicker/assets/svg-icon.js +86 -0
- package/src/components/LocationPicker/common/utils.ts +2 -22
- package/src/components/LocationPicker/components/MapSearch/index.less +1 -1
- package/src/components/LocationPicker/components/ModalContent/index.less +17 -5
- package/src/components/LocationPicker/components/ModalContent/index.tsx +82 -72
- package/src/components/LocationPicker/components/Notice/index.tsx +1 -6
- package/src/components/LocationPicker/components/ResInfo/index.less +8 -2
- package/src/components/LocationPicker/components/ResInfo/index.tsx +14 -20
- package/src/components/LocationPicker/index.tsx +33 -86
- package/src/components/LocationPicker/servers/index.ts +54 -26
- package/src/components/Text/index.tsx +0 -2
- package/lib/static/imgs/marker-icon_ab8bbcc8cb.svg +0 -4
- package/lib/static/imgs/picker-icon_24d725ef02.svg +0 -5
- package/lib/static/imgs/position-icon_5bcb8a742e.svg +0 -6
- package/lib/static/imgs/reset-icon_9edad62306.svg +0 -5
- package/src/components/LocationPicker/assets/marker-icon.svg +0 -4
- package/src/components/LocationPicker/assets/picker-icon.svg +0 -5
- package/src/components/LocationPicker/assets/position-icon.svg +0 -6
- package/src/components/LocationPicker/assets/reset-icon.svg +0 -5
- package/src/components/LocationPicker/marker-icon.png +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from "react";
|
2
2
|
import { Spin, message } from "antd";
|
3
|
-
import {
|
3
|
+
import { observer } from "@formily/react";
|
4
4
|
import { debounce } from "lodash";
|
5
5
|
|
6
6
|
import PickerInfo from "../PickerInfo";
|
@@ -13,13 +13,15 @@ import { MapUtils } from "../../Map/AMap/common/utils";
|
|
13
13
|
import { getAddress } from "../../servers";
|
14
14
|
import { getPropsValue } from "../../common/utils";
|
15
15
|
|
16
|
-
import
|
17
|
-
|
18
|
-
|
16
|
+
import {
|
17
|
+
markerIcon as markerIconDef,
|
18
|
+
positionIcon as positionIconDef,
|
19
|
+
resetIcon as resetIconDef,
|
20
|
+
} from "../../assets/svg-icon";
|
19
21
|
|
20
22
|
import "./index.less";
|
21
23
|
|
22
|
-
export const ModalContent = (props) => {
|
24
|
+
export const ModalContent = observer((props: any) => {
|
23
25
|
const {
|
24
26
|
mode,
|
25
27
|
/**
|
@@ -32,23 +34,10 @@ export const ModalContent = (props) => {
|
|
32
34
|
layout = "ver",
|
33
35
|
// 是否允许搜索
|
34
36
|
hasSearch = true,
|
35
|
-
/**
|
36
|
-
*
|
37
|
-
isObjectRes
|
38
|
-
true: 把所有数据存放在一个对象中(该对象和其他表单项平级),对象 key 为当前项的 name
|
39
|
-
false: 所有数据打平放到当前的 data 中,和其他表单项平级
|
40
|
-
*/
|
41
|
-
isObjectRes = true,
|
42
37
|
/**
|
43
38
|
* 打开地图时是否根据经纬度自动修正已填的地址
|
44
39
|
*/
|
45
40
|
isAutoFixAddr = false,
|
46
|
-
/**
|
47
|
-
* 改变经纬度等数据的触发模式
|
48
|
-
* 移动地图:move
|
49
|
-
* 点击地图:click
|
50
|
-
*/
|
51
|
-
changeMode = "click",
|
52
41
|
lonKey = "longitude",
|
53
42
|
latKey = "latitude",
|
54
43
|
addrKey = "address",
|
@@ -57,88 +46,92 @@ export const ModalContent = (props) => {
|
|
57
46
|
isAutoSearch = true,
|
58
47
|
//
|
59
48
|
visible,
|
60
|
-
|
49
|
+
visibleKey,
|
50
|
+
defaultLocation = {},
|
61
51
|
disabled,
|
62
52
|
readOnly,
|
53
|
+
icons,
|
54
|
+
markerIconConf,
|
55
|
+
getCurPositionConf,
|
63
56
|
} = props;
|
64
57
|
|
65
|
-
const field: any = useField() || {};
|
66
|
-
|
67
58
|
const mapUtilsRef = useRef<MapUtils>();
|
68
59
|
|
69
60
|
// 数据格式转为内部格式,方便存取
|
70
61
|
const formatVal = useMemo(
|
71
62
|
() =>
|
72
|
-
getPropsValue(value,
|
73
|
-
isObjectRes,
|
63
|
+
getPropsValue(value, {
|
74
64
|
lonKey,
|
75
65
|
latKey,
|
76
66
|
addrKey,
|
77
67
|
}),
|
78
|
-
[
|
68
|
+
[lonKey, latKey, addrKey, value, value?.[lonKey], value?.[latKey], value?.[addrKey]],
|
79
69
|
);
|
70
|
+
|
80
71
|
const [loading, setLoading] = useState(props.loading || false);
|
81
72
|
const [addrLoading, setAddrLoading] = useState(false);
|
82
73
|
// 地图选点组件选中的值
|
83
74
|
const [pickInfo, setPickInfo] = useState(formatVal);
|
75
|
+
const pickerInfoRef = useRef(pickInfo);
|
76
|
+
|
77
|
+
const isShowMode = mode === "show";
|
84
78
|
|
85
79
|
useEffect(() => {
|
86
80
|
setLoading(props.loading);
|
87
81
|
}, [props.loading]);
|
88
82
|
|
89
83
|
useEffect(() => {
|
90
|
-
if (
|
84
|
+
if (isShowMode) {
|
85
|
+
// mode === 'show' 的情况
|
86
|
+
let _lon = formatVal.lon;
|
87
|
+
let _lat = formatVal.lat;
|
88
|
+
if (_lon && _lat && _lon !== pickInfo.lon && _lat !== pickInfo.lat) {
|
89
|
+
// 解决关闭弹窗之后点位不居中的问题
|
90
|
+
if (window.AMap && window.AMap.LngLat) {
|
91
|
+
setMapCenter(_lon, _lat);
|
92
|
+
setPickPoint(_lon, _lat, { isAutoFixAddr: false, addr: formatVal.addr });
|
93
|
+
}
|
94
|
+
}
|
95
|
+
} else if (visibleKey) {
|
96
|
+
// 处理弹窗展示数据回显逻辑
|
91
97
|
let _lon = defaultLocation.lon;
|
92
98
|
let _lat = defaultLocation.lat;
|
99
|
+
let addr = defaultLocation.addr;
|
93
100
|
if (formatVal.lon && formatVal.lat) {
|
94
101
|
_lon = formatVal.lon;
|
95
102
|
_lat = formatVal.lat;
|
103
|
+
addr = formatVal.addr;
|
96
104
|
}
|
97
105
|
// 解决关闭弹窗之后点位不居中的问题
|
98
106
|
if (window.AMap && window.AMap.LngLat) {
|
99
107
|
setMapCenter(_lon, _lat);
|
100
108
|
}
|
101
|
-
|
109
|
+
if (_lon && _lat && _lon !== pickerInfoRef.current?.lon && _lat !== pickerInfoRef.current?.lat) {
|
110
|
+
setPickPoint(_lon, _lat, { isAutoFixAddr: false, addr: addr });
|
111
|
+
}
|
102
112
|
}
|
103
|
-
}, [
|
113
|
+
}, [visibleKey, formatVal, isShowMode]);
|
104
114
|
|
105
115
|
function mapInit({ map, mapUtils }) {
|
106
116
|
mapUtilsRef.current = mapUtils;
|
107
|
-
let _lon = defaultLocation.lon;
|
108
|
-
let _lat = defaultLocation.lat;
|
117
|
+
let _lon = isShowMode ? undefined : defaultLocation.lon;
|
118
|
+
let _lat = isShowMode ? undefined : defaultLocation.lat;
|
109
119
|
if (pickInfo.lon && pickInfo.lat) {
|
110
120
|
_lon = pickInfo.lon;
|
111
121
|
_lat = pickInfo.lat;
|
112
122
|
}
|
113
|
-
setPickPoint(_lon, _lat, { isAutoFixAddr });
|
114
123
|
|
115
124
|
setMapCenter(_lon, _lat);
|
116
|
-
console.log("props.loading", props.loading);
|
117
125
|
|
118
126
|
setLoading(props.loading || false);
|
119
127
|
|
120
128
|
if (!(disabled || readOnly)) {
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
});
|
128
|
-
} else {
|
129
|
-
// 移动地图
|
130
|
-
mapUtilsRef.current.on(
|
131
|
-
"mouseup",
|
132
|
-
debounce(function (ev) {
|
133
|
-
let currentCenter = mapUtilsRef.current?.getCenter();
|
134
|
-
const { lng: centerLon, lat: centerLat } = currentCenter || {};
|
135
|
-
// 移动选中点位的情况
|
136
|
-
let _lon = centerLon;
|
137
|
-
let _lat = centerLat;
|
138
|
-
setPickPoint(_lon, _lat);
|
139
|
-
}, 1000),
|
140
|
-
);
|
141
|
-
}
|
129
|
+
mapUtilsRef.current?.setPickerMarker(_lon, _lat);
|
130
|
+
// 点击选中点位的情况
|
131
|
+
mapUtilsRef.current.on("click", function (ev) {
|
132
|
+
const { lng: evLon, lat: evLat } = ev.lnglat || {};
|
133
|
+
setPickPoint(evLon, evLat, { changeCenter: true });
|
134
|
+
});
|
142
135
|
} else {
|
143
136
|
// 禁用、只读情况使用 marker 展示点位
|
144
137
|
mapUtilsRef.current?.setPickerMarker(_lon, _lat);
|
@@ -151,23 +144,26 @@ export const ModalContent = (props) => {
|
|
151
144
|
* @param lat
|
152
145
|
*/
|
153
146
|
function setMapCenter(lon = pickInfo.lon, lat = pickInfo.lat) {
|
154
|
-
mapUtilsRef.current?.setCenter(lon, lat);
|
147
|
+
lon && lat && mapUtilsRef.current?.setCenter(lon, lat);
|
155
148
|
}
|
156
149
|
|
157
150
|
async function setPickPoint(_lon, _lat, opt?: any) {
|
158
|
-
const { isAutoFixAddr: _isAutoFixAddr = isAutoFixAddr || true, changeCenter } = opt || {};
|
151
|
+
const { isAutoFixAddr: _isAutoFixAddr = isAutoFixAddr || true, changeCenter, addr: _addr } = opt || {};
|
159
152
|
const lon = _lon || pickInfo.lon;
|
160
153
|
const lat = _lat || pickInfo.lat;
|
161
|
-
|
162
|
-
|
163
|
-
mapUtilsRef.current?.setPickerMarker(_lon, _lat);
|
164
|
-
}
|
154
|
+
let addr = _addr;
|
155
|
+
mapUtilsRef.current?.setPickerMarker(_lon, _lat);
|
165
156
|
if (changeCenter) {
|
166
157
|
setMapCenter(_lon, _lat);
|
167
158
|
}
|
168
|
-
|
159
|
+
|
160
|
+
// 开启自动修复地址 且 opt 参数中没有地址,请求地址
|
161
|
+
if (_isAutoFixAddr && !addr) {
|
162
|
+
addr = await getAddr(lon, lat);
|
163
|
+
}
|
169
164
|
const res = { ...pickInfo, lon, lat, addr };
|
170
165
|
setPickInfo(res);
|
166
|
+
pickerInfoRef.current = res;
|
171
167
|
props.setPickInfo && props.setPickInfo(res);
|
172
168
|
}
|
173
169
|
|
@@ -182,7 +178,10 @@ export const ModalContent = (props) => {
|
|
182
178
|
getAddress(_lng, _lat)
|
183
179
|
.then((addr) => {
|
184
180
|
setAddrLoading(false);
|
185
|
-
setPickInfo((_p) =>
|
181
|
+
setPickInfo((_p) => {
|
182
|
+
pickerInfoRef.current = { ..._p, addr };
|
183
|
+
return pickerInfoRef.current;
|
184
|
+
});
|
186
185
|
resolve(addr);
|
187
186
|
})
|
188
187
|
.catch((err) => {
|
@@ -200,7 +199,7 @@ export const ModalContent = (props) => {
|
|
200
199
|
function getPosition() {
|
201
200
|
setLoading(true);
|
202
201
|
// 获取当前经纬度
|
203
|
-
getCurrentPosition()
|
202
|
+
getCurrentPosition(getCurPositionConf)
|
204
203
|
.then((res) => {
|
205
204
|
const { coords = {} } = res;
|
206
205
|
setPickPoint(coords.longitude, coords.latitude, { changeCenter: true });
|
@@ -213,8 +212,6 @@ export const ModalContent = (props) => {
|
|
213
212
|
});
|
214
213
|
}
|
215
214
|
|
216
|
-
// 展示已选点位恢复居中按钮:changeMode !== 'move' 或 禁用、只读模式。用于详情等只读情况恢复点位居中
|
217
|
-
const showResetCenter = changeMode !== "move" || disabled || readOnly;
|
218
215
|
// 展示获取当前定位按钮 props.showGetPositionBtn !== false 且非禁用、只读模式
|
219
216
|
const showGetPositionBtn = props.showGetPositionBtn !== false && !(disabled || readOnly);
|
220
217
|
|
@@ -233,25 +230,38 @@ export const ModalContent = (props) => {
|
|
233
230
|
);
|
234
231
|
};
|
235
232
|
|
233
|
+
const { markerIcon, positionIcon, resetIcon } = icons || {};
|
234
|
+
|
236
235
|
return (
|
237
236
|
<div className={`location-picker-modal-content location-mode-${mode} location-modal-content-layout-${layout}`}>
|
238
237
|
{pickInfoRender()}
|
239
238
|
<div className="location-picker-map-wrap">
|
240
239
|
<div className="location-picker-map">
|
241
240
|
{/* 关闭弹窗之后清除搜索内容 */}
|
242
|
-
{hasSearch
|
243
|
-
<AMapCom init={mapInit} loading={loading}
|
241
|
+
{hasSearch ? <MapSearch key={visible} setPoint={setPickPoint} isAutoSearch={isAutoSearch} /> : null}
|
242
|
+
<AMapCom init={mapInit} loading={loading} markerIconConf={markerIconConf} />
|
244
243
|
<div className="set-map-actions">
|
245
244
|
{/* 已选的点位居中 */}
|
246
|
-
|
245
|
+
<div className="actions-icon-box reset-icon-box" onClick={resetCenter}>
|
246
|
+
{typeof resetIcon === "string" ? (
|
247
|
+
<img className="reset-icon" src={resetIcon} />
|
248
|
+
) : (
|
249
|
+
resetIcon || resetIconDef
|
250
|
+
)}
|
251
|
+
</div>
|
247
252
|
{/* 获取当前经纬度 */}
|
248
|
-
{showGetPositionBtn ?
|
253
|
+
{showGetPositionBtn ? (
|
254
|
+
<div className="actions-icon-box center-icon-box" onClick={getPosition}>
|
255
|
+
{typeof positionIcon === "string" ? (
|
256
|
+
<img className="center-icon" src={positionIcon} />
|
257
|
+
) : (
|
258
|
+
positionIcon || positionIconDef
|
259
|
+
)}
|
260
|
+
</div>
|
261
|
+
) : null}
|
249
262
|
</div>
|
250
|
-
{changeMode !== "click" && !(disabled || readOnly) && (
|
251
|
-
<img className="location-picker-center-icon" src={MarkerIcon} />
|
252
|
-
)}
|
253
263
|
</div>
|
254
|
-
<Notice
|
264
|
+
{disabled || readOnly ? null : <Notice />}
|
255
265
|
</div>
|
256
266
|
{loading && (
|
257
267
|
<div className="spin-loading-wrap">
|
@@ -260,6 +270,6 @@ export const ModalContent = (props) => {
|
|
260
270
|
)}
|
261
271
|
</div>
|
262
272
|
);
|
263
|
-
};
|
273
|
+
});
|
264
274
|
|
265
275
|
export default ModalContent;
|
@@ -2,12 +2,7 @@ import { Alert } from "antd";
|
|
2
2
|
|
3
3
|
export const Notice = (props) => {
|
4
4
|
return (
|
5
|
-
<Alert
|
6
|
-
className="location-picker-notice-bar"
|
7
|
-
message={props.changeMode === "click" ? "点击地图上的位置,选择目标地址" : "拖拽移动地图,中心标点为目标地址"}
|
8
|
-
type="info"
|
9
|
-
showIcon
|
10
|
-
/>
|
5
|
+
<Alert className="location-picker-notice-bar" message={"点击地图上的位置,选择目标地址"} type="info" showIcon />
|
11
6
|
);
|
12
7
|
};
|
13
8
|
|
@@ -13,9 +13,15 @@
|
|
13
13
|
&:focus {
|
14
14
|
background: transparent;
|
15
15
|
}
|
16
|
-
.location-picker-icon {
|
17
|
-
|
16
|
+
.location-picker-icon-box {
|
17
|
+
display: inline-block;
|
18
18
|
margin-right: 4px;
|
19
|
+
svg,
|
20
|
+
img {
|
21
|
+
width: 16px;
|
22
|
+
height: 16px;
|
23
|
+
vertical-align: middle;
|
24
|
+
}
|
19
25
|
}
|
20
26
|
.location-picker-text {
|
21
27
|
display: inline-block;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { useMemo } from "react";
|
2
2
|
import { Button } from "antd";
|
3
|
-
import {
|
3
|
+
import { observer } from "@formily/react";
|
4
4
|
|
5
|
-
import pickerIconDefault from "
|
5
|
+
import { pickerIcon as pickerIconDefault } from "../../assets/svg-icon";
|
6
6
|
import { getPropsValue } from "../../common/utils";
|
7
7
|
|
8
8
|
import "./index.less";
|
@@ -12,30 +12,18 @@ import "./index.less";
|
|
12
12
|
* @param props
|
13
13
|
* @returns
|
14
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() || {};
|
15
|
+
export const ResInfo = observer((props: any) => {
|
16
|
+
const { onShow, lonKey, latKey, addrKey, value, pickerText = "选点", pickerIcon } = props || {};
|
28
17
|
|
29
18
|
// 数据格式转为内部格式,方便存取
|
30
19
|
const formatVal = useMemo(
|
31
20
|
() =>
|
32
|
-
getPropsValue(value,
|
33
|
-
isObjectRes,
|
21
|
+
getPropsValue(value, {
|
34
22
|
lonKey,
|
35
23
|
latKey,
|
36
24
|
addrKey,
|
37
25
|
}),
|
38
|
-
[
|
26
|
+
[lonKey, latKey, addrKey, value, value?.[lonKey], value?.[latKey], value?.[addrKey]],
|
39
27
|
);
|
40
28
|
|
41
29
|
return (
|
@@ -46,13 +34,19 @@ export const ResInfo = (props) => {
|
|
46
34
|
<div>纬度:{formatVal.lat}</div>
|
47
35
|
</div>
|
48
36
|
<Button className="location-btn" color="primary" type="text" onClick={onShow}>
|
49
|
-
|
37
|
+
<span className="location-picker-icon-box">
|
38
|
+
{typeof pickerIcon === "string" ? (
|
39
|
+
<img className="location-picker-icon" src={pickerIcon} />
|
40
|
+
) : (
|
41
|
+
pickerIcon || pickerIconDefault
|
42
|
+
)}
|
43
|
+
</span>
|
50
44
|
<span className="location-picker-text">{pickerText}</span>
|
51
45
|
</Button>
|
52
46
|
</div>
|
53
47
|
<div>地址:{formatVal.addr}</div>
|
54
48
|
</div>
|
55
49
|
);
|
56
|
-
};
|
50
|
+
});
|
57
51
|
|
58
52
|
export default ResInfo;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { useEffect,
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
2
2
|
import { Modal } from "antd";
|
3
|
-
import {
|
3
|
+
import { observer } from "@formily/react";
|
4
4
|
|
5
5
|
import ResInfo from "./components/ResInfo";
|
6
6
|
import ModalContent from "./components/ModalContent";
|
@@ -8,11 +8,12 @@ import ModalContent from "./components/ModalContent";
|
|
8
8
|
import { MapUtils } from "./Map/AMap/common/utils";
|
9
9
|
import { getCurrentPosition } from "../../common/location-utils";
|
10
10
|
|
11
|
-
import {
|
11
|
+
import { getPropsValue } from "./common/utils";
|
12
|
+
import { getAddress } from "./servers";
|
12
13
|
|
13
14
|
import "./index.less";
|
14
15
|
|
15
|
-
export
|
16
|
+
export const LocationPicker = observer(function (props: any) {
|
16
17
|
const {
|
17
18
|
/**
|
18
19
|
* 地图显示类型:
|
@@ -28,23 +29,10 @@ export function LocationPicker(props) {
|
|
28
29
|
layout = "ver",
|
29
30
|
// 是否允许搜索
|
30
31
|
hasSearch = true,
|
31
|
-
/**
|
32
|
-
*
|
33
|
-
isObjectRes
|
34
|
-
true: 把所有数据存放在一个对象中(该对象和其他表单项平级),对象 key 为当前项的 name
|
35
|
-
false: 所有数据打平放到当前的 data 中,和其他表单项平级
|
36
|
-
*/
|
37
|
-
isObjectRes = true,
|
38
32
|
/**
|
39
33
|
* 打开地图时是否根据经纬度自动修正已填的地址
|
40
34
|
*/
|
41
35
|
isAutoFixAddr = false,
|
42
|
-
/**
|
43
|
-
* 改变经纬度等数据的触发模式
|
44
|
-
* 移动地图 move
|
45
|
-
* 点击地图 click
|
46
|
-
*/
|
47
|
-
changeMode = "click",
|
48
36
|
lonKey = "longitude",
|
49
37
|
latKey = "latitude",
|
50
38
|
addrKey = "address",
|
@@ -52,24 +40,23 @@ export function LocationPicker(props) {
|
|
52
40
|
// 搜索框是否自动搜索
|
53
41
|
isAutoSearch = true,
|
54
42
|
modalConf = {},
|
43
|
+
icons = {},
|
44
|
+
getCurPositionConf,
|
55
45
|
} = props;
|
56
|
-
const field: any = useField() || {};
|
57
|
-
const fieldSchema: any = useFieldSchema() || {};
|
58
46
|
|
59
|
-
const [loading, setLoading] = useState(
|
47
|
+
const [loading, setLoading] = useState(false);
|
60
48
|
const [defaultLocation, setDefaultLocation] = useState({
|
61
49
|
lon: 120.168893,
|
62
50
|
lat: 30.225404,
|
63
51
|
addr: "浙江省杭州市上城区南星街道杭州西湖风景名胜区",
|
64
52
|
});
|
65
|
-
const [visible, setVisible] = useState(
|
66
|
-
|
67
|
-
const
|
53
|
+
const [visible, setVisible] = useState(mode === "show");
|
54
|
+
// 解决 弹窗关闭之后 visible 无法传入 ModalContent 的问题
|
55
|
+
const [visibleKey, setVisibleKey] = useState(0);
|
68
56
|
const pickInfoRef = useRef(defaultLocation);
|
69
57
|
|
70
58
|
useEffect(() => {
|
71
|
-
const propsVal = getPropsValue(value,
|
72
|
-
isObjectRes,
|
59
|
+
const propsVal = getPropsValue(value, {
|
73
60
|
lonKey,
|
74
61
|
latKey,
|
75
62
|
addrKey,
|
@@ -78,13 +65,18 @@ export function LocationPicker(props) {
|
|
78
65
|
setLoading(true);
|
79
66
|
// 如果没有传入的经纬度,获取当前实际的经纬度数据
|
80
67
|
// 获取当前经纬度
|
81
|
-
getCurrentPosition()
|
82
|
-
.then((res) => {
|
68
|
+
getCurrentPosition(getCurPositionConf)
|
69
|
+
.then(async (res) => {
|
83
70
|
const { coords = {} } = res;
|
71
|
+
const lon = coords.longitude;
|
72
|
+
const lat = coords.latitude;
|
73
|
+
const addr: string = await getAddress(lon, lat).then((addr) => {
|
74
|
+
return addr;
|
75
|
+
});
|
84
76
|
pickInfoRef.current = {
|
85
|
-
lon
|
86
|
-
lat
|
87
|
-
addr
|
77
|
+
lon,
|
78
|
+
lat,
|
79
|
+
addr,
|
88
80
|
};
|
89
81
|
setDefaultLocation(pickInfoRef.current);
|
90
82
|
setLoading(false);
|
@@ -99,13 +91,13 @@ export function LocationPicker(props) {
|
|
99
91
|
}, []);
|
100
92
|
|
101
93
|
function onShow() {
|
102
|
-
// 等待地图加载完毕
|
103
|
-
!mapUtilsRef.current && setVisible(true);
|
104
94
|
setVisible(true);
|
95
|
+
setVisibleKey(Date.now());
|
105
96
|
}
|
106
97
|
|
107
98
|
function onClose() {
|
108
99
|
setVisible(false);
|
100
|
+
setVisibleKey(Date.now());
|
109
101
|
}
|
110
102
|
|
111
103
|
function onChange(res = pickInfoRef.current) {
|
@@ -116,18 +108,6 @@ export function LocationPicker(props) {
|
|
116
108
|
[addrKey]: info.addr,
|
117
109
|
};
|
118
110
|
props.onChange && props.onChange(_res);
|
119
|
-
if (isObjectRes === false) {
|
120
|
-
// 只有一层的情况
|
121
|
-
if (!field.parent) {
|
122
|
-
field.form.setValues(_res);
|
123
|
-
} else if (field.parent && fieldSchema.parent) {
|
124
|
-
// 嵌套在 ArrayBase: ArrayTable ArrayCard 等 里面的情况
|
125
|
-
const parentVal = getParentValue(field);
|
126
|
-
Object.keys(_res).forEach((key) => {
|
127
|
-
parentVal[key] = _res[key];
|
128
|
-
});
|
129
|
-
}
|
130
|
-
}
|
131
111
|
}
|
132
112
|
|
133
113
|
function onOk() {
|
@@ -146,8 +126,7 @@ export function LocationPicker(props) {
|
|
146
126
|
|
147
127
|
const isHor = layout === "hor" || layout === "hor-reverse";
|
148
128
|
const _props = {
|
149
|
-
|
150
|
-
readOnly: props.readOnly,
|
129
|
+
...props,
|
151
130
|
/**
|
152
131
|
* 地图显示类型:
|
153
132
|
* 弹窗 dialog
|
@@ -155,58 +134,33 @@ export function LocationPicker(props) {
|
|
155
134
|
*/
|
156
135
|
mode: mode ?? "dialog",
|
157
136
|
layout: layout ?? "ver",
|
158
|
-
/**
|
159
|
-
* 是否是水平布局
|
160
|
-
*/
|
161
|
-
isHor,
|
162
137
|
// 是否允许搜索
|
163
138
|
hasSearch: hasSearch ?? true,
|
164
|
-
/**
|
165
|
-
*
|
166
|
-
isObjectRes
|
167
|
-
true: 把所有数据存放在一个对象中(该对象和其他表单项平级),对象 key 为当前项的 name
|
168
|
-
false: 所有数据打平放到当前的 data 中,和其他表单项平级
|
169
|
-
*/
|
170
|
-
isObjectRes: isObjectRes ?? true,
|
171
139
|
/**
|
172
140
|
* 打开地图时是否根据经纬度自动修正已填的地址
|
173
141
|
*/
|
174
142
|
isAutoFixAddr: isAutoFixAddr ?? false,
|
175
|
-
/**
|
176
|
-
* 改变经纬度等数据的触发模式
|
177
|
-
* 移动地图:move
|
178
|
-
* 点击地图:click
|
179
|
-
*/
|
180
|
-
changeMode: changeMode ?? "click",
|
181
143
|
lonKey: lonKey ?? "longitude",
|
182
144
|
latKey: latKey ?? "latitude",
|
183
145
|
addrKey: addrKey ?? "address",
|
184
|
-
value,
|
185
146
|
// 搜索框是否自动搜索
|
186
147
|
isAutoSearch: isAutoSearch ?? true,
|
148
|
+
visible,
|
149
|
+
visibleKey,
|
187
150
|
defaultLocation,
|
188
|
-
|
189
|
-
|
190
|
-
// 地图选点按钮的 icon img 的地址
|
191
|
-
pickerIconUrl: props.pickerIconUrl,
|
151
|
+
loading,
|
152
|
+
setLoading,
|
192
153
|
};
|
193
154
|
|
194
155
|
return (
|
195
156
|
<div className="location-picker">
|
196
157
|
{mode === "show" ? (
|
197
|
-
<ModalContent
|
198
|
-
{..._props}
|
199
|
-
visible={visible}
|
200
|
-
setPickInfo={setResInfo}
|
201
|
-
layout={layout}
|
202
|
-
setLoading={setLoading}
|
203
|
-
loading={loading}
|
204
|
-
/>
|
158
|
+
<ModalContent {..._props} setPickInfo={setResInfo} />
|
205
159
|
) : (
|
206
160
|
<>
|
207
161
|
{/* 弹窗 */}
|
208
162
|
{/* 有弹窗时,显示表单选中的结果 */}
|
209
|
-
<ResInfo {..._props} onShow={onShow} />
|
163
|
+
<ResInfo {..._props} onShow={onShow} pickerIcon={icons.pickerIcon} />
|
210
164
|
<Modal
|
211
165
|
className="location-picker-modal"
|
212
166
|
title="地图选点"
|
@@ -216,19 +170,12 @@ export function LocationPicker(props) {
|
|
216
170
|
confirmLoading={loading}
|
217
171
|
width={modalConf?.width || isHor ? "1024px" : "720px"}
|
218
172
|
>
|
219
|
-
<ModalContent
|
220
|
-
{..._props}
|
221
|
-
visible={visible}
|
222
|
-
setPickInfo={setPickInfo}
|
223
|
-
layout={layout}
|
224
|
-
setLoading={setLoading}
|
225
|
-
loading={loading}
|
226
|
-
/>
|
173
|
+
<ModalContent {..._props} setPickInfo={setPickInfo} />
|
227
174
|
</Modal>
|
228
175
|
</>
|
229
176
|
)}
|
230
177
|
</div>
|
231
178
|
);
|
232
|
-
}
|
179
|
+
});
|
233
180
|
|
234
181
|
export default LocationPicker;
|