wx-screen-ui 1.0.16 → 1.0.18
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 +58 -0
- package/dist/example/ExampleIndex.vue +111 -6
- package/dist/example/WxModalExample.vue +217 -0
- package/dist/example/WxRadioExample.vue +4 -3
- package/dist/example/WxSwitchExample.vue +176 -0
- package/dist/wx-screen-ui.css +1 -1
- package/dist/wx-screen-ui.es.js +171 -49
- package/dist/wx-screen-ui.umd.js +56 -56
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -155,6 +155,64 @@ npm run build
|
|
|
155
155
|
|
|
156
156
|
MIT
|
|
157
157
|
|
|
158
|
+
## 主题配置
|
|
159
|
+
|
|
160
|
+
Wx Screen UI 支持主题颜色的自定义,默认主题颜色为 `rgba(18, 154, 232, 1)`。
|
|
161
|
+
|
|
162
|
+
### 主题管理 API
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
import { setTheme, getTheme, resetTheme, initTheme } from "wx-screen-ui";
|
|
166
|
+
|
|
167
|
+
// 设置主题颜色
|
|
168
|
+
setTheme({
|
|
169
|
+
primaryColor: "255, 0, 0" // 红色主题
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// 获取当前主题配置
|
|
173
|
+
const currentTheme = getTheme();
|
|
174
|
+
console.log(currentTheme);
|
|
175
|
+
|
|
176
|
+
// 重置主题到默认值
|
|
177
|
+
resetTheme();
|
|
178
|
+
|
|
179
|
+
// 初始化主题(从本地存储加载)
|
|
180
|
+
initTheme();
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 参数说明
|
|
184
|
+
|
|
185
|
+
- **primaryColor**: 主色调,格式为 "r, g, b",例如 "18, 154, 232"
|
|
186
|
+
|
|
187
|
+
### 主题变量
|
|
188
|
+
|
|
189
|
+
以下是可用于自定义的主题变量:
|
|
190
|
+
|
|
191
|
+
| 变量名 | 描述 | 默认值 |
|
|
192
|
+
| --- | --- | --- |
|
|
193
|
+
| --wx-primary-color | 主色调的 RGB 值 | 18, 154, 232 |
|
|
194
|
+
| --wx-primary | 主色调 | rgba(var(--wx-primary-color), 1) |
|
|
195
|
+
| --wx-primary-light | 主色调的浅色版本 | rgba(var(--wx-primary-color), 0.2) |
|
|
196
|
+
| --wx-primary-hover | 主色调的 hover 版本 | rgba(var(--wx-primary-color), 0.8) |
|
|
197
|
+
| --wx-primary-disabled | 主色调的禁用版本 | rgba(var(--wx-primary-color), 0.4) |
|
|
198
|
+
| --wx-primary-light | 主色调的浅色背景 | rgba(var(--wx-primary-color), 0.2) |
|
|
199
|
+
| --wx-text-primary | 主要文本颜色 | #303133 |
|
|
200
|
+
| --wx-text-secondary | 次要文本颜色 | #606266 |
|
|
201
|
+
| --wx-text-placeholder | 占位文本颜色 | #909399 |
|
|
202
|
+
| --wx-text-disabled | 禁用文本颜色 | #c0c4cc |
|
|
203
|
+
| --wx-bg-color | 背景颜色 | #ffffff |
|
|
204
|
+
| --wx-bg-color-light | 浅色背景颜色 | #f5f7fa |
|
|
205
|
+
| --wx-bg-color-disabled | 禁用背景颜色 | #f5f7fa |
|
|
206
|
+
| --wx-border-color | 边框颜色 | #dcdfe6 |
|
|
207
|
+
| --wx-border-color-light | 浅色边框颜色 | #e4e7ed |
|
|
208
|
+
| --wx-border-color-hover | 边框 hover 颜色 | rgba(var(--wx-primary-color), 0.5) |
|
|
209
|
+
| --wx-shadow | 阴影 | 0 2px 12px 0 rgba(0, 0, 0, 0.1) |
|
|
210
|
+
| --wx-shadow-light | 浅色阴影 | 0 0 0 2px rgba(var(--wx-primary-color), 0.2) |
|
|
211
|
+
|
|
212
|
+
### 深色主题适配
|
|
213
|
+
|
|
214
|
+
组件库默认支持系统的深色主题模式,会根据系统的颜色方案自动切换主题变量。
|
|
215
|
+
|
|
158
216
|
## 贡献
|
|
159
217
|
|
|
160
218
|
欢迎提交 Issue 和 Pull Request 来改进这个组件库。
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="wx-example-index">
|
|
3
|
+
<div class="theme-switcher">
|
|
4
|
+
<h3>主题切换</h3>
|
|
5
|
+
<div class="theme-colors">
|
|
6
|
+
<div
|
|
7
|
+
class="theme-color-item"
|
|
8
|
+
v-for="(theme, index) in themeOptions"
|
|
9
|
+
:key="index"
|
|
10
|
+
:style="{ backgroundColor: theme.color }"
|
|
11
|
+
@click="switchTheme(theme.value)"
|
|
12
|
+
:class="{ active: currentTheme === theme.value }"></div>
|
|
13
|
+
</div>
|
|
14
|
+
<button class="reset-theme-btn" @click="resetTheme">重置主题</button>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
3
17
|
<h2>Wx Screen UI 组件库示例</h2>
|
|
4
18
|
|
|
5
19
|
<div class="example-section">
|
|
@@ -7,6 +21,11 @@
|
|
|
7
21
|
<WxMessageExample />
|
|
8
22
|
</div>
|
|
9
23
|
|
|
24
|
+
<div class="example-section">
|
|
25
|
+
<h3>弹窗组件</h3>
|
|
26
|
+
<WxModalExample />
|
|
27
|
+
</div>
|
|
28
|
+
|
|
10
29
|
<div class="example-section">
|
|
11
30
|
<h3>空状态组件</h3>
|
|
12
31
|
<WxEmptyExample />
|
|
@@ -41,10 +60,22 @@
|
|
|
41
60
|
<h3>选择器组件</h3>
|
|
42
61
|
<WxSelectExample />
|
|
43
62
|
</div>
|
|
63
|
+
|
|
64
|
+
<div class="example-section">
|
|
65
|
+
<h3>弹窗组件</h3>
|
|
66
|
+
<WxModalExample />
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<div class="example-section">
|
|
70
|
+
<h3>开关组件</h3>
|
|
71
|
+
<WxSwitchExample />
|
|
72
|
+
</div>
|
|
44
73
|
</div>
|
|
45
74
|
</template>
|
|
46
75
|
|
|
47
76
|
<script setup>
|
|
77
|
+
import { ref } from "vue";
|
|
78
|
+
import { setTheme, resetTheme } from "../index.js";
|
|
48
79
|
import WxMessageExample from "./WxMessageExample.vue";
|
|
49
80
|
import WxEmptyExample from "./WxEmptyExample.vue";
|
|
50
81
|
import WxTableExample from "./WxTableExample.vue";
|
|
@@ -53,6 +84,24 @@
|
|
|
53
84
|
import WxRadioExample from "./WxRadioExample.vue";
|
|
54
85
|
import WxSelectExample from "./WxSelectExample.vue";
|
|
55
86
|
import WxDescriptionExample from "./WxDescriptionExample.vue";
|
|
87
|
+
import WxModalExample from "./WxModalExample.vue";
|
|
88
|
+
import WxSwitchExample from "./WxSwitchExample.vue";
|
|
89
|
+
|
|
90
|
+
const currentTheme = ref("18, 154, 232");
|
|
91
|
+
|
|
92
|
+
const themeOptions = [
|
|
93
|
+
{ value: "18, 154, 232", color: "rgba(18, 154, 232, 1)" }, // 默认主题色
|
|
94
|
+
{ value: "64, 158, 255", color: "rgba(64, 158, 255, 1)" }, // 蓝色
|
|
95
|
+
{ value: "103, 194, 58", color: "rgba(103, 194, 58, 1)" }, // 绿色
|
|
96
|
+
{ value: "230, 162, 60", color: "rgba(230, 162, 60, 1)" }, // 橙色
|
|
97
|
+
{ value: "245, 108, 108", color: "rgba(245, 108, 108, 1)" }, // 红色
|
|
98
|
+
{ value: "144, 147, 153", color: "rgba(144, 147, 153, 1)" }, // 灰色
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
const switchTheme = color => {
|
|
102
|
+
currentTheme.value = color;
|
|
103
|
+
setTheme({ primaryColor: color });
|
|
104
|
+
};
|
|
56
105
|
</script>
|
|
57
106
|
|
|
58
107
|
<style scoped>
|
|
@@ -62,25 +111,81 @@
|
|
|
62
111
|
margin: 0 auto;
|
|
63
112
|
}
|
|
64
113
|
|
|
114
|
+
.theme-switcher {
|
|
115
|
+
margin-bottom: 40px;
|
|
116
|
+
padding: 20px;
|
|
117
|
+
border: 1px solid var(--wx-border-color);
|
|
118
|
+
border-radius: 8px;
|
|
119
|
+
background-color: var(--wx-bg-color);
|
|
120
|
+
box-shadow: var(--wx-shadow);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.theme-switcher h3 {
|
|
124
|
+
margin-bottom: 20px;
|
|
125
|
+
padding-bottom: 10px;
|
|
126
|
+
border-bottom: 1px solid var(--wx-border-color);
|
|
127
|
+
color: var(--wx-primary);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.theme-colors {
|
|
131
|
+
display: flex;
|
|
132
|
+
gap: 15px;
|
|
133
|
+
margin-bottom: 20px;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.theme-color-item {
|
|
137
|
+
width: 40px;
|
|
138
|
+
height: 40px;
|
|
139
|
+
border-radius: 50%;
|
|
140
|
+
cursor: pointer;
|
|
141
|
+
transition: all 0.3s;
|
|
142
|
+
border: 3px solid transparent;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.theme-color-item:hover {
|
|
146
|
+
transform: scale(1.1);
|
|
147
|
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.theme-color-item.active {
|
|
151
|
+
border-color: var(--wx-text-primary);
|
|
152
|
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.reset-theme-btn {
|
|
156
|
+
padding: 8px 16px;
|
|
157
|
+
border: 1px solid var(--wx-border-color);
|
|
158
|
+
background-color: transparent;
|
|
159
|
+
color: var(--wx-text-secondary);
|
|
160
|
+
border-radius: 4px;
|
|
161
|
+
cursor: pointer;
|
|
162
|
+
transition: all 0.3s;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.reset-theme-btn:hover {
|
|
166
|
+
color: var(--wx-primary);
|
|
167
|
+
border-color: var(--wx-primary);
|
|
168
|
+
}
|
|
169
|
+
|
|
65
170
|
.example-section {
|
|
66
171
|
margin-bottom: 50px;
|
|
67
172
|
padding: 20px;
|
|
68
|
-
border: 1px solid
|
|
173
|
+
border: 1px solid var(--wx-border-color);
|
|
69
174
|
border-radius: 8px;
|
|
70
|
-
background-color:
|
|
71
|
-
box-shadow:
|
|
175
|
+
background-color: var(--wx-bg-color);
|
|
176
|
+
box-shadow: var(--wx-shadow);
|
|
72
177
|
}
|
|
73
178
|
|
|
74
179
|
h2 {
|
|
75
180
|
text-align: center;
|
|
76
181
|
margin-bottom: 40px;
|
|
77
|
-
color:
|
|
182
|
+
color: var(--wx-text-primary);
|
|
78
183
|
}
|
|
79
184
|
|
|
80
185
|
h3 {
|
|
81
186
|
margin-bottom: 20px;
|
|
82
187
|
padding-bottom: 10px;
|
|
83
|
-
border-bottom: 1px solid
|
|
84
|
-
color:
|
|
188
|
+
border-bottom: 1px solid var(--wx-border-color);
|
|
189
|
+
color: var(--wx-primary);
|
|
85
190
|
}
|
|
86
191
|
</style>
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="wx-modal-example">
|
|
3
|
+
<h4>基本弹窗</h4>
|
|
4
|
+
<button class="example-btn" @click="showBasicModal = true">打开基本弹窗</button>
|
|
5
|
+
|
|
6
|
+
<h4>自定义标题和内容的弹窗</h4>
|
|
7
|
+
<button class="example-btn" @click="showCustomModal = true">打开自定义弹窗</button>
|
|
8
|
+
|
|
9
|
+
<h4>自定义底部按钮的弹窗</h4>
|
|
10
|
+
<button class="example-btn" @click="showCustomFooterModal = true">打开自定义底部弹窗</button>
|
|
11
|
+
|
|
12
|
+
<h4>不可关闭的弹窗</h4>
|
|
13
|
+
<button class="example-btn" @click="showUnclosableModal = true">打开不可关闭弹窗</button>
|
|
14
|
+
|
|
15
|
+
<h4>点击遮罩层不可关闭的弹窗</h4>
|
|
16
|
+
<button class="example-btn" @click="showMaskUnclosableModal = true">
|
|
17
|
+
打开遮罩不可关闭弹窗
|
|
18
|
+
</button>
|
|
19
|
+
|
|
20
|
+
<h4>不同宽度的弹窗</h4>
|
|
21
|
+
<button class="example-btn" @click="showSmallModal = true">打开小弹窗 (300px)</button>
|
|
22
|
+
<button class="example-btn" @click="showLargeModal = true">打开大弹窗 (800px)</button>
|
|
23
|
+
|
|
24
|
+
<!-- 基本弹窗 -->
|
|
25
|
+
<modal
|
|
26
|
+
v-model="showBasicModal"
|
|
27
|
+
title="基本弹窗"
|
|
28
|
+
@close="handleClose('基本弹窗')"
|
|
29
|
+
@cancel="handleCancel('基本弹窗')">
|
|
30
|
+
<p>这是一个基本的弹窗示例,包含默认的标题、内容和底部按钮。</p>
|
|
31
|
+
</modal>
|
|
32
|
+
|
|
33
|
+
<!-- 自定义标题和内容的弹窗 -->
|
|
34
|
+
<modal
|
|
35
|
+
v-model="showCustomModal"
|
|
36
|
+
@close="handleClose('自定义弹窗')"
|
|
37
|
+
@cancel="handleCancel('自定义弹窗')">
|
|
38
|
+
<template #title>
|
|
39
|
+
<span style="color: var(--wx-primary)">自定义标题</span>
|
|
40
|
+
</template>
|
|
41
|
+
<div>
|
|
42
|
+
<h5>自定义内容</h5>
|
|
43
|
+
<p>这是一个自定义标题和内容的弹窗示例。</p>
|
|
44
|
+
<ul>
|
|
45
|
+
<li>支持自定义标题</li>
|
|
46
|
+
<li>支持自定义内容</li>
|
|
47
|
+
<li>支持自定义底部按钮</li>
|
|
48
|
+
</ul>
|
|
49
|
+
</div>
|
|
50
|
+
</modal>
|
|
51
|
+
|
|
52
|
+
<!-- 自定义底部按钮的弹窗 -->
|
|
53
|
+
<modal
|
|
54
|
+
v-model="showCustomFooterModal"
|
|
55
|
+
title="自定义底部按钮"
|
|
56
|
+
@close="handleClose('自定义底部弹窗')">
|
|
57
|
+
<p>这是一个自定义底部按钮的弹窗示例,您可以根据需要添加不同的按钮。</p>
|
|
58
|
+
<template #footer>
|
|
59
|
+
<button class="modal-btn cancel-btn" @click="showCustomFooterModal = false">取消</button>
|
|
60
|
+
<button
|
|
61
|
+
class="modal-btn"
|
|
62
|
+
style="
|
|
63
|
+
margin-right: 12px;
|
|
64
|
+
background-color: var(--wx-warning-color, #e6a23c);
|
|
65
|
+
border-color: var(--wx-warning-color, #e6a23c);
|
|
66
|
+
color: #fff;
|
|
67
|
+
">
|
|
68
|
+
保存
|
|
69
|
+
</button>
|
|
70
|
+
<button class="modal-btn confirm-btn" @click="handleConfirm('自定义底部弹窗')">确定</button>
|
|
71
|
+
</template>
|
|
72
|
+
</modal>
|
|
73
|
+
|
|
74
|
+
<!-- 不可关闭的弹窗 -->
|
|
75
|
+
<modal
|
|
76
|
+
v-model="showUnclosableModal"
|
|
77
|
+
title="不可关闭的弹窗"
|
|
78
|
+
:closable="false"
|
|
79
|
+
:maskClosable="false">
|
|
80
|
+
<p>这是一个不可关闭的弹窗示例,您无法通过点击关闭按钮或遮罩层来关闭它。</p>
|
|
81
|
+
<p>只能通过点击底部的取消按钮来关闭。</p>
|
|
82
|
+
</modal>
|
|
83
|
+
|
|
84
|
+
<!-- 点击遮罩层不可关闭的弹窗 -->
|
|
85
|
+
<modal
|
|
86
|
+
v-model="showMaskUnclosableModal"
|
|
87
|
+
title="点击遮罩层不可关闭的弹窗"
|
|
88
|
+
:maskClosable="false"
|
|
89
|
+
@close="handleClose('遮罩不可关闭弹窗')"
|
|
90
|
+
@cancel="handleCancel('遮罩不可关闭弹窗')">
|
|
91
|
+
<p>这是一个点击遮罩层不可关闭的弹窗示例,您只能通过点击关闭按钮或底部的取消按钮来关闭它。</p>
|
|
92
|
+
</modal>
|
|
93
|
+
|
|
94
|
+
<!-- 小弹窗 -->
|
|
95
|
+
<modal
|
|
96
|
+
v-model="showSmallModal"
|
|
97
|
+
title="小弹窗"
|
|
98
|
+
:width="300"
|
|
99
|
+
@close="handleClose('小弹窗')"
|
|
100
|
+
@cancel="handleCancel('小弹窗')">
|
|
101
|
+
<p>这是一个宽度为 300px 的小弹窗示例。</p>
|
|
102
|
+
</modal>
|
|
103
|
+
|
|
104
|
+
<!-- 大弹窗 -->
|
|
105
|
+
<modal
|
|
106
|
+
v-model="showLargeModal"
|
|
107
|
+
title="大弹窗"
|
|
108
|
+
:width="800"
|
|
109
|
+
@close="handleClose('大弹窗')"
|
|
110
|
+
@cancel="handleCancel('大弹窗')">
|
|
111
|
+
<p>这是一个宽度为 800px 的大弹窗示例。</p>
|
|
112
|
+
<p>可以在其中放置更多的内容,例如表单、表格等。</p>
|
|
113
|
+
<div style="margin-top: 20px">
|
|
114
|
+
<h5>示例表单</h5>
|
|
115
|
+
<div class="form-item">
|
|
116
|
+
<label>姓名:</label>
|
|
117
|
+
<input type="text" class="form-input" placeholder="请输入姓名" />
|
|
118
|
+
</div>
|
|
119
|
+
<div class="form-item">
|
|
120
|
+
<label>年龄:</label>
|
|
121
|
+
<input type="number" class="form-input" placeholder="请输入年龄" />
|
|
122
|
+
</div>
|
|
123
|
+
<div class="form-item">
|
|
124
|
+
<label>邮箱:</label>
|
|
125
|
+
<input type="email" class="form-input" placeholder="请输入邮箱" />
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
</modal>
|
|
129
|
+
</div>
|
|
130
|
+
</template>
|
|
131
|
+
|
|
132
|
+
<script setup>
|
|
133
|
+
import { ref } from "vue";
|
|
134
|
+
import modal from "../components/modal/index.vue";
|
|
135
|
+
|
|
136
|
+
// 弹窗状态
|
|
137
|
+
const showBasicModal = ref(false);
|
|
138
|
+
const showCustomModal = ref(false);
|
|
139
|
+
const showCustomFooterModal = ref(false);
|
|
140
|
+
const showUnclosableModal = ref(false);
|
|
141
|
+
const showMaskUnclosableModal = ref(false);
|
|
142
|
+
const showSmallModal = ref(false);
|
|
143
|
+
const showLargeModal = ref(false);
|
|
144
|
+
|
|
145
|
+
// 事件处理函数
|
|
146
|
+
const handleClose = modalName => {
|
|
147
|
+
console.log(`${modalName} 被关闭`);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const handleCancel = modalName => {
|
|
151
|
+
console.log(`${modalName} 取消按钮被点击`);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const handleConfirm = modalName => {
|
|
155
|
+
console.log(`${modalName} 确认按钮被点击`);
|
|
156
|
+
showCustomFooterModal.value = false;
|
|
157
|
+
};
|
|
158
|
+
</script>
|
|
159
|
+
|
|
160
|
+
<style scoped>
|
|
161
|
+
.wx-modal-example {
|
|
162
|
+
padding: 20px;
|
|
163
|
+
background-color: var(--wx-bg-color);
|
|
164
|
+
border-radius: 8px;
|
|
165
|
+
box-shadow: var(--wx-shadow);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
h4 {
|
|
169
|
+
margin: 0 0 15px 0;
|
|
170
|
+
color: var(--wx-text-primary);
|
|
171
|
+
font-size: 16px;
|
|
172
|
+
font-weight: 500;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.example-btn {
|
|
176
|
+
margin: 0 10px 10px 0;
|
|
177
|
+
padding: 8px 16px;
|
|
178
|
+
border: 1px solid var(--wx-border-color);
|
|
179
|
+
background-color: var(--wx-bg-color);
|
|
180
|
+
color: var(--wx-text-primary);
|
|
181
|
+
border-radius: 4px;
|
|
182
|
+
cursor: pointer;
|
|
183
|
+
transition: all 0.3s;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.example-btn:hover {
|
|
187
|
+
color: var(--wx-primary);
|
|
188
|
+
border-color: var(--wx-primary);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.form-item {
|
|
192
|
+
margin-bottom: 15px;
|
|
193
|
+
display: flex;
|
|
194
|
+
align-items: center;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.form-item label {
|
|
198
|
+
width: 80px;
|
|
199
|
+
color: var(--wx-text-primary);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.form-input {
|
|
203
|
+
flex: 1;
|
|
204
|
+
padding: 8px 12px;
|
|
205
|
+
border: 1px solid var(--wx-border-color);
|
|
206
|
+
border-radius: 4px;
|
|
207
|
+
background-color: var(--wx-bg-color);
|
|
208
|
+
color: var(--wx-text-primary);
|
|
209
|
+
transition: all 0.3s;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.form-input:focus {
|
|
213
|
+
outline: none;
|
|
214
|
+
border-color: var(--wx-primary);
|
|
215
|
+
box-shadow: var(--wx-shadow-light);
|
|
216
|
+
}
|
|
217
|
+
</style>
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
const radioValue = ref("1");
|
|
21
21
|
const options = ref([
|
|
22
22
|
{
|
|
23
|
-
label: "
|
|
23
|
+
label: "年",
|
|
24
24
|
value: "1",
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
label: "
|
|
27
|
+
label: "月",
|
|
28
28
|
value: "2",
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
|
-
label: "
|
|
31
|
+
label: "日",
|
|
32
32
|
value: "3",
|
|
33
33
|
},
|
|
34
34
|
]);
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
.radio-group {
|
|
53
|
+
width: 100px;
|
|
53
54
|
display: flex;
|
|
54
55
|
flex-direction: column;
|
|
55
56
|
gap: 10px;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="wx-switch-example">
|
|
3
|
+
<h4>基本开关</h4>
|
|
4
|
+
<div class="switch-item">
|
|
5
|
+
<span>基本开关:</span>
|
|
6
|
+
<WxSwitch v-model="basicSwitch" @change="handleChange('基本开关', $event)" />
|
|
7
|
+
<span class="switch-status">{{ basicSwitch ? "开启" : "关闭" }}</span>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<h4>自定义颜色的开关</h4>
|
|
11
|
+
<div class="switch-item">
|
|
12
|
+
<span>绿色开关:</span>
|
|
13
|
+
<WxSwitch
|
|
14
|
+
v-model="greenSwitch"
|
|
15
|
+
activeColor="rgba(103, 194, 58, 1)"
|
|
16
|
+
inactiveColor="#dcdfe6"
|
|
17
|
+
@change="handleChange('绿色开关', $event)" />
|
|
18
|
+
<span class="switch-status">{{ greenSwitch ? "开启" : "关闭" }}</span>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div class="switch-item">
|
|
22
|
+
<span>红色开关:</span>
|
|
23
|
+
<WxSwitch
|
|
24
|
+
v-model="redSwitch"
|
|
25
|
+
activeColor="rgba(245, 108, 108, 1)"
|
|
26
|
+
inactiveColor="#dcdfe6"
|
|
27
|
+
@change="handleChange('红色开关', $event)" />
|
|
28
|
+
<span class="switch-status">{{ redSwitch ? "开启" : "关闭" }}</span>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div class="switch-item">
|
|
32
|
+
<span>橙色开关:</span>
|
|
33
|
+
<WxSwitch
|
|
34
|
+
v-model="orangeSwitch"
|
|
35
|
+
activeColor="rgba(230, 162, 60, 1)"
|
|
36
|
+
inactiveColor="#dcdfe6"
|
|
37
|
+
@change="handleChange('橙色开关', $event)" />
|
|
38
|
+
<span class="switch-status">{{ orangeSwitch ? "开启" : "关闭" }}</span>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<h4>自定义滑块颜色的开关</h4>
|
|
42
|
+
<div class="switch-item">
|
|
43
|
+
<span>自定义滑块颜色:</span>
|
|
44
|
+
<WxSwitch
|
|
45
|
+
v-model="customThumbSwitch"
|
|
46
|
+
activeColor="rgba(18, 154, 232, 1)"
|
|
47
|
+
inactiveColor="#dcdfe6"
|
|
48
|
+
thumbColor="#7ffffd"
|
|
49
|
+
@change="handleChange('自定义滑块颜色开关', $event)" />
|
|
50
|
+
<span class="switch-status">{{ customThumbSwitch ? "开启" : "关闭" }}</span>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<h4>不同动画 duration 的开关</h4>
|
|
54
|
+
<div class="switch-item">
|
|
55
|
+
<span>快速动画 (0.1s):</span>
|
|
56
|
+
<WxSwitch
|
|
57
|
+
v-model="fastSwitch"
|
|
58
|
+
duration="0.1"
|
|
59
|
+
@change="handleChange('快速动画开关', $event)" />
|
|
60
|
+
<span class="switch-status">{{ fastSwitch ? "开启" : "关闭" }}</span>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<div class="switch-item">
|
|
64
|
+
<span>慢速动画 (1s):</span>
|
|
65
|
+
<WxSwitch v-model="slowSwitch" duration="1" @change="handleChange('慢速动画开关', $event)" />
|
|
66
|
+
<span class="switch-status">{{ slowSwitch ? "开启" : "关闭" }}</span>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<h4>开关组示例</h4>
|
|
70
|
+
<div class="switch-group">
|
|
71
|
+
<div class="switch-item">
|
|
72
|
+
<span>选项 1:</span>
|
|
73
|
+
<WxSwitch v-model="groupSwitches[0]" @change="handleGroupChange(0, $event)" />
|
|
74
|
+
</div>
|
|
75
|
+
<div class="switch-item">
|
|
76
|
+
<span>选项 2:</span>
|
|
77
|
+
<WxSwitch v-model="groupSwitches[1]" @change="handleGroupChange(1, $event)" />
|
|
78
|
+
</div>
|
|
79
|
+
<div class="switch-item">
|
|
80
|
+
<span>选项 3:</span>
|
|
81
|
+
<WxSwitch v-model="groupSwitches[2]" @change="handleGroupChange(2, $event)" />
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
<h4>禁用状态的开关</h4>
|
|
86
|
+
<div class="switch-item">
|
|
87
|
+
<span>禁用的开关:</span>
|
|
88
|
+
<WxSwitch v-model="disabledSwitch" disabled />
|
|
89
|
+
<span class="switch-status">{{ disabledSwitch ? "开启" : "关闭" }}</span>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
</template>
|
|
93
|
+
|
|
94
|
+
<script setup>
|
|
95
|
+
import { ref } from "vue";
|
|
96
|
+
import WxSwitch from "../components/switch/index.vue";
|
|
97
|
+
|
|
98
|
+
// 基本开关
|
|
99
|
+
const basicSwitch = ref(false);
|
|
100
|
+
|
|
101
|
+
// 自定义颜色的开关
|
|
102
|
+
const greenSwitch = ref(false);
|
|
103
|
+
const redSwitch = ref(false);
|
|
104
|
+
const orangeSwitch = ref(false);
|
|
105
|
+
|
|
106
|
+
// 自定义滑块颜色的开关
|
|
107
|
+
const customThumbSwitch = ref(false);
|
|
108
|
+
|
|
109
|
+
// 不同动画 duration 的开关
|
|
110
|
+
const fastSwitch = ref(false);
|
|
111
|
+
const slowSwitch = ref(false);
|
|
112
|
+
|
|
113
|
+
// 开关组
|
|
114
|
+
const groupSwitches = ref([false, false, false]);
|
|
115
|
+
|
|
116
|
+
// 禁用状态的开关
|
|
117
|
+
const disabledSwitch = ref(false);
|
|
118
|
+
|
|
119
|
+
// 事件处理函数
|
|
120
|
+
const handleChange = (switchName, value) => {
|
|
121
|
+
console.log(`${switchName} 状态变化:${value}`);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const handleGroupChange = (index, value) => {
|
|
125
|
+
console.log(`开关组 ${index + 1} 状态变化:${value}`);
|
|
126
|
+
};
|
|
127
|
+
</script>
|
|
128
|
+
|
|
129
|
+
<style scoped>
|
|
130
|
+
.wx-switch-example {
|
|
131
|
+
padding: 20px;
|
|
132
|
+
background-color: var(--wx-bg-color);
|
|
133
|
+
border-radius: 8px;
|
|
134
|
+
box-shadow: var(--wx-shadow);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
h4 {
|
|
138
|
+
margin: 0 0 15px 0;
|
|
139
|
+
color: var(--wx-text-primary);
|
|
140
|
+
font-size: 16px;
|
|
141
|
+
font-weight: 500;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.switch-item {
|
|
145
|
+
margin-bottom: 15px;
|
|
146
|
+
display: flex;
|
|
147
|
+
align-items: center;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.switch-item span {
|
|
151
|
+
margin-right: 15px;
|
|
152
|
+
color: var(--wx-text-primary);
|
|
153
|
+
width: 120px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.switch-status {
|
|
157
|
+
margin-left: 15px;
|
|
158
|
+
color: var(--wx-text-secondary);
|
|
159
|
+
font-size: 14px;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.switch-group {
|
|
163
|
+
padding: 15px;
|
|
164
|
+
background-color: var(--wx-bg-color-light);
|
|
165
|
+
border-radius: 4px;
|
|
166
|
+
margin-bottom: 20px;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.switch-group .switch-item {
|
|
170
|
+
margin-bottom: 10px;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.switch-group .switch-item:last-child {
|
|
174
|
+
margin-bottom: 0;
|
|
175
|
+
}
|
|
176
|
+
</style>
|