xt-element-ui 2.1.22 → 2.1.61

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 (75) hide show
  1. package/docs/components/base/xt-badge.md +0 -2
  2. package/docs/components/base/xt-bar.md +0 -27
  3. package/docs/components/base/xt-button.md +0 -2
  4. package/docs/components/base/xt-card-item.md +0 -2
  5. package/docs/components/base/xt-card.md +17 -19
  6. package/docs/components/base/xt-chart.md +5 -31
  7. package/docs/components/base/xt-config-provider.md +0 -2
  8. package/docs/components/base/xt-date-picker.md +185 -28
  9. package/docs/components/base/xt-flex-box.md +25 -25
  10. package/docs/components/base/xt-form-schema.md +356 -0
  11. package/docs/components/base/xt-grid-box.md +4 -6
  12. package/docs/components/base/xt-icon.md +0 -2
  13. package/docs/components/base/xt-input.md +204 -44
  14. package/docs/components/base/xt-line.md +0 -26
  15. package/docs/components/base/xt-list.md +456 -458
  16. package/docs/components/base/xt-map-provider.md +0 -2
  17. package/docs/components/base/xt-map.md +0 -2
  18. package/docs/components/base/xt-multi.md +0 -39
  19. package/docs/components/base/xt-page.md +17 -6
  20. package/docs/components/base/xt-pie.md +0 -25
  21. package/docs/components/base/xt-progress.md +0 -2
  22. package/docs/components/base/xt-scroll-arrow.md +0 -2
  23. package/docs/components/base/xt-select-tree.md +0 -2
  24. package/docs/components/base/xt-step-price.md +3 -4
  25. package/docs/components/base/xt-table.md +2 -2
  26. package/docs/components/base/xt-tabs.md +0 -2
  27. package/docs/components/base/xt-text.md +1 -2
  28. package/docs/components/base/xt-time.md +0 -2
  29. package/docs/components/base/xt-transfer-tree.md +270 -0
  30. package/docs/components/base/xt-upload.md +11 -8
  31. package/docs/components/utils/config.md +285 -0
  32. package/docs/components/utils/format.md +445 -0
  33. package/lib/index.common.js +96183 -115717
  34. package/lib/index.css +1 -1
  35. package/lib/index.umd.js +96183 -115717
  36. package/lib/index.umd.min.js +1 -34
  37. package/package.json +4 -2
  38. package/src/components/xt-badge/style/index.scss +0 -22
  39. package/src/components/xt-button/index.vue +2 -1
  40. package/src/components/xt-button/style/index.scss +2 -2
  41. package/src/components/xt-card/style/index.scss +2 -2
  42. package/src/components/xt-card-item/style/index.scss +5 -40
  43. package/src/components/xt-chart/XtBar.vue +0 -3
  44. package/src/components/xt-date-picker/component/Picker.vue +196 -0
  45. package/src/components/xt-date-picker/component/RangeDate.vue +136 -0
  46. package/src/components/xt-date-picker/index.vue +220 -80
  47. package/src/components/xt-flex-box/index.vue +1 -1
  48. package/src/components/xt-form-schema/index.js +8 -0
  49. package/src/components/xt-form-schema/index.vue +328 -0
  50. package/src/components/xt-grid-item/index.vue +2 -2
  51. package/src/components/xt-input/index.vue +224 -28
  52. package/src/components/xt-input/style/index.scss +10 -0
  53. package/src/components/xt-layout/ExFieldset.vue +4 -4
  54. package/src/components/xt-list/index.js +7 -7
  55. package/src/components/xt-list/index.vue +885 -885
  56. package/src/components/xt-page/index.vue +148 -75
  57. package/src/components/xt-progress/style/index.scss +0 -14
  58. package/src/components/xt-step-price/style/index.scss +0 -4
  59. package/src/components/xt-step-price-item/index.vue +1 -1
  60. package/src/components/xt-table/XtTableCell.vue +2 -2
  61. package/src/components/xt-table/index.vue +17 -10
  62. package/src/components/xt-tabs/style/index.scss +0 -40
  63. package/src/components/xt-text/index.vue +16 -4
  64. package/src/components/xt-text/style/index.scss +0 -15
  65. package/src/components/xt-transfer-tree/index.js +8 -0
  66. package/src/components/xt-transfer-tree/index.vue +494 -0
  67. package/src/components/xt-upload/index.vue +12 -6
  68. package/src/index.js +8 -2
  69. package/src/styles/theme/colors.scss +0 -44
  70. package/src/styles/theme/dark-variables.scss +0 -29
  71. package/src/styles/variables-export.scss +0 -72
  72. package/src/utils/index.js +278 -1
  73. package/src/components/xt-date-picker/SearchDate.vue +0 -45
  74. package/src/components/xt-date-picker/quarter.vue +0 -154
  75. package/src/components/xt-table/index copy.vue +0 -663
@@ -0,0 +1,285 @@
1
+ ## 全局配置
2
+
3
+ ## 概述
4
+
5
+ 提供全局配置管理工具函数,包括配置的获取、设置、重置以及主色调配置等功能。
6
+
7
+ ## 方法说明
8
+
9
+ ### getConfig()
10
+
11
+ 获取当前全局配置。
12
+
13
+ ```vue
14
+ <template>
15
+ <div>
16
+ <XtText>当前配置:{{ JSON.stringify(config) }}</XtText>
17
+ </div>
18
+ </template>
19
+
20
+ <script>
21
+ import { getConfig } from 'xt-element-ui'
22
+
23
+ export default {
24
+ computed: {
25
+ config() {
26
+ return getConfig()
27
+ }
28
+ }
29
+ }
30
+ </script>
31
+ ```
32
+
33
+ **返回值**:
34
+
35
+ | 属性 | 类型 | 默认值 | 说明 |
36
+ |------|------|--------|------|
37
+ | `theme` | String | 'white' | 主题类型 |
38
+ | `size` | String | 'medium' | 字体大小 |
39
+ | `primaryColor` | String | '#1890ff' | 主色调 |
40
+
41
+ ### setConfig(config)
42
+
43
+ 批量设置全局配置。
44
+
45
+ | 参数 | 类型 | 必填 | 说明 |
46
+ |------|------|------|------|
47
+ | `config` | Object | 是 | 配置对象 |
48
+
49
+ **config 参数**:
50
+
51
+ | 属性 | 类型 | 说明 |
52
+ |------|------|------|
53
+ | `theme` | String | 主题类型:`white`、`dark` |
54
+ | `size` | String | 字体大小:`small`、`medium`、`large` |
55
+ | `primaryColor` | String | 主色调,十六进制颜色格式 |
56
+
57
+ ```vue
58
+ <template>
59
+ <div>
60
+ <XtButton @click="initConfig">初始化配置</XtButton>
61
+ </div>
62
+ </template>
63
+
64
+ <script>
65
+ import { setConfig } from 'xt-element-ui'
66
+
67
+ export default {
68
+ methods: {
69
+ initConfig() {
70
+ setConfig({
71
+ theme: 'dark',
72
+ size: 'large',
73
+ primaryColor: '#1890ff'
74
+ })
75
+ }
76
+ }
77
+ }
78
+ </script>
79
+ ```
80
+
81
+ ### setPrimaryColor(color)
82
+
83
+ 设置全局主色调。
84
+
85
+ | 参数 | 类型 | 必填 | 说明 |
86
+ |------|------|------|------|
87
+ | `color` | String | 是 | 十六进制颜色值 |
88
+
89
+ ```vue
90
+ <template>
91
+ <div>
92
+ <XtButton @click="changePrimaryColor('#ff5722')">橙色主题</XtButton>
93
+ <XtButton @click="changePrimaryColor('#4caf50')">绿色主题</XtButton>
94
+ </div>
95
+ </template>
96
+
97
+ <script>
98
+ import { setPrimaryColor } from 'xt-element-ui'
99
+
100
+ export default {
101
+ methods: {
102
+ changePrimaryColor(color) {
103
+ setPrimaryColor(color)
104
+ }
105
+ }
106
+ }
107
+ </script>
108
+ ```
109
+
110
+ ### getPrimaryColor()
111
+
112
+ 获取当前主色调配置。
113
+
114
+ ```vue
115
+ <template>
116
+ <div>
117
+ <XtText>当前主色调:{{ currentColor }}</XtText>
118
+ </div>
119
+ </template>
120
+
121
+ <script>
122
+ import { getPrimaryColor } from 'xt-element-ui'
123
+
124
+ export default {
125
+ computed: {
126
+ currentColor() {
127
+ return getPrimaryColor()
128
+ }
129
+ }
130
+ }
131
+ </script>
132
+ ```
133
+
134
+ ### resetConfig()
135
+
136
+ 重置为默认配置。
137
+
138
+ ```vue
139
+ <template>
140
+ <div>
141
+ <XtButton @click="reset">重置配置</XtButton>
142
+ </div>
143
+ </template>
144
+
145
+ <script>
146
+ import { resetConfig } from 'xt-element-ui'
147
+
148
+ export default {
149
+ methods: {
150
+ reset() {
151
+ resetConfig()
152
+ }
153
+ }
154
+ }
155
+ </script>
156
+ ```
157
+
158
+ ### onConfigChange(listener)
159
+
160
+ 监听配置变化,返回取消订阅函数。
161
+
162
+ | 参数 | 类型 | 必填 | 说明 |
163
+ |------|------|------|------|
164
+ | `listener` | Function | 是 | 变化监听回调函数 |
165
+
166
+ **回调参数**:
167
+
168
+ | 参数 | 类型 | 说明 |
169
+ |------|------|------|
170
+ | `key` | String | 变化的配置项:`theme`、`size`、`primaryColor` |
171
+ | `value` | Any | 配置项的新值 |
172
+
173
+ ```vue
174
+ <template>
175
+ <div>
176
+ <XtText>配置变化次数:{{ changeCount }}</XtText>
177
+ </div>
178
+ </template>
179
+
180
+ <script>
181
+ import { onConfigChange } from 'xt-element-ui'
182
+
183
+ export default {
184
+ data() {
185
+ return {
186
+ changeCount: 0,
187
+ unsubscribe: null
188
+ }
189
+ },
190
+ mounted() {
191
+ this.unsubscribe = onConfigChange((key, value) => {
192
+ this.changeCount++
193
+ console.log(`配置 ${key} 已变更为:`, value)
194
+ })
195
+ },
196
+ beforeDestroy() {
197
+ if (this.unsubscribe) {
198
+ this.unsubscribe()
199
+ }
200
+ }
201
+ }
202
+ </script>
203
+ ```
204
+
205
+ ## 使用示例
206
+
207
+ ### 完整配置示例
208
+
209
+ ```vue
210
+ <template>
211
+ <XtCard>
212
+ <XtCardItem title="当前配置">
213
+ <XtText>{{ JSON.stringify(config) }}</XtText>
214
+ </XtCardItem>
215
+
216
+ <XtCardItem title="配置操作">
217
+ <XtFlexBox direction="vertical" style="gap: 12px;">
218
+ <XtButton @click="updateConfig">更新配置</XtButton>
219
+ <XtButton @click="changePrimary('#67c23a')">修改主色调</XtButton>
220
+ <XtButton type="danger" @click="reset">重置</XtButton>
221
+ </XtFlexBox>
222
+ </XtCardItem>
223
+
224
+ <XtCardItem title="配置变化">
225
+ <XtText>变化次数:{{ changeCount }}</XtText>
226
+ </XtCardItem>
227
+ </XtCard>
228
+ </template>
229
+
230
+ <script>
231
+ import {
232
+ getConfig,
233
+ setConfig,
234
+ setPrimaryColor,
235
+ resetConfig,
236
+ onConfigChange
237
+ } from 'xt-element-ui'
238
+
239
+ export default {
240
+ data() {
241
+ return {
242
+ changeCount: 0,
243
+ unsubscribe: null
244
+ }
245
+ },
246
+ computed: {
247
+ config() {
248
+ return getConfig()
249
+ }
250
+ },
251
+ mounted() {
252
+ this.unsubscribe = onConfigChange(() => {
253
+ this.changeCount++
254
+ })
255
+ },
256
+ beforeDestroy() {
257
+ if (this.unsubscribe) {
258
+ this.unsubscribe()
259
+ }
260
+ },
261
+ methods: {
262
+ updateConfig() {
263
+ setConfig({
264
+ theme: 'dark',
265
+ size: 'medium',
266
+ primaryColor: '#1890ff'
267
+ })
268
+ },
269
+ changePrimary(color) {
270
+ setPrimaryColor(color)
271
+ },
272
+ reset() {
273
+ resetConfig()
274
+ }
275
+ }
276
+ }
277
+ </script>
278
+ ```
279
+
280
+ ## 注意事项
281
+
282
+ 1. `setPrimaryColor` 只支持十六进制颜色格式(如 `#1890ff`、`#fff`)
283
+ 2. 设置主色调时,会自动生成对应的浅色系列(light-3 到 light-9)
284
+ 3. `onConfigChange` 返回的取消订阅函数应在组件销毁时调用,避免内存泄漏
285
+ 4. 所有配置修改都会触发 `onConfigChange` 监听器
@@ -0,0 +1,445 @@
1
+ ## 格式化工具函数
2
+
3
+ ## 概述
4
+
5
+ 提供常用的数据格式化工具函数,包括数字格式化、日期格式化、金额格式化等。
6
+
7
+ ## 数字格式化
8
+
9
+ ### formatNumber(value, options)
10
+
11
+ 通用数字格式化函数。
12
+
13
+ | 参数 | 类型 | 必填 | 说明 |
14
+ |------|------|------|------|
15
+ | `value` | Number / String | 是 | 要格式化的数字 |
16
+ | `options` | Object | 否 | 格式化选项 |
17
+
18
+ **options 参数**:
19
+
20
+ | 参数 | 类型 | 默认值 | 说明 |
21
+ |------|------|--------|------|
22
+ | `decimals` | Number | 2 | 小数位数 |
23
+ | `thousand` | Boolean | true | 是否千分位分隔 |
24
+ | `prefix` | String | '' | 前缀 |
25
+ | `suffix` | String | '' | 后缀 |
26
+ | `showSign` | Boolean | false | 正数是否显示正号 |
27
+
28
+ ```vue
29
+ <template>
30
+ <div>
31
+ <XtText>{{ formatNumber(12345.6789) }}</XtText>
32
+ <XtText>{{ formatNumber(12345.6789, { decimals: 0 }) }}</XtText>
33
+ <XtText>{{ formatNumber(0.1234, { suffix: '%', decimals: 1 }) }}</XtText>
34
+ </div>
35
+ </template>
36
+
37
+ <script>
38
+ import { formatNumber } from 'xt-element-ui'
39
+
40
+ export default {
41
+ methods: {
42
+ formatNumber
43
+ }
44
+ }
45
+ </script>
46
+ ```
47
+
48
+ ### formatThousand(value, decimals)
49
+
50
+ 千分位格式化,简化版的 formatNumber。
51
+
52
+ | 参数 | 类型 | 必填 | 说明 |
53
+ |------|------|------|------|
54
+ | `value` | Number / String | 是 | 要格式化的数字 |
55
+ | `decimals` | Number | 否 | 小数位数,默认 2 |
56
+
57
+ ```vue
58
+ <template>
59
+ <div>
60
+ <XtText>{{ formatThousand(1234567.89) }}</XtText>
61
+ <XtText>{{ formatThousand(1234567.89, 0) }}</XtText>
62
+ </div>
63
+ </template>
64
+
65
+ <script>
66
+ import { formatThousand } from 'xt-element-ui'
67
+
68
+ export default {
69
+ methods: {
70
+ formatThousand
71
+ }
72
+ }
73
+ </script>
74
+ ```
75
+
76
+ ### formatPercent(value, decimals)
77
+
78
+ 百分比格式化,自动将小数转换为百分比。
79
+
80
+ | 参数 | 类型 | 必填 | 说明 |
81
+ |------|------|------|------|
82
+ | `value` | Number / String | 是 | 要格式化的数字(小数形式) |
83
+ | `decimals` | Number | 否 | 小数位数,默认 2 |
84
+
85
+ ```vue
86
+ <template>
87
+ <div>
88
+ <XtText>{{ formatPercent(0.1234) }}</XtText>
89
+ <XtText>{{ formatPercent(0.5, 1) }}</XtText>
90
+ </div>
91
+ </template>
92
+
93
+ <script>
94
+ import { formatPercent } from 'xt-element-ui'
95
+
96
+ export default {
97
+ methods: {
98
+ formatPercent
99
+ }
100
+ }
101
+ </script>
102
+ ```
103
+
104
+ ## 日期格式化
105
+
106
+ ### formatDate(date, format)
107
+
108
+ 日期格式化函数,支持多种格式。
109
+
110
+ | 参数 | 类型 | 必填 | 说明 |
111
+ |------|------|------|------|
112
+ | `date` | Date / Number / String | 是 | 日期对象、时间戳、日期字符串 |
113
+ | `format` | String | 否 | 格式字符串,默认 `yyyy-MM-dd` |
114
+
115
+ **格式占位符**:
116
+
117
+ | 占位符 | 说明 | 示例 |
118
+ |--------|------|------|
119
+ | `yyyy` | 4位年份 | 2026 |
120
+ | `MM` | 2位月份 | 07 |
121
+ | `M` | 1位月份 | 7 |
122
+ | `dd` | 2位日期 | 08 |
123
+ | `d` | 1位日期 | 8 |
124
+ | `HH` | 24小时制(2位) | 14 |
125
+ | `H` | 24小时制(1位) | 14 |
126
+ | `hh` | 12小时制(2位) | 02 |
127
+ | `h` | 12小时制(1位) | 2 |
128
+ | `mm` | 分钟(2位) | 30 |
129
+ | `m` | 分钟(1位) | 30 |
130
+ | `ss` | 秒(2位) | 45 |
131
+ | `s` | 秒(1位) | 45 |
132
+ | `w` | 星期几(简写) | 一 |
133
+ | `W` | 星期几(完整) | 星期一 |
134
+
135
+ ```vue
136
+ <template>
137
+ <div>
138
+ <XtText>{{ formatDate(new Date()) }}</XtText>
139
+ <XtText>{{ formatDate(new Date(), 'yyyy年MM月dd日') }}</XtText>
140
+ <XtText>{{ formatDate(new Date(), 'MM-dd HH:mm') }}</XtText>
141
+ <XtText>{{ formatDate(new Date(), 'yyyy-MM-dd W') }}</XtText>
142
+ </div>
143
+ </template>
144
+
145
+ <script>
146
+ import { formatDate } from 'xt-element-ui'
147
+
148
+ export default {
149
+ methods: {
150
+ formatDate
151
+ }
152
+ }
153
+ </script>
154
+ ```
155
+
156
+ ### formatDateTime(date, format)
157
+
158
+ 日期时间格式化,默认格式为 `yyyy-MM-dd HH:mm:ss`。
159
+
160
+ ```vue
161
+ <template>
162
+ <div>
163
+ <XtText>{{ formatDateTime(new Date()) }}</XtText>
164
+ <XtText>{{ formatDateTime(new Date(), 'yyyy/MM/dd HH:mm') }}</XtText>
165
+ </div>
166
+ </template>
167
+
168
+ <script>
169
+ import { formatDateTime } from 'xt-element-ui'
170
+
171
+ export default {
172
+ methods: {
173
+ formatDateTime
174
+ }
175
+ }
176
+ </script>
177
+ ```
178
+
179
+ ### formatTime(date, format)
180
+
181
+ 时间格式化,默认格式为 `HH:mm:ss`。
182
+
183
+ ```vue
184
+ <template>
185
+ <div>
186
+ <XtText>{{ formatTime(new Date()) }}</XtText>
187
+ <XtText>{{ formatTime(new Date(), 'HH:mm') }}</XtText>
188
+ </div>
189
+ </template>
190
+
191
+ <script>
192
+ import { formatTime } from 'xt-element-ui'
193
+
194
+ export default {
195
+ methods: {
196
+ formatTime
197
+ }
198
+ }
199
+ </script>
200
+ ```
201
+
202
+ ### formatRelativeTime(date)
203
+
204
+ 相对时间格式化,返回"几分钟前"、"几小时前"等格式。
205
+
206
+ ```vue
207
+ <template>
208
+ <div>
209
+ <XtText>{{ formatRelativeTime(Date.now() - 3600000) }}</XtText>
210
+ <XtText>{{ formatRelativeTime(Date.now() - 86400000) }}</XtText>
211
+ <XtText>{{ formatRelativeTime(Date.now() - 604800000) }}</XtText>
212
+ </div>
213
+ </template>
214
+
215
+ <script>
216
+ import { formatRelativeTime } from 'xt-element-ui'
217
+
218
+ export default {
219
+ methods: {
220
+ formatRelativeTime
221
+ }
222
+ }
223
+ </script>
224
+ ```
225
+
226
+ **相对时间对照表**:
227
+
228
+ | 时间范围 | 显示格式 |
229
+ |----------|----------|
230
+ | < 1分钟 | 刚刚 |
231
+ | < 1小时 | X分钟前 |
232
+ | < 1天 | X小时前 |
233
+ | < 1周 | X天前 |
234
+ | < 1月 | X周前 |
235
+ | < 1年 | X个月前 |
236
+ | >= 1年 | X年前 |
237
+
238
+ ## 金额格式化
239
+
240
+ ### formatMoney(value, options)
241
+
242
+ 通用金额格式化函数。
243
+
244
+ | 参数 | 类型 | 必填 | 说明 |
245
+ |------|------|------|------|
246
+ | `value` | Number / String | 是 | 金额数字 |
247
+ | `options` | Object | 否 | 格式化选项 |
248
+
249
+ **options 参数**:
250
+
251
+ | 参数 | 类型 | 默认值 | 说明 |
252
+ |------|------|--------|------|
253
+ | `currency` | String | 'CNY' | 货币类型 |
254
+ | `decimals` | Number | 2 | 小数位数 |
255
+ | `prefix` | String | '' | 前缀 |
256
+ | `suffix` | String | '' | 后缀 |
257
+ | `showSign` | Boolean | false | 正数是否显示正号 |
258
+
259
+ **支持的货币类型**:
260
+
261
+ | 货币 | 符号 | 说明 |
262
+ |------|------|------|
263
+ | CNY | ¥ | 人民币 |
264
+ | USD | $ | 美元 |
265
+ | EUR | € | 欧元 |
266
+ | JPY | ¥ | 日元 |
267
+ | GBP | £ | 英镑 |
268
+ | AUD | A$ | 澳元 |
269
+ | CAD | C$ | 加元 |
270
+
271
+ ```vue
272
+ <template>
273
+ <div>
274
+ <XtText>{{ formatMoney(12345.67) }}</XtText>
275
+ <XtText>{{ formatMoney(12345.67, { currency: 'USD' }) }}</XtText>
276
+ <XtText>{{ formatMoney(12345.67, { currency: 'EUR', decimals: 0 }) }}</XtText>
277
+ </div>
278
+ </template>
279
+
280
+ <script>
281
+ import { formatMoney } from 'xt-element-ui'
282
+
283
+ export default {
284
+ methods: {
285
+ formatMoney
286
+ }
287
+ }
288
+ </script>
289
+ ```
290
+
291
+ ### formatCNY(value, decimals)
292
+
293
+ 人民币格式化,简化版的 formatMoney。
294
+
295
+ ```vue
296
+ <template>
297
+ <div>
298
+ <XtText>{{ formatCNY(12345.67) }}</XtText>
299
+ <XtText>{{ formatCNY(12345.67, 0) }}</XtText>
300
+ </div>
301
+ </template>
302
+
303
+ <script>
304
+ import { formatCNY } from 'xt-element-ui'
305
+
306
+ export default {
307
+ methods: {
308
+ formatCNY
309
+ }
310
+ }
311
+ </script>
312
+ ```
313
+
314
+ ### formatUSD(value, decimals)
315
+
316
+ 美元格式化,简化版的 formatMoney。
317
+
318
+ ```vue
319
+ <template>
320
+ <div>
321
+ <XtText>{{ formatUSD(12345.67) }}</XtText>
322
+ <XtText>{{ formatUSD(12345.67, 0) }}</XtText>
323
+ </div>
324
+ </template>
325
+
326
+ <script>
327
+ import { formatUSD } from 'xt-element-ui'
328
+
329
+ export default {
330
+ methods: {
331
+ formatUSD
332
+ }
333
+ }
334
+ </script>
335
+ ```
336
+
337
+ ## 文件大小格式化
338
+
339
+ ### formatFileSize(bytes)
340
+
341
+ 文件大小格式化,自动转换单位。
342
+
343
+ | 参数 | 类型 | 必填 | 说明 |
344
+ |------|------|------|------|
345
+ | `bytes` | Number / String | 是 | 文件字节数 |
346
+
347
+ ```vue
348
+ <template>
349
+ <div>
350
+ <XtText>{{ formatFileSize(1024) }}</XtText>
351
+ <XtText>{{ formatFileSize(1024 * 1024) }}</XtText>
352
+ <XtText>{{ formatFileSize(1024 * 1024 * 1024) }}</XtText>
353
+ </div>
354
+ </template>
355
+
356
+ <script>
357
+ import { formatFileSize } from 'xt-element-ui'
358
+
359
+ export default {
360
+ methods: {
361
+ formatFileSize
362
+ }
363
+ }
364
+ </script>
365
+ ```
366
+
367
+ **单位对照表**:
368
+
369
+ | 范围 | 单位 |
370
+ |------|------|
371
+ | < 1KB | B |
372
+ | < 1MB | KB |
373
+ | < 1GB | MB |
374
+ | < 1TB | GB |
375
+ | >= 1TB | TB |
376
+
377
+ ## 综合示例
378
+
379
+ ```vue
380
+ <template>
381
+ <XtCard>
382
+ <XtCardItem title="数字格式化">
383
+ <XtFlexBox>
384
+ <XtText>千分位:{{ formatThousand(1234567.89) }}</XtText>
385
+ <XtText>百分比:{{ formatPercent(0.75) }}</XtText>
386
+ </XtFlexBox>
387
+ </XtCardItem>
388
+
389
+ <XtCardItem title="日期格式化">
390
+ <XtFlexBox>
391
+ <XtText>日期:{{ formatDate(new Date()) }}</XtText>
392
+ <XtText>时间:{{ formatTime(new Date()) }}</XtText>
393
+ <XtText>相对时间:{{ formatRelativeTime(Date.now() - 3600000) }}</XtText>
394
+ </XtFlexBox>
395
+ </XtCardItem>
396
+
397
+ <XtCardItem title="金额格式化">
398
+ <XtFlexBox>
399
+ <XtText>人民币:{{ formatCNY(12345.67) }}</XtText>
400
+ <XtText>美元:{{ formatUSD(12345.67) }}</XtText>
401
+ </XtFlexBox>
402
+ </XtCardItem>
403
+
404
+ <XtCardItem title="文件大小">
405
+ <XtFlexBox>
406
+ <XtText>{{ formatFileSize(524288) }}</XtText>
407
+ <XtText>{{ formatFileSize(1073741824) }}</XtText>
408
+ </XtFlexBox>
409
+ </XtCardItem>
410
+ </XtCard>
411
+ </template>
412
+
413
+ <script>
414
+ import {
415
+ formatThousand,
416
+ formatPercent,
417
+ formatDate,
418
+ formatTime,
419
+ formatRelativeTime,
420
+ formatCNY,
421
+ formatUSD,
422
+ formatFileSize
423
+ } from 'xt-element-ui'
424
+
425
+ export default {
426
+ methods: {
427
+ formatThousand,
428
+ formatPercent,
429
+ formatDate,
430
+ formatTime,
431
+ formatRelativeTime,
432
+ formatCNY,
433
+ formatUSD,
434
+ formatFileSize
435
+ }
436
+ }
437
+ </script>
438
+ ```
439
+
440
+ ## 注意事项
441
+
442
+ 1. 所有格式化函数对 `null`、`undefined`、空字符串返回空字符串
443
+ 2. 对无法转换为数字的值,返回原值的字符串形式
444
+ 3. 时间戳支持 10 位(秒)和 13 位(毫秒)两种格式
445
+ 4. 日期字符串支持 `yyyy-MM-dd`、`yyyy/MM/dd` 等常见格式