Skip to content

Commit af34537

Browse files
dpp0507007insummer
authored andcommitted
feat: 重构form (#679)
* feat: 重构form * feat:新增form表单组件 * feat:新增form表单组件 * feat:新增组件form表单; (为配合表单操作修改对应内容有:组件: radio、checkbox、input、textarea、rate;行为:rule) * feat:完善表单组件 * feat: 增加表单example
1 parent d329960 commit af34537

File tree

104 files changed

+2131
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2131
-324
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<p align="center">
33
<!-- <a href="http://doc.mini.7yue.pro/"> -->
44
<img
5-
class="QR-img" src="https://img-gzb.oss-cn-shanghai.aliyuncs.com/lala/2bdab36cc138813e87fe60000f474b67.jpg">
5+
class="QR-img" src="https://raw.githubusercontent.com/zhc525349965/fisher_book/master/app/image/lin-ui小程序.jpg">
66
<!-- </a> -->
77
</p>
88

@@ -11,7 +11,7 @@
1111
<div class="row" />
1212

1313
<div align="center">
14-
<span class="desc" >Fantastic native based Mini-Program components</span>
14+
<span class="desc" >Fantastic native based Mini-Programe components</span>
1515
</div>
1616

1717
<div align="center">
@@ -39,13 +39,13 @@ Lin UI 是基于 **微信小程序原生语法** 实现的组件库。遵循简
3939

4040
<table>
4141
<tbody>
42-
<tr >
43-
<td align="center" valign="middle" style="border-style:none">
44-
<img class="QR-img" style="height: 60px; width:60px" src="https://img-gzb.oss-cn-shanghai.aliyuncs.com/lala/40D46DF4ED2D741369A4B186738D1534.png">
42+
<tr>
43+
<td align="center" valign="middle">
44+
<img class="QR-img" style="height: 60px; width:60px" src="https://raw.githubusercontent.com/zhc525349965/fisher_book/master/app/image/qq群新.png">
4545
<p style="font-size:12px;">QQ群号:643205479</p>
4646
</td>
47-
<td align="center" valign="middle" style="border-style:none">
48-
<img class="QR-img" style="height: 60px; width:60px" src="https://img-gzb.oss-cn-shanghai.aliyuncs.com/lala/5b4dad8dc5cda58e26922fde2471308f.jpg">
47+
<td align="center" valign="middle">
48+
<img class="QR-img" style="height: 60px; width:60px" src="https://raw.githubusercontent.com/zhc525349965/fisher_book/master/app/image/公众号.jpg">
4949
<p style="font-size:12px;">微信公众号:林间有风</p>
5050
</td>
5151
</tr>
@@ -57,8 +57,8 @@ Lin UI 是基于 **微信小程序原生语法** 实现的组件库。遵循简
5757
<table>
5858
<tbody>
5959
<tr>
60-
<td align="center" valign="middle" style="border-style:none">
61-
<img class="QR-img" style="height: 60px; width:60px" src="https://img-gzb.oss-cn-shanghai.aliyuncs.com/lala/b3aa01f2a1c00573757d3d42248177bf.jpg" alt="风袖">
60+
<td align="center" valign="middle">
61+
<img class="QR-img" style="height: 60px; width:60px" src="https://raw.githubusercontent.com/zhc525349965/fisher_book/master/app/image/风袖.jpg" alt="风袖">
6262
<p style="font-size:12px;">风袖</p>
6363
</td>
6464
</tr>

build/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ module.exports = {
5959
watch(`${srcDevPath}/*.js`, copy(srcDevPath, examplePath, 'js'));
6060
}
6161
)
62-
};
62+
};

dist/badge/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Component({
6666
break;
6767
case 'limit':
6868
this.setData({
69-
finalCount: Number(this.data.value) > 999 ? `${ Number.isInteger(this.data.value / 1000)? (this.data.value/1000) : (this.data.value/1000).toFixed(1) }k` : this.data.value
69+
finalCount: Number(this.data.value) > 999 ? (Number(this.data.value) >= 9999 ? Math.floor(this.data.value / 10000 * 100) / 100 + `w` : Math.floor(this.data.value / 1000 * 100) / 100 + `k`) : this.data.value
7070
});
7171
break;
7272
default:

dist/behaviors/rules.js

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ export default Behavior({
88
properties: {
99
// 校验
1010
rules: {
11-
type: Object,
11+
type: [Object,Array],
12+
value: []
1213
},
1314
tipType: {
1415
type: String,
15-
value: ''
16+
value:'toast'
1617
}
1718
},
1819
data: {
@@ -26,37 +27,69 @@ export default Behavior({
2627
'toast': 'title',
2728
},
2829
errorText: '',
30+
errors: []
2931
},
3032

3133
methods: {
3234
initRules() {
35+
// const rulesName = this.data.name;
36+
const {
37+
rules
38+
} = this.data;
39+
if (!rules) return;
40+
// 如果rule 是单个object
41+
if(Object.prototype.toString.call(rules) === '[object Object]') {
42+
this.data.rules = [rules];
43+
}
44+
45+
this.data.rules.forEach(item => {
46+
if(!item.trigger) {
47+
item.trigger = [];
48+
return;
49+
}
50+
if(typeof item.trigger === 'string') {
51+
item.trigger = [item.trigger];
52+
return;
53+
}
54+
// if(Object.prototype.toString.call(item.trigger) === '[object Object]') {
55+
// item.trigger = ['blur'];
56+
// return;
57+
// }
58+
})
59+
60+
},
61+
getNeedValidateRule(type) {
3362
const rulesName = this.data.name;
3463
const {
3564
rules
3665
} = this.data;
3766
if (!rules) return;
67+
68+
const list = type ? rules.filter(item => {
69+
return item.trigger.indexOf(type) > -1;
70+
}): rules;
3871
const schema = new Schema({
39-
[rulesName]: this.data.rules,
72+
[rulesName]: list,
4073
});
4174
this.setData({
4275
schema,
4376
});
77+
return list;
4478
},
45-
validatorData({
46-
value
47-
}) {
79+
validatorData(value, type) {
4880
const {
49-
rules,
5081
tipType,
5182
tipFun,
5283
tipContent
5384
} = this.data;
85+
const rules = this.getNeedValidateRule(type);
5486

5587
if (!rules) return;
56-
const validateValue = {
57-
[this.data.name]: value
58-
};
59-
this.data.schema.validate(validateValue, (errors) => {
88+
89+
this.data.schema.validate(value, (errors) => {
90+
this.setData({
91+
errors: errors || []
92+
});
6093

6194
this.triggerEvent('linvalidate', {
6295
errors,
@@ -70,22 +103,23 @@ export default Behavior({
70103
this.setData({
71104
errorText: errors[0].message
72105
});
73-
return;
106+
return errors;
74107
}
75108

76109
if (!wx.lin || !wx.lin[funName]) {
77110
wx.showToast({
78111
icon: 'none',
79112
title: `请在页面内引入${tipType}组件`
80113
});
81-
return;
114+
return errors;
82115
}
83116

84117
wx.lin[funName] && wx.lin[funName]({
85118
[contentName]: errors[0].message,
86119
duration: 1500,
87120
mask: false,
88121
});
122+
return errors;
89123
} else if (!errors && tipType) {
90124
this.setData({
91125
errorText: ''
@@ -96,4 +130,4 @@ export default Behavior({
96130

97131
}
98132
}
99-
});
133+
});

dist/card/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ Component({
1616
type:String,
1717
value:'left'
1818
},
19-
imageMode:{
20-
type:String,
21-
value: 'aspectFit'
22-
},
2319
type: {
2420
type: String,
2521
value: 'primary'

dist/card/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<block wx:if="{{type ==='avatar'}}">
1010
<view class="card-avatar-top">
1111
<view class="card-avatar-left">
12-
<image lazy-load mode="{{imageMode}}" class="l-img-class {{ 'card-img-' + type }}" src='{{image}}'></image>
12+
<image mode="aspectFill" class="l-img-class {{ 'card-img-' + type }}" src='{{image}}'></image>
1313
<view class="card-avatar">
1414
<text class="l-title-class card-title {{'card-title-' + type}}">{{title}}</text>
1515
<text class="describe">{{describe}}</text>

dist/checkbox-group/index.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import eventBus from "../utils/eventBus";
2+
13
Component({
24
behaviors: ['wx://form-field'],
35
externalClasses: ['l-class', 'l-error-text', 'l-error-text-class'],
@@ -40,8 +42,8 @@ Component({
4042

4143
init(target) {
4244
if(this._keys === undefined) this._keys = {};
43-
// if(this._selected === undefined) this._selected = {};
44-
// this.checkDefaultItem(target);
45+
if(this._selected === undefined) this._selected = {};
46+
this.checkDefaultItem(target);
4547
this.checkedKeyRepeat(target);
4648
},
4749

@@ -55,9 +57,9 @@ Component({
5557
},
5658

5759
checkDefaultItem(target) {
58-
const { key, checked } = target.properties;
60+
const { key, checked, cell } = target.properties;
5961
if(checked) {
60-
this._selected[key] = checked;
62+
this._selected[key] = {...cell,checked:true, value: key};
6163
}
6264
},
6365

@@ -74,12 +76,13 @@ Component({
7476
},
7577

7678
onEmitEventHandle(currentItem) {
77-
// currentItem.checked ? this.addSelect(currentItem.key):this.removeSelect(currentItem.key);
79+
currentItem.checked ? this.addSelect (currentItem):this.removeSelect(currentItem.key);
7880

7981
this.triggerEvent('linchange', currentItem, {
8082
bubbles: true,
8183
composed: true
8284
});
85+
eventBus.emit(`lin-form-change-${this.id}`,this.id);
8386
},
8487
onEmitOverflowHandle(data){
8588
this.triggerEvent('linout', data, {
@@ -90,16 +93,21 @@ Component({
9093
removeSelect(key) {
9194
delete this._selected[key];
9295
},
93-
addSelect(key) {
94-
this._selected[key] = key;
96+
addSelect(currentItem) {
97+
let {key, ...obj} = currentItem
98+
this._selected[key] = {...obj, value: key};
9599
},
96-
_selected(){
97-
const items = this.getRelationNodes('../checkbox/index');
98-
let num = 0;
99-
items.map(item=> {
100-
item.properties.checked ? num++ : '';
101-
});
102-
return num;
100+
getValues() {
101+
return Object.values(this._selected)
102+
},
103+
reset() {
104+
this._selected = {}
105+
const list = this.getRelationNodes('../checkbox/index');
106+
return list.forEach(item => {
107+
return item.setData({
108+
checked: false
109+
})
110+
})
103111
}
104112

105113
}

dist/checkbox/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Component({
9898

9999
const limit = parent.properties[type];
100100
if (!limit) return false;
101-
const selectedLength = parent._selected();
101+
const selectedLength = Object.values(parent._selected).length;
102102
let isOverflow = type === 'minSelected' ? selectedLength <= limit : selectedLength >= limit;
103103
if (isOverflow) {
104104
let backType = type === 'minSelected' ? 'min_selected' : 'max_selected';

dist/count-selector/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
value="{{result}}"
1414
bindblur="onBlur"></input>
1515
<view wx:else class="l-count-class count" bindtap="onCount">{{result}}</view>
16-
<view class="symbol {{result>=max|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}"
16+
<view class="l-symbol-class symbol {{result>=max|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}"
1717
catchtap="{{result>=max|| disabled?'doNothing':'addTap'}}"
1818
data-type="overflow_max"
1919
hover-class="count-hover">

dist/counter/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
value="{{result}}"
1414
bindblur="onBlur"></input>
1515
<view wx:else class="l-count-class count" bindtap="onCount">{{result}}</view>
16-
<view class="symbol {{result>=max|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}"
16+
<view class="l-symbol-class symbol {{result>=max|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}"
1717
catchtap="{{result>=max|| disabled?'doNothing':'addTap'}}"
1818
data-type="overflow_max"
1919
hover-class="{{isHover?'count-hover':''}}">

0 commit comments

Comments
 (0)