1
1
import eventBus from '../core/utils/event-bus.js' ;
2
+ import eventUtil from '../core/utils/event-util' ;
2
3
Component ( {
3
4
/**
4
5
* 组件的属性列表
@@ -10,12 +11,12 @@ Component({
10
11
relations : {
11
12
'../form-item/index' : {
12
13
type : 'child' ,
13
- linked : function ( target ) {
14
+ linked : function ( target ) {
14
15
this . _initItem ( target ) ;
15
16
} ,
16
- linkChanged : function ( ) {
17
+ linkChanged : function ( ) {
17
18
} ,
18
- unlinked : function ( ) {
19
+ unlinked : function ( ) {
19
20
}
20
21
}
21
22
} ,
@@ -35,7 +36,7 @@ Component({
35
36
this . _init ( ) ;
36
37
} ,
37
38
detached ( ) {
38
- for ( let key in this . _keys ) {
39
+ for ( let key in this . _keys ) {
39
40
if ( Object . prototype . hasOwnProperty . call ( this . _keys , key ) ) {
40
41
eventBus . off ( `lin-form-blur-${ key } ` ) ;
41
42
eventBus . off ( `lin-form-change-${ key } ` ) ;
@@ -83,11 +84,11 @@ Component({
83
84
} ) ;
84
85
eventBus . on ( `lin-form-change-${ key } ` , ( id ) => {
85
86
clearTimeout ( this . change_time ) ;
86
- this . change_time = setTimeout ( ( ) => {
87
+ this . change_time = setTimeout ( ( ) => {
87
88
this . _validateItem ( id , 'change' ) ;
88
89
} , 200 ) ;
89
90
} ) ;
90
- if ( this . _keys [ key ] ) {
91
+ if ( this . _keys [ key ] ) {
91
92
throw new Error ( `表单项存在重复的name:${ key } ` ) ;
92
93
}
93
94
this . _keys [ key ] = '' ;
@@ -100,9 +101,9 @@ Component({
100
101
let params = this . _getValues ( ) ;
101
102
102
103
const items = this . getRelationNodes ( '../form-item/index' ) ;
103
- const currentTarget = items . find ( item => item . properties . name === id ) ;
104
+ const currentTarget = items . find ( item => item . properties . name === id ) ;
104
105
const formItem = _this . selectComponent ( `#${ id } ` ) ;
105
- if ( formItem ) {
106
+ if ( formItem ) {
106
107
currentTarget . validatorData ( params , type ) ;
107
108
} else {
108
109
throw new Error ( `表单项不存在name:${ id } ` ) ;
@@ -129,7 +130,7 @@ Component({
129
130
this . _forEachNodes ( item => {
130
131
const id = item . properties . name ;
131
132
const formItem = _this . selectComponent ( `#${ id } ` ) ;
132
- if ( formItem ) {
133
+ if ( formItem ) {
133
134
item . validatorData ( params ) ;
134
135
} else {
135
136
throw new Error ( `表单项不存在name:${ id } ` ) ;
@@ -147,18 +148,18 @@ Component({
147
148
this . _forEachNodes ( item => {
148
149
const _id = item . properties . name ;
149
150
const formItem = _this . selectComponent ( `#${ _id } ` ) ;
150
- if ( formItem ) {
151
+ if ( formItem ) {
151
152
params [ _id ] = formItem . getValues ( ) ;
152
153
}
153
154
} ) ;
154
155
return params ;
155
156
} ,
156
157
157
158
submit ( ) {
158
- let errors = this . data . isSubmitValidate ? this . _validateForm ( ) : [ ] ;
159
+ let errors = this . data . isSubmitValidate ? this . _validateForm ( ) : [ ] ;
159
160
this . triggerEvent ( 'linsubmit' , {
160
161
values : this . _getValues ( ) ,
161
- errors : this . data . isSubmitValidate ? this . _errors : { } ,
162
+ errors : this . data . isSubmitValidate ? this . _errors : { } ,
162
163
isValidate : errors . length === 0
163
164
} ) ;
164
165
} ,
@@ -170,10 +171,11 @@ Component({
170
171
} ) ;
171
172
const _id = item . properties . name ;
172
173
const formItem = _this . selectComponent ( `#${ _id } ` ) ;
173
- if ( formItem ) {
174
+ if ( formItem ) {
174
175
formItem . reset ( ) ;
175
176
}
176
177
} ) ;
178
+ eventUtil . emit ( this , 'linreset' ) ;
177
179
}
178
180
}
179
181
} ) ;
0 commit comments