@formily-design/formily-antd 1.0.0 → 1.0.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.
Files changed (66) hide show
  1. package/package.json +8 -8
  2. package/.umirc.js +0 -44
  3. package/copy.ts +0 -6
  4. package/playground/components/AsyncSelect/AsyncSelect.tsx +0 -38
  5. package/playground/components/AsyncSelect/index.tsx +0 -1
  6. package/playground/components/AsyncSelect/preview.tsx +0 -36
  7. package/playground/components/ClickEventSetter/ActionConfigModal.tsx +0 -173
  8. package/playground/components/ClickEventSetter/ActionList.tsx +0 -67
  9. package/playground/components/ClickEventSetter/DownloadPanel.tsx +0 -24
  10. package/playground/components/ClickEventSetter/NavigationPanel.tsx +0 -42
  11. package/playground/components/ClickEventSetter/RequestPanel.tsx +0 -190
  12. package/playground/components/ClickEventSetter/index.tsx +0 -90
  13. package/playground/components/ClickEventSetter/styles.less +0 -89
  14. package/playground/components/ClickEventSetter/types.ts +0 -43
  15. package/playground/components/FormButton/FormButton.tsx +0 -189
  16. package/playground/components/FormButton/hooks/useEventActionExecutor.ts +0 -65
  17. package/playground/components/FormButton/index.ts +0 -1
  18. package/playground/components/FormButton/preview.tsx +0 -60
  19. package/playground/components/FormButton/utils/actionExecutors.ts +0 -96
  20. package/playground/components/FormButtonGroup/FormButtonGroup.tsx +0 -21
  21. package/playground/components/FormButtonGroup/index.ts +0 -1
  22. package/playground/components/FormButtonGroup/preview.tsx +0 -66
  23. package/playground/components/FormList/FormList.tsx +0 -164
  24. package/playground/components/FormList/index.tsx +0 -1
  25. package/playground/components/FormList/preview.tsx +0 -429
  26. package/playground/components/LocationPicker/LocationModal.tsx +0 -328
  27. package/playground/components/LocationPicker/LocationPicker.tsx +0 -163
  28. package/playground/components/LocationPicker/SearchBox.tsx +0 -122
  29. package/playground/components/LocationPicker/api.ts +0 -77
  30. package/playground/components/LocationPicker/constants.ts +0 -2
  31. package/playground/components/LocationPicker/index.tsx +0 -44
  32. package/playground/components/LocationPicker/types.ts +0 -160
  33. package/playground/components/LocationPicker/utils.ts +0 -46
  34. package/playground/components/ResourceIcon/index.module.less +0 -10
  35. package/playground/components/ResourceIcon/index.tsx +0 -10
  36. package/playground/designerLocales/en-US.ts +0 -38
  37. package/playground/designerLocales/index.ts +0 -6
  38. package/playground/designerLocales/ko-KR.ts +0 -10
  39. package/playground/designerLocales/zh-CN.ts +0 -38
  40. package/playground/locales/FormButton.ts +0 -38
  41. package/playground/locales/FormButtonGroup.ts +0 -29
  42. package/playground/locales/LocationPicker.ts +0 -30
  43. package/playground/locales/all.ts +0 -3
  44. package/playground/locales/index.ts +0 -3
  45. package/playground/main.tsx +0 -222
  46. package/playground/react-app-env.d.ts +0 -4
  47. package/playground/request.ts +0 -123
  48. package/playground/schemas/FormButton.ts +0 -42
  49. package/playground/schemas/FormButtonGroup.ts +0 -24
  50. package/playground/schemas/LocationPicker.ts +0 -14
  51. package/playground/schemas/all.ts +0 -3
  52. package/playground/schemas/index.ts +0 -3
  53. package/playground/service/index.ts +0 -1
  54. package/playground/service/schema.ts +0 -22
  55. package/playground/template.ejs +0 -20
  56. package/playground/utils.ts +0 -744
  57. package/playground/webpack.base.ts +0 -123
  58. package/playground/webpack.dev.ts +0 -64
  59. package/playground/webpack.prod.ts +0 -46
  60. package/playground/widgets/ActionsWidget.tsx +0 -58
  61. package/playground/widgets/LogoWidget.tsx +0 -20
  62. package/playground/widgets/MarkupSchemaWidget.tsx +0 -164
  63. package/playground/widgets/PreviewWidget.tsx +0 -188
  64. package/playground/widgets/SchemaEditorWidget.tsx +0 -27
  65. package/playground/widgets/index.ts +0 -5
  66. package/tsconfig.build.json +0 -12
@@ -1,328 +0,0 @@
1
- import React, { useState, useCallback, useContext, useEffect } from 'react'
2
- import { Modal, Button, message } from 'antd'
3
- import { EnvironmentOutlined } from '@ant-design/icons'
4
- import { TMap, MapContext, MultiMarker } from 'tlbs-map-react'
5
- import { LocationValue, SearchResult } from './types'
6
- import { SearchBox } from './SearchBox'
7
- import { fetchAddressInfo, fetchMapLocationInfo } from './api'
8
- import { parseAdcode } from './utils'
9
-
10
- interface LocationModalProps {
11
- visible: boolean
12
- value?: LocationValue
13
- onConfirm: (value: LocationValue) => void
14
- onCancel: () => void
15
- mapId?: string
16
- readOnly?: boolean
17
- mapKey: string
18
- }
19
-
20
- interface PointGeometry {
21
- styleId: string
22
- position: {
23
- lat: number
24
- lng: number
25
- }
26
- }
27
-
28
- // 默认中心点(北京)
29
- const DEFAULT_CENTER = {
30
- lat: 39.9042,
31
- lng: 116.4074,
32
- }
33
-
34
- // 标记样式
35
- interface MarkerStyle {
36
- width: number
37
- height: number
38
- anchor: { x: number; y: number }
39
- src?: string
40
- }
41
-
42
- const MARKER_STYLES: Record<string, MarkerStyle> = {
43
- marker: {
44
- width: 30,
45
- height: 40,
46
- anchor: { x: 15, y: 40 },
47
- },
48
- }
49
-
50
- // 地图点击处理组件
51
- const MapClickHandler: React.FC<{
52
- onMapClick: (lat: number, lng: number) => void
53
- }> = ({ onMapClick }) => {
54
- const mapInstance = useContext(MapContext)
55
-
56
- useEffect(() => {
57
- if (!mapInstance) return
58
-
59
- const handleClick = (event: any) => {
60
- const { lat, lng } = event.latLng
61
- onMapClick(lat, lng)
62
- }
63
-
64
- // 监听地图点击事件
65
- mapInstance.on('click', handleClick)
66
-
67
- return () => {
68
- mapInstance.off('click', handleClick)
69
- }
70
- }, [mapInstance, onMapClick])
71
-
72
- return null
73
- }
74
-
75
- // 标记点管理组件
76
- const MarkerController: React.FC<{
77
- location: LocationValue | null
78
- }> = ({ location }) => {
79
- const [geometries, setGeometries] = useState<PointGeometry[]>([])
80
-
81
- useEffect(() => {
82
- if (location) {
83
- setGeometries([
84
- {
85
- styleId: 'marker',
86
- position: {
87
- lat: location.lat,
88
- lng: location.lng,
89
- },
90
- },
91
- ])
92
- } else {
93
- setGeometries([])
94
- }
95
- }, [location])
96
-
97
- return <MultiMarker styles={MARKER_STYLES} geometries={geometries} />
98
- }
99
-
100
- export const LocationModal: React.FC<LocationModalProps> = (props) => {
101
- const { visible, value, onConfirm, onCancel, readOnly, mapKey } = props
102
-
103
- const [selectedLocation, setSelectedLocation] =
104
- useState<LocationValue | null>(null)
105
- const [center, setCenter] = useState(DEFAULT_CENTER)
106
-
107
- /** 处理地图点击 */
108
- const handleMapClick = useCallback(
109
- async (lat: number, lng: number) => {
110
- if (readOnly) return
111
- const { address, ...addressInfo } = await fetchAddressInfo(lat, lng, {
112
- mapKey,
113
- })
114
- const locationData: LocationValue = {
115
- ...addressInfo,
116
- address,
117
- lat,
118
- lng,
119
- name: address ? address.split(',')[0] : '',
120
- }
121
- setSelectedLocation(locationData)
122
- },
123
- [readOnly, mapKey]
124
- )
125
-
126
- /** 处理搜索结果选择 */
127
- const handleSelectSearchResult = useCallback((result: SearchResult) => {
128
- /** 省市区编码 */
129
- const adCodeInfo = parseAdcode(String(result.adcode))
130
- const locationData: LocationValue = {
131
- ...adCodeInfo,
132
- address: result.address || result.title,
133
- lat: result.lat,
134
- lng: result.lng,
135
- name: result.title,
136
- provinceName: result.province,
137
- cityName: result.city,
138
- districtName: result.district,
139
- }
140
- setSelectedLocation(locationData)
141
- setCenter({ lat: result.lat, lng: result.lng })
142
- }, [])
143
-
144
- /** 定位当前位置 */
145
- const handleLocateCurrent = useCallback(() => {
146
- if (!navigator.geolocation) {
147
- message.warning('您的浏览器不支持定位功能')
148
- return
149
- }
150
-
151
- message.loading('正在定位...', 0)
152
-
153
- // 设备 api 获取位置
154
- navigator.geolocation.getCurrentPosition(
155
- (position) => {
156
- message.destroy()
157
- const { latitude, longitude } = position.coords
158
- fetchAddressInfo(latitude, longitude, { mapKey }).then(
159
- ({ address, ...addressInfo }) => {
160
- const locationData: LocationValue = {
161
- ...addressInfo,
162
- address,
163
- lat: latitude,
164
- lng: longitude,
165
- name: '当前位置',
166
- }
167
- setSelectedLocation(locationData)
168
- setCenter({ lat: latitude, lng: longitude })
169
- }
170
- )
171
- },
172
- (error) => {
173
- message.destroy()
174
- console.error('定位失败:', error)
175
- switch (error.code) {
176
- case error.PERMISSION_DENIED:
177
- message.warning('定位权限被拒绝,请手动选择位置')
178
- break
179
- case error.POSITION_UNAVAILABLE:
180
- message.error('位置信息不可用')
181
- break
182
- case error.TIMEOUT:
183
- message.error('定位超时')
184
- break
185
- default:
186
- message.error('定位失败')
187
- }
188
- },
189
- {
190
- enableHighAccuracy: true,
191
- timeout: 10000,
192
- maximumAge: 0,
193
- }
194
- )
195
- }, [mapKey])
196
-
197
- /** 确认选择 */
198
- const handleConfirm = useCallback(async () => {
199
- if (selectedLocation) {
200
- // 如果没有地址,尝试获取
201
- if (!selectedLocation.address) {
202
- const { address, ...addressInfo } = await fetchAddressInfo(
203
- selectedLocation.lat,
204
- selectedLocation.lng,
205
- {
206
- mapKey,
207
- }
208
- )
209
- onConfirm({ ...selectedLocation, ...addressInfo, address })
210
- } else {
211
- onConfirm(selectedLocation)
212
- }
213
- } else if (value) {
214
- onConfirm(value)
215
- } else {
216
- message.warning('请先选择位置')
217
- }
218
- }, [selectedLocation, value, onConfirm, mapKey])
219
-
220
- /** 取消 */
221
- const handleCancel = useCallback(() => {
222
- setSelectedLocation(null)
223
- onCancel()
224
- }, [onCancel])
225
-
226
- /** 地图加载完成回调 */
227
- const onMapInited = () => {
228
- if (visible && !value) {
229
- fetchMapLocationInfo(mapKey).then(({ lat, lng }) => {
230
- setCenter({ lat, lng })
231
- })
232
- }
233
- }
234
-
235
- /** 弹窗打开时重置地图 key 以重新初始化 */
236
- useEffect(() => {
237
- if (visible) {
238
- if (value) {
239
- setSelectedLocation(value)
240
- setCenter({ lat: value.lat, lng: value.lng })
241
- } else {
242
- setCenter(DEFAULT_CENTER)
243
- setSelectedLocation(null)
244
- }
245
- }
246
- }, [visible, value])
247
-
248
- return (
249
- <Modal
250
- title={readOnly ? '查看位置' : '选择位置'}
251
- open={visible}
252
- onCancel={handleCancel}
253
- footer={
254
- readOnly
255
- ? [
256
- <Button key="cancel" onClick={handleCancel}>
257
- 取消
258
- </Button>,
259
- ]
260
- : [
261
- <Button
262
- key="locate"
263
- icon={<EnvironmentOutlined />}
264
- onClick={handleLocateCurrent}
265
- >
266
- 定位当前
267
- </Button>,
268
- <Button key="cancel" onClick={handleCancel}>
269
- 取消
270
- </Button>,
271
- <Button key="confirm" type="primary" onClick={handleConfirm}>
272
- 确认选择
273
- </Button>,
274
- ]
275
- }
276
- width={700}
277
- centered
278
- destroyOnClose
279
- >
280
- <div className="location-modal-content">
281
- {!readOnly && (
282
- <SearchBox onSelect={handleSelectSearchResult} mapKey={mapKey} />
283
- )}
284
- {mapKey ? (
285
- <div
286
- style={{
287
- width: '100%',
288
- height: 400,
289
- marginTop: 16,
290
- borderRadius: 8,
291
- overflow: 'hidden',
292
- }}
293
- >
294
- <TMap
295
- apiKey={mapKey}
296
- options={{ center }}
297
- style={{ width: '100%', height: '100%' }}
298
- onMapInited={onMapInited}
299
- >
300
- <MapClickHandler onMapClick={handleMapClick} />
301
- <MarkerController location={selectedLocation} />
302
- </TMap>
303
- </div>
304
- ) : (
305
- <div style={{ height: 60, display: 'flex', alignItems: 'center' }}>
306
- 地图加载失败,请配置地图 key
307
- </div>
308
- )}
309
- {selectedLocation?.address && (
310
- <div
311
- style={{
312
- marginTop: 12,
313
- padding: 8,
314
- background: '#f0f9ff',
315
- borderRadius: 4,
316
- fontSize: 14,
317
- }}
318
- >
319
- <EnvironmentOutlined style={{ marginRight: 8, color: '#1890ff' }} />
320
- {selectedLocation.address}
321
- </div>
322
- )}
323
- </div>
324
- </Modal>
325
- )
326
- }
327
-
328
- export default LocationModal
@@ -1,163 +0,0 @@
1
- import React, { useState, useCallback, useMemo } from 'react'
2
- import { Input, Space } from 'antd'
3
- import { EnvironmentOutlined } from '@ant-design/icons'
4
- import { LocationPickerProps, LocationValue } from './types'
5
- import { LocationModal } from './LocationModal'
6
- import { PreviewText } from '@formily/antd-v5'
7
- import { connect, mapReadPretty } from '@formily/react'
8
-
9
- /** 业务字段和组件值的映射默认配置 */
10
- const VALUE_MAP = {
11
- /** 完整地址 */
12
- address: 'address',
13
- /** 纬度 */
14
- lat: 'lat',
15
- /** 经度 */
16
- lng: 'lng',
17
- /** 省级编码 */
18
- provinceCode: 'provinceCode',
19
- /** 省级名称 */
20
- provinceName: 'provinceName',
21
- /** 市级编码 */
22
- cityCode: 'cityCode',
23
- /** 市级名称 */
24
- cityName: 'cityName',
25
- /** 区级编码 */
26
- districtCode: 'districtCode',
27
- /** 区级名称 */
28
- districtName: 'districtName',
29
- /** 名称 */
30
- name: 'name',
31
- }
32
-
33
- /** 将组件值映射为业务字段 */
34
- const mapToBusinessFields = (
35
- location: LocationValue,
36
- fieldNames: Record<string, string>
37
- ): Record<string, unknown> => {
38
- const result: Record<string, unknown> = {}
39
- Object.entries(fieldNames).forEach(([key, fieldKey]) => {
40
- const v = location[key as keyof LocationValue]
41
- if (v !== undefined && v !== null) {
42
- result[fieldKey] = v
43
- }
44
- })
45
- return result
46
- }
47
-
48
- /** 将业务字段映射为组件值 */
49
- const mapToComponentValue = (
50
- value: Record<string, unknown>,
51
- fieldNames: Record<string, string>
52
- ): LocationValue => {
53
- const result: LocationValue = {
54
- address: '',
55
- lat: 0,
56
- lng: 0,
57
- provinceCode: '',
58
- provinceName: '',
59
- cityCode: '',
60
- cityName: '',
61
- districtCode: '',
62
- districtName: '',
63
- name: '',
64
- }
65
- Object.entries(fieldNames).forEach(([key, fieldKey]) => {
66
- const v = value[fieldKey]
67
- if (v !== undefined && v !== null) {
68
- result[key as keyof LocationValue] = v as never
69
- }
70
- })
71
- return result
72
- }
73
-
74
- function LocationPickerComp(props: LocationPickerProps) {
75
- const {
76
- value,
77
- onChange,
78
- placeholder = '请选择位置',
79
- disabled,
80
- mapId,
81
- readOnly,
82
- fieldNames: propsFieldNames,
83
- mapApiKey,
84
- ...restProps
85
- } = props
86
- const fieldNames = useMemo(
87
- () => ({ ...VALUE_MAP, ...propsFieldNames }),
88
- [propsFieldNames]
89
- )
90
- const [modalVisible, setModalVisible] = useState(false)
91
-
92
- const handleOpenModal = useCallback(() => {
93
- if (!disabled) {
94
- setModalVisible(true)
95
- }
96
- }, [disabled])
97
-
98
- const handleConfirm = useCallback(
99
- (location: LocationValue) => {
100
- onChange?.(mapToBusinessFields(location, fieldNames))
101
- setModalVisible(false)
102
- },
103
- [onChange, fieldNames]
104
- )
105
-
106
- const handleCancel = useCallback(() => {
107
- setModalVisible(false)
108
- }, [])
109
-
110
- // 将业务字段映射为组件值
111
- const fieldValue = value ? mapToComponentValue(value, fieldNames) : undefined
112
- // 显示值
113
- const displayValue = fieldValue?.address ?? ''
114
-
115
- return (
116
- <>
117
- <Input
118
- {...restProps}
119
- value={displayValue}
120
- placeholder={placeholder}
121
- disabled={disabled}
122
- readOnly
123
- prefix={
124
- <Space>
125
- <EnvironmentOutlined style={{ color: '#1890ff' }} />
126
- </Space>
127
- }
128
- onClick={handleOpenModal}
129
- style={{ cursor: disabled ? 'not-allowed' : 'pointer' }}
130
- />
131
- <LocationModal
132
- visible={modalVisible}
133
- value={fieldValue}
134
- onConfirm={handleConfirm}
135
- onCancel={handleCancel}
136
- mapId={mapId}
137
- mapKey={mapApiKey}
138
- readOnly={readOnly}
139
- />
140
- </>
141
- )
142
- }
143
-
144
- /** 位置选择器阅读模式组件 */
145
- function PockerPreviewText(props: LocationPickerProps) {
146
- const { value, fieldNames: propsFieldNames } = props
147
- const fieldNames = useMemo(
148
- () => ({ ...VALUE_MAP, ...propsFieldNames }),
149
- [propsFieldNames]
150
- )
151
- // 将业务字段映射为组件值
152
- const fieldValue = value ? mapToComponentValue(value, fieldNames) : undefined
153
- // 显示值
154
- const displayValue = fieldValue?.address ?? ''
155
- return <PreviewText.Input value={displayValue} />
156
- }
157
-
158
- export const LocationPicker = connect(
159
- LocationPickerComp,
160
- mapReadPretty(PockerPreviewText)
161
- )
162
-
163
- export default LocationPicker
@@ -1,122 +0,0 @@
1
- import React, { useState, useCallback } from 'react'
2
- import { Input, Button, List, message } from 'antd'
3
- import { SearchOutlined } from '@ant-design/icons'
4
- import { SearchResult } from './types'
5
- import { fetchPlaceSuggestion } from './api'
6
-
7
- interface SearchBoxProps {
8
- onSearch?: () => void
9
- onSelect: (result: SearchResult) => void
10
- mapKey: string
11
- }
12
-
13
- export const SearchBox: React.FC<SearchBoxProps> = (props) => {
14
- const { onSearch, onSelect, mapKey } = props
15
-
16
- const [keyword, setKeyword] = useState('')
17
- const [searchResults, setSearchResults] = useState<SearchResult[]>([])
18
- const [searching, setSearching] = useState(false)
19
-
20
- const handleSearch = useCallback(async () => {
21
- if (!keyword.trim()) {
22
- message.warning('请输入地址关键字')
23
- return
24
- }
25
-
26
- setSearching(true)
27
- try {
28
- const data = await fetchPlaceSuggestion(keyword, { mapKey })
29
- if (data && data.length > 0) {
30
- // 模糊搜索结果
31
- const results: SearchResult[] = data.map((item) => ({
32
- title: item.title || '',
33
- address: item.address || '',
34
- lat: item.location?.lat || 0,
35
- lng: item.location?.lng || 0,
36
- category: item.category,
37
- adcode: item.adcode,
38
- province: item.province,
39
- city: item.city,
40
- district: item.district,
41
- }))
42
- setSearchResults(results)
43
- onSearch?.()
44
- } else {
45
- message.warning('未找到相关地址')
46
- setSearchResults([])
47
- onSearch?.()
48
- }
49
- } catch (error) {
50
- console.error('搜索地址失败:', error)
51
- message.error('搜索地址失败,请稍后重试')
52
- } finally {
53
- setSearching(false)
54
- }
55
- }, [keyword, onSearch, mapKey])
56
-
57
- const handleSelect = useCallback(
58
- (result: SearchResult) => {
59
- setSearchResults([])
60
- setKeyword('')
61
- onSelect(result)
62
- },
63
- [onSelect]
64
- )
65
-
66
- const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
67
- setKeyword(e.target.value)
68
- }, [])
69
-
70
- const handleKeyPress = useCallback(
71
- (e: React.KeyboardEvent<HTMLInputElement>) => {
72
- if (e.key === 'Enter') {
73
- handleSearch()
74
- }
75
- },
76
- [handleSearch]
77
- )
78
-
79
- return (
80
- <div>
81
- <Input
82
- placeholder="输入地址搜索..."
83
- value={keyword}
84
- onChange={handleChange}
85
- onKeyDown={handleKeyPress}
86
- suffix={
87
- <Button
88
- type="primary"
89
- icon={<SearchOutlined />}
90
- loading={searching}
91
- onClick={handleSearch}
92
- style={{ marginRight: -8 }}
93
- />
94
- }
95
- style={{ width: '100%' }}
96
- />
97
- {searchResults.length > 0 && (
98
- <List
99
- size="small"
100
- dataSource={searchResults}
101
- renderItem={(item) => (
102
- <List.Item
103
- onClick={() => handleSelect(item)}
104
- style={{ cursor: 'pointer' }}
105
- >
106
- <List.Item.Meta title={item.title} description={item.address} />
107
- </List.Item>
108
- )}
109
- style={{
110
- maxHeight: 150,
111
- overflow: 'auto',
112
- border: '1px solid #d9d9d9',
113
- borderTop: 'none',
114
- borderRadius: '0 0 8px 8px',
115
- }}
116
- />
117
- )}
118
- </div>
119
- )
120
- }
121
-
122
- export default SearchBox
@@ -1,77 +0,0 @@
1
- import {
2
- GeocoderResponse,
3
- MapLocationResponse,
4
- SuggestionResponse,
5
- } from './types'
6
- import { fetchMapService, parseAdcode } from './utils'
7
-
8
- /** 地址解析函数 */
9
- export function fetchAddressInfo(
10
- lat: number,
11
- lng: number,
12
- options: {
13
- mapKey: string
14
- }
15
- ): Promise<{
16
- address: string
17
- provinceCode: string
18
- cityCode: string
19
- districtCode: string
20
- provinceName: string
21
- cityName: string
22
- districtName: string
23
- }> {
24
- const TENCENT_MAP_KEY = options.mapKey
25
- const url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${lat},${lng}&output=jsonp&key=${TENCENT_MAP_KEY}`
26
- return fetchMapService<GeocoderResponse>(url).then((res) => {
27
- if (!res.result) {
28
- throw new Error('获取地址失败')
29
- }
30
- /** 省市区编码 */
31
- const adCodeInfo = parseAdcode(res.result.ad_info.adcode)
32
- return {
33
- address: res.result.address || '',
34
- ...adCodeInfo,
35
- provinceName: res.result.address_component.province,
36
- cityName: res.result.address_component.city,
37
- districtName: res.result.address_component.district,
38
- }
39
- })
40
- }
41
-
42
- /** 请求地图定位 */
43
- export function fetchMapLocationInfo(
44
- mapKey: string
45
- ): Promise<{ lat: number; lng: number }> {
46
- const url = `https://apis.map.qq.com/ws/location/v1/ip?key=${mapKey}&output=jsonp`
47
- return fetchMapService<MapLocationResponse>(url).then((res) => {
48
- if (res.result) {
49
- return {
50
- lat: res.result.location.lat,
51
- lng: res.result.location.lng,
52
- }
53
- } else {
54
- // 提示错误
55
- throw new Error('获取定位失败')
56
- }
57
- })
58
- }
59
-
60
- /** 关键词输入提示 */
61
- export function fetchPlaceSuggestion(
62
- keyword: string,
63
- options: {
64
- mapKey: string
65
- }
66
- ): Promise<SuggestionResponse['data']> {
67
- const TENCENT_MAP_KEY = options.mapKey
68
- const encodedKeyword = keyword.trim()
69
- const url = `https://apis.map.qq.com/ws/place/v1/suggestion?keyword=${encodedKeyword}&key=${TENCENT_MAP_KEY}&output=jsonp`
70
- return fetchMapService<SuggestionResponse>(url).then((res) => {
71
- if (res.data) {
72
- return res.data
73
- } else {
74
- return []
75
- }
76
- })
77
- }
@@ -1,2 +0,0 @@
1
- /** 腾讯地图 key */
2
- export const MAP_KEY = '4NNBZ-6WLWU-6DWVM-2RYMV-WBZ3V-7MFJS'