xt-element-ui 2.2.2 → 2.2.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.
- package/README.md +140 -192
- package/docs/README.md +162 -81
- package/docs/components/base/theme.md +248 -0
- package/docs/components/base/xt-button.md +11 -4
- package/docs/components/base/xt-card.md +5 -11
- package/docs/components/base/xt-config-provider.md +2 -0
- package/docs/components/base/xt-flow.md +404 -0
- package/docs/components/base/xt-list.md +1 -1
- package/docs/components/base/xt-multi.md +5 -5
- package/docs/components/base/xt-scroll-arrow.md +87 -1
- package/docs/components/base/xt-scroll.md +237 -0
- package/docs/components/business/xt-chart.md +1 -0
- package/docs/components/utils/config.md +18 -4
- package/docs/components/utils/theme.md +280 -183
- package/lib/index.common.1.js +4 -26
- package/lib/index.common.2.js +1 -1
- package/lib/index.common.js +4577 -109925
- package/lib/index.css +1 -1
- package/lib/index.umd.1.js +4 -26
- package/lib/index.umd.2.js +1 -1
- package/lib/index.umd.js +4583 -109930
- package/lib/index.umd.min.1.js +1 -1
- package/lib/index.umd.min.js +1 -1
- package/lib/theme/element-overrides.css +607 -0
- package/lib/theme/element-vars.css +280 -0
- package/lib/xt-badge/xt-badge.common.js +1 -1
- package/lib/xt-badge/xt-badge.css +1 -1
- package/lib/xt-badge/xt-badge.umd.js +1 -1
- package/lib/xt-button/xt-button.common.js +13 -8
- package/lib/xt-button/xt-button.css +1 -1
- package/lib/xt-button/xt-button.umd.js +13 -8
- package/lib/xt-button/xt-button.umd.min.js +1 -1
- package/lib/xt-card/xt-card.common.js +5 -5
- package/lib/xt-card/xt-card.umd.js +5 -5
- package/lib/xt-card/xt-card.umd.min.js +1 -1
- package/lib/xt-card-item/xt-card-item.common.js +4 -4
- package/lib/xt-card-item/xt-card-item.umd.js +4 -4
- package/lib/xt-card-item/xt-card-item.umd.min.js +1 -1
- package/lib/xt-chart/xt-chart.common.js +1969 -108924
- package/lib/xt-chart/xt-chart.css +1 -1
- package/lib/xt-chart/xt-chart.umd.js +1975 -108929
- package/lib/xt-chart/xt-chart.umd.min.js +1 -1
- package/lib/xt-config-provider/xt-config-provider.common.js +561 -107504
- package/lib/xt-config-provider/xt-config-provider.css +1 -1
- package/lib/xt-config-provider/xt-config-provider.umd.js +567 -107509
- package/lib/xt-config-provider/xt-config-provider.umd.min.js +1 -1
- package/lib/xt-date-picker/xt-date-picker.common.1.js +4 -26
- package/lib/xt-date-picker/xt-date-picker.common.2.js +1 -1
- package/lib/xt-date-picker/xt-date-picker.common.js +1 -47
- package/lib/xt-date-picker/xt-date-picker.css +1 -1
- package/lib/xt-date-picker/xt-date-picker.umd.1.js +4 -26
- package/lib/xt-date-picker/xt-date-picker.umd.2.js +1 -1
- package/lib/xt-date-picker/xt-date-picker.umd.js +1 -47
- package/lib/xt-date-picker/xt-date-picker.umd.min.1.js +1 -1
- package/lib/xt-date-picker/xt-date-picker.umd.min.js +1 -1
- package/lib/xt-flex-box/xt-flex-box.common.js +1 -1
- package/lib/xt-flex-box/xt-flex-box.umd.js +1 -1
- package/lib/xt-flow/demo.html +10 -0
- package/lib/xt-flow/index.js +1 -0
- package/lib/xt-flow/xt-flow.common.js +638 -0
- package/lib/xt-flow/xt-flow.css +1 -0
- package/lib/xt-flow/xt-flow.umd.js +648 -0
- package/lib/xt-flow/xt-flow.umd.min.js +1 -0
- package/lib/xt-form-schema/xt-form-schema.common.js +1 -1
- package/lib/xt-form-schema/xt-form-schema.umd.js +1 -1
- package/lib/xt-grid-box/xt-grid-box.common.js +1 -1
- package/lib/xt-grid-box/xt-grid-box.umd.js +1 -1
- package/lib/xt-grid-item/xt-grid-item.common.js +1 -1
- package/lib/xt-grid-item/xt-grid-item.umd.js +1 -1
- package/lib/xt-icon/xt-icon.common.js +1 -1
- package/lib/xt-icon/xt-icon.umd.js +1 -1
- package/lib/xt-input/xt-input.common.js +1 -1
- package/lib/xt-input/xt-input.umd.js +1 -1
- package/lib/xt-list/xt-list.common.js +457 -118
- package/lib/xt-list/xt-list.css +1 -1
- package/lib/xt-list/xt-list.umd.js +457 -118
- package/lib/xt-list/xt-list.umd.min.js +1 -1
- package/lib/xt-map/xt-map.common.js +1 -1
- package/lib/xt-map/xt-map.umd.js +1 -1
- package/lib/xt-map-provider/xt-map-provider.common.js +1 -1
- package/lib/xt-map-provider/xt-map-provider.umd.js +1 -1
- package/lib/xt-page/xt-page.common.js +1 -1
- package/lib/xt-page/xt-page.umd.js +1 -1
- package/lib/xt-progress/xt-progress.common.js +1 -1
- package/lib/xt-progress/xt-progress.umd.js +1 -1
- package/lib/xt-scroll/demo.html +10 -0
- package/lib/xt-scroll/index.js +1 -0
- package/lib/xt-scroll/xt-scroll.common.js +551 -0
- package/lib/xt-scroll/xt-scroll.css +1 -0
- package/lib/xt-scroll/xt-scroll.umd.js +561 -0
- package/lib/xt-scroll/xt-scroll.umd.min.js +1 -0
- package/lib/xt-scroll-arrow/xt-scroll-arrow.common.js +591 -170
- package/lib/xt-scroll-arrow/xt-scroll-arrow.css +1 -1
- package/lib/xt-scroll-arrow/xt-scroll-arrow.umd.js +591 -170
- package/lib/xt-scroll-arrow/xt-scroll-arrow.umd.min.js +1 -1
- package/lib/xt-select-tree/xt-select-tree.common.js +1 -1
- package/lib/xt-select-tree/xt-select-tree.umd.js +1 -1
- package/lib/xt-step-price/xt-step-price.common.js +2 -2
- package/lib/xt-step-price/xt-step-price.umd.js +2 -2
- package/lib/xt-step-price-item/xt-step-price-item.common.js +1 -1
- package/lib/xt-step-price-item/xt-step-price-item.umd.js +1 -1
- package/lib/xt-tab-pane/xt-tab-pane.common.js +1 -1
- package/lib/xt-tab-pane/xt-tab-pane.umd.js +1 -1
- package/lib/xt-table/xt-table.common.js +2 -2
- package/lib/xt-table/xt-table.umd.js +2 -2
- package/lib/xt-tabs/xt-tabs.common.js +1 -1
- package/lib/xt-tabs/xt-tabs.umd.js +1 -1
- package/lib/xt-text/xt-text.common.js +1 -1
- package/lib/xt-text/xt-text.css +1 -1
- package/lib/xt-text/xt-text.umd.js +1 -1
- package/lib/xt-time/xt-time.common.js +1 -1
- package/lib/xt-time/xt-time.umd.js +1 -1
- package/lib/xt-transfer-tree/xt-transfer-tree.common.js +1 -1
- package/lib/xt-transfer-tree/xt-transfer-tree.umd.js +1 -1
- package/lib/xt-upload/xt-upload.common.js +11 -11
- package/lib/xt-upload/xt-upload.umd.js +12 -12
- package/lib/xt-upload/xt-upload.umd.min.js +1 -1
- package/package.json +6 -5
- package/src/components/index.scss +7 -1
- package/src/components/theme/element-overrides.css +607 -0
- package/src/components/theme/element-vars.css +280 -0
- package/src/components/theme/iframe-injector.js +502 -0
- package/src/components/theme/index.js +64 -0
- package/src/components/xt-badge/style/index.scss +6 -6
- package/src/components/xt-button/index.vue +11 -6
- package/src/components/xt-button/style/index.scss +7 -5
- package/src/components/xt-card/index.vue +3 -3
- package/src/components/xt-card-item/index.vue +2 -2
- package/src/components/xt-chart/XtMulti.vue +8 -18
- package/src/components/xt-chart/XtPie.vue +1 -0
- package/src/components/xt-chart/utils.js +84 -50
- package/src/components/xt-config-provider/index.vue +56 -54
- package/src/components/xt-config-provider/style/index.scss +0 -11
- package/src/components/xt-date-picker/component/RangeDate.vue +1 -29
- package/src/components/xt-date-picker/style/index.scss +79 -54
- package/src/components/xt-flow/flowable-parser.js +244 -0
- package/src/components/xt-flow/index.js +8 -0
- package/src/components/xt-flow/index.vue +226 -0
- package/src/components/xt-flow/style/index.scss +359 -0
- package/src/components/xt-list/index.vue +23 -12
- package/src/components/xt-scroll/index.js +9 -0
- package/src/components/xt-scroll/index.vue +363 -0
- package/src/components/xt-scroll/style/index.scss +107 -0
- package/src/components/xt-scroll-arrow/index.vue +200 -83
- package/src/components/xt-scroll-arrow/style/index.scss +16 -5
- package/src/components/xt-text/style/index.scss +6 -6
- package/src/index.js +15 -13
- package/src/styles/css-variables.scss +73 -1
- package/src/utils/color.js +105 -0
- package/src/utils/index.js +456 -468
- package/src/utils/theme-vars.js +134 -0
- package/lib/css/1.87a493be.css +0 -1
- package/lib/xt-date-picker/css/1.87a493be.css +0 -1
package/src/utils/index.js
CHANGED
|
@@ -1,468 +1,456 @@
|
|
|
1
|
-
import EchartsUtil from '../components/xt-chart/utils'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
.replace('
|
|
282
|
-
.replace('
|
|
283
|
-
.replace('
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
return '
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
formatNumber,
|
|
458
|
-
formatThousand,
|
|
459
|
-
formatPercent,
|
|
460
|
-
formatDate,
|
|
461
|
-
formatDateTime,
|
|
462
|
-
formatTime,
|
|
463
|
-
formatRelativeTime,
|
|
464
|
-
formatMoney,
|
|
465
|
-
formatCNY,
|
|
466
|
-
formatUSD,
|
|
467
|
-
formatFileSize
|
|
468
|
-
}
|
|
1
|
+
import EchartsUtil from '../components/xt-chart/utils'
|
|
2
|
+
import { generateXtPrimaryColorVars } from './color'
|
|
3
|
+
import { applyThemeVars } from './theme-vars'
|
|
4
|
+
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
theme: 'white',
|
|
7
|
+
size: 'medium',
|
|
8
|
+
primaryColor: '#1890ff'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let currentConfig = { ...defaultConfig }
|
|
12
|
+
|
|
13
|
+
const configChangeListeners = []
|
|
14
|
+
|
|
15
|
+
const emitConfigChange = function(key, value) {
|
|
16
|
+
configChangeListeners.forEach(listener => {
|
|
17
|
+
listener(key, value)
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const getConfig = function() {
|
|
22
|
+
return { ...currentConfig }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const setConfig = function(config) {
|
|
26
|
+
if (typeof config !== 'object' || config === null) {
|
|
27
|
+
console.warn('[XtElementUI] setConfig 必须传入对象参数')
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (config.theme !== undefined) {
|
|
32
|
+
setTheme(config.theme)
|
|
33
|
+
}
|
|
34
|
+
if (config.size !== undefined) {
|
|
35
|
+
setSize(config.size)
|
|
36
|
+
}
|
|
37
|
+
if (config.primaryColor !== undefined) {
|
|
38
|
+
setPrimaryColor(config.primaryColor)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isBrowser() {
|
|
43
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 设置主题(亮/暗)
|
|
48
|
+
* 通过 applyThemeVars 统一设置 --el-* CSS 变量,确保组件库和 Element UI 同步响应
|
|
49
|
+
* 同时设置 --xt-* CSS 变量供 xt 组件使用
|
|
50
|
+
*/
|
|
51
|
+
export const setTheme = function(theme) {
|
|
52
|
+
const validThemes = ['white', 'dark']
|
|
53
|
+
if (!validThemes.includes(theme)) {
|
|
54
|
+
console.warn(`[XtElementUI] 无效的主题值: ${theme},可选值: ${validThemes.join(', ')}`)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
currentConfig.theme = theme
|
|
59
|
+
|
|
60
|
+
if (isBrowser()) {
|
|
61
|
+
const root = document.documentElement
|
|
62
|
+
|
|
63
|
+
// 统一通过 applyThemeVars 设置 --el-* 变量
|
|
64
|
+
applyThemeVars(root, {
|
|
65
|
+
theme,
|
|
66
|
+
primaryColor: currentConfig.primaryColor
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
// 同步设置 xt 组件主色变量(--xt-*)
|
|
70
|
+
const xtVars = generateXtPrimaryColorVars(currentConfig.primaryColor)
|
|
71
|
+
for (const key in xtVars) {
|
|
72
|
+
root.style.setProperty(key, xtVars[key])
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
EchartsUtil.changeAllTheme(currentConfig.theme, currentConfig.size)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
emitConfigChange('theme', theme)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const setSize = function(size) {
|
|
82
|
+
const validSizes = ['small', 'medium', 'large']
|
|
83
|
+
if (!validSizes.includes(size)) {
|
|
84
|
+
console.warn(`[XtElementUI] 无效的大小值: ${size},可选值: ${validSizes.join(', ')}`)
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
currentConfig.size = size
|
|
89
|
+
|
|
90
|
+
if (isBrowser()) {
|
|
91
|
+
document.documentElement.setAttribute('data-size', size)
|
|
92
|
+
EchartsUtil.changeAllTheme(currentConfig.theme, currentConfig.size)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
emitConfigChange('size', size)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const setPrimaryColor = function(color) {
|
|
99
|
+
const colorRegex = /^#[0-9A-Fa-f]{3}$|^#[0-9A-Fa-f]{6}$|^#[0-9A-Fa-f]{8}$/
|
|
100
|
+
if (!colorRegex.test(color)) {
|
|
101
|
+
console.warn(`[XtElementUI] 无效的颜色值: ${color},请使用十六进制颜色格式,如 #1890ff`)
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let validColor = color
|
|
106
|
+
if (color.length === 4) {
|
|
107
|
+
validColor = '#' + color[1] + color[1] + color[2] + color[2] + color[3] + color[3]
|
|
108
|
+
} else if (color.length === 9) {
|
|
109
|
+
validColor = color.substring(0, 7)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
currentConfig.primaryColor = validColor
|
|
113
|
+
|
|
114
|
+
if (isBrowser()) {
|
|
115
|
+
const root = document.documentElement
|
|
116
|
+
|
|
117
|
+
// 统一通过 applyThemeVars 设置 --el-* 主色变量
|
|
118
|
+
applyThemeVars(root, {
|
|
119
|
+
theme: currentConfig.theme,
|
|
120
|
+
primaryColor: validColor
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
// 同步设置 xt 组件主色变量(--xt-*)
|
|
124
|
+
const xtVars = generateXtPrimaryColorVars(validColor)
|
|
125
|
+
for (const key in xtVars) {
|
|
126
|
+
root.style.setProperty(key, xtVars[key])
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
emitConfigChange('primaryColor', validColor)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 获取当前主题
|
|
134
|
+
export const getTheme = function() {
|
|
135
|
+
return currentConfig.theme
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 获取当前字体大小
|
|
139
|
+
export const getSize = function() {
|
|
140
|
+
return currentConfig.size
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 获取当前主色调
|
|
144
|
+
export const getPrimaryColor = function() {
|
|
145
|
+
return currentConfig.primaryColor
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 重置为默认配置
|
|
149
|
+
export const resetConfig = function() {
|
|
150
|
+
setConfig(defaultConfig)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 监听配置变更
|
|
154
|
+
export const onConfigChange = function(listener) {
|
|
155
|
+
if (typeof listener === 'function') {
|
|
156
|
+
configChangeListeners.push(listener)
|
|
157
|
+
return function() {
|
|
158
|
+
const index = configChangeListeners.indexOf(listener)
|
|
159
|
+
if (index > -1) {
|
|
160
|
+
configChangeListeners.splice(index, 1)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
console.warn('[XtElementUI] onConfigChange 必须传入函数')
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// ==================== 数字格式化 ====================
|
|
169
|
+
|
|
170
|
+
export const formatNumber = function(value, options) {
|
|
171
|
+
if (value === null || value === undefined || value === '') {
|
|
172
|
+
return ''
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const num = typeof value === 'string' ? parseFloat(value) : value
|
|
176
|
+
if (isNaN(num)) {
|
|
177
|
+
return String(value)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const opts = Object.assign({
|
|
181
|
+
decimals: 2,
|
|
182
|
+
thousand: true,
|
|
183
|
+
prefix: '',
|
|
184
|
+
suffix: '',
|
|
185
|
+
showSign: false
|
|
186
|
+
}, options || {})
|
|
187
|
+
|
|
188
|
+
let result = num.toFixed(opts.decimals)
|
|
189
|
+
|
|
190
|
+
if (opts.thousand) {
|
|
191
|
+
const parts = result.split('.')
|
|
192
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
193
|
+
result = parts.join('.')
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (opts.showSign && num > 0) {
|
|
197
|
+
result = '+' + result
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return opts.prefix + result + opts.suffix
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export const formatThousand = function(value, decimals) {
|
|
204
|
+
return formatNumber(value, {
|
|
205
|
+
decimals: decimals != null ? decimals : 2,
|
|
206
|
+
thousand: true
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export const formatPercent = function(value, decimals) {
|
|
211
|
+
if (value === null || value === undefined || value === '') {
|
|
212
|
+
return ''
|
|
213
|
+
}
|
|
214
|
+
const num = typeof value === 'string' ? parseFloat(value) : value
|
|
215
|
+
if (isNaN(num)) {
|
|
216
|
+
return String(value)
|
|
217
|
+
}
|
|
218
|
+
return formatNumber(num * 100, {
|
|
219
|
+
decimals: decimals != null ? decimals : 2,
|
|
220
|
+
thousand: true,
|
|
221
|
+
suffix: '%'
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ==================== 日期格式化 ====================
|
|
226
|
+
|
|
227
|
+
function padZero(num, len) {
|
|
228
|
+
len = len || 2
|
|
229
|
+
return String(num).padStart(len, '0')
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export const formatDate = function(date, format) {
|
|
233
|
+
if (!date) {
|
|
234
|
+
return ''
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let d
|
|
238
|
+
if (date instanceof Date) {
|
|
239
|
+
d = date
|
|
240
|
+
} else if (typeof date === 'number') {
|
|
241
|
+
d = new Date(date.toString().length === 10 ? date * 1000 : date)
|
|
242
|
+
} else if (typeof date === 'string') {
|
|
243
|
+
date = date.trim()
|
|
244
|
+
if (/^\d+$/.test(date)) {
|
|
245
|
+
d = new Date(date.length === 10 ? parseInt(date) * 1000 : parseInt(date))
|
|
246
|
+
} else {
|
|
247
|
+
d = new Date(date.replace(/-/g, '/'))
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
return ''
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (isNaN(d.getTime())) {
|
|
254
|
+
return ''
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const fmt = format || 'yyyy-MM-dd'
|
|
258
|
+
const year = d.getFullYear()
|
|
259
|
+
const month = d.getMonth() + 1
|
|
260
|
+
const day = d.getDate()
|
|
261
|
+
const hour = d.getHours()
|
|
262
|
+
const minute = d.getMinutes()
|
|
263
|
+
const second = d.getSeconds()
|
|
264
|
+
const week = d.getDay()
|
|
265
|
+
|
|
266
|
+
const weekMap = ['日', '一', '二', '三', '四', '五', '六']
|
|
267
|
+
|
|
268
|
+
return fmt
|
|
269
|
+
.replace('yyyy', year)
|
|
270
|
+
.replace('MM', padZero(month))
|
|
271
|
+
.replace('M', month)
|
|
272
|
+
.replace('dd', padZero(day))
|
|
273
|
+
.replace('d', day)
|
|
274
|
+
.replace('HH', padZero(hour))
|
|
275
|
+
.replace('H', hour)
|
|
276
|
+
.replace('hh', padZero(hour % 12 || 12))
|
|
277
|
+
.replace('h', hour % 12 || 12)
|
|
278
|
+
.replace('mm', padZero(minute))
|
|
279
|
+
.replace('m', minute)
|
|
280
|
+
.replace('ss', padZero(second))
|
|
281
|
+
.replace('s', second)
|
|
282
|
+
.replace('w', weekMap[week])
|
|
283
|
+
.replace('W', '星期' + weekMap[week])
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export const formatDateTime = function(date, format) {
|
|
287
|
+
return formatDate(date, format || 'yyyy-MM-dd HH:mm:ss')
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export const formatTime = function(date, format) {
|
|
291
|
+
return formatDate(date, format || 'HH:mm:ss')
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export const formatRelativeTime = function(date) {
|
|
295
|
+
if (!date) {
|
|
296
|
+
return ''
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
let d
|
|
300
|
+
if (date instanceof Date) {
|
|
301
|
+
d = date
|
|
302
|
+
} else if (typeof date === 'number') {
|
|
303
|
+
d = new Date(date.toString().length === 10 ? date * 1000 : date)
|
|
304
|
+
} else if (typeof date === 'string') {
|
|
305
|
+
date = date.trim()
|
|
306
|
+
if (/^\d+$/.test(date)) {
|
|
307
|
+
d = new Date(date.length === 10 ? parseInt(date) * 1000 : parseInt(date))
|
|
308
|
+
} else {
|
|
309
|
+
d = new Date(date.replace(/-/g, '/'))
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
return ''
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (isNaN(d.getTime())) {
|
|
316
|
+
return ''
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const now = new Date()
|
|
320
|
+
const diff = now.getTime() - d.getTime()
|
|
321
|
+
const minute = 60 * 1000
|
|
322
|
+
const hour = 60 * minute
|
|
323
|
+
const day = 24 * hour
|
|
324
|
+
const week = 7 * day
|
|
325
|
+
const month = 30 * day
|
|
326
|
+
const year = 365 * day
|
|
327
|
+
|
|
328
|
+
if (diff < minute) {
|
|
329
|
+
return '刚刚'
|
|
330
|
+
} else if (diff < hour) {
|
|
331
|
+
return Math.floor(diff / minute) + '分钟前'
|
|
332
|
+
} else if (diff < day) {
|
|
333
|
+
return Math.floor(diff / hour) + '小时前'
|
|
334
|
+
} else if (diff < week) {
|
|
335
|
+
return Math.floor(diff / day) + '天前'
|
|
336
|
+
} else if (diff < month) {
|
|
337
|
+
return Math.floor(diff / week) + '周前'
|
|
338
|
+
} else if (diff < year) {
|
|
339
|
+
return Math.floor(diff / month) + '个月前'
|
|
340
|
+
} else {
|
|
341
|
+
return Math.floor(diff / year) + '年前'
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ==================== 金额格式化 ====================
|
|
346
|
+
|
|
347
|
+
export const formatMoney = function(value, options) {
|
|
348
|
+
if (value === null || value === undefined || value === '') {
|
|
349
|
+
return ''
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const num = typeof value === 'string' ? parseFloat(value) : value
|
|
353
|
+
if (isNaN(num)) {
|
|
354
|
+
return String(value)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const opts = Object.assign({
|
|
358
|
+
currency: 'CNY',
|
|
359
|
+
decimals: 2,
|
|
360
|
+
prefix: '',
|
|
361
|
+
suffix: '',
|
|
362
|
+
showSign: false
|
|
363
|
+
}, options || {})
|
|
364
|
+
|
|
365
|
+
const currencySymbols = {
|
|
366
|
+
CNY: '¥',
|
|
367
|
+
USD: '$',
|
|
368
|
+
EUR: '€',
|
|
369
|
+
JPY: '¥',
|
|
370
|
+
GBP: '£',
|
|
371
|
+
AUD: 'A$',
|
|
372
|
+
CAD: 'C$'
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
let symbol = currencySymbols[opts.currency] || ''
|
|
376
|
+
let formatted = num.toFixed(opts.decimals)
|
|
377
|
+
|
|
378
|
+
const parts = formatted.split('.')
|
|
379
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
380
|
+
formatted = parts.join('.')
|
|
381
|
+
|
|
382
|
+
if (opts.showSign && num > 0) {
|
|
383
|
+
formatted = '+' + formatted
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (opts.prefix) {
|
|
387
|
+
formatted = opts.prefix + formatted
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (opts.suffix) {
|
|
391
|
+
formatted = formatted + opts.suffix
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return symbol + formatted
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export const formatCNY = function(value, decimals) {
|
|
398
|
+
return formatMoney(value, {
|
|
399
|
+
currency: 'CNY',
|
|
400
|
+
decimals: decimals != null ? decimals : 2
|
|
401
|
+
})
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export const formatUSD = function(value, decimals) {
|
|
405
|
+
return formatMoney(value, {
|
|
406
|
+
currency: 'USD',
|
|
407
|
+
decimals: decimals != null ? decimals : 2
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// ==================== 文件大小格式化 ====================
|
|
412
|
+
|
|
413
|
+
export const formatFileSize = function(bytes) {
|
|
414
|
+
if (bytes === null || bytes === undefined || bytes === '') {
|
|
415
|
+
return ''
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const num = typeof bytes === 'string' ? parseFloat(bytes) : bytes
|
|
419
|
+
if (isNaN(num)) {
|
|
420
|
+
return String(bytes)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (num === 0) {
|
|
424
|
+
return '0 B'
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const k = 1024
|
|
428
|
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
429
|
+
const i = Math.floor(Math.log(num) / Math.log(k))
|
|
430
|
+
|
|
431
|
+
return parseFloat((num / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export default {
|
|
435
|
+
setTheme,
|
|
436
|
+
setSize,
|
|
437
|
+
setPrimaryColor,
|
|
438
|
+
getConfig,
|
|
439
|
+
setConfig,
|
|
440
|
+
getTheme,
|
|
441
|
+
getSize,
|
|
442
|
+
getPrimaryColor,
|
|
443
|
+
resetConfig,
|
|
444
|
+
onConfigChange,
|
|
445
|
+
formatNumber,
|
|
446
|
+
formatThousand,
|
|
447
|
+
formatPercent,
|
|
448
|
+
formatDate,
|
|
449
|
+
formatDateTime,
|
|
450
|
+
formatTime,
|
|
451
|
+
formatRelativeTime,
|
|
452
|
+
formatMoney,
|
|
453
|
+
formatCNY,
|
|
454
|
+
formatUSD,
|
|
455
|
+
formatFileSize
|
|
456
|
+
}
|