Compare View
Commits (4)
Showing
1 changed file
Show diff stats
src/components/select/select.vue
... | ... | @@ -266,6 +266,7 @@ |
266 | 266 | } |
267 | 267 | |
268 | 268 | this.checkUpdateStatus(); |
269 | + | |
269 | 270 | }, |
270 | 271 | data () { |
271 | 272 | |
... | ... | @@ -347,11 +348,13 @@ |
347 | 348 | return selectOptions && selectOptions.length === 0 && (!remote || (remote && !loading)); |
348 | 349 | }, |
349 | 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 | 357 | return this.multiple ? this.values.map(option => option.value) : (this.values[0] || {}).value; |
354 | - } | |
355 | 358 | }, |
356 | 359 | canBeCleared(){ |
357 | 360 | const uiStateMatch = this.hasMouseHoverHead || this.active; |
... | ... | @@ -442,6 +445,8 @@ |
442 | 445 | } |
443 | 446 | }, |
444 | 447 | clearSingleSelect(){ // PUBLIC API |
448 | + // fix #446 | |
449 | + if (!this.multiple) this.$emit('input', ''); | |
445 | 450 | this.$emit('on-clear'); |
446 | 451 | this.hideMenu(); |
447 | 452 | if (this.clearable) this.reset(); |
... | ... | @@ -450,9 +455,12 @@ |
450 | 455 | const option = this.flatOptions.find(({componentOptions}) => componentOptions.propsData.value === value); |
451 | 456 | if (!option) return null; |
452 | 457 | const label = getOptionLabel(option); |
458 | + // 修复多选时,选项有disabled属性,选中项仍然能删除的 bug | |
459 | + const disabled = option.componentOptions.propsData.disabled; | |
453 | 460 | return { |
454 | 461 | value: value, |
455 | 462 | label: label, |
463 | + disabled: disabled | |
456 | 464 | }; |
457 | 465 | }, |
458 | 466 | getInitialValue(){ |
... | ... | @@ -708,21 +716,36 @@ |
708 | 716 | if (value === '') this.values = []; |
709 | 717 | else if (checkValuesNotEqual(value,publicValue,values)) { |
710 | 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 | 722 | values(now, before){ |
715 | 723 | const newValue = JSON.stringify(now); |
716 | 724 | const oldValue = JSON.stringify(before); |
717 | 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 | 731 | const shouldEmitInput = newValue !== oldValue && vModelValue !== this.value; |
722 | 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 | 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 | 751 | query (query) { | ... | ... |