Skip to content

Commit 7f0cb27

Browse files
committed
feat: uni-forms uni-forms-item 可以设置单独的 rules
feat: uni-forms validate 事件增加 keepitem 参数,可以选择那些字段不过滤 perf: submit 事件重命名为 validate
1 parent e1e26d7 commit 7f0cb27

File tree

7 files changed

+849
-844
lines changed

7 files changed

+849
-844
lines changed

pages/nvue/forms/forms.nvue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<view>
33
<text class="example-info">uni-forms 组件一般由输入框、选择器、单选框、多选框等控件组成,用以收集、校验、提交数据。</text>
44

5-
<uni-forms :rules="rules" :value="formData" ref="form" validate-trigger="bind" err-show-type="undertext">
5+
<uni-forms :rules="rules" :modelValue="formData" ref="form" validate-trigger="bind" err-show-type="undertext">
66
<uni-group title="基本信息" top="0">
77
<uni-forms-item name="name" required label="用户名">
88
<uni-easyinput type="text" :inputBorder="true" v-model="formData.name" placeholder="请输入用户名"></uni-easyinput>

pages/vue/forms/forms.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<view>
33
<text class="example-info">uni-forms 组件一般由输入框、选择器、单选框、多选框等控件组成,用以收集、校验、提交数据。</text>
44

5-
<uni-forms :rules="rules" :value="formData" ref="form" validate-trigger="bind" err-show-type="undertext">
5+
<uni-forms :rules="rules" :modelValue="formData" ref="form" validate-trigger="bind" err-show-type="undertext">
66
<uni-group title="基本信息" top="0">
77
<uni-forms-item name="name" required label="用户名">
88
<uni-easyinput type="text" :inputBorder="true" v-model="formData.name" placeholder="请输入用户名"></uni-easyinput>

uni_modules/uni-data-checkbox/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 0.1.7
2+
- 新增 map 属性,可以方便映射text/value属性
13
## 0.1.6(2021-05-26)
24
- 修复 不关联服务空间的情况下组件报错的Bug
35
## 0.1.5(2021-05-12)

uni_modules/uni-data-checkbox/components/uni-data-checkbox/uni-data-checkbox.vue

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@
88
</template>
99
<template v-else>
1010
<checkbox-group v-if="multiple" class="checklist-group" :class="{'is-list':mode==='list' || wrap}" @change="chagne">
11-
<!-- :class="item.labelClass" -->
1211
<label class="checklist-box" :class="['is--'+mode,item.selected?'is-checked':'',(disabled || !!item.disabled)?'is-disable':'',index!==0&&mode==='list'?'is-list-border':'']"
1312
:style="item.styleBackgroud" v-for="(item,index) in dataList" :key="index">
14-
<checkbox class="hidden" hidden :disabled="disabled || !!item.disabled" :value="item.value+''" :checked="item.selected" />
15-
<!-- :style="item.styleIcon" -->
16-
13+
<checkbox class="hidden" hidden :disabled="disabled || !!item.disabled" :value="item[map.value]+''" :checked="item.selected" />
1714
<view v-if="(mode !=='tag' && mode !== 'list') || ( mode === 'list' && icon === 'left')" class="checkbox__inner" :style="item.styleIcon">
18-
<!-- :class="item.checkboxClass" -->
1915
<view class="checkbox__inner-icon"></view>
2016
</view>
2117
<view class="checklist-content" :class="{'list-content':mode === 'list' && icon ==='left'}">
22-
<!-- :class="item.textClass" -->
23-
<text class="checklist-text" :style="item.styleIconText">{{item.text}}</text>
24-
<!-- :class="item.listClass" -->
18+
<text class="checklist-text" :style="item.styleIconText">{{item[map.text]}}</text>
2519
<view v-if="mode === 'list' && icon === 'right'" class="checkobx__list" :style="item.styleBackgroud"></view>
2620
</view>
2721
</label>
@@ -30,17 +24,13 @@
3024
<!-- -->
3125
<label class="checklist-box" :class="['is--'+mode,item.selected?'is-checked':'',(disabled || !!item.disabled)?'is-disable':'',index!==0&&mode==='list'?'is-list-border':'']"
3226
:style="item.styleBackgroud" v-for="(item,index) in dataList" :key="index">
33-
<radio class="hidden" hidden :disabled="disabled || item.disabled" :value="item.value+''" :checked="item.selected" />
34-
<!-- :class="item.checkboxBgClass" -->
27+
<radio class="hidden" hidden :disabled="disabled || item.disabled" :value="item[map.value]+''" :checked="item.selected" />
3528
<view v-if="(mode !=='tag' && mode !== 'list') || ( mode === 'list' && icon === 'left')" class="radio__inner"
3629
:style="item.styleBackgroud">
37-
<!-- :class="item.checkboxClass" -->
3830
<view class="radio__inner-icon" :style="item.styleIcon"></view>
3931
</view>
4032
<view class="checklist-content" :class="{'list-content':mode === 'list' && icon ==='left'}">
41-
<!-- :class="item.textClass" -->
42-
<text class="checklist-text" :style="item.styleIconText">{{item.text}}</text>
43-
<!-- :class="item.listClass" -->
33+
<text class="checklist-text" :style="item.styleIconText">{{item[map.text]}}</text>
4434
<view v-if="mode === 'list' && icon === 'right'" :style="item.styleRightIcon" class="checkobx__list"></view>
4535
</view>
4636
</label>
@@ -51,9 +41,9 @@
5141

5242
<script>
5343
/**
54-
* DataCheckbox 数据选择器
44+
* DataChecklist 数据选择器
5545
* @description 通过数据渲染 checkbox 和 radio
56-
* @tutorial https://ext.dcloud.net.cn/plugin?id=3456
46+
* @tutorial https://ext.dcloud.net.cn/plugin?id=xxx
5747
* @property {String} mode = [default| list | button | tag] 显示模式
5848
* @value default 默认横排模式
5949
* @value list 列表模式
@@ -74,8 +64,10 @@
7464
* @event {Function} change 选中发生变化触发
7565
*/
7666
67+
// import clientdb from './clientdb.js'
7768
export default {
78-
name: 'uniDataCheckbox',
69+
name: 'uniDataChecklist',
70+
// mixins: [clientdb],
7971
mixins: [uniCloud.mixinDatacom || {}],
8072
props: {
8173
mode: {
@@ -129,6 +121,15 @@
129121
disabled:{
130122
type: Boolean,
131123
default: false
124+
},
125+
map:{
126+
type: Object,
127+
default(){
128+
return {
129+
text:'text',
130+
value:'value'
131+
}
132+
}
132133
}
133134
},
134135
watch: {
@@ -167,7 +168,7 @@
167168
created() {
168169
this.form = this.getForm('uniForms')
169170
this.formItem = this.getForm('uniFormsItem')
170-
this.formItem && this.formItem.setValue(this.value)
171+
// this.formItem && this.formItem.setValue(this.value)
171172
172173
if (this.formItem) {
173174
if (this.formItem.name) {
@@ -224,16 +225,17 @@
224225
225226
if (this.multiple) {
226227
this.range.forEach(item => {
227-
if (values.includes(item.value + '')) {
228-
detail.value.push(item.value)
228+
229+
if (values.includes(item[this.map.value] + '')) {
230+
detail.value.push(item[this.map.value])
229231
detail.data.push(item)
230232
}
231233
})
232234
} else {
233-
const range = this.range.find(item => (item.value + '') === values)
235+
const range = this.range.find(item => (item[this.map.value] + '') === values)
234236
if (range) {
235237
detail = {
236-
value: range.value,
238+
value: range[this.map.value],
237239
data: range
238240
}
239241
}
@@ -270,13 +272,13 @@
270272
item.disabled = item.disable || item.disabled || false
271273
if (this.multiple) {
272274
if (value.length > 0) {
273-
let have = value.find(val => val === item.value)
275+
let have = value.find(val => val === item[this.map.value])
274276
item.selected = have !== undefined
275277
} else {
276278
item.selected = false
277279
}
278280
} else {
279-
item.selected = value === item.value
281+
item.selected = value === item[this.map.value]
280282
}
281283
282284
list.push(item)
@@ -294,14 +296,14 @@
294296
list.forEach((item, index) => {
295297
if (this.multiple) {
296298
if (selectList.length <= min) {
297-
let have = selectList.find(val => val.value === item.value)
299+
let have = selectList.find(val => val[this.map.value] === item[this.map.value])
298300
if (have !== undefined) {
299301
item.disabled = true
300302
}
301303
}
302304
303305
if (selectList.length >= max && max !== '') {
304-
let have = selectList.find(val => val.value === item.value)
306+
let have = selectList.find(val => val[this.map.value] === item[this.map.value])
305307
if (have === undefined) {
306308
item.disabled = true
307309
}
@@ -335,7 +337,7 @@
335337
let selectedArr = []
336338
range.forEach((item) => {
337339
if (item.selected) {
338-
selectedArr.push(item.value)
340+
selectedArr.push(item[this.map.value])
339341
}
340342
})
341343
return this.value.length > 0 ? this.value : selectedArr

uni_modules/uni-forms/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.44
2+
- 新增 uni-forms-item 可以设置单独的 rules
3+
- 新增 validate 事件增加 keepitem 参数,可以选择那些字段不过滤
4+
- 优化 submit 事件重命名为 validate
15
## 1.0.43(2021-05-12)
26
- 新增 组件示例地址
37
## 1.0.42(2021-04-30)

0 commit comments

Comments
 (0)