@ebiz/designer-components 0.1.78 → 0.1.79

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 (219) hide show
  1. package/README.md +29 -29
  2. package/dist/designer-components.css +1 -1
  3. package/dist/index.mjs +20744 -20701
  4. package/package.json +1 -1
  5. package/src/App.vue +26 -26
  6. package/src/apiService/SIMPLE_DATA_SERVICE.md +284 -284
  7. package/src/apiService/mockDataService.js +115 -115
  8. package/src/apiService/simpleDataService.js +299 -299
  9. package/src/assets/base.css +86 -86
  10. package/src/assets/logo.svg +1 -1
  11. package/src/components/Button.vue +149 -149
  12. package/src/components/DataContainer.vue +40 -40
  13. package/src/components/EbizApproval.vue +335 -335
  14. package/src/components/EbizApprovalForm.vue +507 -507
  15. package/src/components/EbizAutoForm.vue +596 -596
  16. package/src/components/EbizAvatar.vue +115 -115
  17. package/src/components/EbizCheckbox.vue +93 -93
  18. package/src/components/EbizCheckboxGroup.vue +69 -69
  19. package/src/components/EbizDepartmentSelector.vue +149 -149
  20. package/src/components/EbizDescriptions.vue +340 -340
  21. package/src/components/EbizDescriptionsItem.vue +47 -47
  22. package/src/components/EbizDetailBlock.vue +81 -81
  23. package/src/components/EbizDetailItem.vue +559 -559
  24. package/src/components/EbizDetailView.md +438 -438
  25. package/src/components/EbizDetailView.vue +355 -355
  26. package/src/components/EbizDialog.vue +260 -260
  27. package/src/components/EbizDiv.vue +40 -40
  28. package/src/components/EbizDivider.vue +96 -96
  29. package/src/components/EbizDropdown.vue +135 -135
  30. package/src/components/EbizDropdownItem.vue +85 -85
  31. package/src/components/EbizEmployeeInfo.vue +138 -138
  32. package/src/components/EbizEmployeeSelector.vue +1159 -1159
  33. package/src/components/EbizFileList.vue +466 -466
  34. package/src/components/EbizMap.vue +541 -541
  35. package/src/components/EbizMeetingRoomSelector.vue +664 -664
  36. package/src/components/EbizMobileMeetingRoomSelector.vue +727 -727
  37. package/src/components/EbizOkrTree.vue +99 -99
  38. package/src/components/EbizPageHeader.vue +95 -95
  39. package/src/components/EbizPagination.vue +162 -162
  40. package/src/components/EbizPdfViewer.vue +540 -540
  41. package/src/components/EbizPopconfirm.vue +47 -47
  42. package/src/components/EbizQrCode.vue +73 -73
  43. package/src/components/EbizRadio.vue +86 -86
  44. package/src/components/EbizRadioGroup.vue +83 -83
  45. package/src/components/EbizRemoteSelect.vue +232 -232
  46. package/src/components/EbizRichTextEditor.vue +275 -275
  47. package/src/components/EbizRouteBreadcrumb.vue +46 -46
  48. package/src/components/EbizSApprovalProcess.vue +1429 -1429
  49. package/src/components/EbizSelect.vue +85 -85
  50. package/src/components/EbizSpace.vue +100 -100
  51. package/src/components/EbizStatistic.vue +149 -149
  52. package/src/components/EbizStatsCard.vue +113 -113
  53. package/src/components/EbizSwiper.vue +113 -113
  54. package/src/components/EbizSwiperItem.vue +13 -13
  55. package/src/components/EbizSwitch.vue +85 -85
  56. package/src/components/EbizTabHeader.vue +132 -132
  57. package/src/components/EbizTabPanel.vue +22 -22
  58. package/src/components/EbizTable.vue +469 -469
  59. package/src/components/EbizTableColumn.vue +116 -116
  60. package/src/components/EbizTableSort.vue +179 -179
  61. package/src/components/EbizTabs.vue +142 -142
  62. package/src/components/EbizTdesignButtonDialog.vue +332 -332
  63. package/src/components/EbizTdesignLoading.vue +107 -107
  64. package/src/components/EbizTimePicker.vue +143 -143
  65. package/src/components/EbizTitle.vue +91 -91
  66. package/src/components/EbizTree.vue +141 -141
  67. package/src/components/EbizTreeMergeTable.vue +1494 -1494
  68. package/src/components/EbizTreeSelector.vue +418 -418
  69. package/src/components/EbizVideo.vue +553 -553
  70. package/src/components/EbizVxeTable.vue +290 -290
  71. package/src/components/Form.vue +28 -28
  72. package/src/components/Home.vue +7 -7
  73. package/src/components/MyComponent.vue +39 -39
  74. package/src/components/Table.vue +45 -45
  75. package/src/components/TdesignAlert.vue +115 -115
  76. package/src/components/TdesignButton.vue +135 -135
  77. package/src/components/TdesignCalendar/index.vue +145 -145
  78. package/src/components/TdesignCard.vue +195 -195
  79. package/src/components/TdesignCol.vue +101 -101
  80. package/src/components/TdesignCollapse.vue +142 -142
  81. package/src/components/TdesignCollapsePanel.vue +79 -79
  82. package/src/components/TdesignDatePicker.vue +124 -124
  83. package/src/components/TdesignDescriptions.vue +74 -74
  84. package/src/components/TdesignDescriptionsItem.vue +50 -50
  85. package/src/components/TdesignDialog.vue +225 -225
  86. package/src/components/TdesignForm.vue +138 -138
  87. package/src/components/TdesignFormItem.vue +105 -105
  88. package/src/components/TdesignGrid.vue +55 -55
  89. package/src/components/TdesignIcon.vue +67 -67
  90. package/src/components/TdesignImage.vue +162 -162
  91. package/src/components/TdesignImageViewer.vue +200 -200
  92. package/src/components/TdesignInput.vue +242 -242
  93. package/src/components/TdesignSelect.vue +446 -446
  94. package/src/components/TdesignTag.vue +117 -117
  95. package/src/components/TdesignTextarea.vue +142 -142
  96. package/src/components/TdesignTimeline.vue +58 -58
  97. package/src/components/TdesignTimelineItem.vue +71 -71
  98. package/src/components/TdesignUpload.vue +414 -414
  99. package/src/components/TdesignWatermark.vue +107 -107
  100. package/src/components/ebiz-form/components/cascader.vue +61 -61
  101. package/src/components/ebiz-form/components/checkbox.vue +37 -37
  102. package/src/components/ebiz-form/components/city.vue +137 -137
  103. package/src/components/ebiz-form/components/date-panel.vue +52 -52
  104. package/src/components/ebiz-form/components/date-range-panel.vue +52 -52
  105. package/src/components/ebiz-form/components/date-range.vue +56 -56
  106. package/src/components/ebiz-form/components/date.vue +52 -52
  107. package/src/components/ebiz-form/components/editor-multi-language.vue +47 -47
  108. package/src/components/ebiz-form/components/editor.vue +78 -78
  109. package/src/components/ebiz-form/components/file-multi-language.vue +52 -52
  110. package/src/components/ebiz-form/components/file.vue +149 -149
  111. package/src/components/ebiz-form/components/images-multi-language.vue +52 -52
  112. package/src/components/ebiz-form/components/images.vue +129 -129
  113. package/src/components/ebiz-form/components/img-multi-language.vue +51 -51
  114. package/src/components/ebiz-form/components/img.vue +129 -129
  115. package/src/components/ebiz-form/components/number.vue +50 -50
  116. package/src/components/ebiz-form/components/radio.vue +28 -28
  117. package/src/components/ebiz-form/components/select.vue +119 -119
  118. package/src/components/ebiz-form/components/switch.vue +23 -23
  119. package/src/components/ebiz-form/components/text-multi-language.vue +47 -47
  120. package/src/components/ebiz-form/components/text.vue +52 -52
  121. package/src/components/ebiz-form/components/textarea-multi-language.vue +48 -48
  122. package/src/components/ebiz-form/components/textarea.vue +29 -29
  123. package/src/components/ebiz-form/components/video-multi-language.vue +51 -51
  124. package/src/components/ebiz-form/components/video.vue +97 -97
  125. package/src/components/ebiz-form/index.vue +157 -157
  126. package/src/components/examples/PopconfirmExample.vue +149 -149
  127. package/src/components/icons/IconCommunity.vue +7 -7
  128. package/src/components/icons/IconDocumentation.vue +7 -7
  129. package/src/components/icons/IconEcosystem.vue +7 -7
  130. package/src/components/icons/IconSupport.vue +7 -7
  131. package/src/components/icons/IconTooling.vue +19 -19
  132. package/src/components/mItems/UserInfo.vue +342 -342
  133. package/src/components/senior/EbizSData/index.vue +273 -273
  134. package/src/components/senior/EbizSDialog/index.vue +770 -772
  135. package/src/components/senior/EbizSForm/README.md +157 -157
  136. package/src/components/senior/EbizSForm/index.vue +667 -667
  137. package/src/components/senior/EbizSForm/item.vue +971 -971
  138. package/src/components/senior/EbizSForm/mItems/DateTimePicker.vue +51 -51
  139. package/src/components/senior/EbizSForm/mItems/Picker.vue +63 -63
  140. package/src/index.js +255 -255
  141. package/src/main.js +55 -55
  142. package/src/router/index.js +415 -415
  143. package/src/utils/formatCode.js +24 -24
  144. package/src/utils/generateImportStatement.js +52 -52
  145. package/src/utils/hasJsx.js +25 -25
  146. package/src/utils/index.js +166 -166
  147. package/src/utils/mergeOptions.js +29 -29
  148. package/src/utils/parseRequiredBlocks.js +18 -18
  149. package/src/utils/vue-sfc-validator.js +155 -155
  150. package/src/views/Button.vue +23 -23
  151. package/src/views/CheckboxDemo.vue +104 -104
  152. package/src/views/DataContainer.vue +19 -19
  153. package/src/views/DialogDemo.vue +125 -125
  154. package/src/views/EbizApprovalDemo.vue +87 -87
  155. package/src/views/EbizApprovalFormDemo.vue +207 -207
  156. package/src/views/EbizAutoFormDemo.vue +129 -129
  157. package/src/views/EbizAvatar.vue +223 -223
  158. package/src/views/EbizDepartmentSelectorDemo.vue +169 -169
  159. package/src/views/EbizDetailBlockDemo.vue +30 -30
  160. package/src/views/EbizDetailViewDemo.vue +412 -412
  161. package/src/views/EbizEmployeeInfo.vue +249 -249
  162. package/src/views/EbizEmployeeSelector.vue +85 -85
  163. package/src/views/EbizFileListDemo.vue +339 -339
  164. package/src/views/EbizMap.vue +201 -201
  165. package/src/views/EbizMeetingRoomSelectorDemo.vue +293 -293
  166. package/src/views/EbizMobileMeetingRoomSelectorDemo.vue +566 -566
  167. package/src/views/EbizRadioDemo.vue +151 -151
  168. package/src/views/EbizSDataDemo.vue +136 -136
  169. package/src/views/EbizSDialogDemo.vue +303 -303
  170. package/src/views/EbizSForm/index.vue +351 -351
  171. package/src/views/EbizSFormDemo.vue +420 -420
  172. package/src/views/EbizSpace.vue +185 -185
  173. package/src/views/EbizSwiper.vue +157 -157
  174. package/src/views/EbizTdesignButtonDialogExample.vue +437 -437
  175. package/src/views/Form.vue +19 -19
  176. package/src/views/GridDemo.vue +238 -238
  177. package/src/views/Home.vue +153 -153
  178. package/src/views/Mindmap.vue +17 -17
  179. package/src/views/MyComponent.vue +19 -19
  180. package/src/views/OkrTree.vue +19 -19
  181. package/src/views/PageHeaderDemo.vue +104 -104
  182. package/src/views/PaginationDemo.vue +96 -96
  183. package/src/views/PdfViewerDemo.vue +433 -433
  184. package/src/views/PermissionBoxDemo.vue +85 -85
  185. package/src/views/PopconfirmDemo.vue +80 -80
  186. package/src/views/RemoteSelect.vue +350 -350
  187. package/src/views/StatisticDemo.vue +190 -190
  188. package/src/views/SwitchDemo.vue +79 -79
  189. package/src/views/Table.vue +19 -19
  190. package/src/views/TableDemo.vue +334 -334
  191. package/src/views/TableSortDemo.vue +143 -143
  192. package/src/views/TableView.vue +68 -68
  193. package/src/views/TabsDemo.vue +282 -282
  194. package/src/views/TagDemo.vue +101 -101
  195. package/src/views/TdesignAlert.vue +98 -98
  196. package/src/views/TdesignButton.vue +190 -190
  197. package/src/views/TdesignCalendar.vue +94 -94
  198. package/src/views/TdesignCard.vue +296 -296
  199. package/src/views/TdesignCollapse.vue +293 -293
  200. package/src/views/TdesignDatePicker.vue +187 -187
  201. package/src/views/TdesignDescriptions.vue +101 -101
  202. package/src/views/TdesignForm.vue +248 -248
  203. package/src/views/TdesignIcon.vue +203 -203
  204. package/src/views/TdesignImage.vue +215 -215
  205. package/src/views/TdesignImageViewer.vue +198 -198
  206. package/src/views/TdesignInput.vue +252 -252
  207. package/src/views/TdesignSelect.vue +473 -473
  208. package/src/views/TdesignSwiper.vue +157 -157
  209. package/src/views/TextareaDemo.vue +93 -93
  210. package/src/views/TimePickerDemo.vue +146 -146
  211. package/src/views/TimelineDemo.vue +160 -160
  212. package/src/views/Title.vue +19 -19
  213. package/src/views/TreeDemo.vue +254 -254
  214. package/src/views/TreeMergeTableDemo.vue +239 -239
  215. package/src/views/TreeSelectorDemo.vue +245 -245
  216. package/src/views/UploadDemo.vue +128 -128
  217. package/src/views/VideoDemo.vue +245 -245
  218. package/src/views/VxeTableDemo.vue +279 -279
  219. package/src/views/WatermarkDemo.vue +85 -85
@@ -1,542 +1,542 @@
1
- <template>
2
- <div class="ebiz-map">
3
- <div v-if="!apiKey && !manualInput" class="manual-input-tip">
4
- <div class="tip-content">
5
- <p>请输入高德地图API Key,或者</p>
6
- <button class="switch-btn" @click="manualInput = true">手动输入经纬度</button>
7
- <p class="tip-link">
8
- <a href="https://lbs.amap.com/tools/picker" target="_blank" rel="noopener noreferrer">
9
- 前往高德地图坐标拾取器获取经纬度
10
- </a>
11
- </p>
12
- </div>
13
- </div>
14
-
15
- <div v-if="manualInput" class="manual-input-container">
16
- <div class="input-group">
17
- <label>经度:</label>
18
- <input
19
- type="number"
20
- step="0.000001"
21
- v-model.number="longitude"
22
- @change="updateCoordinates"
23
- placeholder="请输入经度"
24
- />
25
- </div>
26
- <div class="input-group">
27
- <label>纬度:</label>
28
- <input
29
- type="number"
30
- step="0.000001"
31
- v-model.number="latitude"
32
- @change="updateCoordinates"
33
- placeholder="请输入纬度"
34
- />
35
- </div>
36
- <div class="input-actions">
37
- <button class="switch-btn" @click="manualInput = false" v-if="apiKey">切换到地图模式</button>
38
- </div>
39
- <p class="tip-link">
40
- <a href="https://lbs.amap.com/tools/picker" target="_blank" rel="noopener noreferrer">
41
- 前往高德地图坐标拾取器获取经纬度
42
- </a>
43
- </p>
44
- </div>
45
-
46
- <div v-if="apiKey && !manualInput">
47
- <!-- 搜索框 -->
48
- <div class="search-container">
49
- <!-- <div class="search-input-group">
50
- <input
51
- type="text"
52
- v-model="searchKeyword"
53
- @keyup.enter="searchPlace"
54
- placeholder="搜索位置"
55
- class="search-input"
56
- />
57
- <button class="search-btn" @click="searchPlace">搜索</button>
58
- </div> -->
59
- <!-- 搜索结果列表 -->
60
- <!-- <div class="search-results" v-if="searchResults.length > 0">
61
- <div
62
- v-for="(item, index) in searchResults"
63
- :key="index"
64
- class="search-result-item"
65
- @click="selectSearchResult(item)"
66
- >
67
- <div class="result-name">{{ item.name }}</div>
68
- <div class="result-address">{{ item.address }}</div>
69
- </div>
70
- </div> -->
71
- </div>
72
-
73
- <div ref="mapContainer" class="map-container"></div>
74
- <div v-if="showMarkerInfo && modelValue" class="marker-info">
75
- 经度: {{ modelValue[0] }}, 纬度: {{ modelValue[1] }}
76
- </div>
77
- <div class="map-actions">
78
- <button class="switch-btn" @click="manualInput = true">切换到手动输入</button>
79
- </div>
80
- </div>
81
- </div>
82
- </template>
83
-
84
- <script setup>
85
- import { ref, onMounted, watch, onBeforeUnmount, nextTick } from 'vue';
86
-
87
- const props = defineProps({
88
- /**
89
- * 地图中心点经纬度
90
- */
91
- center: {
92
- type: Array,
93
- default: () => [116.397428, 39.90923]
94
- },
95
- /**
96
- * 地图缩放级别
97
- */
98
- zoom: {
99
- type: Number,
100
- default: 11
101
- },
102
- /**
103
- * 地图类型
104
- */
105
- mapType: {
106
- type: String,
107
- default: 'amap',
108
- validator: (value) => ['amap', 'bmap'].includes(value)
109
- },
110
- /**
111
- * 地图高度
112
- */
113
- height: {
114
- type: String,
115
- default: '400px'
116
- },
117
- /**
118
- * 是否显示标记点信息
119
- */
120
- showMarkerInfo: {
121
- type: Boolean,
122
- default: true
123
- },
124
- /**
125
- * 地图 API Key
126
- */
127
- apiKey: {
128
- type: String,
129
- default: ''
130
- },
131
- /**
132
- * 经纬度值
133
- */
134
- modelValue: {
135
- type: Array,
136
- default: null
137
- }
138
- });
139
-
140
- const emit = defineEmits(['update:modelValue', 'markerClick', 'mapClick']);
141
-
142
- const mapContainer = ref(null);
143
- const manualInput = ref(!props.apiKey);
144
- const longitude = ref(props.modelValue ? props.modelValue[0] : props.center[0]);
145
- const latitude = ref(props.modelValue ? props.modelValue[1] : props.center[1]);
146
- const mapLoadError = ref(false);
147
-
148
- // 搜索相关
149
- const searchKeyword = ref('');
150
- const searchResults = ref([]);
151
- let placeSearch = null; // 高德地图搜索服务
152
-
153
- let map = null;
154
- let marker = null;
155
- let amapScript = null;
156
-
157
- // 更新坐标
158
- const updateCoordinates = () => {
159
- if (longitude.value && latitude.value) {
160
- emit('update:modelValue', [longitude.value, latitude.value]);
161
- }
162
- };
163
-
164
- // 添加标记点
165
- const addMarker = (position) => {
166
- if (marker) {
167
- map.remove(marker);
168
- }
169
- marker = new window.AMap.Marker({
170
- position: position,
171
- draggable: true
172
- });
173
- map.add(marker);
174
-
175
- // 拖拽结束后更新坐标
176
- marker.on('dragend', () => {
177
- const position = marker.getPosition();
178
- const lnglat = [position.getLng(), position.getLat()];
179
- emit('update:modelValue', lnglat);
180
- longitude.value = lnglat[0];
181
- latitude.value = lnglat[1];
182
- });
183
-
184
- // 点击标记点事件
185
- marker.on('click', () => {
186
- emit('markerClick', position);
187
- });
188
- };
189
-
190
- // 搜索位置
191
- const searchPlace = () => {
192
- if (!searchKeyword.value || !placeSearch) return;
193
-
194
- placeSearch.search(searchKeyword.value, (status, result) => {
195
- if (status === 'complete' && result.info === 'OK') {
196
- const pois = result.poiList?.pois || [];
197
- searchResults.value = pois.map(poi => ({
198
- name: poi.name,
199
- address: poi.address,
200
- location: [poi.location.lng, poi.location.lat]
201
- }));
202
- } else {
203
- searchResults.value = [];
204
- }
205
- });
206
- };
207
-
208
- // 选择搜索结果
209
- const selectSearchResult = (item) => {
210
- if (item.location && item.location.length === 2) {
211
- const lnglat = item.location;
212
- emit('update:modelValue', lnglat);
213
- emit('mapClick', lnglat);
214
- addMarker(lnglat);
215
- map.setCenter(lnglat);
216
- searchResults.value = []; // 清空搜索结果
217
- searchKeyword.value = item.name; // 更新搜索框内容为选中的地点名称
218
-
219
- // 同步更新手动输入值
220
- longitude.value = lnglat[0];
221
- latitude.value = lnglat[1];
222
- }
223
- };
224
-
225
- // 监听modelValue更新经纬度输入框
226
- watch(() => props.modelValue, (newVal) => {
227
- if (newVal) {
228
- longitude.value = newVal[0];
229
- latitude.value = newVal[1];
230
- }
231
- }, { deep: true });
232
-
233
- // 加载高德地图脚本
234
- const loadAMapScript = () => {
235
- return new Promise((resolve, reject) => {
236
- if (window.AMap) {
237
- resolve(window.AMap);
238
- return;
239
- }
240
-
241
- const script = document.createElement('script');
242
- script.type = 'text/javascript';
243
- script.async = true;
244
- script.src = `https://webapi.amap.com/maps?v=2.0&key=${props.apiKey}&plugin=AMap.PlaceSearch`;
245
- script.onerror = reject;
246
- script.onload = () => {
247
- resolve(window.AMap);
248
- };
249
- document.head.appendChild(script);
250
- amapScript = script;
251
- });
252
- };
253
-
254
- // 清理地图实例
255
- const cleanupMap = () => {
256
- if (map) {
257
- map.destroy();
258
- map = null;
259
- }
260
- };
261
-
262
- // 初始化高德地图
263
- const initAMap = async () => {
264
- if (!props.apiKey || !mapContainer.value) return;
265
-
266
- try {
267
- cleanupMap(); // 清理之前的地图实例
268
- mapLoadError.value = false;
269
-
270
- await loadAMapScript();
271
-
272
- // 初始化地图
273
- map = new window.AMap.Map(mapContainer.value, {
274
- zoom: props.zoom,
275
- center: props.modelValue || props.center,
276
- resizeEnable: true, // 允许缩放
277
- viewMode: '2D' // 设置为2D模式,提高性能
278
- });
279
-
280
- // 添加标记点
281
- if (props.modelValue) {
282
- addMarker(props.modelValue);
283
- }
284
-
285
- // 点击地图事件
286
- map.on('click', (e) => {
287
- const lnglat = [e.lnglat.getLng(), e.lnglat.getLat()];
288
- emit('update:modelValue', lnglat);
289
- emit('mapClick', lnglat);
290
- addMarker(lnglat);
291
-
292
- // 同步更新手动输入值
293
- longitude.value = lnglat[0];
294
- latitude.value = lnglat[1];
295
- });
296
-
297
- // 添加高德地图内置搜索控件
298
- if (props.enableSearch) {
299
- // 使用nextTick确保DOM已更新
300
- nextTick(() => {
301
- initSearchControl();
302
- });
303
- }
304
- } catch (error) {
305
- // 出错时设置错误状态并切换到手动输入模式
306
- mapLoadError.value = true;
307
- manualInput.value = true;
308
- }
309
- };
310
-
311
- // 监听 center 变化
312
- watch(() => props.center, (newVal) => {
313
- if (map && newVal) {
314
- map.setCenter(newVal);
315
- }
316
- }, { deep: true });
317
-
318
- // 监听 zoom 变化
319
- watch(() => props.zoom, (newVal) => {
320
- if (map) {
321
- map.setZoom(newVal);
322
- }
323
- });
324
-
325
- // 监听 manualInput 变化,切换模式后重新初始化地图
326
- watch(manualInput, (newVal) => {
327
- if (!newVal && props.apiKey) {
328
- // 切回地图模式
329
- setTimeout(() => {
330
- initAMap();
331
- }, 0);
332
- }
333
- });
334
-
335
- // 监听 apiKey 变化,有Key后可以使用地图
336
- watch(() => props.apiKey, (newVal) => {
337
- if (newVal && !manualInput.value) {
338
- setTimeout(() => {
339
- initAMap();
340
- }, 0);
341
- }
342
- });
343
-
344
- onMounted(() => {
345
- if (props.apiKey && !manualInput.value && props.mapType === 'amap') {
346
- initAMap();
347
- }
348
-
349
- // 如果有初始值,更新输入框
350
- if (props.modelValue) {
351
- longitude.value = props.modelValue[0];
352
- latitude.value = props.modelValue[1];
353
- }
354
- });
355
-
356
- onBeforeUnmount(() => {
357
- if (map) {
358
- map.destroy();
359
- }
360
-
361
- // 清理脚本
362
- if (amapScript && amapScript.parentNode) {
363
- amapScript.parentNode.removeChild(amapScript);
364
- }
365
- });
366
- </script>
367
-
368
- <style scoped>
369
- .ebiz-map {
370
- position: relative;
371
- width: 100%;
372
- min-height: 150px;
373
- }
374
-
375
- .map-container {
376
- width: 100%;
377
- height: v-bind(height);
378
- }
379
-
380
- .marker-info {
381
- position: absolute;
382
- bottom: 10px;
383
- left: 10px;
384
- background-color: rgba(255, 255, 255, 0.8);
385
- padding: 5px 10px;
386
- border-radius: 4px;
387
- font-size: 12px;
388
- z-index: 10;
389
- }
390
-
391
- .manual-input-tip {
392
- display: flex;
393
- align-items: center;
394
- justify-content: center;
395
- width: 100%;
396
- height: 200px;
397
- background-color: #f5f5f5;
398
- border: 1px dashed #ccc;
399
- border-radius: 4px;
400
- }
401
-
402
- .tip-content {
403
- text-align: center;
404
- }
405
-
406
- .manual-input-container {
407
- padding: 20px;
408
- background-color: #f9f9f9;
409
- border: 1px solid #eee;
410
- border-radius: 4px;
411
- }
412
-
413
- .input-group {
414
- margin-bottom: 15px;
415
- display: flex;
416
- align-items: center;
417
- }
418
-
419
- .input-group label {
420
- width: 60px;
421
- margin-right: 10px;
422
- }
423
-
424
- .input-group input {
425
- flex: 1;
426
- padding: 8px 12px;
427
- border: 1px solid #ddd;
428
- border-radius: 4px;
429
- font-size: 14px;
430
- }
431
-
432
- .input-actions {
433
- margin-bottom: 15px;
434
- }
435
-
436
- .switch-btn {
437
- padding: 6px 12px;
438
- background-color: #1890ff;
439
- color: white;
440
- border: none;
441
- border-radius: 4px;
442
- cursor: pointer;
443
- font-size: 14px;
444
- margin-top: 10px;
445
- }
446
-
447
- .switch-btn:hover {
448
- background-color: #40a9ff;
449
- }
450
-
451
- .map-actions {
452
- margin-top: 10px;
453
- }
454
-
455
- .tip-link {
456
- margin-top: 10px;
457
- font-size: 13px;
458
- }
459
-
460
- .tip-link a {
461
- color: #1890ff;
462
- text-decoration: none;
463
- }
464
-
465
- .tip-link a:hover {
466
- text-decoration: underline;
467
- }
468
-
469
- /* 搜索框样式 */
470
- .search-container {
471
- position: relative;
472
- margin-bottom: 10px;
473
- z-index: 20;
474
- }
475
-
476
- .search-input-group {
477
- display: flex;
478
- align-items: center;
479
- }
480
-
481
- .search-input {
482
- flex: 1;
483
- padding: 8px 12px;
484
- border: 1px solid #ddd;
485
- border-radius: 4px 0 0 4px;
486
- font-size: 14px;
487
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
488
- }
489
-
490
- .search-btn {
491
- padding: 8px 12px;
492
- background-color: #1890ff;
493
- color: white;
494
- border: none;
495
- border-radius: 0 4px 4px 0;
496
- cursor: pointer;
497
- font-size: 14px;
498
- }
499
-
500
- .search-btn:hover {
501
- background-color: #40a9ff;
502
- }
503
-
504
- /* 搜索结果列表 */
505
- .search-results {
506
- position: absolute;
507
- top: 100%;
508
- left: 0;
509
- right: 0;
510
- background-color: white;
511
- border: 1px solid #e8e8e8;
512
- border-radius: 4px;
513
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
514
- max-height: 300px;
515
- overflow-y: auto;
516
- z-index: 30;
517
- }
518
-
519
- .search-result-item {
520
- padding: 10px 15px;
521
- border-bottom: 1px solid #f0f0f0;
522
- cursor: pointer;
523
- }
524
-
525
- .search-result-item:last-child {
526
- border-bottom: none;
527
- }
528
-
529
- .search-result-item:hover {
530
- background-color: #f5f5f5;
531
- }
532
-
533
- .result-name {
534
- font-weight: bold;
535
- margin-bottom: 3px;
536
- }
537
-
538
- .result-address {
539
- font-size: 12px;
540
- color: #666;
541
- }
1
+ <template>
2
+ <div class="ebiz-map">
3
+ <div v-if="!apiKey && !manualInput" class="manual-input-tip">
4
+ <div class="tip-content">
5
+ <p>请输入高德地图API Key,或者</p>
6
+ <button class="switch-btn" @click="manualInput = true">手动输入经纬度</button>
7
+ <p class="tip-link">
8
+ <a href="https://lbs.amap.com/tools/picker" target="_blank" rel="noopener noreferrer">
9
+ 前往高德地图坐标拾取器获取经纬度
10
+ </a>
11
+ </p>
12
+ </div>
13
+ </div>
14
+
15
+ <div v-if="manualInput" class="manual-input-container">
16
+ <div class="input-group">
17
+ <label>经度:</label>
18
+ <input
19
+ type="number"
20
+ step="0.000001"
21
+ v-model.number="longitude"
22
+ @change="updateCoordinates"
23
+ placeholder="请输入经度"
24
+ />
25
+ </div>
26
+ <div class="input-group">
27
+ <label>纬度:</label>
28
+ <input
29
+ type="number"
30
+ step="0.000001"
31
+ v-model.number="latitude"
32
+ @change="updateCoordinates"
33
+ placeholder="请输入纬度"
34
+ />
35
+ </div>
36
+ <div class="input-actions">
37
+ <button class="switch-btn" @click="manualInput = false" v-if="apiKey">切换到地图模式</button>
38
+ </div>
39
+ <p class="tip-link">
40
+ <a href="https://lbs.amap.com/tools/picker" target="_blank" rel="noopener noreferrer">
41
+ 前往高德地图坐标拾取器获取经纬度
42
+ </a>
43
+ </p>
44
+ </div>
45
+
46
+ <div v-if="apiKey && !manualInput">
47
+ <!-- 搜索框 -->
48
+ <div class="search-container">
49
+ <!-- <div class="search-input-group">
50
+ <input
51
+ type="text"
52
+ v-model="searchKeyword"
53
+ @keyup.enter="searchPlace"
54
+ placeholder="搜索位置"
55
+ class="search-input"
56
+ />
57
+ <button class="search-btn" @click="searchPlace">搜索</button>
58
+ </div> -->
59
+ <!-- 搜索结果列表 -->
60
+ <!-- <div class="search-results" v-if="searchResults.length > 0">
61
+ <div
62
+ v-for="(item, index) in searchResults"
63
+ :key="index"
64
+ class="search-result-item"
65
+ @click="selectSearchResult(item)"
66
+ >
67
+ <div class="result-name">{{ item.name }}</div>
68
+ <div class="result-address">{{ item.address }}</div>
69
+ </div>
70
+ </div> -->
71
+ </div>
72
+
73
+ <div ref="mapContainer" class="map-container"></div>
74
+ <div v-if="showMarkerInfo && modelValue" class="marker-info">
75
+ 经度: {{ modelValue[0] }}, 纬度: {{ modelValue[1] }}
76
+ </div>
77
+ <div class="map-actions">
78
+ <button class="switch-btn" @click="manualInput = true">切换到手动输入</button>
79
+ </div>
80
+ </div>
81
+ </div>
82
+ </template>
83
+
84
+ <script setup>
85
+ import { ref, onMounted, watch, onBeforeUnmount, nextTick } from 'vue';
86
+
87
+ const props = defineProps({
88
+ /**
89
+ * 地图中心点经纬度
90
+ */
91
+ center: {
92
+ type: Array,
93
+ default: () => [116.397428, 39.90923]
94
+ },
95
+ /**
96
+ * 地图缩放级别
97
+ */
98
+ zoom: {
99
+ type: Number,
100
+ default: 11
101
+ },
102
+ /**
103
+ * 地图类型
104
+ */
105
+ mapType: {
106
+ type: String,
107
+ default: 'amap',
108
+ validator: (value) => ['amap', 'bmap'].includes(value)
109
+ },
110
+ /**
111
+ * 地图高度
112
+ */
113
+ height: {
114
+ type: String,
115
+ default: '400px'
116
+ },
117
+ /**
118
+ * 是否显示标记点信息
119
+ */
120
+ showMarkerInfo: {
121
+ type: Boolean,
122
+ default: true
123
+ },
124
+ /**
125
+ * 地图 API Key
126
+ */
127
+ apiKey: {
128
+ type: String,
129
+ default: ''
130
+ },
131
+ /**
132
+ * 经纬度值
133
+ */
134
+ modelValue: {
135
+ type: Array,
136
+ default: null
137
+ }
138
+ });
139
+
140
+ const emit = defineEmits(['update:modelValue', 'markerClick', 'mapClick']);
141
+
142
+ const mapContainer = ref(null);
143
+ const manualInput = ref(!props.apiKey);
144
+ const longitude = ref(props.modelValue ? props.modelValue[0] : props.center[0]);
145
+ const latitude = ref(props.modelValue ? props.modelValue[1] : props.center[1]);
146
+ const mapLoadError = ref(false);
147
+
148
+ // 搜索相关
149
+ const searchKeyword = ref('');
150
+ const searchResults = ref([]);
151
+ let placeSearch = null; // 高德地图搜索服务
152
+
153
+ let map = null;
154
+ let marker = null;
155
+ let amapScript = null;
156
+
157
+ // 更新坐标
158
+ const updateCoordinates = () => {
159
+ if (longitude.value && latitude.value) {
160
+ emit('update:modelValue', [longitude.value, latitude.value]);
161
+ }
162
+ };
163
+
164
+ // 添加标记点
165
+ const addMarker = (position) => {
166
+ if (marker) {
167
+ map.remove(marker);
168
+ }
169
+ marker = new window.AMap.Marker({
170
+ position: position,
171
+ draggable: true
172
+ });
173
+ map.add(marker);
174
+
175
+ // 拖拽结束后更新坐标
176
+ marker.on('dragend', () => {
177
+ const position = marker.getPosition();
178
+ const lnglat = [position.getLng(), position.getLat()];
179
+ emit('update:modelValue', lnglat);
180
+ longitude.value = lnglat[0];
181
+ latitude.value = lnglat[1];
182
+ });
183
+
184
+ // 点击标记点事件
185
+ marker.on('click', () => {
186
+ emit('markerClick', position);
187
+ });
188
+ };
189
+
190
+ // 搜索位置
191
+ const searchPlace = () => {
192
+ if (!searchKeyword.value || !placeSearch) return;
193
+
194
+ placeSearch.search(searchKeyword.value, (status, result) => {
195
+ if (status === 'complete' && result.info === 'OK') {
196
+ const pois = result.poiList?.pois || [];
197
+ searchResults.value = pois.map(poi => ({
198
+ name: poi.name,
199
+ address: poi.address,
200
+ location: [poi.location.lng, poi.location.lat]
201
+ }));
202
+ } else {
203
+ searchResults.value = [];
204
+ }
205
+ });
206
+ };
207
+
208
+ // 选择搜索结果
209
+ const selectSearchResult = (item) => {
210
+ if (item.location && item.location.length === 2) {
211
+ const lnglat = item.location;
212
+ emit('update:modelValue', lnglat);
213
+ emit('mapClick', lnglat);
214
+ addMarker(lnglat);
215
+ map.setCenter(lnglat);
216
+ searchResults.value = []; // 清空搜索结果
217
+ searchKeyword.value = item.name; // 更新搜索框内容为选中的地点名称
218
+
219
+ // 同步更新手动输入值
220
+ longitude.value = lnglat[0];
221
+ latitude.value = lnglat[1];
222
+ }
223
+ };
224
+
225
+ // 监听modelValue更新经纬度输入框
226
+ watch(() => props.modelValue, (newVal) => {
227
+ if (newVal) {
228
+ longitude.value = newVal[0];
229
+ latitude.value = newVal[1];
230
+ }
231
+ }, { deep: true });
232
+
233
+ // 加载高德地图脚本
234
+ const loadAMapScript = () => {
235
+ return new Promise((resolve, reject) => {
236
+ if (window.AMap) {
237
+ resolve(window.AMap);
238
+ return;
239
+ }
240
+
241
+ const script = document.createElement('script');
242
+ script.type = 'text/javascript';
243
+ script.async = true;
244
+ script.src = `https://webapi.amap.com/maps?v=2.0&key=${props.apiKey}&plugin=AMap.PlaceSearch`;
245
+ script.onerror = reject;
246
+ script.onload = () => {
247
+ resolve(window.AMap);
248
+ };
249
+ document.head.appendChild(script);
250
+ amapScript = script;
251
+ });
252
+ };
253
+
254
+ // 清理地图实例
255
+ const cleanupMap = () => {
256
+ if (map) {
257
+ map.destroy();
258
+ map = null;
259
+ }
260
+ };
261
+
262
+ // 初始化高德地图
263
+ const initAMap = async () => {
264
+ if (!props.apiKey || !mapContainer.value) return;
265
+
266
+ try {
267
+ cleanupMap(); // 清理之前的地图实例
268
+ mapLoadError.value = false;
269
+
270
+ await loadAMapScript();
271
+
272
+ // 初始化地图
273
+ map = new window.AMap.Map(mapContainer.value, {
274
+ zoom: props.zoom,
275
+ center: props.modelValue || props.center,
276
+ resizeEnable: true, // 允许缩放
277
+ viewMode: '2D' // 设置为2D模式,提高性能
278
+ });
279
+
280
+ // 添加标记点
281
+ if (props.modelValue) {
282
+ addMarker(props.modelValue);
283
+ }
284
+
285
+ // 点击地图事件
286
+ map.on('click', (e) => {
287
+ const lnglat = [e.lnglat.getLng(), e.lnglat.getLat()];
288
+ emit('update:modelValue', lnglat);
289
+ emit('mapClick', lnglat);
290
+ addMarker(lnglat);
291
+
292
+ // 同步更新手动输入值
293
+ longitude.value = lnglat[0];
294
+ latitude.value = lnglat[1];
295
+ });
296
+
297
+ // 添加高德地图内置搜索控件
298
+ if (props.enableSearch) {
299
+ // 使用nextTick确保DOM已更新
300
+ nextTick(() => {
301
+ initSearchControl();
302
+ });
303
+ }
304
+ } catch (error) {
305
+ // 出错时设置错误状态并切换到手动输入模式
306
+ mapLoadError.value = true;
307
+ manualInput.value = true;
308
+ }
309
+ };
310
+
311
+ // 监听 center 变化
312
+ watch(() => props.center, (newVal) => {
313
+ if (map && newVal) {
314
+ map.setCenter(newVal);
315
+ }
316
+ }, { deep: true });
317
+
318
+ // 监听 zoom 变化
319
+ watch(() => props.zoom, (newVal) => {
320
+ if (map) {
321
+ map.setZoom(newVal);
322
+ }
323
+ });
324
+
325
+ // 监听 manualInput 变化,切换模式后重新初始化地图
326
+ watch(manualInput, (newVal) => {
327
+ if (!newVal && props.apiKey) {
328
+ // 切回地图模式
329
+ setTimeout(() => {
330
+ initAMap();
331
+ }, 0);
332
+ }
333
+ });
334
+
335
+ // 监听 apiKey 变化,有Key后可以使用地图
336
+ watch(() => props.apiKey, (newVal) => {
337
+ if (newVal && !manualInput.value) {
338
+ setTimeout(() => {
339
+ initAMap();
340
+ }, 0);
341
+ }
342
+ });
343
+
344
+ onMounted(() => {
345
+ if (props.apiKey && !manualInput.value && props.mapType === 'amap') {
346
+ initAMap();
347
+ }
348
+
349
+ // 如果有初始值,更新输入框
350
+ if (props.modelValue) {
351
+ longitude.value = props.modelValue[0];
352
+ latitude.value = props.modelValue[1];
353
+ }
354
+ });
355
+
356
+ onBeforeUnmount(() => {
357
+ if (map) {
358
+ map.destroy();
359
+ }
360
+
361
+ // 清理脚本
362
+ if (amapScript && amapScript.parentNode) {
363
+ amapScript.parentNode.removeChild(amapScript);
364
+ }
365
+ });
366
+ </script>
367
+
368
+ <style scoped>
369
+ .ebiz-map {
370
+ position: relative;
371
+ width: 100%;
372
+ min-height: 150px;
373
+ }
374
+
375
+ .map-container {
376
+ width: 100%;
377
+ height: v-bind(height);
378
+ }
379
+
380
+ .marker-info {
381
+ position: absolute;
382
+ bottom: 10px;
383
+ left: 10px;
384
+ background-color: rgba(255, 255, 255, 0.8);
385
+ padding: 5px 10px;
386
+ border-radius: 4px;
387
+ font-size: 12px;
388
+ z-index: 10;
389
+ }
390
+
391
+ .manual-input-tip {
392
+ display: flex;
393
+ align-items: center;
394
+ justify-content: center;
395
+ width: 100%;
396
+ height: 200px;
397
+ background-color: #f5f5f5;
398
+ border: 1px dashed #ccc;
399
+ border-radius: 4px;
400
+ }
401
+
402
+ .tip-content {
403
+ text-align: center;
404
+ }
405
+
406
+ .manual-input-container {
407
+ padding: 20px;
408
+ background-color: #f9f9f9;
409
+ border: 1px solid #eee;
410
+ border-radius: 4px;
411
+ }
412
+
413
+ .input-group {
414
+ margin-bottom: 15px;
415
+ display: flex;
416
+ align-items: center;
417
+ }
418
+
419
+ .input-group label {
420
+ width: 60px;
421
+ margin-right: 10px;
422
+ }
423
+
424
+ .input-group input {
425
+ flex: 1;
426
+ padding: 8px 12px;
427
+ border: 1px solid #ddd;
428
+ border-radius: 4px;
429
+ font-size: 14px;
430
+ }
431
+
432
+ .input-actions {
433
+ margin-bottom: 15px;
434
+ }
435
+
436
+ .switch-btn {
437
+ padding: 6px 12px;
438
+ background-color: #1890ff;
439
+ color: white;
440
+ border: none;
441
+ border-radius: 4px;
442
+ cursor: pointer;
443
+ font-size: 14px;
444
+ margin-top: 10px;
445
+ }
446
+
447
+ .switch-btn:hover {
448
+ background-color: #40a9ff;
449
+ }
450
+
451
+ .map-actions {
452
+ margin-top: 10px;
453
+ }
454
+
455
+ .tip-link {
456
+ margin-top: 10px;
457
+ font-size: 13px;
458
+ }
459
+
460
+ .tip-link a {
461
+ color: #1890ff;
462
+ text-decoration: none;
463
+ }
464
+
465
+ .tip-link a:hover {
466
+ text-decoration: underline;
467
+ }
468
+
469
+ /* 搜索框样式 */
470
+ .search-container {
471
+ position: relative;
472
+ margin-bottom: 10px;
473
+ z-index: 20;
474
+ }
475
+
476
+ .search-input-group {
477
+ display: flex;
478
+ align-items: center;
479
+ }
480
+
481
+ .search-input {
482
+ flex: 1;
483
+ padding: 8px 12px;
484
+ border: 1px solid #ddd;
485
+ border-radius: 4px 0 0 4px;
486
+ font-size: 14px;
487
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
488
+ }
489
+
490
+ .search-btn {
491
+ padding: 8px 12px;
492
+ background-color: #1890ff;
493
+ color: white;
494
+ border: none;
495
+ border-radius: 0 4px 4px 0;
496
+ cursor: pointer;
497
+ font-size: 14px;
498
+ }
499
+
500
+ .search-btn:hover {
501
+ background-color: #40a9ff;
502
+ }
503
+
504
+ /* 搜索结果列表 */
505
+ .search-results {
506
+ position: absolute;
507
+ top: 100%;
508
+ left: 0;
509
+ right: 0;
510
+ background-color: white;
511
+ border: 1px solid #e8e8e8;
512
+ border-radius: 4px;
513
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
514
+ max-height: 300px;
515
+ overflow-y: auto;
516
+ z-index: 30;
517
+ }
518
+
519
+ .search-result-item {
520
+ padding: 10px 15px;
521
+ border-bottom: 1px solid #f0f0f0;
522
+ cursor: pointer;
523
+ }
524
+
525
+ .search-result-item:last-child {
526
+ border-bottom: none;
527
+ }
528
+
529
+ .search-result-item:hover {
530
+ background-color: #f5f5f5;
531
+ }
532
+
533
+ .result-name {
534
+ font-weight: bold;
535
+ margin-bottom: 3px;
536
+ }
537
+
538
+ .result-address {
539
+ font-size: 12px;
540
+ color: #666;
541
+ }
542
542
  </style>