@hzab/form-render 0.5.0 → 0.5.2
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/utils.ts +2 -1
- package/src/components/LocationPicker/README.md +20 -20
- package/src/components/LocationPicker/assets/svg-icon.js +2 -0
- package/src/components/LocationPicker/common/utils.ts +0 -14
- package/src/components/LocationPicker/components/ModalContent/index.less +7 -3
- package/src/components/LocationPicker/components/ModalContent/index.tsx +20 -53
- package/src/components/LocationPicker/components/Notice/index.tsx +1 -6
- package/src/components/LocationPicker/index.tsx +12 -17
- package/src/components/LocationPicker/servers/index.ts +54 -26
- package/src/components/TreeCheckbox/README.md +8 -9
- package/src/components/TreeCheckbox/common/utils.ts +22 -11
- package/src/components/TreeCheckbox/components/CheckboxTable/index.less +0 -0
- package/src/components/TreeCheckbox/components/CheckboxTable/index.tsx +55 -0
- package/src/components/TreeCheckbox/index.tsx +42 -48
@@ -1,59 +1,68 @@
|
|
1
|
-
import { useField, useFieldSchema,
|
2
|
-
import { DatePicker as AntdDatePicker } from "antd";
|
3
|
-
import type { DatePickerProps, RangePickerProps } from 'antd/es/date-picker';
|
4
|
-
import { connect, mapProps } from "@formily/react";
|
1
|
+
import { useField, useFieldSchema, connect, mapProps } from "@formily/react";
|
2
|
+
import { DatePicker as AntdDatePicker } from "@formily/antd";
|
5
3
|
|
6
|
-
|
4
|
+
import { DatePickerProps, RangePickerProps } from "antd/lib/date-picker";
|
7
5
|
|
6
|
+
import { getParentValue } from "../../common/formily-utils";
|
7
|
+
import { dateable } from "../../common/date-utils";
|
8
8
|
|
9
|
-
|
10
|
-
/**
|
11
|
-
* 获取父级的数据对象(包括当前项的对象)
|
12
|
-
* { 当详情: xxx, 其他项: lll }
|
13
|
-
* @param field
|
14
|
-
* @returns
|
15
|
-
*/
|
16
|
-
export function getParentValue(field) {
|
17
|
-
let form = field?.parent?.value || field?.value;
|
18
|
-
if (Array.isArray(form)) {
|
19
|
-
form = form[field.index];
|
20
|
-
}
|
21
|
-
return form;
|
22
|
-
}
|
9
|
+
const { RangePicker } = AntdDatePicker;
|
23
10
|
|
24
11
|
type DatePickerT = React.FC<any> & {
|
25
12
|
RangePicker?: React.FC<any>;
|
26
13
|
};
|
27
14
|
|
28
|
-
|
29
|
-
|
30
|
-
{
|
31
|
-
|
32
|
-
})
|
15
|
+
const handleProps = (props: DatePickerProps) => {
|
16
|
+
const getDefaultFormat = (props: DatePickerProps) => {
|
17
|
+
if (props["picker"] === "month") {
|
18
|
+
return "YYYY-MM";
|
19
|
+
} else if (props["picker"] === "quarter") {
|
20
|
+
return "YYYY-\\QQ";
|
21
|
+
} else if (props["picker"] === "year") {
|
22
|
+
return "YYYY";
|
23
|
+
} else if (props["picker"] === "week") {
|
24
|
+
return "gggg-wo";
|
25
|
+
}
|
26
|
+
return props["showTime"] ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD";
|
27
|
+
};
|
28
|
+
const format = props["format"] || (getDefaultFormat(props) as any);
|
33
29
|
|
30
|
+
return {
|
31
|
+
...props,
|
32
|
+
format,
|
33
|
+
value: dateable(props.value, format === "gggg-wo" ? "gggg-ww" : format),
|
34
|
+
};
|
35
|
+
};
|
34
36
|
|
35
|
-
DatePicker
|
37
|
+
export const DatePicker: DatePickerT = connect(
|
38
|
+
AntdDatePicker,
|
39
|
+
mapProps((props: any) => {
|
40
|
+
const datePickerProps = handleProps(props);
|
41
|
+
return datePickerProps;
|
42
|
+
}),
|
43
|
+
);
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
DatePicker.RangePicker = connect(
|
46
|
+
(props: any) => {
|
47
|
+
const field: any = useField();
|
48
|
+
const fieldSchema = useFieldSchema();
|
49
|
+
const {
|
50
|
+
/**
|
41
51
|
*
|
42
52
|
isSplitTimes
|
43
53
|
true: 拆分为 startKey和 endKey 两个字段
|
44
54
|
false: 不做拆分
|
45
55
|
*/
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
56
|
+
isSplitTimes = false,
|
57
|
+
startKey = "startTime",
|
58
|
+
endKey = "endTime",
|
59
|
+
} = props;
|
51
60
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
61
|
+
const handleOnConfirm = (startTime, endTime) => {
|
62
|
+
const res = {
|
63
|
+
[startKey]: startTime,
|
64
|
+
[endKey]: endTime,
|
65
|
+
};
|
57
66
|
|
58
67
|
if (!field.parent) {
|
59
68
|
field.form.setValues(res);
|
@@ -64,26 +73,31 @@ DatePicker.RangePicker = observer((props:any) => {
|
|
64
73
|
parentVal[key] = res[key];
|
65
74
|
});
|
66
75
|
}
|
67
|
-
|
68
|
-
|
69
|
-
const handleOnChange = (dates, dateStrings) => {
|
70
|
-
const startTime = dateStrings[0]
|
71
|
-
const endTime = dateStrings[1]
|
72
|
-
props.onChange && props.onChange(dates);
|
73
|
-
if(!isSplitTimes) return
|
74
|
-
if ((props.pick === 'date' || !props.pick) && !props.showTime) {
|
75
|
-
handleOnConfirm(startTime + " 00:00:00", endTime + " 23:59:59")
|
76
|
-
return
|
77
|
-
}
|
78
|
-
handleOnConfirm(startTime, endTime)
|
79
|
-
};
|
76
|
+
};
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
78
|
+
const handleOnChange = (dates, dateStrings) => {
|
79
|
+
const startTime = dates[0];
|
80
|
+
const endTime = dates[1];
|
81
|
+
props.onChange && props.onChange(dates);
|
82
|
+
if (!isSplitTimes) return;
|
83
|
+
if ((props.pick === "date" || !props.pick) && !props.showTime) {
|
84
|
+
handleOnConfirm(startTime + " 00:00:00", endTime + " 23:59:59");
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
handleOnConfirm(startTime, endTime);
|
88
|
+
};
|
89
89
|
|
90
|
+
return (
|
91
|
+
<RangePicker
|
92
|
+
{...props}
|
93
|
+
onChange={(
|
94
|
+
value: DatePickerProps["value"] | RangePickerProps["value"],
|
95
|
+
dateString: [string, string] | string,
|
96
|
+
) => handleOnChange(value, dateString)}
|
97
|
+
/>
|
98
|
+
);
|
99
|
+
},
|
100
|
+
mapProps((props: any) => {
|
101
|
+
return handleProps(props);
|
102
|
+
}),
|
103
|
+
);
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import AMapLoader from "./loader";
|
2
|
+
import { markerIconBase64 } from "../../../assets/svg-icon";
|
2
3
|
|
3
4
|
if (!window._AMapLoaderTemp) {
|
4
5
|
window._AMapLoaderTemp = {};
|
@@ -104,7 +105,7 @@ export class MapUtils {
|
|
104
105
|
|
105
106
|
const icon = new AMap.Icon({
|
106
107
|
size: new AMap.Size(34, 34), //图标尺寸
|
107
|
-
image:
|
108
|
+
image: markerIconBase64, // Icon 的图像
|
108
109
|
imageSize: new AMap.Size(34, 34), // 根据所设置的大小拉伸或压缩图片
|
109
110
|
...this.markerIconConf,
|
110
111
|
...markerIconConf,
|
@@ -5,6 +5,7 @@ npm install @amap/amap-jsapi-loader
|
|
5
5
|
## 注意事项
|
6
6
|
|
7
7
|
- isObjectRes 在 @hzab/form-render0.5.0 版本中去除,结果全部存放在对象中
|
8
|
+
- changeMode 在 @hzab/form-render0.5.1 版本中去除,仅允许点击地图选点
|
8
9
|
|
9
10
|
## 引入
|
10
11
|
|
@@ -18,26 +19,25 @@ export default function AMap(props) {
|
|
18
19
|
|
19
20
|
### InfoPanel Attributes
|
20
21
|
|
21
|
-
| 参数 | 类型 | 必填 | 默认值 | 说明
|
22
|
-
| ------------------ | ------- | ---- | --------- |
|
23
|
-
| mode | string | 否 | dialog | 地图显示的类型, dialog 弹窗显示、 show 直接显示
|
24
|
-
| layout | string | 否 | ver | 选择器和地图的布局 hor 水平、 ver 垂直
|
25
|
-
| hasSearch | boolean | 否 | true | 是否允许搜索
|
26
|
-
| isAutoFixAddr | boolean | 否 | false | 打开地图时是否根据经纬度自动修正已填的地址
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
| getCurPositionConf | Object | 否 | - | getCurrentPosition Config |
|
22
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
23
|
+
| ------------------ | ------- | ---- | --------- | ------------------------------------------------ |
|
24
|
+
| mode | string | 否 | dialog | 地图显示的类型, dialog 弹窗显示、 show 直接显示 |
|
25
|
+
| layout | string | 否 | ver | 选择器和地图的布局 hor 水平、 ver 垂直 |
|
26
|
+
| hasSearch | boolean | 否 | true | 是否允许搜索 |
|
27
|
+
| isAutoFixAddr | boolean | 否 | false | 打开地图时是否根据经纬度自动修正已填的地址 |
|
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
35
|
|
36
36
|
#### icons
|
37
37
|
|
38
|
-
| 参数 | 类型 | 必填 | 默认值 | 说明
|
39
|
-
| ------------ | ------ | ---- | ------ |
|
40
|
-
| markerIcon | string | 否 | dialog | marker icon
|
41
|
-
| pickerIcon | string | 否 | dialog | 选点 icon
|
42
|
-
| positionIcon | string | 否 | dialog | 定位 icon
|
43
|
-
| resetIcon | string | 否 | dialog | 重置 icon
|
38
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
39
|
+
| ------------ | ------ | ---- | ------ | ------------------------ |
|
40
|
+
| markerIcon | string | 否 | dialog | marker icon 图片地址 |
|
41
|
+
| pickerIcon | string | 否 | dialog | 选点 icon 图片地址或元素 |
|
42
|
+
| positionIcon | string | 否 | dialog | 定位 icon 图片地址或元素 |
|
43
|
+
| resetIcon | string | 否 | dialog | 重置 icon 图片地址或元素 |
|
@@ -17,6 +17,8 @@ export const markerIcon = (
|
|
17
17
|
</svg>
|
18
18
|
);
|
19
19
|
|
20
|
+
export const markerIconBase64 = `data:image/svg+xml;charset=utf-8;base64,ICA8c3ZnCiAgICB0PSIxNzA4NDk3MTY0NjU0IgogICAgY2xhc3M9Imljb24iCiAgICB2aWV3Qm94PSIwIDAgMTAyNCAxMDI0IgogICAgdmVyc2lvbj0iMS4xIgogICAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICAgcC1pZD0iODQ4OSIKICAgIHdpZHRoPSIyMDAiCiAgICBoZWlnaHQ9IjIwMCIKICA+CiAgICA8cGF0aAogICAgICBkPSJNNTEyIDEwMjRjLTIwNS43Ni0yNDEuNDcyLTMyNi4yNzItNDExLjcxMi0zNjEuNjY0LTUxMC43MmEzODQgMzg0IDAgMSAxIDcyMy4wNzIgMC44MzJDODM3Ljc2IDYxMi45MjggNzE3LjMxMiA3ODIuODQ4IDUxMiAxMDI0LjA2NHogbTAtNTEyYTEyOCAxMjggMCAxIDAgMC0yNTYgMTI4IDEyOCAwIDAgMCAwIDI1NnoiCiAgICAgIGZpbGw9IiMxNjc3ZmYiCiAgICAgIHAtaWQ9Ijg0OTAiCiAgICA+PC9wYXRoPgogIDwvc3ZnPg==`;
|
21
|
+
|
20
22
|
export const pickerIcon = (
|
21
23
|
<svg
|
22
24
|
t="1708305242338"
|
@@ -23,17 +23,3 @@ export function getPropsValue(value = {}, opt) {
|
|
23
23
|
};
|
24
24
|
return res;
|
25
25
|
}
|
26
|
-
|
27
|
-
/**
|
28
|
-
* 获取父级的数据对象(包括当前项的对象)
|
29
|
-
* { 当详情: xxx, 其他项: lll }
|
30
|
-
* @param field
|
31
|
-
* @returns
|
32
|
-
*/
|
33
|
-
export function getParentValue(field) {
|
34
|
-
let form = field?.parent?.value || field?.value;
|
35
|
-
if (Array.isArray(form)) {
|
36
|
-
form = form[field.index];
|
37
|
-
}
|
38
|
-
return form;
|
39
|
-
}
|
@@ -26,10 +26,12 @@
|
|
26
26
|
height: 34px;
|
27
27
|
transform: translate(-50%, -100%);
|
28
28
|
color: #1677ff;
|
29
|
+
pointer-events: none;
|
29
30
|
img,
|
30
31
|
svg {
|
31
32
|
width: 34px;
|
32
33
|
height: 34px;
|
34
|
+
pointer-events: none;
|
33
35
|
}
|
34
36
|
}
|
35
37
|
|
@@ -37,12 +39,14 @@
|
|
37
39
|
position: absolute;
|
38
40
|
right: 20px;
|
39
41
|
bottom: 20px;
|
40
|
-
|
41
|
-
|
42
|
+
.actions-icon-box {
|
43
|
+
margin-bottom: 8px;
|
44
|
+
}
|
45
|
+
img,
|
46
|
+
svg {
|
42
47
|
display: block;
|
43
48
|
width: 32px;
|
44
49
|
height: 32px;
|
45
|
-
margin-bottom: 8px;
|
46
50
|
padding: 4px;
|
47
51
|
background-color: #fff;
|
48
52
|
border-radius: 8px;
|
@@ -38,12 +38,6 @@ export const ModalContent = observer((props: any) => {
|
|
38
38
|
* 打开地图时是否根据经纬度自动修正已填的地址
|
39
39
|
*/
|
40
40
|
isAutoFixAddr = false,
|
41
|
-
/**
|
42
|
-
* 改变经纬度等数据的触发模式
|
43
|
-
* 移动地图:move
|
44
|
-
* 点击地图:click
|
45
|
-
*/
|
46
|
-
changeMode = "click",
|
47
41
|
lonKey = "longitude",
|
48
42
|
latKey = "latitude",
|
49
43
|
addrKey = "address",
|
@@ -132,27 +126,12 @@ export const ModalContent = observer((props: any) => {
|
|
132
126
|
setLoading(props.loading || false);
|
133
127
|
|
134
128
|
if (!(disabled || readOnly)) {
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
});
|
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);
|
151
|
-
// 移动地图
|
152
|
-
mapUtilsRef.current.on("mouseup", handleMove);
|
153
|
-
// PC 端需要额外监听地图缩放事件
|
154
|
-
mapUtilsRef.current.on("zoomend", handleMove);
|
155
|
-
}
|
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
|
+
});
|
156
135
|
} else {
|
157
136
|
// 禁用、只读情况使用 marker 展示点位
|
158
137
|
mapUtilsRef.current?.setPickerMarker(_lon, _lat);
|
@@ -173,10 +152,7 @@ export const ModalContent = observer((props: any) => {
|
|
173
152
|
const lon = _lon || pickInfo.lon;
|
174
153
|
const lat = _lat || pickInfo.lat;
|
175
154
|
let addr = _addr;
|
176
|
-
|
177
|
-
if (changeMode === "click" || disabled || readOnly) {
|
178
|
-
mapUtilsRef.current?.setPickerMarker(_lon, _lat);
|
179
|
-
}
|
155
|
+
mapUtilsRef.current?.setPickerMarker(_lon, _lat);
|
180
156
|
if (changeCenter) {
|
181
157
|
setMapCenter(_lon, _lat);
|
182
158
|
}
|
@@ -236,8 +212,6 @@ export const ModalContent = observer((props: any) => {
|
|
236
212
|
});
|
237
213
|
}
|
238
214
|
|
239
|
-
// 展示已选点位恢复居中按钮:changeMode !== 'move' 或 禁用、只读模式。用于详情等只读情况恢复点位居中
|
240
|
-
const showResetCenter = changeMode !== "move" || disabled || readOnly;
|
241
215
|
// 展示获取当前定位按钮 props.showGetPositionBtn !== false 且非禁用、只读模式
|
242
216
|
const showGetPositionBtn = props.showGetPositionBtn !== false && !(disabled || readOnly);
|
243
217
|
|
@@ -268,33 +242,26 @@ export const ModalContent = observer((props: any) => {
|
|
268
242
|
<AMapCom init={mapInit} loading={loading} markerIconConf={markerIconConf} />
|
269
243
|
<div className="set-map-actions">
|
270
244
|
{/* 已选的点位居中 */}
|
271
|
-
|
272
|
-
typeof resetIcon === "string" ? (
|
273
|
-
<img className="reset-icon" src={resetIcon}
|
245
|
+
<div className="actions-icon-box reset-icon-box" onClick={resetCenter}>
|
246
|
+
{typeof resetIcon === "string" ? (
|
247
|
+
<img className="reset-icon" src={resetIcon} />
|
274
248
|
) : (
|
275
249
|
resetIcon || resetIconDef
|
276
|
-
)
|
277
|
-
|
250
|
+
)}
|
251
|
+
</div>
|
278
252
|
{/* 获取当前经纬度 */}
|
279
253
|
{showGetPositionBtn ? (
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
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>
|
285
261
|
) : null}
|
286
262
|
</div>
|
287
|
-
{changeMode !== "click" && !(disabled || readOnly) && (
|
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>
|
295
|
-
)}
|
296
263
|
</div>
|
297
|
-
{disabled || readOnly ? null : <Notice
|
264
|
+
{disabled || readOnly ? null : <Notice />}
|
298
265
|
</div>
|
299
266
|
{loading && (
|
300
267
|
<div className="spin-loading-wrap">
|
@@ -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
|
|
@@ -9,6 +9,7 @@ import { MapUtils } from "./Map/AMap/common/utils";
|
|
9
9
|
import { getCurrentPosition } from "../../common/location-utils";
|
10
10
|
|
11
11
|
import { getPropsValue } from "./common/utils";
|
12
|
+
import { getAddress } from "./servers";
|
12
13
|
|
13
14
|
import "./index.less";
|
14
15
|
|
@@ -32,12 +33,6 @@ export const LocationPicker = observer(function (props: any) {
|
|
32
33
|
* 打开地图时是否根据经纬度自动修正已填的地址
|
33
34
|
*/
|
34
35
|
isAutoFixAddr = false,
|
35
|
-
/**
|
36
|
-
* 改变经纬度等数据的触发模式
|
37
|
-
* 移动地图 move
|
38
|
-
* 点击地图 click
|
39
|
-
*/
|
40
|
-
changeMode = "click",
|
41
36
|
lonKey = "longitude",
|
42
37
|
latKey = "latitude",
|
43
38
|
addrKey = "address",
|
@@ -45,6 +40,7 @@ export const LocationPicker = observer(function (props: any) {
|
|
45
40
|
// 搜索框是否自动搜索
|
46
41
|
isAutoSearch = true,
|
47
42
|
modalConf = {},
|
43
|
+
icons = {},
|
48
44
|
getCurPositionConf,
|
49
45
|
} = props;
|
50
46
|
|
@@ -70,12 +66,17 @@ export const LocationPicker = observer(function (props: any) {
|
|
70
66
|
// 如果没有传入的经纬度,获取当前实际的经纬度数据
|
71
67
|
// 获取当前经纬度
|
72
68
|
getCurrentPosition(getCurPositionConf)
|
73
|
-
.then((res) => {
|
69
|
+
.then(async (res) => {
|
74
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
|
+
});
|
75
76
|
pickInfoRef.current = {
|
76
|
-
lon
|
77
|
-
lat
|
78
|
-
addr
|
77
|
+
lon,
|
78
|
+
lat,
|
79
|
+
addr,
|
79
80
|
};
|
80
81
|
setDefaultLocation(pickInfoRef.current);
|
81
82
|
setLoading(false);
|
@@ -139,12 +140,6 @@ export const LocationPicker = observer(function (props: any) {
|
|
139
140
|
* 打开地图时是否根据经纬度自动修正已填的地址
|
140
141
|
*/
|
141
142
|
isAutoFixAddr: isAutoFixAddr ?? false,
|
142
|
-
/**
|
143
|
-
* 改变经纬度等数据的触发模式
|
144
|
-
* 移动地图:move
|
145
|
-
* 点击地图:click
|
146
|
-
*/
|
147
|
-
changeMode: changeMode ?? "click",
|
148
143
|
lonKey: lonKey ?? "longitude",
|
149
144
|
latKey: latKey ?? "latitude",
|
150
145
|
addrKey: addrKey ?? "address",
|
@@ -165,7 +160,7 @@ export const LocationPicker = observer(function (props: any) {
|
|
165
160
|
<>
|
166
161
|
{/* 弹窗 */}
|
167
162
|
{/* 有弹窗时,显示表单选中的结果 */}
|
168
|
-
<ResInfo {..._props} onShow={onShow} />
|
163
|
+
<ResInfo {..._props} onShow={onShow} pickerIcon={icons.pickerIcon} />
|
169
164
|
<Modal
|
170
165
|
className="location-picker-modal"
|
171
166
|
title="地图选点"
|
@@ -1,13 +1,33 @@
|
|
1
|
+
export interface addressErrorI extends Error {
|
2
|
+
result?: string;
|
3
|
+
}
|
4
|
+
|
1
5
|
/**
|
2
6
|
* 根据经纬度获取定义的地址
|
3
7
|
* @param lon
|
4
8
|
* @param lat
|
5
9
|
* @returns
|
6
10
|
*/
|
7
|
-
export function getAddress(lon, lat) {
|
11
|
+
export function getAddress(lon, lat): Promise<string> {
|
12
|
+
return new Promise((resolve, reject) => {
|
13
|
+
getAddressByAMap(lon, lat)
|
14
|
+
.then(resolve)
|
15
|
+
.catch((err) => {
|
16
|
+
if (err.result === "USER_DAILY_QUERY_OVER_LIMIT" || err.result === "A_MAP_IS_NOT_DEFINED") {
|
17
|
+
getAddressByFetch(lon, lat).then(resolve).catch(reject);
|
18
|
+
} else {
|
19
|
+
reject(err);
|
20
|
+
}
|
21
|
+
});
|
22
|
+
});
|
23
|
+
}
|
24
|
+
|
25
|
+
export const getAddressByAMap = function (lon, lat): Promise<string> {
|
8
26
|
return new Promise((resolve, reject) => {
|
9
27
|
if (!window.AMap) {
|
10
|
-
|
28
|
+
const error: addressErrorI = Error("Error getAddress window.AMap is not defined.");
|
29
|
+
error.result = "A_MAP_IS_NOT_DEFINED";
|
30
|
+
reject(error);
|
11
31
|
return;
|
12
32
|
}
|
13
33
|
const geocoder = new window.AMap.Geocoder({});
|
@@ -17,35 +37,43 @@ export function getAddress(lon, lat) {
|
|
17
37
|
resolve(formattedAddress);
|
18
38
|
return formattedAddress;
|
19
39
|
} else if (result === "USER_DAILY_QUERY_OVER_LIMIT") {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
return;
|
24
|
-
}
|
25
|
-
fetch(
|
26
|
-
`https://restapi.amap.com/v3/geocode/regeo?location=${lon?.toFixed(6)},${lat?.toFixed(6)}&key=${
|
27
|
-
window._AMapLoaderTemp.serverKey
|
28
|
-
}`,
|
29
|
-
{
|
30
|
-
mode: "cors",
|
31
|
-
},
|
32
|
-
)
|
33
|
-
.then((res) => res.json())
|
34
|
-
.then((res) => {
|
35
|
-
if (res.status === "1") {
|
36
|
-
resolve(res.regeocode?.formatted_address);
|
37
|
-
} else {
|
38
|
-
console.warn("Warn getAddress fetch: ", res);
|
39
|
-
reject(new Error(res.info));
|
40
|
-
}
|
41
|
-
})
|
42
|
-
.catch(reject);
|
40
|
+
const error: addressErrorI = new Error("超出使用限制,请联系管理员");
|
41
|
+
error.result = result;
|
42
|
+
reject(error);
|
43
43
|
} else {
|
44
44
|
reject(result);
|
45
45
|
}
|
46
46
|
});
|
47
47
|
});
|
48
|
-
}
|
48
|
+
};
|
49
|
+
|
50
|
+
export const getAddressByFetch = function (lon, lat): Promise<string> {
|
51
|
+
return new Promise((resolve, reject) => {
|
52
|
+
// 超出限制,使用 webServer 进行请求
|
53
|
+
if (!window._AMapLoaderTemp.serverKey) {
|
54
|
+
reject(new Error("请配置 serverKey"));
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
fetch(
|
58
|
+
`https://restapi.amap.com/v3/geocode/regeo?location=${lon?.toFixed(6)},${lat?.toFixed(6)}&key=${
|
59
|
+
window._AMapLoaderTemp.serverKey
|
60
|
+
}`,
|
61
|
+
{
|
62
|
+
mode: "cors",
|
63
|
+
},
|
64
|
+
)
|
65
|
+
.then((res) => res.json())
|
66
|
+
.then((res) => {
|
67
|
+
if (res.status === "1") {
|
68
|
+
resolve(res.regeocode?.formatted_address);
|
69
|
+
} else {
|
70
|
+
console.warn("Warn getAddressByFetch: ", res);
|
71
|
+
reject(new Error(res.info));
|
72
|
+
}
|
73
|
+
})
|
74
|
+
.catch(reject);
|
75
|
+
});
|
76
|
+
};
|
49
77
|
|
50
78
|
/**
|
51
79
|
* 获取搜索提示
|
@@ -1,11 +1,10 @@
|
|
1
1
|
### InfoPanel Attributes
|
2
2
|
|
3
|
-
| 参数
|
4
|
-
|
|
5
|
-
| dataSource
|
6
|
-
| mergeLast
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| readOnly | boolean | 否 | - | 只读状态 |
|
3
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
4
|
+
| ---------- | ------- | ---- | -------------------------------------------------- | --------------------------------------------- |
|
5
|
+
| dataSource | Array | 是 | - | 树数据 |
|
6
|
+
| mergeLast | boolean | 否 | true | 最后一列是否合并到一个单元格 |
|
7
|
+
| fieldNames | Object | 否 | { label: label, value: value, children: children } | 自定义 options 中 label value children 的字段 |
|
8
|
+
| disabled | boolean | 否 | false | 禁用状态 |
|
9
|
+
| readOnly | boolean | 否 | false | 只读状态 |
|
10
|
+
| tabBox | boolean | 否 | false | 最外层使用 tab |
|