Skip to content

Commit 59940f9

Browse files
committed
feat(Switch): 新增 Switch 组件
1 parent be268fd commit 59940f9

File tree

16 files changed

+206
-2
lines changed

16 files changed

+206
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ yarn-error.log
1919
.vscode
2020
package-lock.json
2121
examples/project.config.json
22+
examples/project.private.config.json
2223
/.run
2324
yarn.lock

commitlint.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ module.exports = {
7575
'TabBar',
7676
'DynamicBuild',
7777
'Calendar',
78-
'Script'
78+
'Script',
79+
'Switch'
7980
]
8081
]
8182
}

examples/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
{
9494
"root": "pages/components/form",
9595
"pages": [
96+
"pages/switch/index",
9697
"pages/input/index",
9798
"pages/radio/index",
9899
"pages/checkbox/index",
712 Bytes
Loading

examples/pages/components/form/pages/form/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Page({
3737
music: '',
3838
sex: '',
3939
desc: '',
40-
score: ''
40+
score: '',
41+
status: false
4142
},
4243
items: [
4344
{
@@ -95,6 +96,19 @@ Page({
9596
trigger: 'change'
9697
}
9798
],
99+
statusRules: [
100+
{
101+
validator(rule, value, callback) {
102+
if (value !== true) {
103+
callback(false);
104+
} else {
105+
callback();
106+
}
107+
},
108+
message: '必须启用',
109+
trigger: 'change'
110+
}
111+
],
98112
register: {
99113
loginId: '',
100114
password: '',

examples/pages/components/form/pages/form/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"l-radio-group": "/dist/radio-group/index",
1414
"l-radio": "/dist/radio/index",
1515
"l-rate": "/dist/rate/index",
16+
"l-switch": "/dist/switch/index",
1617
"l-button": "/dist/button/index"
1718
}
1819
}

examples/pages/components/form/pages/form/index.wxml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@
166166
<l-form-item tip-type="{{tipType}}" align-items="{{alignType}}" rules="{{descRules}}" label="性格描述:" name="ruleDesc">
167167
<l-textarea l-class="l-input-container-class" border="{{false}}" id="ruleDesc" value="{{ruleForm.desc}}" />
168168
</l-form-item>
169+
<l-form-item tip-type="{{tipType}}" align-items="{{alignType}}" rules="{{statusRules}}" label="是否启用:" name="ruleStatus">
170+
<l-switch id="ruleStatus" value="{{ruleForm.status}}" />
171+
</l-form-item>
169172

170173
<view slot="submit">
171174
<l-button>提交验证</l-button>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// pages/components/form/pages/switch/index.js
2+
Page({
3+
/**
4+
* 页面的初始数据
5+
*/
6+
data: {
7+
customValue: 0
8+
},
9+
10+
onChange(e) {
11+
this.setData({
12+
customValue: e.detail.checked
13+
});
14+
}
15+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"usingComponents": {
3+
"content-title": "/components/content-title/index",
4+
"content-card": "/components/content-card/index",
5+
"l-switch": "/dist/switch/index"
6+
}
7+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--pages/components/form/pages/switch/index.wxml-->
2+
<view class='container'>
3+
<content-title name="Switch" describe="开关">
4+
<content-card
5+
class="content"
6+
name="基本案例"
7+
>
8+
<l-switch />
9+
10+
</content-card>
11+
12+
<!-- 设置禁用 -->
13+
<content-card
14+
class="content"
15+
name="设置禁用"
16+
>
17+
<l-switch disabled />
18+
</content-card>
19+
20+
<content-card
21+
class="content"
22+
name="自定义大小"
23+
>
24+
<l-switch size="50rpx" />
25+
</content-card>
26+
27+
<content-card
28+
class="content"
29+
name="自定义颜色"
30+
>
31+
<l-switch color="#ccc" select-color="#34BFA3"/>
32+
</content-card>
33+
34+
<content-card
35+
class="content"
36+
name="自定义打开或关闭的值"
37+
>
38+
<l-switch checked="{{ customValue }}" active-value="{{ 1 }}" inactive-value="{{ 0 }}" bind:linchange="onChange"/>
39+
<view>当前选中的值:{{ customValue }}</view>
40+
</content-card>
41+
</content-title>
42+
</view>

0 commit comments

Comments
 (0)