xt-element-ui 1.3.0 → 1.3.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.
- package/docs/components/base/xt-map.md +331 -0
- package/docs/components/base/xt-step-price.md +103 -217
- package/lib/index.common.js +2118 -40
- package/lib/index.css +1 -1
- package/lib/index.umd.js +2118 -40
- package/lib/index.umd.min.js +5 -5
- package/package.json +4 -3
- package/src/components/ex-button/index.js +8 -2
- package/src/components/ex-chart/index.js +6 -0
- package/src/components/ex-date-picker/index.js +8 -2
- package/src/components/ex-icon/index.js +6 -0
- package/src/components/ex-page/index.js +8 -2
- package/src/components/ex-select-tree/index.js +8 -2
- package/src/components/ex-table/index.js +6 -0
- package/src/components/ex-upload/index.js +6 -0
- package/src/components/xt-button/index.js +8 -2
- package/src/components/xt-button/index.vue +1 -1
- package/src/components/xt-card/index.js +8 -2
- package/src/components/xt-card-item/index.js +8 -2
- package/src/components/xt-config-provider/index.js +6 -0
- package/src/components/xt-flex-box/index.js +8 -2
- package/src/components/xt-flex-box/style/index.scss +0 -9
- package/src/components/xt-grid-box/index.js +8 -2
- package/src/components/xt-grid-item/index.js +7 -1
- package/src/components/xt-input/index.js +8 -2
- package/src/components/xt-map/adapters/amap.js +235 -0
- package/src/components/xt-map/adapters/baidu.js +254 -0
- package/src/components/xt-map/adapters/base.js +267 -0
- package/src/components/xt-map/adapters/index.js +29 -0
- package/src/components/xt-map/adapters/tianditu.js +242 -0
- package/src/components/xt-map/config/xt-map-config.js +197 -0
- package/src/components/xt-map/index.js +30 -0
- package/src/components/xt-map/index.vue +351 -0
- package/src/components/xt-map/loaders/script-loader.js +114 -0
- package/src/components/xt-map/provider.vue +200 -0
- package/src/components/xt-map/style/index.scss +77 -0
- package/src/components/xt-step-price/index.js +9 -0
- package/src/components/xt-step-price-item/index.js +6 -0
- package/src/components/xt-step-price-item/index.vue +3 -1
- package/src/components/xt-text/index.js +8 -2
- package/src/components/xt-time/index.js +6 -0
- package/src/index.js +6 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="xt-map-wrapper">
|
|
3
|
+
<div ref="mapContainer" class="xt-map-container" :data-theme="mergedTheme"></div>
|
|
4
|
+
<div v-if="loading" class="xt-map-loading">
|
|
5
|
+
<span>地图加载中...</span>
|
|
6
|
+
</div>
|
|
7
|
+
<div v-if="errorMessage" class="xt-map-error">
|
|
8
|
+
<span>{{ errorMessage }}</span>
|
|
9
|
+
</div>
|
|
10
|
+
<slot name="overlay"></slot>
|
|
11
|
+
</div>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
import { getAdapterClass } from './adapters/index'
|
|
16
|
+
import { clearScriptCache } from './loaders/script-loader'
|
|
17
|
+
import {
|
|
18
|
+
getMapConfig,
|
|
19
|
+
getMapProvider,
|
|
20
|
+
getMapApiKey,
|
|
21
|
+
getMapApiUrl,
|
|
22
|
+
getMapType,
|
|
23
|
+
getMapTheme,
|
|
24
|
+
getMapCenter,
|
|
25
|
+
getMapZoom,
|
|
26
|
+
setSecurityJsCode,
|
|
27
|
+
MAP_PROVIDERS,
|
|
28
|
+
MAP_TYPES,
|
|
29
|
+
MAP_THEMES,
|
|
30
|
+
onMapConfigChange
|
|
31
|
+
} from './config/xt-map-config'
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
name: 'XtMap',
|
|
35
|
+
|
|
36
|
+
props: {
|
|
37
|
+
provider: {
|
|
38
|
+
type: String,
|
|
39
|
+
default: '',
|
|
40
|
+
validator: (val) => val === '' || MAP_PROVIDERS.includes(val)
|
|
41
|
+
},
|
|
42
|
+
apiKey: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: ''
|
|
45
|
+
},
|
|
46
|
+
apiUrl: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: ''
|
|
49
|
+
},
|
|
50
|
+
mapType: {
|
|
51
|
+
type: String,
|
|
52
|
+
default: '',
|
|
53
|
+
validator: (val) => val === '' || MAP_TYPES.includes(val)
|
|
54
|
+
},
|
|
55
|
+
theme: {
|
|
56
|
+
type: String,
|
|
57
|
+
default: '',
|
|
58
|
+
validator: (val) => val === '' || MAP_THEMES.includes(val)
|
|
59
|
+
},
|
|
60
|
+
center: {
|
|
61
|
+
type: Array,
|
|
62
|
+
default: () => null
|
|
63
|
+
},
|
|
64
|
+
zoom: {
|
|
65
|
+
type: Number,
|
|
66
|
+
default: null
|
|
67
|
+
},
|
|
68
|
+
plugins: {
|
|
69
|
+
type: Array,
|
|
70
|
+
default: () => []
|
|
71
|
+
},
|
|
72
|
+
width: {
|
|
73
|
+
type: String,
|
|
74
|
+
default: '100%'
|
|
75
|
+
},
|
|
76
|
+
height: {
|
|
77
|
+
type: String,
|
|
78
|
+
default: '400px'
|
|
79
|
+
},
|
|
80
|
+
securityJsCode: {
|
|
81
|
+
type: String,
|
|
82
|
+
default: ''
|
|
83
|
+
},
|
|
84
|
+
tiandituLayerType: {
|
|
85
|
+
type: String,
|
|
86
|
+
default: 'vec'
|
|
87
|
+
},
|
|
88
|
+
baiduCoordType: {
|
|
89
|
+
type: String,
|
|
90
|
+
default: 'bd09ll'
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
data() {
|
|
95
|
+
return {
|
|
96
|
+
loading: true,
|
|
97
|
+
errorMessage: '',
|
|
98
|
+
adapter: null,
|
|
99
|
+
_unsubscribeConfig: null
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
computed: {
|
|
104
|
+
mergedProvider() {
|
|
105
|
+
return this.provider || getMapProvider() || 'amap'
|
|
106
|
+
},
|
|
107
|
+
mergedApiKey() {
|
|
108
|
+
return this.apiKey || getMapApiKey() || ''
|
|
109
|
+
},
|
|
110
|
+
mergedApiUrl() {
|
|
111
|
+
return this.apiUrl || getMapApiUrl() || ''
|
|
112
|
+
},
|
|
113
|
+
mergedMapType() {
|
|
114
|
+
return this.mapType || getMapType() || 'standard'
|
|
115
|
+
},
|
|
116
|
+
mergedTheme() {
|
|
117
|
+
return this.theme || getMapTheme() || 'light'
|
|
118
|
+
},
|
|
119
|
+
mergedCenter() {
|
|
120
|
+
return this.center || getMapCenter() || [116.397428, 39.90923]
|
|
121
|
+
},
|
|
122
|
+
mergedZoom() {
|
|
123
|
+
return this.zoom !== null ? this.zoom : getMapZoom()
|
|
124
|
+
},
|
|
125
|
+
mergedSecurityJsCode() {
|
|
126
|
+
return this.securityJsCode || (getMapConfig().securityJsCode) || ''
|
|
127
|
+
},
|
|
128
|
+
mergedPlugins() {
|
|
129
|
+
return this.plugins.length > 0 ? this.plugins : getMapConfig().plugins || []
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
watch: {
|
|
134
|
+
mergedProvider: {
|
|
135
|
+
handler() {
|
|
136
|
+
this.$nextTick(() => this.rebuildMap())
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
mergedApiKey: {
|
|
140
|
+
handler() {
|
|
141
|
+
this.$nextTick(() => this.rebuildMap())
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
mergedMapType: {
|
|
145
|
+
handler(newVal) {
|
|
146
|
+
if (this.adapter) this.adapter.setMapType(newVal)
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
mergedTheme: {
|
|
150
|
+
handler(newVal) {
|
|
151
|
+
if (this.adapter) this.adapter.setTheme(newVal)
|
|
152
|
+
if (this.$refs.mapContainer) {
|
|
153
|
+
this.$refs.mapContainer.setAttribute('data-theme', newVal)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
mergedCenter: {
|
|
158
|
+
handler(newVal) {
|
|
159
|
+
if (this.adapter) this.adapter.setCenter(newVal)
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
mergedZoom: {
|
|
163
|
+
handler(newVal) {
|
|
164
|
+
if (this.adapter) this.adapter.setZoom(newVal)
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
width: {
|
|
168
|
+
handler() {
|
|
169
|
+
this.$nextTick(() => {
|
|
170
|
+
if (this.adapter) this.adapter.resize()
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
height: {
|
|
175
|
+
handler() {
|
|
176
|
+
this.$nextTick(() => {
|
|
177
|
+
if (this.adapter) this.adapter.resize()
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
securityJsCode: {
|
|
182
|
+
handler(newVal) {
|
|
183
|
+
if (newVal) {
|
|
184
|
+
setSecurityJsCode(newVal)
|
|
185
|
+
// 高德 2.0:SDK 已加载后再设置 securityJsCode 无效,需要重建地图
|
|
186
|
+
if (this.mergedProvider === 'amap' && this.adapter && this.adapter.ready) {
|
|
187
|
+
this.$nextTick(() => this.rebuildMap())
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
mounted() {
|
|
195
|
+
// 监听全局配置变更
|
|
196
|
+
this._unsubscribeConfig = onMapConfigChange((key, value) => {
|
|
197
|
+
if (!this.provider && (key === 'provider')) this.$nextTick(() => this.rebuildMap())
|
|
198
|
+
if (!this.apiKey && (key === 'apiKey')) this.$nextTick(() => this.rebuildMap())
|
|
199
|
+
if (!this.apiUrl && (key === 'apiUrl')) this.$nextTick(() => this.rebuildMap())
|
|
200
|
+
if (!this.theme && key === 'theme' && this.adapter) this.adapter.setTheme(value)
|
|
201
|
+
if (!this.mapType && key === 'mapType' && this.adapter) this.adapter.setMapType(value)
|
|
202
|
+
if (!this.center && key === 'center' && this.adapter) this.adapter.setCenter(value)
|
|
203
|
+
if (this.zoom === null && key === 'zoom' && this.adapter) this.adapter.setZoom(value)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
// 设置高德安全密钥
|
|
207
|
+
if (this.securityJsCode) setSecurityJsCode(this.securityJsCode)
|
|
208
|
+
|
|
209
|
+
this.$nextTick(() => this.initMap())
|
|
210
|
+
|
|
211
|
+
// 监听窗口尺寸变化
|
|
212
|
+
this._onWindowResize = () => {
|
|
213
|
+
if (this.adapter) this.adapter.resize()
|
|
214
|
+
}
|
|
215
|
+
if (typeof window !== 'undefined') {
|
|
216
|
+
window.addEventListener('resize', this._onWindowResize)
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
beforeDestroy() {
|
|
221
|
+
this.destroyMap()
|
|
222
|
+
if (this._unsubscribeConfig) this._unsubscribeConfig()
|
|
223
|
+
if (this._onWindowResize && typeof window !== 'undefined') {
|
|
224
|
+
window.removeEventListener('resize', this._onWindowResize)
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
methods: {
|
|
229
|
+
async initMap() {
|
|
230
|
+
const container = this.$refs.mapContainer
|
|
231
|
+
if (!container) return
|
|
232
|
+
|
|
233
|
+
// 设置容器尺寸
|
|
234
|
+
container.style.width = this.width
|
|
235
|
+
container.style.height = this.height
|
|
236
|
+
|
|
237
|
+
// 设置安全密钥(高德需要)
|
|
238
|
+
if (this.securityJsCode) setSecurityJsCode(this.securityJsCode)
|
|
239
|
+
|
|
240
|
+
this.loading = true
|
|
241
|
+
this.errorMessage = ''
|
|
242
|
+
|
|
243
|
+
const AdapterClass = getAdapterClass(this.mergedProvider)
|
|
244
|
+
|
|
245
|
+
this.adapter = new AdapterClass(container, {
|
|
246
|
+
apiKey: this.mergedApiKey,
|
|
247
|
+
apiUrl: this.mergedApiUrl,
|
|
248
|
+
mapType: this.mergedMapType,
|
|
249
|
+
theme: this.mergedTheme,
|
|
250
|
+
center: this.mergedCenter,
|
|
251
|
+
zoom: this.mergedZoom,
|
|
252
|
+
plugins: this.mergedPlugins,
|
|
253
|
+
securityJsCode: this.mergedSecurityJsCode,
|
|
254
|
+
tiandituLayerType: this.tiandituLayerType,
|
|
255
|
+
baiduCoordType: this.baiduCoordType
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
await this.adapter.init()
|
|
260
|
+
this.loading = false
|
|
261
|
+
|
|
262
|
+
// 绑定事件
|
|
263
|
+
this._bindAdapterEvents()
|
|
264
|
+
|
|
265
|
+
// 向父组件发出 ready 事件
|
|
266
|
+
this.$emit('ready', {
|
|
267
|
+
provider: this.mergedProvider,
|
|
268
|
+
map: this.adapter.getNativeMap(),
|
|
269
|
+
adapter: this.adapter
|
|
270
|
+
})
|
|
271
|
+
} catch (err) {
|
|
272
|
+
this.loading = false
|
|
273
|
+
this.errorMessage = err.message || '地图初始化失败'
|
|
274
|
+
this.$emit('error', err)
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
rebuildMap() {
|
|
279
|
+
this.destroyMap()
|
|
280
|
+
// 清理脚本缓存,确保新配置能生效(例如切换密钥后重新加载)
|
|
281
|
+
if (typeof clearScriptCache === 'function') {
|
|
282
|
+
clearScriptCache()
|
|
283
|
+
}
|
|
284
|
+
this.$nextTick(() => this.initMap())
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
destroyMap() {
|
|
288
|
+
if (this.adapter) {
|
|
289
|
+
this.adapter.destroy()
|
|
290
|
+
this.adapter = null
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
_bindAdapterEvents() {
|
|
295
|
+
if (!this.adapter) return
|
|
296
|
+
|
|
297
|
+
const events = ['click', 'moveend', 'zoomend', 'zoomchange', 'mapmove']
|
|
298
|
+
events.forEach((evt) => {
|
|
299
|
+
this.adapter.on(evt, (data) => {
|
|
300
|
+
this.$emit(evt, data)
|
|
301
|
+
})
|
|
302
|
+
})
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
// 对外暴露的统一 API
|
|
306
|
+
setCenter(center) {
|
|
307
|
+
if (this.adapter) this.adapter.setCenter(center)
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
setZoom(zoom) {
|
|
311
|
+
if (this.adapter) this.adapter.setZoom(zoom)
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
setMapType(type) {
|
|
315
|
+
if (this.adapter) this.adapter.setMapType(type)
|
|
316
|
+
},
|
|
317
|
+
|
|
318
|
+
setTheme(theme) {
|
|
319
|
+
if (this.adapter) this.adapter.setTheme(theme)
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
getCenter() {
|
|
323
|
+
return this.adapter ? this.adapter.getCenter() : this.mergedCenter
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
getZoom() {
|
|
327
|
+
return this.adapter ? this.adapter.getZoom() : this.mergedZoom
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
getNativeMap() {
|
|
331
|
+
return this.adapter ? this.adapter.getNativeMap() : null
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
resize() {
|
|
335
|
+
if (this.adapter) this.adapter.resize()
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
on(eventName, handler) {
|
|
339
|
+
if (this.adapter) this.adapter.on(eventName, handler)
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
off(eventName) {
|
|
343
|
+
if (this.adapter) this.adapter.off(eventName)
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
rebuild() {
|
|
347
|
+
this.rebuildMap()
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
</script>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 动态脚本加载器
|
|
3
|
+
* 负责动态注入地图 SDK <script> 标签,并返回 Promise
|
|
4
|
+
* 同一 URL 只会加载一次,缓存已加载的结果
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const loadedScripts = new Map() // URL -> Promise
|
|
8
|
+
const loadingScripts = new Map() // URL -> Promise (正在加载中)
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 动态加载单个脚本
|
|
12
|
+
* @param {string} url - 脚本 URL
|
|
13
|
+
* @param {object} options - 配置
|
|
14
|
+
* @param {string} options.charset - 字符集,默认 'utf-8'
|
|
15
|
+
* @param {boolean} options.async - 是否异步,默认 true
|
|
16
|
+
* @param {number} options.timeout - 超时时间(ms),默认 30000
|
|
17
|
+
* @returns {Promise<HTMLScriptElement>}
|
|
18
|
+
*/
|
|
19
|
+
export const loadScript = (url, options = {}) => {
|
|
20
|
+
if (typeof window === 'undefined') {
|
|
21
|
+
return Promise.reject(new Error('[XtMap] 非浏览器环境'))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { charset = 'utf-8', async = true, timeout = 30000 } = options
|
|
25
|
+
|
|
26
|
+
if (loadedScripts.has(url)) {
|
|
27
|
+
return loadedScripts.get(url)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (loadingScripts.has(url)) {
|
|
31
|
+
return loadingScripts.get(url)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const promise = new Promise((resolve, reject) => {
|
|
35
|
+
const script = document.createElement('script')
|
|
36
|
+
script.type = 'text/javascript'
|
|
37
|
+
script.src = url
|
|
38
|
+
script.charset = charset
|
|
39
|
+
script.async = async
|
|
40
|
+
|
|
41
|
+
let timer = null
|
|
42
|
+
let done = false
|
|
43
|
+
|
|
44
|
+
const cleanup = () => {
|
|
45
|
+
done = true
|
|
46
|
+
if (timer) clearTimeout(timer)
|
|
47
|
+
script.onload = null
|
|
48
|
+
script.onerror = null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
script.onload = () => {
|
|
52
|
+
if (done) return
|
|
53
|
+
cleanup()
|
|
54
|
+
loadingScripts.delete(url)
|
|
55
|
+
loadedScripts.set(url, Promise.resolve(script))
|
|
56
|
+
resolve(script)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
script.onerror = (err) => {
|
|
60
|
+
if (done) return
|
|
61
|
+
cleanup()
|
|
62
|
+
loadingScripts.delete(url)
|
|
63
|
+
reject(new Error(`[XtMap] 脚本加载失败: ${url}`))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (timeout > 0) {
|
|
67
|
+
timer = setTimeout(() => {
|
|
68
|
+
if (done) return
|
|
69
|
+
cleanup()
|
|
70
|
+
loadingScripts.delete(url)
|
|
71
|
+
reject(new Error(`[XtMap] 脚本加载超时: ${url}`))
|
|
72
|
+
}, timeout)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
document.head.appendChild(script)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
loadingScripts.set(url, promise)
|
|
79
|
+
return promise
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 批量加载脚本(按顺序)
|
|
84
|
+
* @param {string[]} urls
|
|
85
|
+
* @param {object} options
|
|
86
|
+
*/
|
|
87
|
+
export const loadScripts = async (urls, options = {}) => {
|
|
88
|
+
for (const url of urls) {
|
|
89
|
+
await loadScript(url, options)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 清除加载缓存(切换密钥等场景使用)
|
|
95
|
+
*/
|
|
96
|
+
export const clearScriptCache = () => {
|
|
97
|
+
loadedScripts.clear()
|
|
98
|
+
loadingScripts.clear()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 检查全局对象是否存在
|
|
103
|
+
*/
|
|
104
|
+
export const hasGlobal = (name) => {
|
|
105
|
+
if (typeof window === 'undefined') return false
|
|
106
|
+
return window[name] !== undefined
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default {
|
|
110
|
+
loadScript,
|
|
111
|
+
loadScripts,
|
|
112
|
+
clearScriptCache,
|
|
113
|
+
hasGlobal
|
|
114
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="['xt-map-provider', { 'xt-map-provider--dark': mergedTheme === 'dark' }]" :style="wrapperStyle">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import {
|
|
9
|
+
getMapConfig,
|
|
10
|
+
setMapConfig,
|
|
11
|
+
setMapProvider,
|
|
12
|
+
setMapApiKey,
|
|
13
|
+
setMapApiUrl,
|
|
14
|
+
setMapType,
|
|
15
|
+
setMapTheme,
|
|
16
|
+
setMapCenter,
|
|
17
|
+
setMapZoom,
|
|
18
|
+
setMapPlugins,
|
|
19
|
+
setSecurityJsCode,
|
|
20
|
+
getMapProvider,
|
|
21
|
+
getMapApiKey,
|
|
22
|
+
getMapApiUrl,
|
|
23
|
+
getMapType,
|
|
24
|
+
getMapTheme,
|
|
25
|
+
getMapCenter,
|
|
26
|
+
getMapZoom,
|
|
27
|
+
getMapPlugins,
|
|
28
|
+
MAP_PROVIDERS,
|
|
29
|
+
MAP_TYPES,
|
|
30
|
+
MAP_THEMES,
|
|
31
|
+
onMapConfigChange
|
|
32
|
+
} from './config/xt-map-config'
|
|
33
|
+
|
|
34
|
+
export default {
|
|
35
|
+
name: 'XtMapProvider',
|
|
36
|
+
|
|
37
|
+
props: {
|
|
38
|
+
provider: {
|
|
39
|
+
type: String,
|
|
40
|
+
default: '',
|
|
41
|
+
validator: (val) => val === '' || MAP_PROVIDERS.includes(val)
|
|
42
|
+
},
|
|
43
|
+
apiKey: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: ''
|
|
46
|
+
},
|
|
47
|
+
apiUrl: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: ''
|
|
50
|
+
},
|
|
51
|
+
mapType: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: '',
|
|
54
|
+
validator: (val) => val === '' || MAP_TYPES.includes(val)
|
|
55
|
+
},
|
|
56
|
+
theme: {
|
|
57
|
+
type: String,
|
|
58
|
+
default: '',
|
|
59
|
+
validator: (val) => val === '' || MAP_THEMES.includes(val)
|
|
60
|
+
},
|
|
61
|
+
center: {
|
|
62
|
+
type: Array,
|
|
63
|
+
default: () => null
|
|
64
|
+
},
|
|
65
|
+
zoom: {
|
|
66
|
+
type: Number,
|
|
67
|
+
default: null
|
|
68
|
+
},
|
|
69
|
+
plugins: {
|
|
70
|
+
type: Array,
|
|
71
|
+
default: () => []
|
|
72
|
+
},
|
|
73
|
+
securityJsCode: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: ''
|
|
76
|
+
},
|
|
77
|
+
tag: {
|
|
78
|
+
type: String,
|
|
79
|
+
default: 'div'
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
data() {
|
|
84
|
+
return {
|
|
85
|
+
mergedTheme: this.theme || getMapTheme() || 'light'
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
computed: {
|
|
90
|
+
wrapperStyle() {
|
|
91
|
+
return {}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
watch: {
|
|
96
|
+
provider: {
|
|
97
|
+
immediate: true,
|
|
98
|
+
handler(newVal) {
|
|
99
|
+
if (newVal) setMapProvider(newVal)
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
apiKey: {
|
|
103
|
+
immediate: true,
|
|
104
|
+
handler(newVal) {
|
|
105
|
+
if (newVal) setMapApiKey(newVal)
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
apiUrl: {
|
|
109
|
+
immediate: true,
|
|
110
|
+
handler(newVal) {
|
|
111
|
+
if (newVal) setMapApiUrl(newVal)
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
mapType: {
|
|
115
|
+
immediate: true,
|
|
116
|
+
handler(newVal) {
|
|
117
|
+
if (newVal) setMapType(newVal)
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
theme: {
|
|
121
|
+
immediate: true,
|
|
122
|
+
handler(newVal) {
|
|
123
|
+
if (newVal) {
|
|
124
|
+
setMapTheme(newVal)
|
|
125
|
+
this.mergedTheme = newVal
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
center: {
|
|
130
|
+
immediate: true,
|
|
131
|
+
handler(newVal) {
|
|
132
|
+
if (newVal) setMapCenter(newVal)
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
zoom: {
|
|
136
|
+
immediate: true,
|
|
137
|
+
handler(newVal) {
|
|
138
|
+
if (newVal !== null && newVal !== undefined) setMapZoom(newVal)
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
plugins: {
|
|
142
|
+
immediate: true,
|
|
143
|
+
handler(newVal) {
|
|
144
|
+
if (newVal && newVal.length > 0) setMapPlugins(newVal)
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
securityJsCode: {
|
|
148
|
+
immediate: true,
|
|
149
|
+
handler(newVal) {
|
|
150
|
+
if (newVal) setSecurityJsCode(newVal)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
provide() {
|
|
156
|
+
return {
|
|
157
|
+
xtMapConfig: {
|
|
158
|
+
getProvider: () => this.provider || getMapProvider(),
|
|
159
|
+
getApiKey: () => this.apiKey || getMapApiKey(),
|
|
160
|
+
getApiUrl: () => this.apiUrl || getMapApiUrl(),
|
|
161
|
+
getMapType: () => this.mapType || getMapType(),
|
|
162
|
+
getTheme: () => this.theme || getMapTheme(),
|
|
163
|
+
getCenter: () => this.center || getMapCenter(),
|
|
164
|
+
getZoom: () => this.zoom !== null ? this.zoom : getMapZoom(),
|
|
165
|
+
getPlugins: () => this.plugins.length > 0 ? this.plugins : getMapPlugins(),
|
|
166
|
+
getConfig: () => ({
|
|
167
|
+
provider: this.provider || getMapProvider(),
|
|
168
|
+
apiKey: this.apiKey || getMapApiKey(),
|
|
169
|
+
apiUrl: this.apiUrl || getMapApiUrl(),
|
|
170
|
+
mapType: this.mapType || getMapType(),
|
|
171
|
+
theme: this.theme || getMapTheme(),
|
|
172
|
+
center: this.center || getMapCenter(),
|
|
173
|
+
zoom: this.zoom !== null ? this.zoom : getMapZoom()
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
created() {
|
|
180
|
+
this._unsubscribe = onMapConfigChange((key, value) => {
|
|
181
|
+
if (key === 'theme') this.mergedTheme = this.theme || value
|
|
182
|
+
})
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
beforeDestroy() {
|
|
186
|
+
if (this._unsubscribe) this._unsubscribe()
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
</script>
|
|
190
|
+
|
|
191
|
+
<style scoped>
|
|
192
|
+
.xt-map-provider {
|
|
193
|
+
width: 100%;
|
|
194
|
+
height: 100%;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.xt-map-provider--dark {
|
|
198
|
+
background-color: transparent;
|
|
199
|
+
}
|
|
200
|
+
</style>
|