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.
Files changed (42) hide show
  1. package/docs/components/base/xt-map.md +331 -0
  2. package/docs/components/base/xt-step-price.md +103 -217
  3. package/lib/index.common.js +2118 -40
  4. package/lib/index.css +1 -1
  5. package/lib/index.umd.js +2118 -40
  6. package/lib/index.umd.min.js +5 -5
  7. package/package.json +4 -3
  8. package/src/components/ex-button/index.js +8 -2
  9. package/src/components/ex-chart/index.js +6 -0
  10. package/src/components/ex-date-picker/index.js +8 -2
  11. package/src/components/ex-icon/index.js +6 -0
  12. package/src/components/ex-page/index.js +8 -2
  13. package/src/components/ex-select-tree/index.js +8 -2
  14. package/src/components/ex-table/index.js +6 -0
  15. package/src/components/ex-upload/index.js +6 -0
  16. package/src/components/xt-button/index.js +8 -2
  17. package/src/components/xt-button/index.vue +1 -1
  18. package/src/components/xt-card/index.js +8 -2
  19. package/src/components/xt-card-item/index.js +8 -2
  20. package/src/components/xt-config-provider/index.js +6 -0
  21. package/src/components/xt-flex-box/index.js +8 -2
  22. package/src/components/xt-flex-box/style/index.scss +0 -9
  23. package/src/components/xt-grid-box/index.js +8 -2
  24. package/src/components/xt-grid-item/index.js +7 -1
  25. package/src/components/xt-input/index.js +8 -2
  26. package/src/components/xt-map/adapters/amap.js +235 -0
  27. package/src/components/xt-map/adapters/baidu.js +254 -0
  28. package/src/components/xt-map/adapters/base.js +267 -0
  29. package/src/components/xt-map/adapters/index.js +29 -0
  30. package/src/components/xt-map/adapters/tianditu.js +242 -0
  31. package/src/components/xt-map/config/xt-map-config.js +197 -0
  32. package/src/components/xt-map/index.js +30 -0
  33. package/src/components/xt-map/index.vue +351 -0
  34. package/src/components/xt-map/loaders/script-loader.js +114 -0
  35. package/src/components/xt-map/provider.vue +200 -0
  36. package/src/components/xt-map/style/index.scss +77 -0
  37. package/src/components/xt-step-price/index.js +9 -0
  38. package/src/components/xt-step-price-item/index.js +6 -0
  39. package/src/components/xt-step-price-item/index.vue +3 -1
  40. package/src/components/xt-text/index.js +8 -2
  41. package/src/components/xt-time/index.js +6 -0
  42. package/src/index.js +6 -0
@@ -0,0 +1,242 @@
1
+ /**
2
+ * 天地图适配器 (Tianditu)
3
+ * 天地图使用 WMTS 切片服务,不支持原生主题切换,
4
+ * dark/light 通过图层样式参数模拟(部分图层可调整色调)
5
+ */
6
+
7
+ import { MapAdapterBase } from './base'
8
+ import { hasGlobal } from '../loaders/script-loader'
9
+
10
+ // 天地图地图类型映射
11
+ const TIANDITU_MAP_TYPES = {
12
+ standard: 'vec', // 矢量地图
13
+ satellite: 'img', // 影像地图
14
+ hybrid: 'img', // 混合(影像 + 注记)
15
+ traffic: 'vec' // 天地图不支持原生路况,降级为矢量
16
+ }
17
+
18
+ // 天地图主题色模拟:通过调整图层透明度/色调CSS滤镜
19
+ const TIANDITU_THEME_FILTER = {
20
+ light: 'none',
21
+ dark: 'invert(1) hue-rotate(180deg) saturate(1.2) brightness(0.95)'
22
+ }
23
+
24
+ export class TiandituAdapter extends MapAdapterBase {
25
+ constructor(container, options = {}) {
26
+ super(container, options)
27
+ this._mapTypeMap = { ...TIANDITU_MAP_TYPES }
28
+ this._layerType = options.tiandituLayerType || 'vec'
29
+ this._currentLayer = null
30
+ this._annotationLayer = null
31
+ }
32
+
33
+ getScriptUrl() {
34
+ if (this.apiUrl) return this.apiUrl
35
+ if (!this.apiKey) {
36
+ console.warn('[XtMap] 天地图需要配置 apiKey (tk)')
37
+ return ''
38
+ }
39
+ return `https://api.tianditu.gov.cn/api?v=4.0&tk=${encodeURIComponent(this.apiKey)}`
40
+ }
41
+
42
+ isSdkLoaded() {
43
+ return hasGlobal('T') && typeof window.T === 'object' && window.T.Map
44
+ }
45
+
46
+ async createMap() {
47
+ const T = window.T
48
+ if (!T || !T.Map) throw new Error('[XtMap] 天地图 SDK 未加载')
49
+
50
+ const mapOptions = {
51
+ center: new T.LngLat(this.center[0], this.center[1]),
52
+ zoom: this.zoom
53
+ }
54
+
55
+ this.mapInstance = new T.Map(this.container, mapOptions)
56
+
57
+ // 应用地图类型
58
+ this._applyMapType(this.mapType)
59
+
60
+ // 应用主题
61
+ this._applyTheme(this.theme)
62
+
63
+ // 等待地图就绪
64
+ await new Promise((resolve) => {
65
+ setTimeout(resolve, 500)
66
+ })
67
+
68
+ // 绑定事件
69
+ for (const [eventName, handler] of this.eventHandlers.entries()) {
70
+ this._bindEvent(eventName, handler)
71
+ }
72
+ }
73
+
74
+ _applyMapType(type) {
75
+ if (!this.mapInstance) return
76
+ const T = window.T
77
+ if (!T) return
78
+
79
+ try {
80
+ // 天地图通过 switchTo 方法切换图层
81
+ const layerType = this._mapTypeMap[type] || 'vec'
82
+
83
+ if (type === 'standard') {
84
+ // 矢量地图
85
+ this.mapInstance.setMapType(window.TMAP_NORMAL_MAP || 1)
86
+ } else if (type === 'satellite') {
87
+ // 影像地图
88
+ this.mapInstance.setMapType(window.TMAP_SATELLITE_MAP || 2)
89
+ } else if (type === 'hybrid') {
90
+ // 混合(影像+注记)
91
+ this.mapInstance.setMapType(window.TMAP_HYBRID_MAP || 3)
92
+ } else {
93
+ // 路况等特殊类型,天地图无原生支持
94
+ this.mapInstance.setMapType(window.TMAP_NORMAL_MAP || 1)
95
+ }
96
+ } catch (e) {
97
+ console.warn('[XtMap] 天地图切换地图类型失败:', e)
98
+ }
99
+ }
100
+
101
+ _applyTheme(theme) {
102
+ if (!this.container) return
103
+ // 天地图不支持原生 dark 主题,通过 CSS 滤镜模拟
104
+ const filter = TIANDITU_THEME_FILTER[theme] || 'none'
105
+ const imgElements = this.container.querySelectorAll('img')
106
+ imgElements.forEach((img) => {
107
+ img.style.filter = filter
108
+ img.style.webkitFilter = filter
109
+ })
110
+ // 同时设置容器级 CSS 变量,方便样式覆盖
111
+ this.container.setAttribute('data-map-theme', theme)
112
+ // 监听后续新增的 tile 图片(通过 MutationObserver)
113
+ this._setupThemeObserver(theme)
114
+ }
115
+
116
+ _setupThemeObserver(theme) {
117
+ if (this._themeObserver) {
118
+ this._themeObserver.disconnect()
119
+ }
120
+ if (theme !== 'dark') return
121
+ const filter = TIANDITU_THEME_FILTER[theme]
122
+ this._themeObserver = new MutationObserver((mutations) => {
123
+ mutations.forEach((mutation) => {
124
+ mutation.addedNodes.forEach((node) => {
125
+ if (node.nodeType === 1) {
126
+ if (node.tagName === 'IMG') {
127
+ node.style.filter = filter
128
+ node.style.webkitFilter = filter
129
+ } else if (node.querySelectorAll) {
130
+ const imgs = node.querySelectorAll('img')
131
+ imgs.forEach((img) => {
132
+ img.style.filter = filter
133
+ img.style.webkitFilter = filter
134
+ })
135
+ }
136
+ }
137
+ })
138
+ })
139
+ })
140
+ try {
141
+ this._themeObserver.observe(this.container, {
142
+ childList: true,
143
+ subtree: true
144
+ })
145
+ } catch (e) {
146
+ // 忽略
147
+ }
148
+ }
149
+
150
+ _applyCenter(center) {
151
+ if (!this.mapInstance || !window.T) return
152
+ try {
153
+ this.mapInstance.centerAndZoom(new window.T.LngLat(center[0], center[1]), this.zoom)
154
+ } catch (e) {
155
+ // 忽略
156
+ }
157
+ }
158
+
159
+ _applyZoom(zoom) {
160
+ if (!this.mapInstance) return
161
+ try {
162
+ this.mapInstance.setZoom(zoom)
163
+ } catch (e) {
164
+ // 忽略
165
+ }
166
+ }
167
+
168
+ getCenter() {
169
+ if (this.mapInstance && this.mapInstance.getCenter) {
170
+ const c = this.mapInstance.getCenter()
171
+ if (c && c.getLng !== undefined) {
172
+ return [c.getLng(), c.getLat()]
173
+ }
174
+ }
175
+ return this.center
176
+ }
177
+
178
+ getZoom() {
179
+ if (this.mapInstance && this.mapInstance.getZoom) {
180
+ return this.mapInstance.getZoom()
181
+ }
182
+ return this.zoom
183
+ }
184
+
185
+ _bindEvent(eventName, handler) {
186
+ if (!this.mapInstance) return
187
+ try {
188
+ const eventMap = {
189
+ click: 'click',
190
+ moveend: 'moveend',
191
+ zoomend: 'zoomend',
192
+ zoomchange: 'zoomend'
193
+ }
194
+ const nativeEvent = eventMap[eventName] || eventName
195
+ this.mapInstance.addEventListener(nativeEvent, (e) => {
196
+ const normalized = {
197
+ originalEvent: e,
198
+ lnglat: e && e.lnglat ? [e.lnglat.getLng(), e.lnglat.getLat()] : null
199
+ }
200
+ handler(normalized)
201
+ })
202
+ } catch (err) {
203
+ console.warn('[XtMap] 天地图事件绑定失败:', eventName, err)
204
+ }
205
+ }
206
+
207
+ _unbindEvent(eventName, handler) {
208
+ if (!this.mapInstance) return
209
+ try {
210
+ this.mapInstance.removeEventListener(eventName, handler)
211
+ } catch (e) {
212
+ // 忽略
213
+ }
214
+ }
215
+
216
+ _applyResize() {
217
+ if (this.mapInstance && this.mapInstance.checkResize) {
218
+ try {
219
+ this.mapInstance.checkResize()
220
+ } catch (e) {
221
+ // 忽略
222
+ }
223
+ }
224
+ }
225
+
226
+ destroy() {
227
+ if (this._themeObserver) {
228
+ this._themeObserver.disconnect()
229
+ this._themeObserver = null
230
+ }
231
+ if (this.mapInstance && typeof this.mapInstance.clearOverLays === 'function') {
232
+ try {
233
+ this.mapInstance.clearOverLays()
234
+ } catch (e) {
235
+ // 忽略
236
+ }
237
+ }
238
+ super.destroy()
239
+ }
240
+ }
241
+
242
+ export default TiandituAdapter
@@ -0,0 +1,197 @@
1
+ /**
2
+ * XtMap 全局配置管理
3
+ * 支持通过 Vue.use 配置或运行时动态设置地图提供商、密钥、URL、主题等
4
+ */
5
+
6
+ // 支持的地图提供商
7
+ export const MAP_PROVIDERS = ['amap', 'tianditu', 'baidu']
8
+
9
+ // 支持的地图类型(统一枚举,各适配器会转成对应引擎的类型)
10
+ export const MAP_TYPES = ['standard', 'satellite', 'hybrid', 'traffic']
11
+
12
+ // 支持的主题
13
+ export const MAP_THEMES = ['light', 'dark']
14
+
15
+ // 默认配置 - 以高德地图为基准
16
+ const defaultConfig = {
17
+ provider: 'amap',
18
+ apiKey: '',
19
+ apiUrl: null,
20
+ mapType: 'standard',
21
+ theme: 'light',
22
+ center: [116.397428, 39.90923],
23
+ zoom: 11,
24
+ plugins: [],
25
+ securityJsCode: null,
26
+ // 天地图专用:图层类型(vec:矢量, img:影像, ter:地形)
27
+ tiandituLayerType: 'vec',
28
+ // 百度地图专用:坐标系(bd09ll:百度经纬度, bd09mc:百度墨卡托)
29
+ baiduCoordType: 'bd09ll'
30
+ }
31
+
32
+ // 当前配置
33
+ let currentConfig = { ...defaultConfig }
34
+
35
+ // 配置变更监听器
36
+ const configChangeListeners = []
37
+
38
+ const emitConfigChange = (key, value) => {
39
+ configChangeListeners.forEach(listener => {
40
+ try {
41
+ listener(key, value)
42
+ } catch (e) {
43
+ console.warn('[XtMap] 配置变更监听异常:', e)
44
+ }
45
+ })
46
+ }
47
+
48
+ // 获取完整配置
49
+ export const getMapConfig = () => ({ ...currentConfig })
50
+
51
+ // 设置完整配置
52
+ export const setMapConfig = (config) => {
53
+ if (typeof config !== 'object' || config === null) {
54
+ console.warn('[XtMap] setMapConfig 必须传入对象参数')
55
+ return
56
+ }
57
+
58
+ if (config.provider !== undefined) setMapProvider(config.provider)
59
+ if (config.apiKey !== undefined) setMapApiKey(config.apiKey)
60
+ if (config.apiUrl !== undefined) setMapApiUrl(config.apiUrl)
61
+ if (config.mapType !== undefined) setMapType(config.mapType)
62
+ if (config.theme !== undefined) setMapTheme(config.theme)
63
+ if (config.center !== undefined) setMapCenter(config.center)
64
+ if (config.zoom !== undefined) setMapZoom(config.zoom)
65
+ if (config.plugins !== undefined) setMapPlugins(config.plugins)
66
+ if (config.securityJsCode !== undefined) setSecurityJsCode(config.securityJsCode)
67
+ }
68
+
69
+ export const setMapProvider = (provider) => {
70
+ if (!MAP_PROVIDERS.includes(provider)) {
71
+ console.warn(`[XtMap] 无效的地图提供商: ${provider},可选: ${MAP_PROVIDERS.join(', ')}`)
72
+ return
73
+ }
74
+ currentConfig.provider = provider
75
+ emitConfigChange('provider', provider)
76
+ }
77
+
78
+ export const setMapApiKey = (key) => {
79
+ currentConfig.apiKey = key
80
+ emitConfigChange('apiKey', key)
81
+ }
82
+
83
+ export const setMapApiUrl = (url) => {
84
+ currentConfig.apiUrl = url
85
+ emitConfigChange('apiUrl', url)
86
+ }
87
+
88
+ export const setMapType = (type) => {
89
+ if (!MAP_TYPES.includes(type)) {
90
+ console.warn(`[XtMap] 无效的地图类型: ${type},可选: ${MAP_TYPES.join(', ')}`)
91
+ return
92
+ }
93
+ currentConfig.mapType = type
94
+ emitConfigChange('mapType', type)
95
+ }
96
+
97
+ export const setMapTheme = (theme) => {
98
+ if (!MAP_THEMES.includes(theme)) {
99
+ console.warn(`[XtMap] 无效的主题: ${theme},可选: ${MAP_THEMES.join(', ')}`)
100
+ return
101
+ }
102
+ currentConfig.theme = theme
103
+ emitConfigChange('theme', theme)
104
+ }
105
+
106
+ export const setMapCenter = (center) => {
107
+ if (!Array.isArray(center) || center.length !== 2) {
108
+ console.warn('[XtMap] center 必须是 [lng, lat] 数组')
109
+ return
110
+ }
111
+ currentConfig.center = center
112
+ emitConfigChange('center', center)
113
+ }
114
+
115
+ export const setMapZoom = (zoom) => {
116
+ const z = Number(zoom)
117
+ if (isNaN(z)) {
118
+ console.warn('[XtMap] zoom 必须是数字')
119
+ return
120
+ }
121
+ currentConfig.zoom = z
122
+ emitConfigChange('zoom', z)
123
+ }
124
+
125
+ export const setMapPlugins = (plugins) => {
126
+ if (!Array.isArray(plugins)) {
127
+ console.warn('[XtMap] plugins 必须是数组')
128
+ return
129
+ }
130
+ currentConfig.plugins = plugins
131
+ emitConfigChange('plugins', plugins)
132
+ }
133
+
134
+ export const setSecurityJsCode = (code) => {
135
+ currentConfig.securityJsCode = code
136
+ // 高德地图安全密钥:设置 window._AMapSecurityConfig
137
+ if (typeof window !== 'undefined' && code) {
138
+ window._AMapSecurityConfig = {
139
+ securityJsCode: code,
140
+ ...(window._AMapSecurityConfig || {})
141
+ }
142
+ }
143
+ emitConfigChange('securityJsCode', code)
144
+ }
145
+
146
+ // 获取当前配置的快捷方法
147
+ export const getMapProvider = () => currentConfig.provider
148
+ export const getMapApiKey = () => currentConfig.apiKey
149
+ export const getMapApiUrl = () => currentConfig.apiUrl
150
+ export const getMapType = () => currentConfig.mapType
151
+ export const getMapTheme = () => currentConfig.theme
152
+ export const getMapCenter = () => currentConfig.center
153
+ export const getMapZoom = () => currentConfig.zoom
154
+ export const getMapPlugins = () => currentConfig.plugins
155
+
156
+ // 监听配置变更
157
+ export const onMapConfigChange = (listener) => {
158
+ if (typeof listener === 'function') {
159
+ configChangeListeners.push(listener)
160
+ return () => {
161
+ const index = configChangeListeners.indexOf(listener)
162
+ if (index > -1) configChangeListeners.splice(index, 1)
163
+ }
164
+ }
165
+ }
166
+
167
+ // 重置为默认配置
168
+ export const resetMapConfig = () => {
169
+ setMapConfig(defaultConfig)
170
+ }
171
+
172
+ export default {
173
+ MAP_PROVIDERS,
174
+ MAP_TYPES,
175
+ MAP_THEMES,
176
+ getMapConfig,
177
+ setMapConfig,
178
+ setMapProvider,
179
+ setMapApiKey,
180
+ setMapApiUrl,
181
+ setMapType,
182
+ setMapTheme,
183
+ setMapCenter,
184
+ setMapZoom,
185
+ setMapPlugins,
186
+ setSecurityJsCode,
187
+ getMapProvider,
188
+ getMapApiKey,
189
+ getMapApiUrl,
190
+ getMapType,
191
+ getMapTheme,
192
+ getMapCenter,
193
+ getMapZoom,
194
+ getMapPlugins,
195
+ onMapConfigChange,
196
+ resetMapConfig
197
+ }
@@ -0,0 +1,30 @@
1
+ import XtMap from './index.vue'
2
+ import XtMapProvider from './provider.vue'
3
+ import './style/index.scss'
4
+
5
+ // 为组件添加 install 方法,支持 Vue.use() 单独引入
6
+ XtMap.install = function (Vue) {
7
+ Vue.component(XtMap.name, XtMap)
8
+ }
9
+
10
+ XtMapProvider.install = function (Vue) {
11
+ Vue.component(XtMapProvider.name, XtMapProvider)
12
+ }
13
+
14
+ // 导出单个组件,支持按需引入
15
+ export { XtMap, XtMapProvider }
16
+
17
+ // 导出默认对象,支持全量引入
18
+ export default {
19
+ install(Vue) {
20
+ Vue.component(XtMap.name, XtMap)
21
+ Vue.component(XtMapProvider.name, XtMapProvider)
22
+ },
23
+ // 确保导出的组件对象包含 name 属性
24
+ XtMap,
25
+ XtMapProvider
26
+ }
27
+
28
+ // 为了兼容旧版本,同时导出组件的 name 属性
29
+ export const XtMapName = XtMap.name
30
+ export const XtMapProviderName = XtMapProvider.name