xt-element-ui 2.1.5 → 2.1.7
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-badge.md +0 -2
- package/docs/components/base/xt-bar.md +5 -32
- package/docs/components/base/xt-button.md +0 -2
- package/docs/components/base/xt-card-item.md +0 -2
- package/docs/components/base/xt-card.md +17 -19
- package/docs/components/base/xt-chart.md +5 -31
- package/docs/components/base/xt-config-provider.md +0 -2
- package/docs/components/base/xt-date-picker.md +268 -180
- package/docs/components/base/xt-flex-box.md +25 -25
- package/docs/components/base/xt-form-schema.md +356 -0
- package/docs/components/base/xt-grid-box.md +4 -6
- package/docs/components/base/xt-icon.md +0 -2
- package/docs/components/base/xt-input.md +204 -44
- package/docs/components/base/xt-line.md +4 -30
- package/docs/components/base/xt-list.md +456 -458
- package/docs/components/base/xt-map-provider.md +0 -2
- package/docs/components/base/xt-map.md +0 -2
- package/docs/components/base/xt-multi.md +5 -44
- package/docs/components/base/xt-page.md +17 -6
- package/docs/components/base/xt-pie.md +5 -30
- package/docs/components/base/xt-progress.md +0 -2
- package/docs/components/base/xt-scroll-arrow.md +0 -2
- package/docs/components/base/xt-select-tree.md +0 -2
- package/docs/components/base/xt-step-price.md +0 -2
- package/docs/components/base/xt-table.md +2 -2
- package/docs/components/base/xt-tabs.md +0 -2
- package/docs/components/base/xt-text.md +1 -2
- package/docs/components/base/xt-time.md +0 -2
- package/docs/components/base/xt-transfer-tree.md +0 -2
- package/docs/components/base/xt-upload.md +11 -8
- package/docs/components/utils/config.md +285 -0
- package/docs/components/utils/format.md +445 -0
- package/package.json +5 -2
- package/src/components/xt-badge/style/index.scss +0 -22
- package/src/components/xt-chart/XtBar.vue +0 -3
- package/src/components/xt-date-picker/component/Picker.vue +196 -0
- package/src/components/xt-date-picker/component/RangeDate.vue +136 -0
- package/src/components/xt-date-picker/index.vue +164 -144
- package/src/components/xt-flex-box/index.vue +1 -1
- package/src/components/xt-form-schema/index.js +8 -0
- package/src/components/xt-form-schema/index.vue +328 -0
- package/src/components/xt-grid-item/index.vue +2 -2
- package/src/components/xt-input/index.vue +224 -28
- package/src/components/xt-input/style/index.scss +10 -0
- package/src/components/xt-layout/ExFieldset.vue +4 -4
- package/src/components/xt-list/index.js +7 -7
- package/src/components/xt-list/index.vue +885 -885
- package/src/components/xt-page/index.vue +148 -75
- package/src/components/xt-progress/style/index.scss +0 -14
- package/src/components/xt-tab-pane/index.js +10 -0
- package/src/components/{xt-tabs/TabPane.vue → xt-tab-pane/index.vue} +14 -1
- package/src/components/xt-table/XtTableCell.vue +2 -2
- package/src/components/xt-table/index.vue +5 -7
- package/src/components/xt-tabs/index.js +1 -3
- package/src/components/xt-tabs/index.vue +303 -44
- package/src/components/xt-tabs/style/index.scss +0 -40
- package/src/components/xt-text/style/index.scss +0 -15
- package/src/components/xt-transfer-tree/index.js +7 -7
- package/src/components/xt-transfer-tree/index.vue +493 -493
- package/src/components/xt-upload/index.vue +12 -6
- package/src/enhance/index.scss +13 -0
- package/src/index.js +7 -2
- package/src/styles/theme/colors.scss +0 -44
- package/src/styles/theme/dark-variables.scss +0 -29
- package/lib/demo.html +0 -10
- package/lib/index.common.js +0 -126851
- package/lib/index.css +0 -1
- package/lib/index.umd.js +0 -126861
- package/lib/index.umd.min.js +0 -1
- package/src/components/xt-date-picker/SearchDate.vue +0 -45
- package/src/components/xt-date-picker/quarter.vue +0 -154
- package/src/components/xt-table/index copy.vue +0 -663
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
## XtMulti 组合图组件
|
|
2
|
-
|
|
3
1
|
基于 ECharts 封装的组合图组件,支持多系列数据展示,自动根据单位分组使用不同 Y 轴。
|
|
4
2
|
|
|
5
3
|
## 基本用法
|
|
@@ -7,7 +5,7 @@
|
|
|
7
5
|
::: demo 基本用法
|
|
8
6
|
```vue
|
|
9
7
|
<template>
|
|
10
|
-
<XtMulti :chart-data="chartData"
|
|
8
|
+
<div class="demo-container"><XtMulti :chart-data="chartData" /></div>
|
|
11
9
|
</template>
|
|
12
10
|
|
|
13
11
|
<script>
|
|
@@ -70,7 +68,7 @@ export default {
|
|
|
70
68
|
::: demo 多单位组合图
|
|
71
69
|
```vue
|
|
72
70
|
<template>
|
|
73
|
-
<XtMulti :chart-data="chartData"
|
|
71
|
+
<div class="demo-container"><XtMulti :chart-data="chartData" /></div>
|
|
74
72
|
</template>
|
|
75
73
|
|
|
76
74
|
<script>
|
|
@@ -118,7 +116,7 @@ export default {
|
|
|
118
116
|
::: demo 折线与柱状图组合
|
|
119
117
|
```vue
|
|
120
118
|
<template>
|
|
121
|
-
<XtMulti :chart-data="chartData"
|
|
119
|
+
<div class="demo-container"><XtMulti :chart-data="chartData" /></div>
|
|
122
120
|
</template>
|
|
123
121
|
|
|
124
122
|
<script>
|
|
@@ -159,7 +157,7 @@ export default {
|
|
|
159
157
|
::: demo 自定义颜色
|
|
160
158
|
```vue
|
|
161
159
|
<template>
|
|
162
|
-
<XtMulti :chart-data="chartData" :colors="['#1890ff', '#52c41a', '#faad14']"
|
|
160
|
+
<div class="demo-container"><XtMulti :chart-data="chartData" :colors="['#1890ff', '#52c41a', '#faad14']" /></div>
|
|
163
161
|
</template>
|
|
164
162
|
|
|
165
163
|
<script>
|
|
@@ -204,7 +202,7 @@ export default {
|
|
|
204
202
|
::: demo 极简模式
|
|
205
203
|
```vue
|
|
206
204
|
<template>
|
|
207
|
-
<XtMulti :chart-data="chartData" simple-mode
|
|
205
|
+
<div class="demo-container"><XtMulti :chart-data="chartData" simple-mode /></div>
|
|
208
206
|
</template>
|
|
209
207
|
|
|
210
208
|
<script>
|
|
@@ -234,43 +232,6 @@ export default {
|
|
|
234
232
|
```
|
|
235
233
|
:::
|
|
236
234
|
|
|
237
|
-
### 暗色主题
|
|
238
|
-
|
|
239
|
-
::: demo 暗色主题
|
|
240
|
-
```vue
|
|
241
|
-
<template>
|
|
242
|
-
<XtMulti :chart-data="chartData" theme="dark" />
|
|
243
|
-
</template>
|
|
244
|
-
|
|
245
|
-
<script>
|
|
246
|
-
export default {
|
|
247
|
-
data() {
|
|
248
|
-
return {
|
|
249
|
-
chartData: [
|
|
250
|
-
{
|
|
251
|
-
label: "入户数",
|
|
252
|
-
unit: "户",
|
|
253
|
-
data: [
|
|
254
|
-
{ label: "01月", value: 980 },
|
|
255
|
-
{ label: "02月", value: 806 }
|
|
256
|
-
]
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
label: "隐患数",
|
|
260
|
-
unit: "个",
|
|
261
|
-
data: [
|
|
262
|
-
{ label: "01月", value: 200 },
|
|
263
|
-
{ label: "02月", value: 120 }
|
|
264
|
-
]
|
|
265
|
-
}
|
|
266
|
-
]
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
</script>
|
|
271
|
-
```
|
|
272
|
-
:::
|
|
273
|
-
|
|
274
235
|
## 注意事项
|
|
275
236
|
|
|
276
237
|
- 相同 unit 的 series 会共用同一条 Y 轴
|
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
```vue
|
|
9
9
|
<template>
|
|
10
10
|
<XtPage>
|
|
11
|
-
<template
|
|
12
|
-
<template
|
|
13
|
-
<XtTable
|
|
11
|
+
<template slot="header">页面标题</template>
|
|
12
|
+
<template slot-scope="scope">
|
|
13
|
+
<XtTable
|
|
14
|
+
:table-data="tableData"
|
|
15
|
+
:height="scope.tableHeight"
|
|
16
|
+
:columns="columns"
|
|
17
|
+
/>
|
|
14
18
|
</template>
|
|
15
|
-
<template
|
|
19
|
+
<template slot="footer">页面底部</template>
|
|
16
20
|
</XtPage>
|
|
17
21
|
</template>
|
|
18
22
|
|
|
@@ -20,8 +24,15 @@
|
|
|
20
24
|
export default {
|
|
21
25
|
data() {
|
|
22
26
|
return {
|
|
23
|
-
tableData: [
|
|
24
|
-
|
|
27
|
+
tableData: [
|
|
28
|
+
{ name: '张三', age: 18 },
|
|
29
|
+
{ name: '李四', age: 20 }
|
|
30
|
+
],
|
|
31
|
+
columns: [
|
|
32
|
+
{ prop: "name", label:"姓名" },
|
|
33
|
+
{ prop: "age", label:"年龄" },
|
|
34
|
+
{ label: '操作', slot: 'action' }
|
|
35
|
+
]
|
|
25
36
|
}
|
|
26
37
|
}
|
|
27
38
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
## XtPie 饼图组件
|
|
2
|
-
|
|
3
1
|
基于 ECharts 封装的饼图组件,支持环形图、玫瑰图、自定义颜色等功能。
|
|
4
2
|
|
|
5
3
|
## 基本用法
|
|
@@ -7,7 +5,7 @@
|
|
|
7
5
|
::: demo 基本用法
|
|
8
6
|
```vue
|
|
9
7
|
<template>
|
|
10
|
-
<XtPie :chart-data="chartData"
|
|
8
|
+
<div class="demo-container"><XtPie :chart-data="chartData" /></div>
|
|
11
9
|
</template>
|
|
12
10
|
|
|
13
11
|
<script>
|
|
@@ -49,7 +47,7 @@ export default {
|
|
|
49
47
|
::: demo 玫瑰图
|
|
50
48
|
```vue
|
|
51
49
|
<template>
|
|
52
|
-
<XtPie :chart-data="chartData" rose-type="radius"
|
|
50
|
+
<div class="demo-container"><XtPie :chart-data="chartData" rose-type="radius" /></div>
|
|
53
51
|
</template>
|
|
54
52
|
|
|
55
53
|
<script>
|
|
@@ -75,7 +73,7 @@ export default {
|
|
|
75
73
|
::: demo 隐藏图例
|
|
76
74
|
```vue
|
|
77
75
|
<template>
|
|
78
|
-
<XtPie :chart-data="chartData" :show-legend="false"
|
|
76
|
+
<div class="demo-container"><XtPie :chart-data="chartData" :show-legend="false" /></div>
|
|
79
77
|
</template>
|
|
80
78
|
|
|
81
79
|
<script>
|
|
@@ -100,7 +98,7 @@ export default {
|
|
|
100
98
|
::: demo 自定义颜色
|
|
101
99
|
```vue
|
|
102
100
|
<template>
|
|
103
|
-
<XtPie :chart-data="chartData" :colors="['#1890ff', '#52c41a', '#faad14', '#f5222d']"
|
|
101
|
+
<div class="demo-container"><XtPie :chart-data="chartData" :colors="['#1890ff', '#52c41a', '#faad14', '#f5222d']" /></div>
|
|
104
102
|
</template>
|
|
105
103
|
|
|
106
104
|
<script>
|
|
@@ -125,7 +123,7 @@ export default {
|
|
|
125
123
|
::: demo 极简模式
|
|
126
124
|
```vue
|
|
127
125
|
<template>
|
|
128
|
-
<XtPie :chart-data="chartData" simple-mode
|
|
126
|
+
<div class="demo-container"><XtPie :chart-data="chartData" simple-mode /></div>
|
|
129
127
|
</template>
|
|
130
128
|
|
|
131
129
|
<script>
|
|
@@ -145,29 +143,6 @@ export default {
|
|
|
145
143
|
```
|
|
146
144
|
:::
|
|
147
145
|
|
|
148
|
-
### 暗色主题
|
|
149
|
-
|
|
150
|
-
::: demo 暗色主题
|
|
151
|
-
```vue
|
|
152
|
-
<template>
|
|
153
|
-
<XtPie :chart-data="chartData" theme="dark" />
|
|
154
|
-
</template>
|
|
155
|
-
|
|
156
|
-
<script>
|
|
157
|
-
export default {
|
|
158
|
-
data() {
|
|
159
|
-
return {
|
|
160
|
-
chartData: [
|
|
161
|
-
{ value: 53, label: "张三" },
|
|
162
|
-
{ value: 60, label: "李四" },
|
|
163
|
-
{ value: 78, label: "王五" }
|
|
164
|
-
]
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
</script>
|
|
169
|
-
```
|
|
170
|
-
:::
|
|
171
146
|
|
|
172
147
|
## 注意事项
|
|
173
148
|
|
|
@@ -93,8 +93,8 @@ export default {
|
|
|
93
93
|
fixed: true, // 是否固定
|
|
94
94
|
align: 'center', // 对齐方式
|
|
95
95
|
sortable: true, // 是否可排序
|
|
96
|
-
render: (
|
|
97
|
-
formatter: (row,
|
|
96
|
+
render: (h, { row, index, column }) => {}, // 自定义渲染函数 返回 VNode
|
|
97
|
+
formatter: (row, index, column) => {}, // 返回字符串
|
|
98
98
|
slot: 'custom-slot', // 自定义插槽名
|
|
99
99
|
children: [] // 多级表头
|
|
100
100
|
}
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
::: demo 基本用法
|
|
8
8
|
```vue
|
|
9
9
|
<template>
|
|
10
|
-
<
|
|
10
|
+
<div>
|
|
11
|
+
<XtUpload v-model="imageSrc" action="/upload" base-url="/api" />
|
|
12
|
+
</div>
|
|
11
13
|
</template>
|
|
12
14
|
|
|
13
15
|
<script>
|
|
@@ -35,6 +37,13 @@ export default {
|
|
|
35
37
|
| `accept` | String | `.jpg,.jpeg,.png` | 允许的文件类型 |
|
|
36
38
|
| `autoUpload` | Boolean | `true` | 是否自动上传 |
|
|
37
39
|
| `size` | String | `''` | 缩略图大小,可选 `big` |
|
|
40
|
+
| `icon` | String | `el-icon-camera` | 自定义图标 |
|
|
41
|
+
|
|
42
|
+
## 事件
|
|
43
|
+
|
|
44
|
+
| 事件名 | 说明 | 参数 |
|
|
45
|
+
|--------|------|------|
|
|
46
|
+
| `change` | 文件上传或删除时触发 | `src` |
|
|
38
47
|
|
|
39
48
|
## 示例
|
|
40
49
|
|
|
@@ -43,7 +52,7 @@ export default {
|
|
|
43
52
|
::: demo 多文件上传
|
|
44
53
|
```vue
|
|
45
54
|
<template>
|
|
46
|
-
<XtUpload v-model="fileSrc" action="/upload" multiple />
|
|
55
|
+
<XtUpload v-model="fileSrc" icon="el-icon-plus" action="/upload" multiple />
|
|
47
56
|
</template>
|
|
48
57
|
|
|
49
58
|
<script>
|
|
@@ -77,9 +86,3 @@ export default {
|
|
|
77
86
|
</script>
|
|
78
87
|
```
|
|
79
88
|
:::
|
|
80
|
-
|
|
81
|
-
## 事件
|
|
82
|
-
|
|
83
|
-
| 事件名 | 说明 | 参数 |
|
|
84
|
-
|--------|------|------|
|
|
85
|
-
| `change` | 文件上传或删除时触发 | `src` |
|
|
@@ -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` 监听器
|