@cloudbase/weda-ui 0.2.15 → 0.2.16
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/package.json +10 -7
- package/src/configs/components/calendar.json +75 -0
- package/src/configs/components/carousel.json +273 -0
- package/src/configs/components/chart/statisticsCard.json +331 -0
- package/src/configs/components/dataView.json +139 -0
- package/src/configs/components/form/location.json +152 -0
- package/src/configs/components/form/uploaderFile.json +2 -1
- package/src/configs/components/graphicCard.json +399 -0
- package/src/configs/components/link.json +2 -2
- package/src/configs/components/listView.json +230 -0
- package/src/configs/components/navLayout.json +350 -0
- package/src/configs/components/swiper.json +3 -3
- package/src/configs/index.js +16 -0
- package/src/mp/components/button/index.js +12 -13
- package/src/mp/components/button/index.wxml +1 -1
- package/src/mp/components/calendar/arrowright--line.svg +11 -0
- package/src/mp/components/calendar/index.js +238 -0
- package/src/mp/components/calendar/index.json +4 -0
- package/src/mp/components/calendar/index.wxml +37 -0
- package/src/mp/components/calendar/index.wxss +178 -0
- package/src/mp/components/carousel/index.js +88 -0
- package/src/mp/components/carousel/index.json +7 -0
- package/src/mp/components/carousel/index.wxml +6 -0
- package/src/mp/components/chart/statisticsCard/index.js +226 -0
- package/src/mp/components/chart/statisticsCard/index.json +4 -0
- package/src/mp/components/chart/statisticsCard/index.wxml +9 -0
- package/src/mp/components/chart/statisticsCard/index.wxss +45 -0
- package/src/mp/components/dataView/index.js +34 -0
- package/src/mp/components/dataView/index.json +7 -0
- package/src/mp/components/dataView/index.wxml +15 -0
- package/src/mp/components/dataView/index.wxss +0 -0
- package/src/mp/components/form/location/components/mapChoose/index.js +201 -0
- package/src/mp/components/form/location/components/mapChoose/index.json +4 -0
- package/src/mp/components/form/location/components/mapChoose/index.wxml +42 -0
- package/src/mp/components/form/location/components/mapChoose/index.wxss +188 -0
- package/src/mp/components/form/location/index.js +341 -0
- package/src/mp/components/form/location/index.json +6 -0
- package/src/mp/components/form/location/index.wxml +25 -0
- package/src/mp/components/form/location/index.wxss +91 -0
- package/src/mp/components/form/uploader/index.js +39 -35
- package/src/mp/components/form/uploaderFile/index.js +61 -14
- package/src/mp/components/graphicCard/chevron-right.svg +3 -0
- package/src/mp/components/graphicCard/index.js +205 -0
- package/src/mp/components/graphicCard/index.json +4 -0
- package/src/mp/components/graphicCard/index.wxml +29 -0
- package/src/mp/components/graphicCard/index.wxss +157 -0
- package/src/mp/components/image/index.js +0 -1
- package/src/mp/components/listView/arrow-right-line.svg +3 -0
- package/src/mp/components/listView/index.js +286 -0
- package/src/mp/components/listView/index.json +4 -0
- package/src/mp/components/listView/index.wxml +40 -0
- package/src/mp/components/listView/index.wxss +150 -0
- package/src/mp/components/listView/more-line.svg +3 -0
- package/src/mp/components/navLayout/index.js +123 -0
- package/src/mp/components/navLayout/index.json +7 -0
- package/src/mp/components/navLayout/index.wxml +25 -0
- package/src/mp/components/navLayout/index.wxss +1193 -0
- package/src/mp/components/swiper/index.wxml +2 -0
- package/src/mp/index.json +9 -1
- package/src/mp/utils/debounce.js +133 -0
- package/src/mp/utils/dr_square_point.js +25 -0
- package/src/mp/utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js +1336 -0
- package/src/mp/utils/spark-md5.js +776 -0
- package/src/mp/utils/tcb.js +18 -0
- package/src/web/components/calendar/index.css +382 -0
- package/src/web/components/calendar/index.jsx +312 -0
- package/src/web/components/calendar/util.js +90 -0
- package/src/web/components/carousel/index.css +119 -0
- package/src/web/components/carousel/index.tsx +417 -0
- package/src/web/components/chart/statisticsCard/index.css +62 -0
- package/src/web/components/chart/statisticsCard/index.tsx +286 -0
- package/src/web/components/chart/statisticsCard/interface.ts +14 -0
- package/src/web/components/dataView/index.tsx +20 -0
- package/src/web/components/dataView/interface.ts +6 -0
- package/src/web/components/form/location/common/mapChoose.css +178 -0
- package/src/web/components/form/location/common/mapChoose.jsx +343 -0
- package/src/web/components/form/location/common/mapView.jsx +190 -0
- package/src/web/components/form/location/common/propsConfig.js +54 -0
- package/src/web/components/form/location/common/selectModal.css +44 -0
- package/src/web/components/form/location/common/selectModal.jsx +82 -0
- package/src/web/components/form/location/common/useLocationInfo.js +100 -0
- package/src/web/components/form/location/components/LocationH5/index.css +243 -0
- package/src/web/components/form/location/components/LocationH5/location.h5.jsx +403 -0
- package/src/web/components/form/location/components/LocationPC/Header.jsx +109 -0
- package/src/web/components/form/location/components/LocationPC/index.css +44 -0
- package/src/web/components/form/location/components/LocationPC/location.PC.jsx +323 -0
- package/src/web/components/form/location/constants.js +4 -0
- package/src/web/components/form/location/index.css +0 -0
- package/src/web/components/form/location/index.jsx +25 -0
- package/src/web/components/form/uploader/uploader.h5.tsx +16 -10
- package/src/web/components/form/uploader/uploader.pc.tsx +15 -11
- package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +122 -107
- package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +22 -19
- package/src/web/components/graphicCard/index.css +163 -0
- package/src/web/components/graphicCard/index.tsx +309 -0
- package/src/web/components/image/image.tsx +0 -1
- package/src/web/components/index.js +12 -0
- package/src/web/components/listView/arrow-right-line.svg +3 -0
- package/src/web/components/listView/index.css +139 -0
- package/src/web/components/listView/index.tsx +354 -0
- package/src/web/components/listView/interface.ts +98 -0
- package/src/web/components/navLayout/index.css +332 -0
- package/src/web/components/navLayout/index.tsx +247 -0
- package/src/web/components/tabs/index.tsx +2 -2
- package/src/web/components/tabs/tabs.h5.tsx +7 -4
- package/src/web/components/uploaderFileView/index.css +9 -9
- package/src/web/components/uploaderFileView/index.jsx +32 -23
- package/src/web/types.d.ts +15 -14
- package/src/web/utils/debounce.js +98 -0
- package/src/web/utils/platform.js +31 -0
- package/src/web/utils/tcb.js +35 -0
- package/src/web/utils/tmap.js +4 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as PropTypes from 'prop-types';
|
|
3
|
+
import classNames from '../../../../utils/classnames';
|
|
4
|
+
import debounce from '../../../../utils/debounce';
|
|
5
|
+
import { tmapApiUrl } from '../constants';
|
|
6
|
+
import { getTMap } from '../../../../utils/tmap';
|
|
7
|
+
import './mapChoose.css';
|
|
8
|
+
|
|
9
|
+
const { useEffect, useState, useRef } = React;
|
|
10
|
+
|
|
11
|
+
export default function MapChoose({
|
|
12
|
+
changeLocation,
|
|
13
|
+
latlng = {
|
|
14
|
+
lat: null,
|
|
15
|
+
lng: null,
|
|
16
|
+
},
|
|
17
|
+
isPC,
|
|
18
|
+
APIKEY = '',
|
|
19
|
+
}) {
|
|
20
|
+
const { lat, lng } = latlng;
|
|
21
|
+
|
|
22
|
+
const mapRef = useRef();
|
|
23
|
+
const markerRef = useRef();
|
|
24
|
+
const centerRef = useRef();
|
|
25
|
+
|
|
26
|
+
const [isSearch, setIsSearch] = useState(false);
|
|
27
|
+
const [searchValue, setSearchValue] = useState('');
|
|
28
|
+
const [chooseLoc, setChooseLoc] = useState({
|
|
29
|
+
location: {
|
|
30
|
+
lat: null,
|
|
31
|
+
lng: null,
|
|
32
|
+
},
|
|
33
|
+
title: '',
|
|
34
|
+
address: '',
|
|
35
|
+
id: '',
|
|
36
|
+
});
|
|
37
|
+
const [exploreList, setExploreList] = useState([]);
|
|
38
|
+
const [searchList, setSearchList] = useState([]);
|
|
39
|
+
const [mapDomName, setMapDomName] = useState(new Date().getTime());
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!APIKEY || APIKEY == '这里是示例') return;
|
|
43
|
+
function loadScript() {
|
|
44
|
+
const script = document.createElement('script');
|
|
45
|
+
script.type = 'text/javascript';
|
|
46
|
+
script.src = `${tmapApiUrl}?v=2.exp&key=${APIKEY}&callback=init&libraries=service`;
|
|
47
|
+
script.onload = () => {
|
|
48
|
+
initMap();
|
|
49
|
+
};
|
|
50
|
+
script.onerror = (error) => {
|
|
51
|
+
console.log(' load mapchoose error success', APIKEY);
|
|
52
|
+
};
|
|
53
|
+
document.body.appendChild(script);
|
|
54
|
+
}
|
|
55
|
+
if (getTMap()) {
|
|
56
|
+
initMap();
|
|
57
|
+
} else {
|
|
58
|
+
loadScript();
|
|
59
|
+
}
|
|
60
|
+
exploreNear();
|
|
61
|
+
return () => {
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
mapRef.current && mapRef.current.destroy();
|
|
64
|
+
};
|
|
65
|
+
}, [APIKEY]);
|
|
66
|
+
|
|
67
|
+
const initMap = () => {
|
|
68
|
+
if (!getTMap()) return;
|
|
69
|
+
const TMap = getTMap();
|
|
70
|
+
//定义地图中心点坐标
|
|
71
|
+
const center = new TMap.LatLng(lat, lng);
|
|
72
|
+
//定义map变量,调用 TMap.Map() 构造函数创建地图
|
|
73
|
+
mapRef.current = new TMap.Map(
|
|
74
|
+
document.getElementById(`form-map-choose-${mapDomName}`),
|
|
75
|
+
{
|
|
76
|
+
center, //设置地图中心点坐标
|
|
77
|
+
zoom: 16, //设置地图缩放级别
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
initMarker(getTMap(), mapRef.current);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const initMarker = (TMap, map) => {
|
|
84
|
+
const canLoad = lat && lng && TMap && map;
|
|
85
|
+
if (canLoad) {
|
|
86
|
+
const position = new TMap.LatLng(lat, lng);
|
|
87
|
+
markerRef.current = new TMap.MultiMarker({
|
|
88
|
+
map: mapRef.current,
|
|
89
|
+
styles: {
|
|
90
|
+
pointer: new TMap.MarkerStyle({
|
|
91
|
+
width: 26,
|
|
92
|
+
height: 35,
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
geometries: [
|
|
96
|
+
{
|
|
97
|
+
id: `pointer-origin-${mapDomName}`,
|
|
98
|
+
styleId: 'pointer',
|
|
99
|
+
position,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: `pointer-${mapDomName}`,
|
|
103
|
+
styleId: 'pointer',
|
|
104
|
+
position,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
});
|
|
108
|
+
// 监听中心点变化事件,更新marker的位置
|
|
109
|
+
map.on('center_changed', updateCenter);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const updateCenter = () => {
|
|
114
|
+
const TMap = getTMap();
|
|
115
|
+
const canLoad = TMap && lat && lng && mapRef.current;
|
|
116
|
+
if (canLoad) {
|
|
117
|
+
const nowPosition = new TMap.LatLng(lat, lng);
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
let centerPosition = mapRef.current.getCenter();
|
|
120
|
+
centerRef.current = centerPosition;
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
markerRef.current.updateGeometries([
|
|
123
|
+
{
|
|
124
|
+
id: `pointer-origin-${mapDomName}`,
|
|
125
|
+
styleId: 'pointer',
|
|
126
|
+
position: nowPosition,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: `pointer-${mapDomName}`,
|
|
130
|
+
styleId: 'pointer',
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
position: mapRef.current.getCenter(),
|
|
133
|
+
},
|
|
134
|
+
]);
|
|
135
|
+
exploreNear();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const handleFocus = (value) => {
|
|
140
|
+
setIsSearch(value);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const exploreNear = debounce(() => {
|
|
144
|
+
const { lat, lng } = centerRef.current || latlng;
|
|
145
|
+
let TMap = getTMap();
|
|
146
|
+
let search = new TMap.service.Search({ pageSize: 20 }); // 新建一个地点搜索类
|
|
147
|
+
search
|
|
148
|
+
.explore({
|
|
149
|
+
center: new TMap.LatLng(lat, lng),
|
|
150
|
+
policy: 1,
|
|
151
|
+
radius: 2000,
|
|
152
|
+
pageIndex: 1,
|
|
153
|
+
})
|
|
154
|
+
.then((res) => {
|
|
155
|
+
res.data && setExploreList(res.data);
|
|
156
|
+
});
|
|
157
|
+
}, 500);
|
|
158
|
+
|
|
159
|
+
const chooseLoction = (value, type) => {
|
|
160
|
+
const TMap = getTMap();
|
|
161
|
+
//定义地图中心点坐标
|
|
162
|
+
const center = new TMap.LatLng(value.location.lat, value.location.lng);
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
mapRef.current.setCenter(center);
|
|
165
|
+
setChooseLoc(value);
|
|
166
|
+
changeLocation(value);
|
|
167
|
+
type && cancleSearch();
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const changeSearchValue = (event) => {
|
|
171
|
+
if (event.target.value) {
|
|
172
|
+
setSearchValue(event.target.value);
|
|
173
|
+
let TMap = getTMap();
|
|
174
|
+
let search = new TMap.service.Search({ pageSize: 10 }); // 新建一个地点搜索类
|
|
175
|
+
search
|
|
176
|
+
.searchNearby({
|
|
177
|
+
keyword: event.target.value,
|
|
178
|
+
center: new TMap.LatLng(lat, lng),
|
|
179
|
+
radius: 2000,
|
|
180
|
+
pageIndex: 1,
|
|
181
|
+
})
|
|
182
|
+
.then((res) => {
|
|
183
|
+
setSearchList(res.data);
|
|
184
|
+
})
|
|
185
|
+
.catch((error) => {
|
|
186
|
+
console.log('error', error);
|
|
187
|
+
});
|
|
188
|
+
} else {
|
|
189
|
+
setSearchValue('');
|
|
190
|
+
setTimeout(() => {
|
|
191
|
+
setSearchList([]);
|
|
192
|
+
}, 300);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const cancleSearch = () => {
|
|
197
|
+
handleFocus(false);
|
|
198
|
+
setSearchValue('');
|
|
199
|
+
setSearchList([]);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const renderHeader = () => {
|
|
203
|
+
return (
|
|
204
|
+
<div
|
|
205
|
+
className={classNames({
|
|
206
|
+
'map-choose-header': true,
|
|
207
|
+
'map-choose-header_focus': isSearch,
|
|
208
|
+
})}
|
|
209
|
+
>
|
|
210
|
+
<div className="map-choose-header_search">
|
|
211
|
+
<input
|
|
212
|
+
type="text"
|
|
213
|
+
onFocus={() => {
|
|
214
|
+
handleFocus(true);
|
|
215
|
+
}}
|
|
216
|
+
onChange={changeSearchValue}
|
|
217
|
+
value={searchValue}
|
|
218
|
+
/>
|
|
219
|
+
{!searchValue && (
|
|
220
|
+
<div className="map-choose-header_search_place">
|
|
221
|
+
<img
|
|
222
|
+
src="https://qcloudimg.tencent-cloud.cn/raw/388c48cdcbe9ca07f5682fb10d05ebdd.png"
|
|
223
|
+
alt=""
|
|
224
|
+
/>
|
|
225
|
+
<span>搜索地点</span>
|
|
226
|
+
</div>
|
|
227
|
+
)}
|
|
228
|
+
</div>
|
|
229
|
+
<span
|
|
230
|
+
className="map-choose-header_search_cancel"
|
|
231
|
+
onClick={cancleSearch}
|
|
232
|
+
>
|
|
233
|
+
取消
|
|
234
|
+
</span>
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
const renderMapView = () => {
|
|
239
|
+
return (
|
|
240
|
+
<div
|
|
241
|
+
id={`form-map-choose-${mapDomName}`}
|
|
242
|
+
style={{ height: isPC ? '100%' : '45%', width: '100%' }}
|
|
243
|
+
></div>
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
const renderSuggestList = () => {
|
|
247
|
+
return (
|
|
248
|
+
<div
|
|
249
|
+
className={classNames({
|
|
250
|
+
'map-choose-warp_sugges': true,
|
|
251
|
+
'map-choose-explore_show_inSearch': isSearch,
|
|
252
|
+
'map-choose-warp_sugges-pc': isPC,
|
|
253
|
+
})}
|
|
254
|
+
>
|
|
255
|
+
<ul>
|
|
256
|
+
{exploreList.map((item, index) => (
|
|
257
|
+
<li
|
|
258
|
+
key={index}
|
|
259
|
+
onClick={() => {
|
|
260
|
+
chooseLoction(item);
|
|
261
|
+
}}
|
|
262
|
+
className={classNames({
|
|
263
|
+
'map-choose-warp_sugges_choosed': chooseLoc.id == item.id,
|
|
264
|
+
})}
|
|
265
|
+
>
|
|
266
|
+
<div className="map-choose-warp_sugges_title">{item.title}</div>
|
|
267
|
+
<div>{item.address}</div>
|
|
268
|
+
<span />
|
|
269
|
+
</li>
|
|
270
|
+
))}
|
|
271
|
+
</ul>
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
const renderExplore = () => {
|
|
276
|
+
return (
|
|
277
|
+
<div
|
|
278
|
+
className={classNames({
|
|
279
|
+
'map-choose-explore': true,
|
|
280
|
+
'map-choose-explore_show': isSearch,
|
|
281
|
+
'map-choose-explore_show-h5': isSearch && !isPC,
|
|
282
|
+
'map-choose-explore-pc': isPC,
|
|
283
|
+
'map-choose-explore_show-pc': isPC,
|
|
284
|
+
})}
|
|
285
|
+
>
|
|
286
|
+
<ul>
|
|
287
|
+
{searchList.map((item, index) => (
|
|
288
|
+
<li
|
|
289
|
+
key={index}
|
|
290
|
+
onClick={() => {
|
|
291
|
+
chooseLoction(item, true);
|
|
292
|
+
}}
|
|
293
|
+
className={classNames({
|
|
294
|
+
'map-choose-explore_choosed': chooseLoc.id == item.id,
|
|
295
|
+
})}
|
|
296
|
+
>
|
|
297
|
+
<div className="map-choose-explore_title">{item.title}</div>
|
|
298
|
+
<div>{item.address}</div>
|
|
299
|
+
<span />
|
|
300
|
+
</li>
|
|
301
|
+
))}
|
|
302
|
+
</ul>
|
|
303
|
+
</div>
|
|
304
|
+
);
|
|
305
|
+
};
|
|
306
|
+
if (isPC) {
|
|
307
|
+
return (
|
|
308
|
+
<div
|
|
309
|
+
className={classNames(
|
|
310
|
+
'map-choose',
|
|
311
|
+
'map-choose-pc',
|
|
312
|
+
'weda-ui_map-choose'
|
|
313
|
+
)}
|
|
314
|
+
>
|
|
315
|
+
<div className="map-choose-pc-left">
|
|
316
|
+
{renderHeader()}
|
|
317
|
+
{renderSuggestList()}
|
|
318
|
+
{renderExplore()}
|
|
319
|
+
</div>
|
|
320
|
+
<div className="map-choose-pc-right">{renderMapView()}</div>
|
|
321
|
+
</div>
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
return (
|
|
325
|
+
<div className="map-choose weda-ui_map-choose">
|
|
326
|
+
{renderHeader()}
|
|
327
|
+
<div className="map-choose-con">
|
|
328
|
+
<div className="map-choose-warp">
|
|
329
|
+
{renderMapView()}
|
|
330
|
+
{renderSuggestList()}
|
|
331
|
+
</div>
|
|
332
|
+
{renderExplore()}
|
|
333
|
+
</div>
|
|
334
|
+
</div>
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
MapChoose.propTypes = {
|
|
339
|
+
APIKEY: PropTypes.string,
|
|
340
|
+
latlng: PropTypes.object,
|
|
341
|
+
changeLocation: PropTypes.func,
|
|
342
|
+
isPC: PropTypes.bool,
|
|
343
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as PropTypes from 'prop-types';
|
|
3
|
+
import { tmapApiUrl } from '../constants';
|
|
4
|
+
import { getTMap } from '../../../../utils/tmap';
|
|
5
|
+
|
|
6
|
+
const { useEffect, useRef, useState } = React;
|
|
7
|
+
|
|
8
|
+
export default function MapView({
|
|
9
|
+
APIKEY = '',
|
|
10
|
+
drag = true,
|
|
11
|
+
zoom = true,
|
|
12
|
+
latlng = {
|
|
13
|
+
lat: null,
|
|
14
|
+
lng: null,
|
|
15
|
+
},
|
|
16
|
+
}) {
|
|
17
|
+
const mapRef = useRef();
|
|
18
|
+
const markerRef = useRef();
|
|
19
|
+
const mapDom = useRef();
|
|
20
|
+
const mapDomName = useRef(new Date().getTime());
|
|
21
|
+
const [mapStatus, setMapStatus] = useState(false);
|
|
22
|
+
const { lat, lng } = latlng;
|
|
23
|
+
|
|
24
|
+
const initMap = () => {
|
|
25
|
+
if (mapRef.current || !mapDom.current) return;
|
|
26
|
+
try {
|
|
27
|
+
const TMap = getTMap();
|
|
28
|
+
//定义地图中心点坐标
|
|
29
|
+
const center = new TMap.LatLng(lat, lng);
|
|
30
|
+
//定义map变量,调用 TMap.Map() 构造函数创建地图
|
|
31
|
+
mapRef.current = new TMap.Map(mapDom.current, {
|
|
32
|
+
center, //设置地图中心点坐标
|
|
33
|
+
zoom: 16, //设置地图缩放级别
|
|
34
|
+
minZoom: 3,
|
|
35
|
+
maxZoom: 20,
|
|
36
|
+
});
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
mapRef.current.setDraggable(drag);
|
|
39
|
+
removeOrAddZoom(mapRef.current, TMap);
|
|
40
|
+
initMarker();
|
|
41
|
+
setMapStatus(true);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.log('initMap error', error);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const initMarker = () => {
|
|
48
|
+
try {
|
|
49
|
+
const TMap = getTMap();
|
|
50
|
+
const canLoad = TMap && lat && lng && mapRef.current;
|
|
51
|
+
if (canLoad) {
|
|
52
|
+
const position = new TMap.LatLng(lat, lng);
|
|
53
|
+
markerRef.current = new TMap.MultiMarker({
|
|
54
|
+
map: mapRef.current,
|
|
55
|
+
styles: {
|
|
56
|
+
pointer: new TMap.MarkerStyle({
|
|
57
|
+
width: 26,
|
|
58
|
+
height: 35,
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
geometries: [
|
|
62
|
+
{
|
|
63
|
+
id: `pointer-${mapDomName.current}`,
|
|
64
|
+
styleId: 'pointer',
|
|
65
|
+
position,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.log('initMarker err', err);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!APIKEY || APIKEY == '这里是示例') return;
|
|
77
|
+
function loadScript() {
|
|
78
|
+
// 移除之前的
|
|
79
|
+
if (document.getElementById('tmap-script')) {
|
|
80
|
+
document.body.removeChild(document.getElementById('tmap-script'));
|
|
81
|
+
}
|
|
82
|
+
const script = document.createElement('script');
|
|
83
|
+
script.type = 'text/javascript';
|
|
84
|
+
script.src = `${tmapApiUrl}?v=2.exp&key=${APIKEY}&callback=init&libraries=service`;
|
|
85
|
+
script.setAttribute('id', 'tmap-script');
|
|
86
|
+
script.onload = () => {
|
|
87
|
+
initMap();
|
|
88
|
+
};
|
|
89
|
+
script.onerror = (err) => {
|
|
90
|
+
console.log('loadScript err', err);
|
|
91
|
+
};
|
|
92
|
+
document.body.appendChild(script);
|
|
93
|
+
}
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
loadScript();
|
|
96
|
+
}, 1000);
|
|
97
|
+
return () => {
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
mapRef.current && mapRef.current.destroy();
|
|
100
|
+
mapRef.current = null;
|
|
101
|
+
setMapStatus(false);
|
|
102
|
+
};
|
|
103
|
+
}, [APIKEY]);
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
mapRef.current && mapRef.current.setDraggable(drag);
|
|
108
|
+
}, [drag, mapRef.current]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
mapRef.current && getTMap() && removeOrAddZoom(mapRef.current, getTMap());
|
|
112
|
+
}, [zoom, mapRef.current]);
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
const TMap = getTMap();
|
|
116
|
+
const canLoad = TMap && lat && lng && mapRef.current && mapStatus;
|
|
117
|
+
if (canLoad) {
|
|
118
|
+
try {
|
|
119
|
+
const newLatLng = new TMap.LatLng(lat, lng);
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
mapRef.current.setCenter(newLatLng);
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
mapRef.current.panTo(newLatLng);
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
markerRef.current.updateGeometries([
|
|
126
|
+
{
|
|
127
|
+
styleId: 'pointer',
|
|
128
|
+
id: `pointer-${mapDomName.current}`,
|
|
129
|
+
position: newLatLng,
|
|
130
|
+
},
|
|
131
|
+
]);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.log('updateGeometries error view', error);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}, [lat, lng, mapStatus]);
|
|
137
|
+
|
|
138
|
+
// 缩放事件
|
|
139
|
+
const removeOrAddZoom = (map, TMap) => {
|
|
140
|
+
try {
|
|
141
|
+
let level = map.getZoom();
|
|
142
|
+
map.setScrollable(zoom);
|
|
143
|
+
map.setDoubleClickZoom(zoom);
|
|
144
|
+
// 缩放控件
|
|
145
|
+
if (zoom) {
|
|
146
|
+
addControl(map, TMap);
|
|
147
|
+
map.setMaxZoom(20);
|
|
148
|
+
map.setMinZoom(3);
|
|
149
|
+
} else {
|
|
150
|
+
removeControl(map, TMap);
|
|
151
|
+
map.setMaxZoom(level);
|
|
152
|
+
map.setMinZoom(level);
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
console.log('removeOrAddZoom error', error);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// 移除缩放控件
|
|
160
|
+
const removeControl = (map, TMap) => {
|
|
161
|
+
if (!map.getControl(TMap.constants.DEFAULT_CONTROL_ID.ZOOM)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.ZOOM);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// 缩放控件添加到地图上
|
|
168
|
+
const addControl = (map, TMap) => {
|
|
169
|
+
let control = map.getControl(TMap.constants.DEFAULT_CONTROL_ID.ZOOM);
|
|
170
|
+
if (!control) {
|
|
171
|
+
map.addControl(control);
|
|
172
|
+
control.setPosition(TMap.constants.CONTROL_POSITION.BOTTOM_RIGHT);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<div
|
|
178
|
+
ref={mapDom}
|
|
179
|
+
id={`form-location-map-${mapDomName.current}`}
|
|
180
|
+
style={{ height: '100%', width: '100%' }}
|
|
181
|
+
></div>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
MapView.propTypes = {
|
|
186
|
+
APIKEY: PropTypes.string,
|
|
187
|
+
drag: PropTypes.bool,
|
|
188
|
+
zoom: PropTypes.bool,
|
|
189
|
+
latlng: PropTypes.object,
|
|
190
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as PropTypes from 'prop-types';
|
|
2
|
+
|
|
3
|
+
export const propTypes = {
|
|
4
|
+
// 系统属性
|
|
5
|
+
id: PropTypes.string,
|
|
6
|
+
className: PropTypes.string,
|
|
7
|
+
style: PropTypes.string,
|
|
8
|
+
events: PropTypes.object,
|
|
9
|
+
// 组件属性
|
|
10
|
+
label: PropTypes.string,
|
|
11
|
+
labelVisible: PropTypes.bool,
|
|
12
|
+
APIKEY: PropTypes.string,
|
|
13
|
+
showLngLat: PropTypes.bool,
|
|
14
|
+
showMap: PropTypes.bool,
|
|
15
|
+
defauleShowLocation: PropTypes.bool,
|
|
16
|
+
drag: PropTypes.bool,
|
|
17
|
+
zoom: PropTypes.bool,
|
|
18
|
+
disabled: PropTypes.bool,
|
|
19
|
+
requiredFlag: PropTypes.bool,
|
|
20
|
+
decorator: PropTypes.oneOfType([PropTypes.array, PropTypes.node]),
|
|
21
|
+
value: PropTypes.object,
|
|
22
|
+
locationType: PropTypes.number,
|
|
23
|
+
customLocation: PropTypes.object,
|
|
24
|
+
dataSource: PropTypes.object,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const defaultProps = {
|
|
28
|
+
// 系统属性
|
|
29
|
+
events: {},
|
|
30
|
+
// 组件属性
|
|
31
|
+
label: '地图定位',
|
|
32
|
+
labelVisible: true,
|
|
33
|
+
APIKEY: '',
|
|
34
|
+
showLngLat: false,
|
|
35
|
+
showMap: false,
|
|
36
|
+
defauleShowLocation: false,
|
|
37
|
+
drag: true,
|
|
38
|
+
zoom: true,
|
|
39
|
+
disabled: false,
|
|
40
|
+
requiredFlag: false,
|
|
41
|
+
locationType: 1,
|
|
42
|
+
customLocation: {},
|
|
43
|
+
// 模型应用属性
|
|
44
|
+
value: {
|
|
45
|
+
address: '',
|
|
46
|
+
geopoint: {
|
|
47
|
+
coordinates: [39.984104, 116.307503],
|
|
48
|
+
type: 'Point',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
readOnly: false,
|
|
52
|
+
isModalApp: false,
|
|
53
|
+
dataSource: {},
|
|
54
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
.form-select-map .tea-dialog__inner {
|
|
2
|
+
width: 100vw !important;
|
|
3
|
+
height: 100vh !important;
|
|
4
|
+
min-width: auto !important;
|
|
5
|
+
padding: 0;
|
|
6
|
+
}
|
|
7
|
+
.form-select-map .wedatea2td-dialog__inner {
|
|
8
|
+
box-shadow: none;
|
|
9
|
+
border: 0;
|
|
10
|
+
min-width: 100vw !important;
|
|
11
|
+
width: 100vw !important;
|
|
12
|
+
height: 100vh !important;
|
|
13
|
+
overflow-x: scroll;
|
|
14
|
+
}
|
|
15
|
+
.form-select-map .wedatea2td-dialog__inner .wedatea2td-dialog__header {
|
|
16
|
+
margin-bottom: 0;
|
|
17
|
+
}
|
|
18
|
+
.form-select-map .tea-dialog__header {
|
|
19
|
+
height: 30px;
|
|
20
|
+
margin-bottom: 0;
|
|
21
|
+
margin-left: 15px;
|
|
22
|
+
margin-right: 15px;
|
|
23
|
+
}
|
|
24
|
+
.form-select-map .tea-dialog__header .tea-dialog__headertitle {
|
|
25
|
+
line-height: 30px;
|
|
26
|
+
margin-bottom: 0;
|
|
27
|
+
}
|
|
28
|
+
.form-select-map .tea-dialog__body {
|
|
29
|
+
height: calc(100vh - 90px);
|
|
30
|
+
}
|
|
31
|
+
.form-select-map .tea-dialog__footer {
|
|
32
|
+
height: 30px;
|
|
33
|
+
margin-top: 10px;
|
|
34
|
+
}
|
|
35
|
+
.weda-ui_form-select {
|
|
36
|
+
background-color: #fff;
|
|
37
|
+
}
|
|
38
|
+
/* 大屏版样式 */
|
|
39
|
+
.form-select-map-pc .wedatea2td-dialog__inner {
|
|
40
|
+
height: 800px !important;
|
|
41
|
+
}
|
|
42
|
+
.form-select-map-pc .wedatea2td-dialog__body {
|
|
43
|
+
height: calc(100% - 100px);
|
|
44
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Modal, Button } from 'tea-component';
|
|
3
|
+
import * as PropTypes from 'prop-types';
|
|
4
|
+
import { usePlatform } from '../../../../utils/platform';
|
|
5
|
+
import classNames from '../../../../utils/classnames';
|
|
6
|
+
import MapChoose from './mapChoose';
|
|
7
|
+
import './selectModal.css';
|
|
8
|
+
|
|
9
|
+
const { useRef } = React;
|
|
10
|
+
|
|
11
|
+
export default function SelectModal({
|
|
12
|
+
location = { latlng: { lat: null, lng: null } },
|
|
13
|
+
setLocation,
|
|
14
|
+
isSelectMapVisible = false,
|
|
15
|
+
setIsSelectMapVisible,
|
|
16
|
+
chooseLocation,
|
|
17
|
+
APIKEY = '',
|
|
18
|
+
}) {
|
|
19
|
+
const latlng = location.latlng || { lat: null, lng: null };
|
|
20
|
+
const positionRef = useRef({});
|
|
21
|
+
const platform = usePlatform();
|
|
22
|
+
const isPC = platform === 'pc';
|
|
23
|
+
|
|
24
|
+
const close = () => setIsSelectMapVisible(false);
|
|
25
|
+
const confirm = () => {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
if (positionRef.current.latlng) {
|
|
28
|
+
setLocation(positionRef.current);
|
|
29
|
+
chooseLocation(positionRef.current);
|
|
30
|
+
}
|
|
31
|
+
close();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getPosition = (value) => {
|
|
35
|
+
const { title, location } = value;
|
|
36
|
+
let loc = {
|
|
37
|
+
poiname: title,
|
|
38
|
+
latlng: { lat: location.lat, lng: location.lng },
|
|
39
|
+
};
|
|
40
|
+
positionRef.current = loc;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Modal
|
|
45
|
+
visible={isSelectMapVisible}
|
|
46
|
+
caption="选择地理位置"
|
|
47
|
+
onClose={close}
|
|
48
|
+
className={classNames({
|
|
49
|
+
'weda-ui_form-select': true,
|
|
50
|
+
'form-select-map': !isPC,
|
|
51
|
+
'form-select-map-pc': isPC,
|
|
52
|
+
})}
|
|
53
|
+
{...(isPC ? { size: 1200 } : {})}
|
|
54
|
+
>
|
|
55
|
+
<Modal.Body>
|
|
56
|
+
<MapChoose
|
|
57
|
+
latlng={latlng}
|
|
58
|
+
changeLocation={getPosition}
|
|
59
|
+
isPC={isPC}
|
|
60
|
+
APIKEY={APIKEY}
|
|
61
|
+
/>
|
|
62
|
+
</Modal.Body>
|
|
63
|
+
<Modal.Footer>
|
|
64
|
+
<Button type="primary" onClick={confirm}>
|
|
65
|
+
确定
|
|
66
|
+
</Button>
|
|
67
|
+
<Button type="weak" onClick={close}>
|
|
68
|
+
取消
|
|
69
|
+
</Button>
|
|
70
|
+
</Modal.Footer>
|
|
71
|
+
</Modal>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
SelectModal.propTypes = {
|
|
76
|
+
location: PropTypes.object,
|
|
77
|
+
isSelectMapVisible: PropTypes.bool,
|
|
78
|
+
APIKEY: PropTypes.string,
|
|
79
|
+
setLocation: PropTypes.func,
|
|
80
|
+
setIsSelectMapVisible: PropTypes.func,
|
|
81
|
+
chooseLocation: PropTypes.func,
|
|
82
|
+
};
|