Commit cd78c9c488698dcb8c669a3e85d2acca597a373f

Authored by 梁灏
1 parent 7778edfa

some comps support dispatch event to FormItem

some comps support dispatch event to FormItem
src/components/cascader/cascader.vue
@@ -162,8 +162,10 @@ @@ -162,8 +162,10 @@
162 emitValue (val, oldVal) { 162 emitValue (val, oldVal) {
163 if (JSON.stringify(val) !== oldVal) { 163 if (JSON.stringify(val) !== oldVal) {
164 this.$emit('on-change', this.currentValue, JSON.parse(JSON.stringify(this.selected))); 164 this.$emit('on-change', this.currentValue, JSON.parse(JSON.stringify(this.selected)));
165 - // todo 事件  
166 -// this.$dispatch('on-form-change', this.currentValue, JSON.parse(JSON.stringify(this.selected))); 165 + this.dispatch('FormItem', 'on-form-change', {
  166 + value: this.currentValue,
  167 + selected: JSON.parse(JSON.stringify(this.selected))
  168 + });
167 } 169 }
168 } 170 }
169 }, 171 },
src/components/checkbox/checkbox-group.vue
@@ -4,10 +4,12 @@ @@ -4,10 +4,12 @@
4 </div> 4 </div>
5 </template> 5 </template>
6 <script> 6 <script>
  7 + import Emitter from '../../mixins/emitter';
7 const prefixCls = 'ivu-checkbox-group'; 8 const prefixCls = 'ivu-checkbox-group';
8 9
9 export default { 10 export default {
10 name: 'CheckboxGroup', 11 name: 'CheckboxGroup',
  12 + mixins: [ Emitter ],
11 props: { 13 props: {
12 value: { 14 value: {
13 type: Array, 15 type: Array,
@@ -46,8 +48,7 @@ @@ -46,8 +48,7 @@
46 this.currentValue = data; 48 this.currentValue = data;
47 this.$emit('input', data); 49 this.$emit('input', data);
48 this.$emit('on-change', data); 50 this.$emit('on-change', data);
49 - // todo 事件  
50 -// this.$dispatch('on-form-change', data); 51 + this.dispatch('FormItem', 'on-form-change', data);
51 } 52 }
52 }, 53 },
53 watch: { 54 watch: {
src/components/checkbox/checkbox.vue
@@ -22,10 +22,13 @@ @@ -22,10 +22,13 @@
22 </label> 22 </label>
23 </template> 23 </template>
24 <script> 24 <script>
  25 + import Emitter from '../../mixins/emitter';
  26 +
25 const prefixCls = 'ivu-checkbox'; 27 const prefixCls = 'ivu-checkbox';
26 28
27 export default { 29 export default {
28 name: 'Checkbox', 30 name: 'Checkbox',
  31 + mixins: [ Emitter ],
29 props: { 32 props: {
30 disabled: { 33 disabled: {
31 type: Boolean, 34 type: Boolean,
@@ -106,8 +109,7 @@ @@ -106,8 +109,7 @@
106 this.$parent.change(this.model); 109 this.$parent.change(this.model);
107 } else { 110 } else {
108 this.$emit('on-change', checked); 111 this.$emit('on-change', checked);
109 - // todo 事件  
110 -// this.$dispatch('on-form-change', checked); 112 + this.dispatch('FormItem', 'on-form-change', checked);
111 } 113 }
112 }, 114 },
113 updateModel () { 115 updateModel () {
src/components/date-picker/picker.vue
@@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
33 import clickoutside from '../../directives/clickoutside'; 33 import clickoutside from '../../directives/clickoutside';
34 import { oneOf } from '../../utils/assist'; 34 import { oneOf } from '../../utils/assist';
35 import { formatDate, parseDate } from './util'; 35 import { formatDate, parseDate } from './util';
  36 + import Emitter from '../../mixins/emitter';
36 37
37 const prefixCls = 'ivu-date-picker'; 38 const prefixCls = 'ivu-date-picker';
38 39
@@ -138,6 +139,7 @@ @@ -138,6 +139,7 @@
138 }; 139 };
139 140
140 export default { 141 export default {
  142 + mixins: [ Emitter ],
141 components: { iInput, Drop }, 143 components: { iInput, Drop },
142 directives: { clickoutside }, 144 directives: { clickoutside },
143 props: { 145 props: {
@@ -363,8 +365,7 @@ @@ -363,8 +365,7 @@
363 this.internalValue = ''; 365 this.internalValue = '';
364 this.currentValue = ''; 366 this.currentValue = '';
365 this.$emit('on-clear'); 367 this.$emit('on-clear');
366 - // todo 事件  
367 -// this.$dispatch('on-form-change', ''); 368 + this.dispatch('FormItem', 'on-form-change', '');
368 }, 369 },
369 showPicker () { 370 showPicker () {
370 if (!this.picker) { 371 if (!this.picker) {
@@ -430,8 +431,7 @@ @@ -430,8 +431,7 @@
430 } 431 }
431 432
432 this.$emit('on-change', newDate); 433 this.$emit('on-change', newDate);
433 - // todo 事件  
434 -// this.$dispatch('on-form-change', newDate); 434 + this.dispatch('FormItem', 'on-form-change', newDate);
435 } 435 }
436 }, 436 },
437 watch: { 437 watch: {
src/components/input-number/input-number.vue
@@ -29,6 +29,7 @@ @@ -29,6 +29,7 @@
29 </template> 29 </template>
30 <script> 30 <script>
31 import { oneOf } from '../../utils/assist'; 31 import { oneOf } from '../../utils/assist';
  32 + import Emitter from '../../mixins/emitter';
32 33
33 const prefixCls = 'ivu-input-number'; 34 const prefixCls = 'ivu-input-number';
34 const iconPrefixCls = 'ivu-icon'; 35 const iconPrefixCls = 'ivu-icon';
@@ -62,6 +63,7 @@ @@ -62,6 +63,7 @@
62 63
63 export default { 64 export default {
64 name: 'InputNumber', 65 name: 'InputNumber',
  66 + mixins: [ Emitter ],
65 props: { 67 props: {
66 max: { 68 max: {
67 type: Number, 69 type: Number,
@@ -201,8 +203,7 @@ @@ -201,8 +203,7 @@
201 this.currentValue = val; 203 this.currentValue = val;
202 this.$emit('input', val); 204 this.$emit('input', val);
203 this.$emit('on-change', val); 205 this.$emit('on-change', val);
204 - // todo 事件  
205 -// this.$dispatch('on-form-change', val); 206 + this.dispatch('FormItem', 'on-form-change', val);
206 }); 207 });
207 }, 208 },
208 focus () { 209 focus () {
src/components/input/input.vue
@@ -45,11 +45,13 @@ @@ -45,11 +45,13 @@
45 <script> 45 <script>
46 import { oneOf } from '../../utils/assist'; 46 import { oneOf } from '../../utils/assist';
47 import calcTextareaHeight from '../../utils/calcTextareaHeight'; 47 import calcTextareaHeight from '../../utils/calcTextareaHeight';
  48 + import Emitter from '../../mixins/emitter';
48 49
49 const prefixCls = 'ivu-input'; 50 const prefixCls = 'ivu-input';
50 51
51 export default { 52 export default {
52 name: 'Input', 53 name: 'Input',
  54 + mixins: [ Emitter ],
53 props: { 55 props: {
54 type: { 56 type: {
55 validator (value) { 57 validator (value) {
@@ -150,8 +152,7 @@ @@ -150,8 +152,7 @@
150 }, 152 },
151 handleBlur () { 153 handleBlur () {
152 this.$emit('on-blur'); 154 this.$emit('on-blur');
153 - // todo 事件  
154 -// this.$dispatch('on-form-blur', this.currentValue); 155 + this.dispatch('FormItem', 'on-form-blur', this.currentValue);
155 }, 156 },
156 handleInput (event) { 157 handleInput (event) {
157 const value = event.target.value; 158 const value = event.target.value;
@@ -168,8 +169,7 @@ @@ -168,8 +169,7 @@
168 this.resizeTextarea(); 169 this.resizeTextarea();
169 }); 170 });
170 this.currentValue = value; 171 this.currentValue = value;
171 - // todo 事件  
172 -// this.$dispatch('on-form-change', value); 172 + this.dispatch('FormItem', 'on-form-change', value);
173 }, 173 },
174 resizeTextarea () { 174 resizeTextarea () {
175 const autosize = this.autosize; 175 const autosize = this.autosize;
src/components/radio/radio-group.vue
@@ -5,11 +5,13 @@ @@ -5,11 +5,13 @@
5 </template> 5 </template>
6 <script> 6 <script>
7 import { oneOf } from '../../utils/assist'; 7 import { oneOf } from '../../utils/assist';
  8 + import Emitter from '../../mixins/emitter';
8 9
9 const prefixCls = 'ivu-radio-group'; 10 const prefixCls = 'ivu-radio-group';
10 11
11 export default { 12 export default {
12 name: 'RadioGroup', 13 name: 'RadioGroup',
  14 + mixins: [ Emitter ],
13 props: { 15 props: {
14 value: { 16 value: {
15 type: [String, Number], 17 type: [String, Number],
@@ -63,8 +65,7 @@ @@ -63,8 +65,7 @@
63 this.updateValue(); 65 this.updateValue();
64 this.$emit('input', data.value); 66 this.$emit('input', data.value);
65 this.$emit('on-change', data.value); 67 this.$emit('on-change', data.value);
66 - // todo 事件  
67 -// this.$dispatch('on-form-change', data.value); 68 + this.dispatch('FormItem', 'on-form-change', data.value);
68 } 69 }
69 }, 70 },
70 watch: { 71 watch: {
src/components/radio/radio.vue
@@ -12,10 +12,13 @@ @@ -12,10 +12,13 @@
12 </label> 12 </label>
13 </template> 13 </template>
14 <script> 14 <script>
  15 + import Emitter from '../../mixins/emitter';
  16 +
15 const prefixCls = 'ivu-radio'; 17 const prefixCls = 'ivu-radio';
16 18
17 export default { 19 export default {
18 name: 'Radio', 20 name: 'Radio',
  21 + mixins: [ Emitter ],
19 props: { 22 props: {
20 value: { 23 value: {
21 type: Boolean, 24 type: Boolean,
@@ -87,8 +90,7 @@ @@ -87,8 +90,7 @@
87 } 90 }
88 if (!this.group) { 91 if (!this.group) {
89 this.$emit('on-change', checked); 92 this.$emit('on-change', checked);
90 - // todo 事件  
91 -// this.$dispatch('on-form-change', checked); 93 + this.dispatch('FormItem', 'on-form-change', checked);
92 } 94 }
93 }, 95 },
94 updateValue () { 96 updateValue () {
src/components/rate/rate.vue
@@ -123,8 +123,7 @@ @@ -123,8 +123,7 @@
123 this.currentValue = value; 123 this.currentValue = value;
124 this.$emit('input', value); 124 this.$emit('input', value);
125 this.$emit('on-change', value); 125 this.$emit('on-change', value);
126 - // @todo  
127 -// this.$dispatch('on-form-change', value); 126 + this.dispatch('FormItem', 'on-form-change', value);
128 } 127 }
129 } 128 }
130 }; 129 };
src/components/select/select.vue
@@ -321,15 +321,13 @@ @@ -321,15 +321,13 @@
321 value: value, 321 value: value,
322 label: label 322 label: label
323 }); 323 });
324 - // todo 事件  
325 -// this.$dispatch('on-form-change', {  
326 -// value: value,  
327 -// label: label  
328 -// }); 324 + this.dispatch('FormItem', 'on-form-change', {
  325 + value: value,
  326 + label: label
  327 + });
329 } else { 328 } else {
330 this.$emit('on-change', value); 329 this.$emit('on-change', value);
331 - // todo 事件  
332 -// this.$dispatch('on-form-change', value); 330 + this.dispatch('FormItem', 'on-form-change', value);
333 } 331 }
334 } 332 }
335 } 333 }
@@ -358,12 +356,10 @@ @@ -358,12 +356,10 @@
358 if (!init) { 356 if (!init) {
359 if (this.labelInValue) { 357 if (this.labelInValue) {
360 this.$emit('on-change', hybridValue); 358 this.$emit('on-change', hybridValue);
361 - // todo 事件  
362 -// this.$dispatch('on-form-change', hybridValue);  
363 -// } else { 359 + this.dispatch('FormItem', 'on-form-change', hybridValue);
  360 + } else {
364 this.$emit('on-change', value); 361 this.$emit('on-change', value);
365 - // todo 事件  
366 -// this.$dispatch('on-form-change', value); 362 + this.dispatch('FormItem', 'on-form-change', value);
367 } 363 }
368 } 364 }
369 } 365 }
src/components/slider/slider.vue
@@ -48,11 +48,13 @@ @@ -48,11 +48,13 @@
48 import InputNumber from '../../components/input-number/input-number.vue'; 48 import InputNumber from '../../components/input-number/input-number.vue';
49 import Tooltip from '../../components/tooltip/tooltip.vue'; 49 import Tooltip from '../../components/tooltip/tooltip.vue';
50 import { getStyle, oneOf } from '../../utils/assist'; 50 import { getStyle, oneOf } from '../../utils/assist';
  51 + import Emitter from '../../mixins/emitter';
51 52
52 const prefixCls = 'ivu-slider'; 53 const prefixCls = 'ivu-slider';
53 54
54 export default { 55 export default {
55 name: 'Slider', 56 name: 'Slider',
  57 + mixins: [ Emitter ],
56 components: { InputNumber, Tooltip }, 58 components: { InputNumber, Tooltip },
57 props: { 59 props: {
58 min: { 60 min: {
@@ -308,8 +310,7 @@ @@ -308,8 +310,7 @@
308 if (!this.dragging) { 310 if (!this.dragging) {
309 if (this.currentValue !== this.oldSingleValue) { 311 if (this.currentValue !== this.oldSingleValue) {
310 this.$emit('on-change', this.currentValue); 312 this.$emit('on-change', this.currentValue);
311 - // todo 事件  
312 -// this.$dispatch('on-form-change', this.currentValue); 313 + this.dispatch('FormItem', 'on-form-change', this.currentValue);
313 this.oldSingleValue = this.currentValue; 314 this.oldSingleValue = this.currentValue;
314 } 315 }
315 } 316 }
@@ -322,8 +323,7 @@ @@ -322,8 +323,7 @@
322 this.currentValue = val; 323 this.currentValue = val;
323 this.setSinglePosition(val); 324 this.setSinglePosition(val);
324 this.$emit('on-change', this.currentValue); 325 this.$emit('on-change', this.currentValue);
325 - // todo 事件  
326 -// this.$dispatch('on-form-change', this.currentValue); 326 + this.dispatch('FormItem', 'on-form-change', this.currentValue);
327 }, 327 },
328 // for range use first 328 // for range use first
329 onFirstButtonDown (event) { 329 onFirstButtonDown (event) {
@@ -366,8 +366,7 @@ @@ -366,8 +366,7 @@
366 if (!this.firstDragging) { 366 if (!this.firstDragging) {
367 if (this.currentValue[0] !== this.oldFirstValue) { 367 if (this.currentValue[0] !== this.oldFirstValue) {
368 this.$emit('on-change', this.currentValue); 368 this.$emit('on-change', this.currentValue);
369 - // todo 事件  
370 -// this.$dispatch('on-form-change', this.currentValue); 369 + this.dispatch('FormItem', 'on-form-change', this.currentValue);
371 this.oldFirstValue = this.currentValue[0]; 370 this.oldFirstValue = this.currentValue[0];
372 } 371 }
373 } 372 }
@@ -417,8 +416,7 @@ @@ -417,8 +416,7 @@
417 if (!this.secondDragging) { 416 if (!this.secondDragging) {
418 if (this.currentValue[1] !== this.oldSecondValue) { 417 if (this.currentValue[1] !== this.oldSecondValue) {
419 this.$emit('on-change', this.currentValue); 418 this.$emit('on-change', this.currentValue);
420 - // todo 事件  
421 -// this.$dispatch('on-form-change', this.currentValue); 419 + this.dispatch('FormItem', 'on-form-change', this.currentValue);
422 this.oldSecondValue = this.currentValue[1]; 420 this.oldSecondValue = this.currentValue[1];
423 } 421 }
424 } 422 }
src/components/switch/switch.vue
@@ -8,11 +8,13 @@ @@ -8,11 +8,13 @@
8 </template> 8 </template>
9 <script> 9 <script>
10 import { oneOf } from '../../utils/assist'; 10 import { oneOf } from '../../utils/assist';
  11 + import Emitter from '../../mixins/emitter';
11 12
12 const prefixCls = 'ivu-switch'; 13 const prefixCls = 'ivu-switch';
13 14
14 export default { 15 export default {
15 name: 'Switch', 16 name: 'Switch',
  17 + mixins: [ Emitter ],
16 props: { 18 props: {
17 value: { 19 value: {
18 type: Boolean, 20 type: Boolean,
@@ -58,8 +60,7 @@ @@ -58,8 +60,7 @@
58 this.currentValue = checked; 60 this.currentValue = checked;
59 this.$emit('input', checked); 61 this.$emit('input', checked);
60 this.$emit('on-change', checked); 62 this.$emit('on-change', checked);
61 - // todo 事件  
62 -// this.$dispatch('on-form-change', this.checked); 63 + this.dispatch('FormItem', 'on-form-change', data.checked);
63 } 64 }
64 }, 65 },
65 watch: { 66 watch: {
src/components/transfer/transfer.vue
@@ -44,10 +44,12 @@ @@ -44,10 +44,12 @@
44 import List from './list.vue'; 44 import List from './list.vue';
45 import Operation from './operation.vue'; 45 import Operation from './operation.vue';
46 import { t } from '../../locale'; 46 import { t } from '../../locale';
  47 + import Emitter from '../../mixins/emitter';
47 48
48 const prefixCls = 'ivu-transfer'; 49 const prefixCls = 'ivu-transfer';
49 50
50 export default { 51 export default {
  52 + mixins: [ Emitter ],
51 render (createElement) { 53 render (createElement) {
52 54
53 function cloneVNode (vnode) { 55 function cloneVNode (vnode) {
@@ -256,8 +258,11 @@ @@ -256,8 +258,11 @@
256 258
257 this.$refs[opposite].toggleSelectAll(false); 259 this.$refs[opposite].toggleSelectAll(false);
258 this.$emit('on-change', newTargetKeys, direction, moveKeys); 260 this.$emit('on-change', newTargetKeys, direction, moveKeys);
259 - // todo 事件  
260 -// this.$dispatch('on-form-change', newTargetKeys, direction, moveKeys); 261 + this.dispatch('FormItem', 'on-form-change', {
  262 + tarketKeys: newTargetKeys,
  263 + direction: direction,
  264 + moveKeys: moveKeys
  265 + });
261 }, 266 },
262 handleLeftCheckedKeysChange (keys) { 267 handleLeftCheckedKeysChange (keys) {
263 this.leftCheckedKeys = keys; 268 this.leftCheckedKeys = keys;
src/components/upload/upload.vue
@@ -27,11 +27,13 @@ @@ -27,11 +27,13 @@
27 import UploadList from './upload-list.vue'; 27 import UploadList from './upload-list.vue';
28 import ajax from './ajax'; 28 import ajax from './ajax';
29 import { oneOf } from '../../utils/assist'; 29 import { oneOf } from '../../utils/assist';
  30 + import Emitter from '../../mixins/emitter';
30 31
31 const prefixCls = 'ivu-upload'; 32 const prefixCls = 'ivu-upload';
32 33
33 export default { 34 export default {
34 name: 'Upload', 35 name: 'Upload',
  36 + mixins: [ Emitter ],
35 components: { UploadList }, 37 components: { UploadList },
36 props: { 38 props: {
37 action: { 39 action: {
@@ -277,8 +279,7 @@ @@ -277,8 +279,7 @@
277 _file.status = 'finished'; 279 _file.status = 'finished';
278 _file.response = res; 280 _file.response = res;
279 281
280 - // todo 事件  
281 -// this.$dispatch('on-form-change', _file); 282 + this.dispatch('FormItem', 'on-form-change', _file);
282 this.onSuccess(res, _file, this.fileList); 283 this.onSuccess(res, _file, this.fileList);
283 284
284 setTimeout(() => { 285 setTimeout(() => {