@hzab/form-render 0.4.1 → 0.5.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.
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/src/components/LocationPicker/Map/AMap/common/loader.ts +1 -1
- package/src/components/LocationPicker/Map/AMap/common/utils.ts +13 -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 +84 -0
- package/src/components/LocationPicker/common/utils.ts +2 -8
- package/src/components/LocationPicker/components/MapSearch/index.less +1 -1
- package/src/components/LocationPicker/components/ModalContent/index.less +12 -4
- package/src/components/LocationPicker/components/ModalContent/index.tsx +99 -49
- 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 +54 -67
- 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,8 +1,12 @@
|
|
1
|
-
|
1
|
+
## 使用前安装依赖
|
2
2
|
|
3
3
|
npm install @amap/amap-jsapi-loader
|
4
4
|
|
5
|
-
|
5
|
+
## 注意事项
|
6
|
+
|
7
|
+
- isObjectRes 在 @hzab/form-render0.5.0 版本中去除,结果全部存放在对象中
|
8
|
+
|
9
|
+
## 引入
|
6
10
|
|
7
11
|
```jsx
|
8
12
|
import MapLocationPoint from "./mapLocationPoint";
|
@@ -14,22 +18,26 @@ export default function AMap(props) {
|
|
14
18
|
|
15
19
|
### InfoPanel Attributes
|
16
20
|
|
17
|
-
| 参数
|
18
|
-
|
|
19
|
-
| mode
|
20
|
-
| layout
|
21
|
-
| hasSearch
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
21
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
22
|
+
| ------------------ | ------- | ---- | --------- | ----------------------------------------------------------- |
|
23
|
+
| mode | string | 否 | dialog | 地图显示的类型, dialog 弹窗显示、 show 直接显示 |
|
24
|
+
| layout | string | 否 | ver | 选择器和地图的布局 hor 水平、 ver 垂直 |
|
25
|
+
| hasSearch | boolean | 否 | true | 是否允许搜索 |
|
26
|
+
| isAutoFixAddr | boolean | 否 | false | 打开地图时是否根据经纬度自动修正已填的地址 |
|
27
|
+
| changeMode | string | 否 | move | 改变经纬度等数据的触发模式;移动地图:move,点击地图:click |
|
28
|
+
| lonKey | string | 否 | longitude | 经度字段 key |
|
29
|
+
| latKey | string | 否 | latitude | 维度字段 key |
|
30
|
+
| addrKey | string | 否 | address | 地址字段 key |
|
31
|
+
| isAutoSearch | boolean | 否 | false | 搜索框是否自动搜索 |
|
32
|
+
| markerIconConf | Object | 否 | - | markerIcon 配置对象 |
|
33
|
+
| icons | Object | 否 | - | icon 图片 |
|
34
|
+
| getCurPositionConf | Object | 否 | - | getCurrentPosition Config |
|
35
|
+
|
36
|
+
#### icons
|
37
|
+
|
38
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
39
|
+
| ------------ | ------ | ---- | ------ | ---------------- |
|
40
|
+
| markerIcon | string | 否 | dialog | marker icon 图片 |
|
41
|
+
| pickerIcon | string | 否 | dialog | 选点 icon 图片 |
|
42
|
+
| positionIcon | string | 否 | dialog | 定位 icon 图片 |
|
43
|
+
| resetIcon | string | 否 | dialog | 重置 icon 图片 |
|
@@ -0,0 +1,84 @@
|
|
1
|
+
export const markerIcon = (
|
2
|
+
<svg
|
3
|
+
t="1708497164654"
|
4
|
+
className="marker-icon"
|
5
|
+
viewBox="0 0 1024 1024"
|
6
|
+
version="1.1"
|
7
|
+
xmlns="http://www.w3.org/2000/svg"
|
8
|
+
p-id="8489"
|
9
|
+
width="200"
|
10
|
+
height="200"
|
11
|
+
>
|
12
|
+
<path
|
13
|
+
d="M512 1024c-205.76-241.472-326.272-411.712-361.664-510.72a384 384 0 1 1 723.072 0.832C837.76 612.928 717.312 782.848 512 1024.064z m0-512a128 128 0 1 0 0-256 128 128 0 0 0 0 256z"
|
14
|
+
fill="#1677ff"
|
15
|
+
p-id="8490"
|
16
|
+
></path>
|
17
|
+
</svg>
|
18
|
+
);
|
19
|
+
|
20
|
+
export const pickerIcon = (
|
21
|
+
<svg
|
22
|
+
t="1708305242338"
|
23
|
+
className="picker-icon"
|
24
|
+
viewBox="0 0 1088 1024"
|
25
|
+
version="1.1"
|
26
|
+
xmlns="http://www.w3.org/2000/svg"
|
27
|
+
p-id="1494"
|
28
|
+
width="200"
|
29
|
+
height="200"
|
30
|
+
>
|
31
|
+
<path
|
32
|
+
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"
|
33
|
+
fill="#1677ff"
|
34
|
+
p-id="1495"
|
35
|
+
></path>
|
36
|
+
<path
|
37
|
+
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"
|
38
|
+
fill="#1677ff"
|
39
|
+
p-id="1496"
|
40
|
+
></path>
|
41
|
+
</svg>
|
42
|
+
);
|
43
|
+
|
44
|
+
export const positionIcon = (
|
45
|
+
<svg
|
46
|
+
t="1708478996666"
|
47
|
+
className="position-icon"
|
48
|
+
viewBox="0 0 1024 1024"
|
49
|
+
version="1.1"
|
50
|
+
xmlns="http://www.w3.org/2000/svg"
|
51
|
+
p-id="6897"
|
52
|
+
// xmlns:xlink="http://www.w3.org/1999/xlink"
|
53
|
+
width="200"
|
54
|
+
height="200"
|
55
|
+
>
|
56
|
+
<path
|
57
|
+
d="M895.044488 550.176484l-42.200124 0C834.62235 708.540282 709.048353 834.001715 550.718325 852.244194l0 42.258453c0 21.946848-17.790178 39.730886-39.729863 39.730886s-39.729863-17.784038-39.729863-39.730886l0-42.258453C312.926524 834.001715 187.354574 708.540282 169.131537 550.176484l-42.199101 0c-21.940708 0-39.730886-17.786085-39.730886-39.729863 0-21.940708 17.789155-39.726793 39.730886-39.726793l42.257429 0c18.24248-158.335145 143.711076-283.907095 302.068733-302.126039l0-42.200124c0-21.940708 17.789155-39.730886 39.729863-39.730886s39.729863 17.789155 39.729863 39.730886l0 42.258453c158.331052 18.241456 283.904025 143.706983 302.126039 302.06771l42.200124 0c21.940708 0 39.729863 17.786085 39.729863 39.726793C934.774351 532.390399 916.986219 550.176484 895.044488 550.176484zM696.395172 470.719828l76.16161 0c-17.251919-114.39847-107.492176-204.651007-221.838458-221.913159l0 76.236312c0 21.939685-17.790178 39.726793-39.729863 39.726793s-39.729863-17.787108-39.729863-39.726793l0-76.165704c-114.39233 17.256012-204.644867 107.495246-221.910089 221.842551l76.233242 0c21.946848 0 39.729863 17.786085 39.729863 39.726793 0 21.943778-17.781992 39.729863-39.729863 39.729863l-76.162634 0c17.251919 114.39847 107.498316 204.649983 221.839481 221.910089l0-76.234265c0-21.943778 17.789155-39.72577 39.729863-39.72577s39.729863 17.781992 39.729863 39.72577l0 76.234265c114.346281-17.260106 204.586538-107.511619 221.838458-221.910089l-76.16161 0c-21.941732 0-39.729863-17.786085-39.729863-39.729863C656.665309 488.505913 674.453441 470.719828 696.395172 470.719828zM510.988462 550.176484c-21.939685 0-39.729863-17.786085-39.729863-39.729863 0-21.940708 17.789155-39.726793 39.729863-39.726793s39.729863 17.786085 39.729863 39.726793C550.718325 532.390399 532.928147 550.176484 510.988462 550.176484z"
|
58
|
+
fill="#000000"
|
59
|
+
p-id="6898"
|
60
|
+
></path>
|
61
|
+
</svg>
|
62
|
+
);
|
63
|
+
|
64
|
+
export const resetIcon = (
|
65
|
+
<svg
|
66
|
+
t="1708485324277"
|
67
|
+
className="reset-icon"
|
68
|
+
viewBox="0 0 1024 1024"
|
69
|
+
version="1.1"
|
70
|
+
xmlns="http://www.w3.org/2000/svg"
|
71
|
+
p-id="7503"
|
72
|
+
width="200"
|
73
|
+
height="200"
|
74
|
+
>
|
75
|
+
<path
|
76
|
+
d="M512 682.666667c71.296 0 128-56.789333 128-128s-56.704-128-128-128-128 56.789333-128 128 56.704 128 128 128z"
|
77
|
+
p-id="7504"
|
78
|
+
></path>
|
79
|
+
<path
|
80
|
+
d="M888.192 477.269333a381.44 381.44 0 0 0-57.813333-137.344 386.261333 386.261333 0 0 0-103.68-103.68 381.866667 381.866667 0 0 0-137.344-57.813333 385.194667 385.194667 0 0 0-78.421334-7.68V85.333333L341.333333 213.333333l169.6 128V256.085333c20.650667-0.085333 41.301333 1.877333 61.226667 5.973334a297.002667 297.002667 0 0 1 106.752 44.928 298.88 298.88 0 0 1 80.725333 80.725333A297.258667 297.258667 0 0 1 810.666667 554.666667a300.032 300.032 0 0 1-23.466667 116.266666 303.36 303.36 0 0 1-27.477333 50.688 307.2 307.2 0 0 1-36.608 44.330667 299.861333 299.861333 0 0 1-150.869334 81.365333 304.213333 304.213333 0 0 1-120.405333 0 297.002667 297.002667 0 0 1-106.794667-44.970666 298.752 298.752 0 0 1-80.64-80.64A298.496 298.496 0 0 1 213.333333 554.666667H128a384.853333 384.853333 0 0 0 65.664 214.784 388.096 388.096 0 0 0 103.594667 103.594666A381.866667 381.866667 0 0 0 512 938.666667a387.84 387.84 0 0 0 77.397333-7.808 384.597333 384.597333 0 0 0 137.301334-57.813334 379.136 379.136 0 0 0 56.789333-46.890666 393.728 393.728 0 0 0 46.933333-56.832A381.952 381.952 0 0 0 896 554.666667a387.84 387.84 0 0 0-7.808-77.397334z"
|
81
|
+
p-id="7505"
|
82
|
+
></path>
|
83
|
+
</svg>
|
84
|
+
);
|
@@ -10,18 +10,12 @@
|
|
10
10
|
addr: value[addrKey],
|
11
11
|
}
|
12
12
|
*/
|
13
|
-
export function getPropsValue(value = {},
|
14
|
-
const {
|
13
|
+
export function getPropsValue(value = {}, opt) {
|
14
|
+
const { lonKey = "longitude", latKey = "latitude", addrKey = "address" } = opt || {};
|
15
15
|
let lon = value[lonKey];
|
16
16
|
let lat = value[latKey];
|
17
17
|
let addr = value[addrKey];
|
18
18
|
// 数据和其他子项平级的情况
|
19
|
-
let form = getParentValue(field);
|
20
|
-
if (form && isObjectRes === false) {
|
21
|
-
lon = form[lonKey];
|
22
|
-
lat = form[latKey];
|
23
|
-
addr = form[addrKey];
|
24
|
-
}
|
25
19
|
const res = {
|
26
20
|
lon,
|
27
21
|
lat,
|
@@ -9,6 +9,7 @@
|
|
9
9
|
position: relative;
|
10
10
|
width: 100%;
|
11
11
|
flex: 1;
|
12
|
+
height: 500px;
|
12
13
|
.a-map-container {
|
13
14
|
height: inherit;
|
14
15
|
.amap-logo,
|
@@ -17,22 +18,30 @@
|
|
17
18
|
}
|
18
19
|
}
|
19
20
|
|
20
|
-
.location-picker-center-icon {
|
21
|
+
.location-picker-center-icon-box {
|
21
22
|
position: absolute;
|
22
23
|
top: 50%;
|
23
24
|
left: 50%;
|
24
|
-
transform: translate(-50%, -100%);
|
25
25
|
width: 34px;
|
26
|
+
height: 34px;
|
27
|
+
transform: translate(-50%, -100%);
|
26
28
|
color: #1677ff;
|
29
|
+
img,
|
30
|
+
svg {
|
31
|
+
width: 34px;
|
32
|
+
height: 34px;
|
33
|
+
}
|
27
34
|
}
|
28
35
|
|
29
36
|
.set-map-actions {
|
30
37
|
position: absolute;
|
31
38
|
right: 20px;
|
32
39
|
bottom: 20px;
|
33
|
-
& > img
|
40
|
+
& > img,
|
41
|
+
& > svg {
|
34
42
|
display: block;
|
35
43
|
width: 32px;
|
44
|
+
height: 32px;
|
36
45
|
margin-bottom: 8px;
|
37
46
|
padding: 4px;
|
38
47
|
background-color: #fff;
|
@@ -70,7 +79,6 @@
|
|
70
79
|
.location-picker-info {
|
71
80
|
margin-right: 20px;
|
72
81
|
}
|
73
|
-
.location-picker-info;
|
74
82
|
}
|
75
83
|
&.location-modal-content-layout-hor-reverse {
|
76
84
|
flex-direction: row-reverse;
|
@@ -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,13 +34,6 @@ 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
|
*/
|
@@ -57,59 +52,85 @@ export const ModalContent = (props) => {
|
|
57
52
|
isAutoSearch = true,
|
58
53
|
//
|
59
54
|
visible,
|
60
|
-
|
55
|
+
visibleKey,
|
56
|
+
defaultLocation = {},
|
61
57
|
disabled,
|
62
58
|
readOnly,
|
59
|
+
icons,
|
60
|
+
markerIconConf,
|
61
|
+
getCurPositionConf,
|
63
62
|
} = props;
|
64
63
|
|
65
|
-
const field: any = useField() || {};
|
66
|
-
|
67
64
|
const mapUtilsRef = useRef<MapUtils>();
|
68
65
|
|
69
66
|
// 数据格式转为内部格式,方便存取
|
70
67
|
const formatVal = useMemo(
|
71
68
|
() =>
|
72
|
-
getPropsValue(value,
|
73
|
-
isObjectRes,
|
69
|
+
getPropsValue(value, {
|
74
70
|
lonKey,
|
75
71
|
latKey,
|
76
72
|
addrKey,
|
77
73
|
}),
|
78
|
-
[
|
74
|
+
[lonKey, latKey, addrKey, value, value?.[lonKey], value?.[latKey], value?.[addrKey]],
|
79
75
|
);
|
80
|
-
|
76
|
+
|
77
|
+
const [loading, setLoading] = useState(props.loading || false);
|
81
78
|
const [addrLoading, setAddrLoading] = useState(false);
|
82
79
|
// 地图选点组件选中的值
|
83
80
|
const [pickInfo, setPickInfo] = useState(formatVal);
|
81
|
+
const pickerInfoRef = useRef(pickInfo);
|
82
|
+
|
83
|
+
const isShowMode = mode === "show";
|
84
|
+
|
85
|
+
useEffect(() => {
|
86
|
+
setLoading(props.loading);
|
87
|
+
}, [props.loading]);
|
84
88
|
|
85
89
|
useEffect(() => {
|
86
|
-
if (
|
90
|
+
if (isShowMode) {
|
91
|
+
// mode === 'show' 的情况
|
92
|
+
let _lon = formatVal.lon;
|
93
|
+
let _lat = formatVal.lat;
|
94
|
+
if (_lon && _lat && _lon !== pickInfo.lon && _lat !== pickInfo.lat) {
|
95
|
+
// 解决关闭弹窗之后点位不居中的问题
|
96
|
+
if (window.AMap && window.AMap.LngLat) {
|
97
|
+
setMapCenter(_lon, _lat);
|
98
|
+
setPickPoint(_lon, _lat, { isAutoFixAddr: false, addr: formatVal.addr });
|
99
|
+
}
|
100
|
+
}
|
101
|
+
} else if (visibleKey) {
|
102
|
+
// 处理弹窗展示数据回显逻辑
|
87
103
|
let _lon = defaultLocation.lon;
|
88
104
|
let _lat = defaultLocation.lat;
|
105
|
+
let addr = defaultLocation.addr;
|
89
106
|
if (formatVal.lon && formatVal.lat) {
|
90
107
|
_lon = formatVal.lon;
|
91
108
|
_lat = formatVal.lat;
|
109
|
+
addr = formatVal.addr;
|
92
110
|
}
|
93
111
|
// 解决关闭弹窗之后点位不居中的问题
|
94
112
|
if (window.AMap && window.AMap.LngLat) {
|
95
113
|
setMapCenter(_lon, _lat);
|
96
114
|
}
|
97
|
-
|
115
|
+
if (_lon && _lat && _lon !== pickerInfoRef.current?.lon && _lat !== pickerInfoRef.current?.lat) {
|
116
|
+
setPickPoint(_lon, _lat, { isAutoFixAddr: false, addr: addr });
|
117
|
+
}
|
98
118
|
}
|
99
|
-
}, [
|
119
|
+
}, [visibleKey, formatVal, isShowMode]);
|
100
120
|
|
101
121
|
function mapInit({ map, mapUtils }) {
|
102
122
|
mapUtilsRef.current = mapUtils;
|
103
|
-
let _lon = defaultLocation.lon;
|
104
|
-
let _lat = defaultLocation.lat;
|
123
|
+
let _lon = isShowMode ? undefined : defaultLocation.lon;
|
124
|
+
let _lat = isShowMode ? undefined : defaultLocation.lat;
|
105
125
|
if (pickInfo.lon && pickInfo.lat) {
|
106
126
|
_lon = pickInfo.lon;
|
107
127
|
_lat = pickInfo.lat;
|
108
128
|
}
|
109
|
-
setPickPoint(_lon, _lat, { isAutoFixAddr });
|
110
129
|
|
111
130
|
setMapCenter(_lon, _lat);
|
112
|
-
|
131
|
+
|
132
|
+
setLoading(props.loading || false);
|
133
|
+
|
113
134
|
if (!(disabled || readOnly)) {
|
114
135
|
if (changeMode === "click") {
|
115
136
|
mapUtilsRef.current?.setPickerMarker(_lon, _lat);
|
@@ -119,18 +140,18 @@ export const ModalContent = (props) => {
|
|
119
140
|
setPickPoint(evLon, evLat, { changeCenter: true });
|
120
141
|
});
|
121
142
|
} else {
|
143
|
+
const handleMove = debounce(function (ev) {
|
144
|
+
let currentCenter = mapUtilsRef.current?.getCenter();
|
145
|
+
const { lng: centerLon, lat: centerLat } = currentCenter || {};
|
146
|
+
// 移动选中点位的情况
|
147
|
+
let _lon = centerLon;
|
148
|
+
let _lat = centerLat;
|
149
|
+
setPickPoint(_lon, _lat);
|
150
|
+
}, 1000);
|
122
151
|
// 移动地图
|
123
|
-
mapUtilsRef.current.on(
|
124
|
-
|
125
|
-
|
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
|
-
);
|
152
|
+
mapUtilsRef.current.on("mouseup", handleMove);
|
153
|
+
// PC 端需要额外监听地图缩放事件
|
154
|
+
mapUtilsRef.current.on("zoomend", handleMove);
|
134
155
|
}
|
135
156
|
} else {
|
136
157
|
// 禁用、只读情况使用 marker 展示点位
|
@@ -144,13 +165,14 @@ export const ModalContent = (props) => {
|
|
144
165
|
* @param lat
|
145
166
|
*/
|
146
167
|
function setMapCenter(lon = pickInfo.lon, lat = pickInfo.lat) {
|
147
|
-
mapUtilsRef.current?.setCenter(lon, lat);
|
168
|
+
lon && lat && mapUtilsRef.current?.setCenter(lon, lat);
|
148
169
|
}
|
149
170
|
|
150
171
|
async function setPickPoint(_lon, _lat, opt?: any) {
|
151
|
-
const { isAutoFixAddr: _isAutoFixAddr = isAutoFixAddr || true, changeCenter } = opt || {};
|
172
|
+
const { isAutoFixAddr: _isAutoFixAddr = isAutoFixAddr || true, changeCenter, addr: _addr } = opt || {};
|
152
173
|
const lon = _lon || pickInfo.lon;
|
153
174
|
const lat = _lat || pickInfo.lat;
|
175
|
+
let addr = _addr;
|
154
176
|
// 禁用、只读情况使用 marker 展示点位
|
155
177
|
if (changeMode === "click" || disabled || readOnly) {
|
156
178
|
mapUtilsRef.current?.setPickerMarker(_lon, _lat);
|
@@ -158,9 +180,14 @@ export const ModalContent = (props) => {
|
|
158
180
|
if (changeCenter) {
|
159
181
|
setMapCenter(_lon, _lat);
|
160
182
|
}
|
161
|
-
|
183
|
+
|
184
|
+
// 开启自动修复地址 且 opt 参数中没有地址,请求地址
|
185
|
+
if (_isAutoFixAddr && !addr) {
|
186
|
+
addr = await getAddr(lon, lat);
|
187
|
+
}
|
162
188
|
const res = { ...pickInfo, lon, lat, addr };
|
163
189
|
setPickInfo(res);
|
190
|
+
pickerInfoRef.current = res;
|
164
191
|
props.setPickInfo && props.setPickInfo(res);
|
165
192
|
}
|
166
193
|
|
@@ -175,7 +202,10 @@ export const ModalContent = (props) => {
|
|
175
202
|
getAddress(_lng, _lat)
|
176
203
|
.then((addr) => {
|
177
204
|
setAddrLoading(false);
|
178
|
-
setPickInfo((_p) =>
|
205
|
+
setPickInfo((_p) => {
|
206
|
+
pickerInfoRef.current = { ..._p, addr };
|
207
|
+
return pickerInfoRef.current;
|
208
|
+
});
|
179
209
|
resolve(addr);
|
180
210
|
})
|
181
211
|
.catch((err) => {
|
@@ -193,7 +223,7 @@ export const ModalContent = (props) => {
|
|
193
223
|
function getPosition() {
|
194
224
|
setLoading(true);
|
195
225
|
// 获取当前经纬度
|
196
|
-
getCurrentPosition()
|
226
|
+
getCurrentPosition(getCurPositionConf)
|
197
227
|
.then((res) => {
|
198
228
|
const { coords = {} } = res;
|
199
229
|
setPickPoint(coords.longitude, coords.latitude, { changeCenter: true });
|
@@ -226,25 +256,45 @@ export const ModalContent = (props) => {
|
|
226
256
|
);
|
227
257
|
};
|
228
258
|
|
259
|
+
const { markerIcon, positionIcon, resetIcon } = icons || {};
|
260
|
+
|
229
261
|
return (
|
230
262
|
<div className={`location-picker-modal-content location-mode-${mode} location-modal-content-layout-${layout}`}>
|
231
263
|
{pickInfoRender()}
|
232
264
|
<div className="location-picker-map-wrap">
|
233
265
|
<div className="location-picker-map">
|
234
266
|
{/* 关闭弹窗之后清除搜索内容 */}
|
235
|
-
{hasSearch
|
236
|
-
<AMapCom init={mapInit} loading={loading}
|
267
|
+
{hasSearch ? <MapSearch key={visible} setPoint={setPickPoint} isAutoSearch={isAutoSearch} /> : null}
|
268
|
+
<AMapCom init={mapInit} loading={loading} markerIconConf={markerIconConf} />
|
237
269
|
<div className="set-map-actions">
|
238
270
|
{/* 已选的点位居中 */}
|
239
|
-
{showResetCenter ?
|
271
|
+
{showResetCenter ? (
|
272
|
+
typeof resetIcon === "string" ? (
|
273
|
+
<img className="reset-icon" src={resetIcon} onClick={resetCenter} />
|
274
|
+
) : (
|
275
|
+
resetIcon || resetIconDef
|
276
|
+
)
|
277
|
+
) : null}
|
240
278
|
{/* 获取当前经纬度 */}
|
241
|
-
{showGetPositionBtn ?
|
279
|
+
{showGetPositionBtn ? (
|
280
|
+
typeof positionIcon === "string" ? (
|
281
|
+
<img className="center-icon" src={positionIcon} onClick={getPosition} />
|
282
|
+
) : (
|
283
|
+
positionIcon || positionIconDef
|
284
|
+
)
|
285
|
+
) : null}
|
242
286
|
</div>
|
243
287
|
{changeMode !== "click" && !(disabled || readOnly) && (
|
244
|
-
<
|
288
|
+
<div className="location-picker-center-icon-box">
|
289
|
+
{typeof positionIcon === "string" ? (
|
290
|
+
<img className="location-picker-center-icon" src={markerIcon} />
|
291
|
+
) : (
|
292
|
+
markerIcon || markerIconDef
|
293
|
+
)}
|
294
|
+
</div>
|
245
295
|
)}
|
246
296
|
</div>
|
247
|
-
<Notice changeMode={changeMode} />
|
297
|
+
{disabled || readOnly ? null : <Notice changeMode={changeMode} />}
|
248
298
|
</div>
|
249
299
|
{loading && (
|
250
300
|
<div className="spin-loading-wrap">
|
@@ -253,6 +303,6 @@ export const ModalContent = (props) => {
|
|
253
303
|
)}
|
254
304
|
</div>
|
255
305
|
);
|
256
|
-
};
|
306
|
+
});
|
257
307
|
|
258
308
|
export default ModalContent;
|
@@ -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;
|