Compare View
Commits (4)
Showing
1 changed file
Show diff stats
src/components/select/select.vue
@@ -266,6 +266,7 @@ | @@ -266,6 +266,7 @@ | ||
266 | } | 266 | } |
267 | 267 | ||
268 | this.checkUpdateStatus(); | 268 | this.checkUpdateStatus(); |
269 | + | ||
269 | }, | 270 | }, |
270 | data () { | 271 | data () { |
271 | 272 | ||
@@ -347,11 +348,13 @@ | @@ -347,11 +348,13 @@ | ||
347 | return selectOptions && selectOptions.length === 0 && (!remote || (remote && !loading)); | 348 | return selectOptions && selectOptions.length === 0 && (!remote || (remote && !loading)); |
348 | }, | 349 | }, |
349 | publicValue(){ | 350 | publicValue(){ |
350 | - if (this.labelInValue){ | ||
351 | - return this.multiple ? this.values : this.values[0]; | ||
352 | - } else { | 351 | + // 改变 labelInValue 实现,解决 bug:Select,label-in-value时,搜索、多选,先选一个,再选第二个,会替代第一个 |
352 | + // if (this.labelInValue){ | ||
353 | + // return this.multiple ? this.values : this.values[0]; | ||
354 | + // } else { | ||
355 | + // return this.multiple ? this.values.map(option => option.value) : (this.values[0] || {}).value; | ||
356 | + // } | ||
353 | return this.multiple ? this.values.map(option => option.value) : (this.values[0] || {}).value; | 357 | return this.multiple ? this.values.map(option => option.value) : (this.values[0] || {}).value; |
354 | - } | ||
355 | }, | 358 | }, |
356 | canBeCleared(){ | 359 | canBeCleared(){ |
357 | const uiStateMatch = this.hasMouseHoverHead || this.active; | 360 | const uiStateMatch = this.hasMouseHoverHead || this.active; |
@@ -442,6 +445,8 @@ | @@ -442,6 +445,8 @@ | ||
442 | } | 445 | } |
443 | }, | 446 | }, |
444 | clearSingleSelect(){ // PUBLIC API | 447 | clearSingleSelect(){ // PUBLIC API |
448 | + // fix #446 | ||
449 | + if (!this.multiple) this.$emit('input', ''); | ||
445 | this.$emit('on-clear'); | 450 | this.$emit('on-clear'); |
446 | this.hideMenu(); | 451 | this.hideMenu(); |
447 | if (this.clearable) this.reset(); | 452 | if (this.clearable) this.reset(); |
@@ -450,9 +455,12 @@ | @@ -450,9 +455,12 @@ | ||
450 | const option = this.flatOptions.find(({componentOptions}) => componentOptions.propsData.value === value); | 455 | const option = this.flatOptions.find(({componentOptions}) => componentOptions.propsData.value === value); |
451 | if (!option) return null; | 456 | if (!option) return null; |
452 | const label = getOptionLabel(option); | 457 | const label = getOptionLabel(option); |
458 | + // 修复多选时,选项有disabled属性,选中项仍然能删除的 bug | ||
459 | + const disabled = option.componentOptions.propsData.disabled; | ||
453 | return { | 460 | return { |
454 | value: value, | 461 | value: value, |
455 | label: label, | 462 | label: label, |
463 | + disabled: disabled | ||
456 | }; | 464 | }; |
457 | }, | 465 | }, |
458 | getInitialValue(){ | 466 | getInitialValue(){ |
@@ -708,21 +716,36 @@ | @@ -708,21 +716,36 @@ | ||
708 | if (value === '') this.values = []; | 716 | if (value === '') this.values = []; |
709 | else if (checkValuesNotEqual(value,publicValue,values)) { | 717 | else if (checkValuesNotEqual(value,publicValue,values)) { |
710 | this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean)); | 718 | this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean)); |
711 | - this.dispatch('FormItem', 'on-form-change', this.publicValue); | 719 | + if (!this.multiple) this.dispatch('FormItem', 'on-form-change', this.publicValue); |
712 | } | 720 | } |
713 | }, | 721 | }, |
714 | values(now, before){ | 722 | values(now, before){ |
715 | const newValue = JSON.stringify(now); | 723 | const newValue = JSON.stringify(now); |
716 | const oldValue = JSON.stringify(before); | 724 | const oldValue = JSON.stringify(before); |
717 | // v-model is always just the value, event with labelInValue === true | 725 | // v-model is always just the value, event with labelInValue === true |
718 | - const vModelValue = (this.publicValue && this.labelInValue) ? | ||
719 | - (this.multiple ? this.publicValue.map(({value}) => value) : this.publicValue.value) : | ||
720 | - this.publicValue; | 726 | + // const vModelValue = (this.publicValue && this.labelInValue === false) ? |
727 | + // (this.multiple ? this.publicValue.map(({value}) => value) : this.publicValue.value) : | ||
728 | + // this.publicValue; | ||
729 | + // 改变 labelInValue 的实现:直接在 emit 时改数据 | ||
730 | + let vModelValue = this.publicValue; | ||
721 | const shouldEmitInput = newValue !== oldValue && vModelValue !== this.value; | 731 | const shouldEmitInput = newValue !== oldValue && vModelValue !== this.value; |
722 | if (shouldEmitInput) { | 732 | if (shouldEmitInput) { |
733 | + let emitValue = this.publicValue; | ||
734 | + if (this.labelInValue) { | ||
735 | + if (this.multiple) { | ||
736 | + emitValue = this.values; | ||
737 | + } else { | ||
738 | + emitValue = this.values[0]; | ||
739 | + } | ||
740 | + } | ||
741 | + | ||
742 | + // Form 重置时,如果初始值是 null,也置为 null,而不是 [] | ||
743 | + if (Array.isArray(vModelValue) && !vModelValue.length && this.value === null) vModelValue = null; | ||
744 | + else if (vModelValue === undefined && this.value === null) vModelValue = null; | ||
745 | + | ||
723 | this.$emit('input', vModelValue); // to update v-model | 746 | this.$emit('input', vModelValue); // to update v-model |
724 | - this.$emit('on-change', this.publicValue); | ||
725 | - this.dispatch('FormItem', 'on-form-change', this.publicValue); | 747 | + this.$emit('on-change', emitValue); |
748 | + this.dispatch('FormItem', 'on-form-change', emitValue); | ||
726 | } | 749 | } |
727 | }, | 750 | }, |
728 | query (query) { | 751 | query (query) { |