提交 a09a3dc8 编写于 作者: Y yurj26

feat: checkbox、radio

上级 3ca102f4
...@@ -30,7 +30,7 @@ describe('Checkbox.uvue', () => { ...@@ -30,7 +30,7 @@ describe('Checkbox.uvue', () => {
const checkboxGroupElements = await page.$$('.checkbox-group') const checkboxGroupElements = await page.$$('.checkbox-group')
expect(checkboxGroupElements.length).toBe(3) expect(checkboxGroupElements.length).toBe(3)
const checkboxElements = await page.$$('.checkbox') const checkboxElements = await page.$$('.checkbox')
expect(checkboxElements.length).toBe(11) expect(checkboxElements.length).toBe(12)
}) })
it('text', async () => { it('text', async () => {
const cb = await page.$('.cb1') const cb = await page.$('.cb1')
......
...@@ -8,11 +8,14 @@ ...@@ -8,11 +8,14 @@
</text> </text>
</view> </view>
<view> <view>
<checkbox-group class="uni-flex uni-row checkbox-group" @change="testChange"> <checkbox-group class="uni-flex uni-row checkbox-group" @change="testChange" style="flex-wrap: wrap;">
<checkbox value="cb" :checked="checked" :color="color" style="margin-right: 30rpx;" <checkbox value="cb" :checked="checked" :color="color" style="margin-right: 30rpx;"
class="checkbox cb">选中</checkbox> class="checkbox cb">选中</checkbox>
<checkbox value="cb1" style="margin-right: 30rpx;" class="checkbox cb1">{{text}}</checkbox> <checkbox value="cb1" style="margin-right: 30rpx;" class="checkbox cb1">{{text}}</checkbox>
<checkbox value="cb2" :disabled="disabled" class="checkbox cb2">禁用</checkbox> <checkbox value="cb2" :disabled="disabled" class="checkbox cb2">禁用</checkbox>
<checkbox value="cb3" style="margin-top: 20rpx;" class="checkbox cb3">
{{wrapText}}
</checkbox>
</checkbox-group> </checkbox-group>
</view> </view>
<view class="uni-title uni-common-mt"> <view class="uni-title uni-common-mt">
...@@ -35,9 +38,6 @@ ...@@ -35,9 +38,6 @@
<text class="uni-title-text"> <text class="uni-title-text">
推荐展示样式 推荐展示样式
</text> </text>
<text class="uni-subtitle-text">
使用 uni-list 布局
</text>
</view> </view>
</view> </view>
<view class="uni-list uni-common-pl"> <view class="uni-list uni-common-pl">
...@@ -61,16 +61,17 @@ ...@@ -61,16 +61,17 @@
data() { data() {
return { return {
title: 'checkbox 复选框', title: 'checkbox 复选框',
items: [{ items: [
value: 'USA',
name: '美国',
checked: false
},
{ {
value: 'CHN', value: 'CHN',
name: '中国', name: '中国',
checked: true checked: true
}, },
{
value: 'USA',
name: '美国',
checked: false
},
{ {
value: 'BRA', value: 'BRA',
name: '巴西', name: '巴西',
...@@ -94,24 +95,25 @@ ...@@ -94,24 +95,25 @@
] as ItemType[], ] as ItemType[],
text: '未选中', text: '未选中',
wrapText: 'uni-app x,终极跨平台方案\nuts,大一统语言',
value: [] as string[], value: [] as string[],
disabled: true, disabled: true,
checked: true, checked: true,
color: '#007aff' color: '#007aff',
} }
}, },
methods: { methods: {
checkboxChange: function (e : CheckboxGroupChangeEvent) { checkboxChange: function (e : CheckboxGroupChangeEvent) {
var items = this.items, const selectedNames : string[] = []
values = e.detail.value; this.items.forEach(item => {
for (var i = 0, lenI = items.length; i < lenI; ++i) { if (e.detail.value.includes(item.value)) {
const item = items[i] selectedNames.push(item.name)
if (values.indexOf(item.value) >= 0) {
item.checked = true
} else {
item.checked = false
}
} }
})
uni.showToast({
icon: 'none',
title: '当前选中:' + selectedNames.join(',')
})
}, },
testChange: function (e : CheckboxGroupChangeEvent) { testChange: function (e : CheckboxGroupChangeEvent) {
this.value = e.detail.value this.value = e.detail.value
......
...@@ -28,7 +28,7 @@ describe('Radio.uvue', () => { ...@@ -28,7 +28,7 @@ describe('Radio.uvue', () => {
const radioGroupElements = await page.$$('.radio-group') const radioGroupElements = await page.$$('.radio-group')
expect(radioGroupElements.length).toBe(3) expect(radioGroupElements.length).toBe(3)
const radioElements = await page.$$('.radio') const radioElements = await page.$$('.radio')
expect(radioElements.length).toBe(11) expect(radioElements.length).toBe(12)
}) })
it('text', async () => { it('text', async () => {
const radio = await page.$('.r1') const radio = await page.$('.r1')
......
...@@ -7,13 +7,15 @@ ...@@ -7,13 +7,15 @@
默认样式 默认样式
</text> </text>
</view> </view>
<radio-group class="uni-flex uni-row radio-group" @change="testChange"> <radio-group class="uni-flex uni-row radio-group" @change="testChange" style="flex-wrap: wrap;">
<radio value="r" :checked="checked" :color="color" style="margin-right: 30rpx;" class="radio r">选中 <radio value="r" :checked="checked" :color="color" style="margin-right: 30rpx;" class="radio r">选中
</radio> </radio>
<radio value="r1" style="margin-right: 30rpx;" class="radio r1">{{text}}</radio> <radio value="r1" style="margin-right: 30rpx;" class="radio r1">{{text}}</radio>
<radio value="r2" :disabled="disabled" class="radio r2">禁用</radio> <radio value="r2" :disabled="disabled" class="radio r2">禁用</radio>
<radio value="r3" class="radio r3" style="margin-top: 20rpx;">{{wrapText}}</radio>
</radio-group> </radio-group>
</view> </view>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<view class="uni-title uni-common-mt"> <view class="uni-title uni-common-mt">
<text class="uni-title-text"> <text class="uni-title-text">
...@@ -27,6 +29,7 @@ ...@@ -27,6 +29,7 @@
<radio value="r2" color="#FFCC33" style="transform:scale(0.7)" class="radio">未选中</radio> <radio value="r2" color="#FFCC33" style="transform:scale(0.7)" class="radio">未选中</radio>
</radio-group> </radio-group>
</view> </view>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<view class="uni-title uni-common-mt"> <view class="uni-title uni-common-mt">
<text class="uni-title-text"> <text class="uni-title-text">
...@@ -54,14 +57,16 @@ ...@@ -54,14 +57,16 @@
data() { data() {
return { return {
title: 'radio 单选框', title: 'radio 单选框',
items: [{ items: [
value: 'USA',
name: '美国'
},
{ {
value: 'CHN', value: 'CHN',
name: '中国' name: '中国'
}, },
{
value: 'USA',
name: '美国'
},
{ {
value: 'BRA', value: 'BRA',
name: '巴西' name: '巴西'
...@@ -83,6 +88,7 @@ ...@@ -83,6 +88,7 @@
value: '', value: '',
text: '未选中', text: '未选中',
wrapText: 'uni-app x,终极跨平台方案\nuts,大一统语言',
disabled: true, disabled: true,
checked: true, checked: true,
color: '#007aff' color: '#007aff'
...@@ -90,12 +96,13 @@ ...@@ -90,12 +96,13 @@
}, },
methods: { methods: {
radioChange(e : RadioGroupChangeEvent) { radioChange(e : RadioGroupChangeEvent) {
for (let i = 0; i < this.items.length; i++) { const selected = this.items.find((item) : boolean => {
if (this.items[i].value === e.detail.value) { return item.value == e.detail.value
this.current = i; })
break; uni.showToast({
} icon: 'none',
} title: '当前选中:' + selected?.name
})
}, },
testChange(e : RadioGroupChangeEvent) { testChange(e : RadioGroupChangeEvent) {
this.value = e.detail.value this.value = e.detail.value
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册