@ebiz/designer-components 0.0.31 → 0.0.33

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebiz/designer-components",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -0,0 +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
+ }
542
+ </style>
@@ -20,8 +20,7 @@
20
20
  </div>
21
21
  </div>
22
22
  <div class="sort-footer">
23
- <t-button theme="default" variant="outline" @click="addSortItem"
24
- v-if="sortItems.length < maxSortItems">
23
+ <t-button theme="default" variant="outline" @click="addSortItem" v-if="sortItems.length < maxSortItems">
25
24
  <template #icon>
26
25
  <t-icon name="add" />
27
26
  </template>
@@ -33,7 +32,7 @@
33
32
  </template>
34
33
  <t-button block variant="outline" :title="title">
35
34
  <template #icon>
36
- <t-icon :name="icon" />
35
+ <t-icon name="filter"></t-icon>
37
36
  </template>
38
37
  <div v-if="buttonText">
39
38
  {{ buttonText }}
@@ -1,16 +1,10 @@
1
1
  <template>
2
2
  <div class="ebiz-tdesign-button-dialog">
3
- <t-button
4
- :theme="buttonTheme"
5
- :variant="buttonVariant"
6
- :size="buttonSize"
7
- :block="buttonBlock"
8
- :shape="buttonShape"
9
- :disabled="buttonDisabled"
10
- :loading="buttonLoading"
11
- :icon="buttonIcon"
12
- @click="handleButtonClick"
13
- >
3
+ <t-button :theme="buttonTheme" :variant="buttonVariant" :size="buttonSize" :block="buttonBlock" :shape="buttonShape"
4
+ :disabled="buttonDisabled" :loading="buttonLoading" @click="handleButtonClick">
5
+ <template v-if="buttonIcon" #icon>
6
+ <t-icon :name="buttonIcon"></t-icon>
7
+ </template>
14
8
  <template v-if="$slots.buttonContent">
15
9
  <slot name="buttonContent"></slot>
16
10
  </template>
@@ -19,23 +13,11 @@
19
13
  </template>
20
14
  </t-button>
21
15
 
22
- <t-dialog
23
- v-model:visible="dialogVisible"
24
- :header="title || computedTitle"
25
- :width="dialogWidth"
26
- :top="dialogTop"
27
- :attach="dialogAttach"
28
- :destroy-on-close="dialogDestroyOnClose"
29
- :mode="dialogMode"
30
- :placement="dialogPlacement"
31
- :show-overlay="dialogShowOverlay"
32
- :close-on-esc-keydown="dialogCloseOnEscKeydown"
33
- :close-on-overlay-click="dialogCloseOnOverlayClick"
34
- :show-footer="dialogShowFooter"
35
- @close="handleDialogClose"
36
- @confirm="handleDialogConfirm"
37
- @cancel="handleDialogCancel"
38
- >
16
+ <t-dialog v-model:visible="dialogVisible" :header="title || computedTitle" :width="dialogWidth" :top="dialogTop"
17
+ :attach="dialogAttach" :destroy-on-close="dialogDestroyOnClose" :mode="dialogMode" :placement="dialogPlacement"
18
+ :show-overlay="dialogShowOverlay" :close-on-esc-keydown="dialogCloseOnEscKeydown"
19
+ :close-on-overlay-click="dialogCloseOnOverlayClick" :show-footer="dialogShowFooter" @close="handleDialogClose"
20
+ @confirm="handleDialogConfirm" @cancel="handleDialogCancel">
39
21
  <template #header>
40
22
  <slot name="header">
41
23
  <div :class="['dialog-header', dialogType === 'delete' ? 'dialog-header-delete' : '']">
@@ -53,14 +35,14 @@
53
35
  </slot>
54
36
  </template>
55
37
 
56
- <template #footer>
38
+ <!-- <template #footer>
57
39
  <slot name="footer">
58
40
  <t-space>
59
41
  <t-button v-if="cancelText" theme="default" @click="handleDialogCancel">{{ cancelText }}</t-button>
60
42
  <t-button v-if="confirmText" theme="primary" :loading="apiLoading" @click="handleDialogConfirm">{{ confirmText }}</t-button>
61
43
  </t-space>
62
44
  </slot>
63
- </template>
45
+ </template> -->
64
46
  </t-dialog>
65
47
  </div>
66
48
  </template>
@@ -12,6 +12,7 @@
12
12
  :theme="theme"
13
13
  :type="type"
14
14
  :variant="variant"
15
+ :icon="icon"
15
16
  @click="handleClick"
16
17
  >
17
18
  <!-- 图标插槽 -->
@@ -115,6 +116,11 @@ defineProps({
115
116
  type: String,
116
117
  default: 'base',
117
118
  validator: (val) => ['base', 'outline', 'dashed', 'text'].includes(val)
119
+ },
120
+ // 按钮图标
121
+ icon: {
122
+ type: String,
123
+ default: ''
118
124
  }
119
125
  });
120
126