web-component-gallery 2.2.18 → 2.2.19

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.
@@ -1,4 +1,5 @@
1
- import Modal from 'ant-design-vue/es/modal'
1
+ import { Modal } from '../lib'
2
+
2
3
  export default (Vue) => {
3
4
  function dialog (component, componentProps, modalProps) {
4
5
  const _vm = this
@@ -101,7 +102,7 @@ export default (Vue) => {
101
102
  return h(Modal, ModalProps, [h(component, ComponentProps)])
102
103
  }
103
104
  }).$mount(dialogDiv)
104
- }
105
+ }
105
106
 
106
107
  Object.defineProperty(Vue.prototype, '$dialog', {
107
108
  get: () => {
@@ -0,0 +1,331 @@
1
+ /** 入口文件不同 作用域不同 */
2
+ let TMapKey = null
3
+ let TMapLayer = null
4
+ let TMapInstance = null
5
+
6
+ /** 默认天地图配置 */
7
+ let TMapConfig = {
8
+ key: 'a32ac7f489c946ec19be06a1d6d7e3ae',
9
+ tileLayer: 'vec' // 矢量底图:vec-矢量,img-影像,cia-影像注记
10
+ }
11
+
12
+ // 安全配置 / 地图样式配置
13
+ export const setTMapSecurity = (config = TMapConfig) => {
14
+ const { key, tileLayer } = config
15
+ TMapKey = key
16
+ TMapLayer = tileLayer
17
+ // 天地图无需安全JS代码配置
18
+ }
19
+
20
+ // 核心地图服务类
21
+ class TMapService {
22
+ constructor(T) {
23
+ this.T = T
24
+ this._iconCache = new Map() // 图标缓存
25
+
26
+ /** 常用覆盖物 */
27
+ this.layers = {
28
+ setIcon: this.setIcon.bind(this),
29
+ setMarker: this.setMarker.bind(this),
30
+ setInfoWindow: this._createInfoWindowHandler()
31
+ }
32
+
33
+ /** 抛出地图常用方法 */
34
+ this.methods = {
35
+ getMapAddress: this.getMapAddress.bind(this),
36
+ getMapSearch: this.getMapSearch.bind(this),
37
+ setMapDriving: this.setMapDriving.bind(this),
38
+ drawMapAnimation,
39
+ parseRouteToPath,
40
+ getOverlayPos
41
+ }
42
+ }
43
+
44
+ /** 初始化地图 */
45
+ initMap(container, options = {}) {
46
+ const map = new this.T.Map(container, {
47
+ center: new this.T.LngLat(118.868228, 28.892844),
48
+ zoom: 13,
49
+ ...options
50
+ })
51
+
52
+ // 添加天地图图层
53
+ const layer = new this.T.TileLayer(TMapLayer, {
54
+ key: TMapKey
55
+ })
56
+ map.addLayer(layer)
57
+
58
+ options.zoomTool && map.addControl(new this.T.Control.Zoom())
59
+ options.directionTool && map.addControl(new this.T.Control.Navigation())
60
+
61
+ return map
62
+ }
63
+
64
+ /** 格式化地图经纬度 */
65
+ setLngLat(position) {
66
+ return new this.T.LngLat(position[0], position[1])
67
+ }
68
+
69
+ /** 创建信息窗口处理器(柯里化函数) */
70
+ _createInfoWindowHandler() {
71
+ return (Vue) => {
72
+ if (!Vue || !Vue.extend) {
73
+ throw new Error('必须传入有效的Vue构造函数')
74
+ }
75
+
76
+ return ({component, props, options = {}}) => {
77
+ if (!component) throw new Error('component参数必填')
78
+
79
+ const InfoWindowComponent = Vue.extend(component)
80
+ const instance = new InfoWindowComponent({
81
+ propsData: props
82
+ }).$mount(document.createElement('div'))
83
+
84
+ return new this.T.InfoWindow({
85
+ content: instance.$el,
86
+ ...options
87
+ })
88
+ }
89
+ }
90
+ }
91
+
92
+ /** 带缓存的图标创建方法 */
93
+ async setIcon(iconUrl) {
94
+ if (this._iconCache.has(iconUrl)) {
95
+ return this._iconCache.get(iconUrl)
96
+ }
97
+
98
+ return new Promise((resolve, reject) => {
99
+ const img = new Image()
100
+ img.onload = () => {
101
+ const icon = new this.T.Icon({
102
+ iconUrl: iconUrl,
103
+ iconSize: new this.T.Point(img.width, img.height)
104
+ })
105
+ this._iconCache.set(iconUrl, icon)
106
+ resolve(icon)
107
+ }
108
+ img.onerror = () => reject(new Error(`图标加载失败: ${iconUrl}`))
109
+ img.src = iconUrl
110
+ })
111
+ }
112
+
113
+ /** 增强的标记点创建方法 */
114
+ async setMarker(iconUrl, options = {}) {
115
+ try {
116
+ const icon = await this.setIcon(iconUrl)
117
+ const marker = new this.T.Marker({
118
+ ...options,
119
+ icon
120
+ })
121
+ return marker
122
+ } catch (error) {
123
+ console.error('创建标记点失败:', error)
124
+ throw error
125
+ }
126
+ }
127
+
128
+ /** 地图逆地理编码 */
129
+ getMapAddress({longitude, latitude}, callBack) {
130
+ return new Promise((resolve, reject) => {
131
+ const geocoder = new this.T.Geocoder()
132
+
133
+ geocoder.getLocation(new this.T.Point(longitude, latitude))
134
+ .then(result => {
135
+ const addressMsg = {
136
+ address: result.address,
137
+ addressInfo: result.addressComponents
138
+ }
139
+ callBack?.(addressMsg)
140
+ resolve(addressMsg)
141
+ })
142
+ .catch(error => {
143
+ reject(new Error('转换失败'))
144
+ })
145
+ })
146
+ }
147
+
148
+ /** 根据地址搜索地图poi点及其他信息 */
149
+ /**
150
+ *
151
+ * @param {*} keywords 根据关键字搜索
152
+ * @param {*} callBack 查询成功后过滤信息及转换格式 传递回调函数 兼容老版本代码
153
+ */
154
+ getMapSearch(keywords, callBack) {
155
+ return new Promise((resolve) => {
156
+ const localSearch = new this.T.LocalSearch(map, {
157
+ onSearchComplete: (result) => {
158
+ const options = result.poiList.map(node => ({
159
+ ...node,
160
+ label: `${node.name}(${node.address})`
161
+ }))
162
+ callBack?.(options)
163
+ resolve(options)
164
+ }
165
+ })
166
+ localSearch.search(keywords)
167
+ })
168
+ }
169
+
170
+ /** 道路规划 */
171
+ /**
172
+ *
173
+ * @param {*} TMapInit 当前地图实例
174
+ * @param {*} paths 需查询的路径起始点及途径点集合
175
+ * @param {*} roadOptions 路线规划的其他参数
176
+ * { paths: 需查询的路径起始点及途径点集合, options: 为查询路线配置项 }
177
+ * @param {*} callBack 查询成功后回调函数 兼容老版本代码
178
+ */
179
+ async setMapDriving(mapInstance, roadOptions, callBack) {
180
+ const { paths, options = {} } = roadOptions
181
+ return new Promise((resolve) => {
182
+ const driving = new this.T.DrivingRoute(mapInstance, {
183
+ ...options
184
+ })
185
+
186
+ driving.search(
187
+ this.setLngLat(paths[0]),
188
+ this.setLngLat(paths[paths.length - 1]),
189
+ {
190
+ waypoints: paths.slice(1, -1).map(path => this.setLngLat(path))
191
+ },
192
+ (status, result) => status === this.T.DrivingResult.OK && (
193
+ callBack?.(driving, result.routes),
194
+ resolve({ driving, routes: result.routes })
195
+ )
196
+ )
197
+ })
198
+ }
199
+
200
+ // 其他方法保持类似改造...
201
+ }
202
+
203
+ // 获取TMap实例(组件内使用)
204
+ export const getTMapInstance = async (options = {}) => {
205
+ if (TMapInstance) return TMapInstance
206
+
207
+ // 确保key存在
208
+ if (!TMapKey) {
209
+ try {
210
+ setTMapSecurity()
211
+ } catch (e) {
212
+ throw new Error('请先设置地图Key!')
213
+ }
214
+ }
215
+
216
+ try {
217
+ // 天地图JS API加载(假设已通过CDN引入)
218
+ const T = await window.T // 确保天地图API已加载
219
+ TMapInstance = new TMapService(T)
220
+ return TMapInstance
221
+ } catch (e) {
222
+ throw new Error(`天地图加载失败: ${e.message}`)
223
+ }
224
+ }
225
+
226
+ // 在 Vue 插件中封装天地图的初始化和常用方法
227
+ export default {
228
+ async install(Vue, options = {}) {
229
+
230
+ const tmap = await getTMapInstance(options)
231
+
232
+ const { T, methods, layers } = tmap
233
+
234
+ Vue.prototype.$tmap = T
235
+
236
+ /** 初始化地图 */
237
+ Vue.prototype.$initTMap = (mapOptions, callBack) => {
238
+ const tmapInit = tmap.initMap(
239
+ mapOptions.el,
240
+ mapOptions.options || {}
241
+ )
242
+ /** 兼容之前版本代码 */
243
+ callBack?.(tmapInit)
244
+ return tmapInit
245
+ }
246
+
247
+ /** 地图加载完成 */
248
+ Vue.prototype.$bus.$emit('onTMapMounted')
249
+
250
+ /** 常用覆盖物 */
251
+ Vue.prototype.$tmapLayers = {
252
+ ...layers,
253
+ setInfoWindow: layers.setInfoWindow(Vue)
254
+ }
255
+
256
+ /** 抛出地图常用方法 */
257
+ Vue.prototype.$tmapMethods = methods || {}
258
+
259
+ }
260
+ }
261
+
262
+ /**
263
+ * 安全获取覆盖物坐标信息
264
+ * @param {T.Overlay} overlay 地图覆盖物实例
265
+ * @returns {Array<Array<number>>} 坐标点数组
266
+ */
267
+ function getOverlayPos(overlay) {
268
+ if (!overlay) throw new Error('覆盖物实例不存在')
269
+
270
+ try {
271
+ return overlay instanceof this.T.Marker
272
+ ? [overlay.getLngLat().lng, overlay.getLngLat().lat]
273
+ : overlay.getPath().map(({lng, lat}) => [lng, lat])
274
+ } catch (e) {
275
+ console.error('转换失败', e)
276
+ return []
277
+ }
278
+ }
279
+
280
+ /**
281
+ * 轨迹动画执行器
282
+ * @param {T.Map} TMapInit 地图实例
283
+ * @param {T.Marker} animationMarker 动画标记物
284
+ * @param {Array<Array<number>>} paths 路径坐标数组
285
+ * @param {Object} [options] 动画配置
286
+ * @param {Function} [callBack] 动画完成回调
287
+ */
288
+ function drawMapAnimation(TMapInit, animationMarker, paths, options = {}, callBack) {
289
+ if (!TMapInit || !animationMarker || !paths?.length) {
290
+ return console.error('缺少参数信息')
291
+ }
292
+
293
+ const defaultOptions = {
294
+ duration: 500,
295
+ autoRotation: true,
296
+ ...options
297
+ }
298
+
299
+ animationMarker.moveAlong(paths, defaultOptions)
300
+ callBack?.(animationMarker)
301
+ }
302
+
303
+ /**
304
+ * 转换导航路线为可绘制路径
305
+ * @param {T.DrivingRoute} route 导航路线对象
306
+ * @returns {{
307
+ * path: Array<Array<number>>,
308
+ * approachPoints: Array<number>
309
+ * }}
310
+ */
311
+ function parseRouteToPath(route) {
312
+ if (!route?.steps) return { path: [], approachPoints: [] }
313
+
314
+ const result = {
315
+ path: [],
316
+ approachPoints: []
317
+ }
318
+
319
+ route.steps.forEach((step, stepIndex) => {
320
+ step.path.forEach((point, pointIndex) => {
321
+ result.path.push([point.lng, point.lat])
322
+
323
+ if (step.assistant_action === "到达途经地" &&
324
+ pointIndex === step.path.length - 1) {
325
+ result.approachPoints.push(result.path.length - 1)
326
+ }
327
+ })
328
+ })
329
+
330
+ return result
331
+ }
@@ -31,7 +31,7 @@ export const AmapDrawProps = {
31
31
  isExhibition: PropTypes.bool.def(false),
32
32
  /** 绘制操作自定义 */
33
33
  drawButtonOperate: PropTypes.object
34
- }
34
+ }
35
35
 
36
36
  const AmapDraw = {
37
37
  name: 'AmapDraw',
@@ -10,7 +10,7 @@
10
10
  @sc-title-2: linear-gradient(180deg, @white 36.35%, @sc-title-color 67.08%);
11
11
 
12
12
  // 基础色
13
- @sc-color-1: #0a4676;
13
+ @sc-color-1: #0a4676;
14
14
 
15
15
  // 阴影色
16
16
  @sc-shadow-1: #0A1834;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-component-gallery",
3
- "version": "2.2.18",
3
+ "version": "2.2.19",
4
4
  "description": "基础vue、antdvue、less实现的私有组件库",
5
5
  "main": "dist/index.umd.js",
6
6
  "files": [