xt-element-ui 1.3.3 → 1.3.4

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 (111) hide show
  1. package/CHANGELOG.md +72 -72
  2. package/LICENSE +21 -21
  3. package/README.md +240 -240
  4. package/docs/README.md +100 -100
  5. package/docs/components/base/xt-button.md +114 -114
  6. package/docs/components/base/xt-card-item.md +104 -104
  7. package/docs/components/base/xt-card.md +108 -108
  8. package/docs/components/base/xt-config-provider.md +199 -199
  9. package/docs/components/base/xt-flex-box.md +115 -115
  10. package/docs/components/base/xt-grid-box.md +302 -302
  11. package/docs/components/base/xt-input.md +150 -150
  12. package/docs/components/base/xt-map-provider.md +23 -23
  13. package/docs/components/base/xt-map.md +331 -331
  14. package/docs/components/base/xt-step-price.md +165 -165
  15. package/docs/components/base/xt-text.md +212 -212
  16. package/docs/components/base/xt-time.md +165 -165
  17. package/docs/components/extend/ex-bar.md +67 -67
  18. package/docs/components/extend/ex-button.md +62 -62
  19. package/docs/components/extend/ex-card.md +86 -86
  20. package/docs/components/extend/ex-chart.md +463 -463
  21. package/docs/components/extend/ex-icon.md +189 -189
  22. package/docs/components/extend/ex-line.md +70 -70
  23. package/docs/components/extend/ex-multi.md +155 -155
  24. package/docs/components/extend/ex-pie.md +69 -69
  25. package/docs/components/extend/ex-select-tree.md +210 -210
  26. package/docs/components/extend/ex-table.md +590 -590
  27. package/docs/components/extend/ex-upload.md +134 -134
  28. package/docs/components/utils/size.md +147 -147
  29. package/docs/components/utils/theme.md +182 -182
  30. package/lib/index.common.js +4112 -4122
  31. package/lib/index.umd.js +4072 -4081
  32. package/lib/index.umd.min.js +3 -3
  33. package/package.json +80 -81
  34. package/src/components/ex-button/index.js +7 -7
  35. package/src/components/ex-button/index.vue +66 -66
  36. package/src/components/ex-button/style/index.scss +67 -67
  37. package/src/components/ex-card/index.js +7 -7
  38. package/src/components/ex-card/index.vue +68 -68
  39. package/src/components/ex-card/style/index.scss +73 -73
  40. package/src/components/ex-chart/index.js +7 -7
  41. package/src/components/ex-chart/index.vue +136 -136
  42. package/src/components/ex-date-picker/index.js +7 -7
  43. package/src/components/ex-icon/index.js +7 -7
  44. package/src/components/ex-icon/index.vue +168 -168
  45. package/src/components/ex-icon/style/index.scss +7 -7
  46. package/src/components/ex-page/index.js +7 -7
  47. package/src/components/ex-select-tree/index.js +7 -7
  48. package/src/components/ex-table/ExTableCell.vue +22 -22
  49. package/src/components/ex-table/index.js +7 -7
  50. package/src/components/ex-table/virtualScrollData.js +35 -35
  51. package/src/components/ex-upload/index.js +7 -7
  52. package/src/components/index.scss +39 -39
  53. package/src/components/xt-button/index.js +7 -7
  54. package/src/components/xt-button/index.vue +97 -97
  55. package/src/components/xt-card/index.js +7 -7
  56. package/src/components/xt-card/style/index.scss +48 -48
  57. package/src/components/xt-card-item/index.js +7 -7
  58. package/src/components/xt-card-item/style/index copy.scss +71 -71
  59. package/src/components/xt-card-item/style/index.scss +82 -82
  60. package/src/components/xt-config-provider/index.js +7 -7
  61. package/src/components/xt-config-provider/index.vue +362 -362
  62. package/src/components/xt-config-provider/style/index.scss +11 -11
  63. package/src/components/xt-flex-box/index.js +7 -7
  64. package/src/components/xt-flex-box/style/index.scss +81 -81
  65. package/src/components/xt-grid-box/index.js +7 -7
  66. package/src/components/xt-grid-box/style/index.scss +92 -92
  67. package/src/components/xt-grid-item/index.js +7 -7
  68. package/src/components/xt-grid-item/index.vue +106 -106
  69. package/src/components/xt-input/index.js +7 -7
  70. package/src/components/xt-input/index.vue +66 -66
  71. package/src/components/xt-input/style/index.scss +84 -84
  72. package/src/components/xt-map/adapters/amap.js +235 -235
  73. package/src/components/xt-map/adapters/baidu.js +254 -254
  74. package/src/components/xt-map/adapters/base.js +267 -267
  75. package/src/components/xt-map/adapters/index.js +29 -29
  76. package/src/components/xt-map/adapters/tianditu.js +242 -242
  77. package/src/components/xt-map/config/xt-map-config.js +197 -197
  78. package/src/components/xt-map/index.js +8 -8
  79. package/src/components/xt-map/index.vue +351 -351
  80. package/src/components/xt-map/loaders/script-loader.js +114 -114
  81. package/src/components/xt-map/provider.vue +200 -200
  82. package/src/components/xt-map/style/index.scss +77 -77
  83. package/src/components/xt-map-provider/index.js +8 -8
  84. package/src/components/xt-step-price/index.js +10 -10
  85. package/src/components/xt-step-price/index.vue +272 -272
  86. package/src/components/xt-step-price/style/index.scss +123 -123
  87. package/src/components/xt-step-price-item/index.js +7 -7
  88. package/src/components/xt-step-price-item/index.vue +187 -187
  89. package/src/components/xt-text/index.js +7 -7
  90. package/src/components/xt-text/index.vue +1 -1
  91. package/src/components/xt-text/style/index.scss +92 -92
  92. package/src/components/xt-time/index.js +7 -7
  93. package/src/components/xt-time/index.vue +313 -313
  94. package/src/components/xt-time/style/index.scss +23 -23
  95. package/src/config/element-registry.js +135 -135
  96. package/src/index.js +162 -178
  97. package/src/styles/css-variables.scss +257 -257
  98. package/src/styles/theme/background.scss +5 -5
  99. package/src/styles/theme/border-radius.scss +3 -3
  100. package/src/styles/theme/borders.scss +3 -3
  101. package/src/styles/theme/colors.scss +101 -101
  102. package/src/styles/theme/component-variables.scss +69 -69
  103. package/src/styles/theme/dark-variables.scss +28 -28
  104. package/src/styles/theme/font.scss +12 -12
  105. package/src/styles/theme/index.scss +11 -11
  106. package/src/styles/theme/shadows.scss +2 -2
  107. package/src/styles/theme/spacing.scss +4 -4
  108. package/src/styles/theme/transitions.scss +2 -2
  109. package/src/styles/theme/typography.scss +4 -4
  110. package/src/styles/variables-export.scss +85 -85
  111. package/src/utils/index.js +191 -202
@@ -1,86 +1,86 @@
1
- @import './theme/index.scss';
2
-
3
- // SCSS 变量导出给 JavaScript 使用
4
- :export {
5
- // ===========================
6
- // 主色调系列
7
- // ===========================
8
- xtColorPrimary: #{$xt-color-primary}; // 主颜色 - Element UI 标准蓝色
9
- xtColorSuccess: #{$xt-color-success}; // 成功色 - Element UI 标准绿色
10
- xtColorWarning: #{$xt-color-warning}; // 警告色 - Element UI 标准橙色
11
- xtColorDanger: #{$xt-color-danger}; // 危险色 - Element UI 标准红色
12
- xtColorInfo: #{$xt-color-info}; // 信息色 - Element UI 标准灰色
13
-
14
- // 主色调浅色系列
15
- xtColorPrimaryLight3: #{$xt-color-primary-light-3}; // 主色浅色 30%
16
- xtColorPrimaryLight5: #{$xt-color-primary-light-5}; // 主色浅色 50%
17
- xtColorPrimaryLight7: #{$xt-color-primary-light-7}; // 主色浅色 70%
18
- xtColorPrimaryLight8: #{$xt-color-primary-light-8}; // 主色浅色 80%
19
- xtColorPrimaryLight9: #{$xt-color-primary-light-9}; // 主色浅色 90%
20
-
21
- // ===========================
22
- // 文字颜色
23
- // ===========================
24
- xtColorTextPrimary: #{$xt-color-text-primary}; // 主要文字颜色 - 最深
25
- xtColorTextRegular: #{$xt-color-text-regular}; // 常规文字颜色 - 中等
26
- xtColorTextSecondary: #{$xt-color-text-secondary}; // 次要文字颜色 - 较浅
27
- xtColorTextPlaceholder: #{$xt-color-text-placeholder}; // 占位符文字颜色
28
- xtColorTextDisabled: #{$xt-color-text-disabled}; // 禁用状态文字颜色
29
-
30
- // ===========================
31
- // 背景颜色
32
- // ===========================
33
- xtColorBgPrimary: #{$xt-color-bg-primary}; // 主背景色 - 白色
34
- xtColorBgSecondary: #{$xt-color-bg-secondary}; // 次要背景色 - 浅灰
35
- xtColorBgHover: #{$xt-color-bg-hover}; // 悬停背景色
36
- xtColorBgContainer: #{$xt-color-bg-container}; // 容器背景色
37
- xtColorBgOverlay: #{$xt-color-bg-overlay}; // 浮层背景色
38
-
39
- // ===========================
40
- // 边框颜色
41
- // ===========================
42
- xtColorBorder: #{$xt-color-border}; // 边框颜色 - 标准
43
- xtColorBorderLight: #{$xt-color-border-light}; // 边框浅色
44
- xtColorBorderLighter: #{$xt-color-border-lighter}; // 边框更浅色
45
- xtColorBorderExtraLight: #{$xt-color-border-extra-light}; // 边框极浅色
46
-
47
- // ===========================
48
- // 字体大小
49
- // ===========================
50
- xtFontSizeExtraLarge: #{$xt-font-size-extra-large}; // 特大字体
51
- xtFontSizeLarge: #{$xt-font-size-large}; // 大字体
52
- xtFontSizeMedium: #{$xt-font-size-medium}; // 中等字体
53
- xtFontSizeBase: #{$xt-font-size-base}; // 基准字体
54
- xtFontSizeSmall: #{$xt-font-size-small}; // 小字体
55
- xtFontSizeExtraSmall: #{$xt-font-size-extra-small}; // 特小字体
56
-
57
- // ===========================
58
- // 间距
59
- // ===========================
60
- xtSpacingXs: #{$xt-spacing-xs}; // 最小间距
61
- xtSpacingSm: #{$xt-spacing-sm}; // 小间距
62
- xtSpacingMd: #{$xt-spacing-md}; // 中间距
63
- xtSpacingLg: #{$xt-spacing-lg}; // 大间距
64
- xtSpacingXl: #{$xt-spacing-xl}; // 特大间距
65
-
66
- // ===========================
67
- // 圆角
68
- // ===========================
69
- xtBorderRadiusBase: #{$xt-border-radius-base}; // 基准圆角
70
- xtBorderRadiusSmall: #{$xt-border-radius-small}; // 小圆角
71
- xtBorderRadiusRound: #{$xt-border-radius-round}; // 圆角(胶囊状)
72
- xtBorderRadiusCircle: #{$xt-border-radius-circle}; // 圆形
73
-
74
- // ===========================
75
- // 阴影
76
- // ===========================
77
- xtShadowSm: #{$xt-shadow-sm}; // 小阴影
78
- xtShadowMd: #{$xt-shadow-md}; // 中等阴影
79
- xtShadowLg: #{$xt-shadow-lg}; // 大阴影
80
-
81
- // ===========================
82
- // 过渡动画
83
- // ===========================
84
- xtTransitionDuration: #{$xt-transition-duration}; // 默认过渡时长
85
- xtTransitionDurationFast: #{$xt-transition-duration-fast}; // 快速过渡时长
1
+ @import './theme/index.scss';
2
+
3
+ // SCSS 变量导出给 JavaScript 使用
4
+ :export {
5
+ // ===========================
6
+ // 主色调系列
7
+ // ===========================
8
+ xtColorPrimary: #{$xt-color-primary}; // 主颜色 - Element UI 标准蓝色
9
+ xtColorSuccess: #{$xt-color-success}; // 成功色 - Element UI 标准绿色
10
+ xtColorWarning: #{$xt-color-warning}; // 警告色 - Element UI 标准橙色
11
+ xtColorDanger: #{$xt-color-danger}; // 危险色 - Element UI 标准红色
12
+ xtColorInfo: #{$xt-color-info}; // 信息色 - Element UI 标准灰色
13
+
14
+ // 主色调浅色系列
15
+ xtColorPrimaryLight3: #{$xt-color-primary-light-3}; // 主色浅色 30%
16
+ xtColorPrimaryLight5: #{$xt-color-primary-light-5}; // 主色浅色 50%
17
+ xtColorPrimaryLight7: #{$xt-color-primary-light-7}; // 主色浅色 70%
18
+ xtColorPrimaryLight8: #{$xt-color-primary-light-8}; // 主色浅色 80%
19
+ xtColorPrimaryLight9: #{$xt-color-primary-light-9}; // 主色浅色 90%
20
+
21
+ // ===========================
22
+ // 文字颜色
23
+ // ===========================
24
+ xtColorTextPrimary: #{$xt-color-text-primary}; // 主要文字颜色 - 最深
25
+ xtColorTextRegular: #{$xt-color-text-regular}; // 常规文字颜色 - 中等
26
+ xtColorTextSecondary: #{$xt-color-text-secondary}; // 次要文字颜色 - 较浅
27
+ xtColorTextPlaceholder: #{$xt-color-text-placeholder}; // 占位符文字颜色
28
+ xtColorTextDisabled: #{$xt-color-text-disabled}; // 禁用状态文字颜色
29
+
30
+ // ===========================
31
+ // 背景颜色
32
+ // ===========================
33
+ xtColorBgPrimary: #{$xt-color-bg-primary}; // 主背景色 - 白色
34
+ xtColorBgSecondary: #{$xt-color-bg-secondary}; // 次要背景色 - 浅灰
35
+ xtColorBgHover: #{$xt-color-bg-hover}; // 悬停背景色
36
+ xtColorBgContainer: #{$xt-color-bg-container}; // 容器背景色
37
+ xtColorBgOverlay: #{$xt-color-bg-overlay}; // 浮层背景色
38
+
39
+ // ===========================
40
+ // 边框颜色
41
+ // ===========================
42
+ xtColorBorder: #{$xt-color-border}; // 边框颜色 - 标准
43
+ xtColorBorderLight: #{$xt-color-border-light}; // 边框浅色
44
+ xtColorBorderLighter: #{$xt-color-border-lighter}; // 边框更浅色
45
+ xtColorBorderExtraLight: #{$xt-color-border-extra-light}; // 边框极浅色
46
+
47
+ // ===========================
48
+ // 字体大小
49
+ // ===========================
50
+ xtFontSizeExtraLarge: #{$xt-font-size-extra-large}; // 特大字体
51
+ xtFontSizeLarge: #{$xt-font-size-large}; // 大字体
52
+ xtFontSizeMedium: #{$xt-font-size-medium}; // 中等字体
53
+ xtFontSizeBase: #{$xt-font-size-base}; // 基准字体
54
+ xtFontSizeSmall: #{$xt-font-size-small}; // 小字体
55
+ xtFontSizeExtraSmall: #{$xt-font-size-extra-small}; // 特小字体
56
+
57
+ // ===========================
58
+ // 间距
59
+ // ===========================
60
+ xtSpacingXs: #{$xt-spacing-xs}; // 最小间距
61
+ xtSpacingSm: #{$xt-spacing-sm}; // 小间距
62
+ xtSpacingMd: #{$xt-spacing-md}; // 中间距
63
+ xtSpacingLg: #{$xt-spacing-lg}; // 大间距
64
+ xtSpacingXl: #{$xt-spacing-xl}; // 特大间距
65
+
66
+ // ===========================
67
+ // 圆角
68
+ // ===========================
69
+ xtBorderRadiusBase: #{$xt-border-radius-base}; // 基准圆角
70
+ xtBorderRadiusSmall: #{$xt-border-radius-small}; // 小圆角
71
+ xtBorderRadiusRound: #{$xt-border-radius-round}; // 圆角(胶囊状)
72
+ xtBorderRadiusCircle: #{$xt-border-radius-circle}; // 圆形
73
+
74
+ // ===========================
75
+ // 阴影
76
+ // ===========================
77
+ xtShadowSm: #{$xt-shadow-sm}; // 小阴影
78
+ xtShadowMd: #{$xt-shadow-md}; // 中等阴影
79
+ xtShadowLg: #{$xt-shadow-lg}; // 大阴影
80
+
81
+ // ===========================
82
+ // 过渡动画
83
+ // ===========================
84
+ xtTransitionDuration: #{$xt-transition-duration}; // 默认过渡时长
85
+ xtTransitionDurationFast: #{$xt-transition-duration-fast}; // 快速过渡时长
86
86
  }
@@ -1,202 +1,191 @@
1
- import EchartsUtil from '../components/ex-chart/utils'
2
- // 默认配置
3
- const defaultConfig = {
4
- theme: 'white',
5
- size: 'medium',
6
- primaryColor: '#1890ff'
7
- }
8
-
9
- // 当前配置
10
- let currentConfig = { ...defaultConfig }
11
-
12
- // 调试:输出初始化信息
13
- console.log('[XtElementUI] utils initialized with currentConfig:', currentConfig)
14
-
15
- // 配置变更事件处理
16
- const configChangeListeners = []
17
-
18
- const emitConfigChange = function(key, value) {
19
- configChangeListeners.forEach(listener => {
20
- listener(key, value)
21
- })
22
- }
23
-
24
- // 获取所有配置
25
- export const getConfig = function() {
26
- return { ...currentConfig }
27
- }
28
-
29
- // 设置全局配置
30
- export const setConfig = function(config) {
31
- if (typeof config !== 'object' || config === null) {
32
- console.warn('[XtElementUI] setConfig 必须传入对象参数')
33
- return
34
- }
35
-
36
- if (config.theme !== undefined) {
37
- setTheme(config.theme)
38
- }
39
- if (config.size !== undefined) {
40
- setSize(config.size)
41
- }
42
- if (config.primaryColor !== undefined) {
43
- setPrimaryColor(config.primaryColor)
44
- }
45
- }
46
-
47
-
48
- // 设置主题 并更新图表主题
49
- export const setTheme = function(theme) {
50
- const validThemes = ['white', 'dark']
51
- if (!validThemes.includes(theme)) {
52
- console.warn(`[XtElementUI] 无效的主题值: ${theme},可选值: ${validThemes.join(', ')}`)
53
- return
54
- }
55
-
56
- currentConfig.theme = theme
57
- const root = document.documentElement
58
-
59
- // 使用类名方式切换主题(兼容 Element Plus 风格)
60
- if (theme === 'dark') {
61
- root.setAttribute('data-theme', 'dark')
62
- } else {
63
- root.setAttribute('data-theme', theme)
64
- }
65
-
66
- // 更新图表主题
67
- EchartsUtil.changeAllTheme(currentConfig.theme, currentConfig.size)
68
- console.log('更新图表主题')
69
-
70
- emitConfigChange('theme', theme)
71
- }
72
-
73
- // 设置字体大小
74
- export const setSize = function(size) {
75
- const validSizes = ['small', 'medium', 'large']
76
- if (!validSizes.includes(size)) {
77
- console.warn(`[XtElementUI] 无效的大小值: ${size},可选值: ${validSizes.join(', ')}`)
78
- return
79
- }
80
-
81
- currentConfig.size = size
82
- document.documentElement.setAttribute('data-size', size)
83
- // 更新图表主题
84
- EchartsUtil.changeAllTheme(currentConfig.theme, currentConfig.size)
85
- console.log('更新图表字体')
86
-
87
- emitConfigChange('size', size)
88
- }
89
-
90
- // 将十六进制颜色转换为 RGB 对象
91
- function hexToRgb(hex) {
92
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
93
- return result ? {
94
- r: parseInt(result[1], 16),
95
- g: parseInt(result[2], 16),
96
- b: parseInt(result[3], 16)
97
- } : null
98
- }
99
-
100
- // 将 RGB 对象转换为十六进制颜色
101
- function rgbToHex(r, g, b) {
102
- return '#' + [r, g, b].map(x => {
103
- const hex = x.toString(16)
104
- return hex.length === 1 ? '0' + hex : hex
105
- }).join('')
106
- }
107
-
108
- // 计算浅色系列(混合白色)
109
- function lightenColor(hex, percent) {
110
- const rgb = hexToRgb(hex)
111
- if (!rgb) return hex
112
-
113
- const amount = Math.round(2.55 * percent)
114
- const r = Math.min(255, rgb.r + amount)
115
- const g = Math.min(255, rgb.g + amount)
116
- const b = Math.min(255, rgb.b + amount)
117
-
118
- return rgbToHex(r, g, b)
119
- }
120
-
121
- // 设置主色调
122
- export const setPrimaryColor = function(color) {
123
- // 颜色格式验证(支持 3/6/8 位十六进制)
124
- const colorRegex = /^#[0-9A-Fa-f]{3}$|^#[0-9A-Fa-f]{6}$|^#[0-9A-Fa-f]{8}$/
125
- if (!colorRegex.test(color)) {
126
- console.warn(`[XtElementUI] 无效的颜色值: ${color},请使用十六进制颜色格式,如 #1890ff`)
127
- return
128
- }
129
-
130
- // 转换为 6 位十六进制(去掉透明度)
131
- let validColor = color
132
- if (color.length === 4) {
133
- // #RGB 转换为 #RRGGBB
134
- validColor = '#' + color[1] + color[1] + color[2] + color[2] + color[3] + color[3]
135
- } else if (color.length === 9) {
136
- // #RRGGBBAA 转换为 #RRGGBB(去掉 Alpha)
137
- validColor = color.substring(0, 7)
138
- }
139
-
140
- currentConfig.primaryColor = validColor
141
-
142
- // 设置主色调
143
- document.documentElement.style.setProperty('--xt-color-primary', validColor)
144
-
145
- // 动态计算并设置浅色系列
146
- document.documentElement.style.setProperty('--xt-color-primary-light-3', lightenColor(validColor, 30))
147
- document.documentElement.style.setProperty('--xt-color-primary-light-5', lightenColor(validColor, 50))
148
- document.documentElement.style.setProperty('--xt-color-primary-light-7', lightenColor(validColor, 70))
149
- document.documentElement.style.setProperty('--xt-color-primary-light-8', lightenColor(validColor, 80))
150
- document.documentElement.style.setProperty('--xt-color-primary-light-9', lightenColor(validColor, 90))
151
-
152
- emitConfigChange('primaryColor', validColor)
153
- console.log('[XtElementUI] 主色调已设置为:', validColor)
154
- }
155
-
156
- // 获取当前主题
157
- export const getTheme = function() {
158
- return currentConfig.theme
159
- }
160
-
161
- // 获取当前字体大小
162
- export const getSize = function() {
163
- return currentConfig.size
164
- }
165
-
166
- // 获取当前主色调
167
- export const getPrimaryColor = function() {
168
- return currentConfig.primaryColor
169
- }
170
-
171
- // 重置为默认配置
172
- export const resetConfig = function() {
173
- setConfig(defaultConfig)
174
- }
175
-
176
- // 监听配置变更
177
- export const onConfigChange = function(listener) {
178
- if (typeof listener === 'function') {
179
- configChangeListeners.push(listener)
180
- return function() {
181
- const index = configChangeListeners.indexOf(listener)
182
- if (index > -1) {
183
- configChangeListeners.splice(index, 1)
184
- }
185
- }
186
- } else {
187
- console.warn('[XtElementUI] onConfigChange 必须传入函数')
188
- }
189
- }
190
-
191
- export default {
192
- setTheme,
193
- setSize,
194
- setPrimaryColor,
195
- getConfig,
196
- setConfig,
197
- getTheme,
198
- getSize,
199
- getPrimaryColor,
200
- resetConfig,
201
- onConfigChange
202
- }
1
+ import EchartsUtil from '../components/ex-chart/utils'
2
+
3
+ const defaultConfig = {
4
+ theme: 'white',
5
+ size: 'medium',
6
+ primaryColor: '#1890ff'
7
+ }
8
+
9
+ let currentConfig = { ...defaultConfig }
10
+
11
+ const configChangeListeners = []
12
+
13
+ const emitConfigChange = function(key, value) {
14
+ configChangeListeners.forEach(listener => {
15
+ listener(key, value)
16
+ })
17
+ }
18
+
19
+ export const getConfig = function() {
20
+ return { ...currentConfig }
21
+ }
22
+
23
+ export const setConfig = function(config) {
24
+ if (typeof config !== 'object' || config === null) {
25
+ console.warn('[XtElementUI] setConfig 必须传入对象参数')
26
+ return
27
+ }
28
+
29
+ if (config.theme !== undefined) {
30
+ setTheme(config.theme)
31
+ }
32
+ if (config.size !== undefined) {
33
+ setSize(config.size)
34
+ }
35
+ if (config.primaryColor !== undefined) {
36
+ setPrimaryColor(config.primaryColor)
37
+ }
38
+ }
39
+
40
+ function isBrowser() {
41
+ return typeof window !== 'undefined' && typeof document !== 'undefined'
42
+ }
43
+
44
+ export const setTheme = function(theme) {
45
+ const validThemes = ['white', 'dark']
46
+ if (!validThemes.includes(theme)) {
47
+ console.warn(`[XtElementUI] 无效的主题值: ${theme},可选值: ${validThemes.join(', ')}`)
48
+ return
49
+ }
50
+
51
+ currentConfig.theme = theme
52
+
53
+ if (isBrowser()) {
54
+ const root = document.documentElement
55
+
56
+ if (theme === 'dark') {
57
+ root.setAttribute('data-theme', 'dark')
58
+ } else {
59
+ root.setAttribute('data-theme', theme)
60
+ }
61
+
62
+ EchartsUtil.changeAllTheme(currentConfig.theme, currentConfig.size)
63
+ }
64
+
65
+ emitConfigChange('theme', theme)
66
+ }
67
+
68
+ export const setSize = function(size) {
69
+ const validSizes = ['small', 'medium', 'large']
70
+ if (!validSizes.includes(size)) {
71
+ console.warn(`[XtElementUI] 无效的大小值: ${size},可选值: ${validSizes.join(', ')}`)
72
+ return
73
+ }
74
+
75
+ currentConfig.size = size
76
+
77
+ if (isBrowser()) {
78
+ document.documentElement.setAttribute('data-size', size)
79
+ EchartsUtil.changeAllTheme(currentConfig.theme, currentConfig.size)
80
+ }
81
+
82
+ emitConfigChange('size', size)
83
+ }
84
+
85
+ // 将十六进制颜色转换为 RGB 对象
86
+ function hexToRgb(hex) {
87
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
88
+ return result ? {
89
+ r: parseInt(result[1], 16),
90
+ g: parseInt(result[2], 16),
91
+ b: parseInt(result[3], 16)
92
+ } : null
93
+ }
94
+
95
+ // RGB 对象转换为十六进制颜色
96
+ function rgbToHex(r, g, b) {
97
+ return '#' + [r, g, b].map(x => {
98
+ const hex = x.toString(16)
99
+ return hex.length === 1 ? '0' + hex : hex
100
+ }).join('')
101
+ }
102
+
103
+ // 计算浅色系列(混合白色)
104
+ function lightenColor(hex, percent) {
105
+ const rgb = hexToRgb(hex)
106
+ if (!rgb) return hex
107
+
108
+ const amount = Math.round(2.55 * percent)
109
+ const r = Math.min(255, rgb.r + amount)
110
+ const g = Math.min(255, rgb.g + amount)
111
+ const b = Math.min(255, rgb.b + amount)
112
+
113
+ return rgbToHex(r, g, b)
114
+ }
115
+
116
+ export const setPrimaryColor = function(color) {
117
+ const colorRegex = /^#[0-9A-Fa-f]{3}$|^#[0-9A-Fa-f]{6}$|^#[0-9A-Fa-f]{8}$/
118
+ if (!colorRegex.test(color)) {
119
+ console.warn(`[XtElementUI] 无效的颜色值: ${color},请使用十六进制颜色格式,如 #1890ff`)
120
+ return
121
+ }
122
+
123
+ let validColor = color
124
+ if (color.length === 4) {
125
+ validColor = '#' + color[1] + color[1] + color[2] + color[2] + color[3] + color[3]
126
+ } else if (color.length === 9) {
127
+ validColor = color.substring(0, 7)
128
+ }
129
+
130
+ currentConfig.primaryColor = validColor
131
+
132
+ if (isBrowser()) {
133
+ document.documentElement.style.setProperty('--xt-color-primary', validColor)
134
+
135
+ document.documentElement.style.setProperty('--xt-color-primary-light-3', lightenColor(validColor, 30))
136
+ document.documentElement.style.setProperty('--xt-color-primary-light-5', lightenColor(validColor, 50))
137
+ document.documentElement.style.setProperty('--xt-color-primary-light-7', lightenColor(validColor, 70))
138
+ document.documentElement.style.setProperty('--xt-color-primary-light-8', lightenColor(validColor, 80))
139
+ document.documentElement.style.setProperty('--xt-color-primary-light-9', lightenColor(validColor, 90))
140
+ }
141
+
142
+ emitConfigChange('primaryColor', validColor)
143
+ }
144
+
145
+ // 获取当前主题
146
+ export const getTheme = function() {
147
+ return currentConfig.theme
148
+ }
149
+
150
+ // 获取当前字体大小
151
+ export const getSize = function() {
152
+ return currentConfig.size
153
+ }
154
+
155
+ // 获取当前主色调
156
+ export const getPrimaryColor = function() {
157
+ return currentConfig.primaryColor
158
+ }
159
+
160
+ // 重置为默认配置
161
+ export const resetConfig = function() {
162
+ setConfig(defaultConfig)
163
+ }
164
+
165
+ // 监听配置变更
166
+ export const onConfigChange = function(listener) {
167
+ if (typeof listener === 'function') {
168
+ configChangeListeners.push(listener)
169
+ return function() {
170
+ const index = configChangeListeners.indexOf(listener)
171
+ if (index > -1) {
172
+ configChangeListeners.splice(index, 1)
173
+ }
174
+ }
175
+ } else {
176
+ console.warn('[XtElementUI] onConfigChange 必须传入函数')
177
+ }
178
+ }
179
+
180
+ export default {
181
+ setTheme,
182
+ setSize,
183
+ setPrimaryColor,
184
+ getConfig,
185
+ setConfig,
186
+ getTheme,
187
+ getSize,
188
+ getPrimaryColor,
189
+ resetConfig,
190
+ onConfigChange
191
+ }