Commit b953cb71cc4ee6123a441467d9bd5047f08ba292

Authored by FEI
1 parent 30c1b9d3

bug fix

Showing 1 changed file with 32 additions and 26 deletions   Show diff stats
src/components/select/select.vue
@@ -267,22 +267,6 @@ @@ -267,22 +267,6 @@
267 267
268 this.checkUpdateStatus(); 268 this.checkUpdateStatus();
269 269
270 - // remote search, set instanceof  
271 - if (this.remote && this.value && this.initialLabel) {  
272 - if (!this.multiple) {  
273 - this.query = this.initialLabel;  
274 - } else if (this.multiple && (this.initialLabel instanceof Array) && this.value.length === this.initialLabel.length) {  
275 - const values = this.value.map((item, index) => {  
276 - return {  
277 - value: item,  
278 - label: this.initialLabel[index]  
279 - };  
280 - });  
281 - setTimeout(() => {  
282 - this.values = values;  
283 - });  
284 - }  
285 - }  
286 }, 270 },
287 data () { 271 data () {
288 272
@@ -364,11 +348,13 @@ @@ -364,11 +348,13 @@
364 return selectOptions && selectOptions.length === 0 && (!remote || (remote && !loading)); 348 return selectOptions && selectOptions.length === 0 && (!remote || (remote && !loading));
365 }, 349 },
366 publicValue(){ 350 publicValue(){
367 - if (this.labelInValue){  
368 - return this.multiple ? this.values : this.values[0];  
369 - } 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 + // }
370 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;
371 - }  
372 }, 358 },
373 canBeCleared(){ 359 canBeCleared(){
374 const uiStateMatch = this.hasMouseHoverHead || this.active; 360 const uiStateMatch = this.hasMouseHoverHead || this.active;
@@ -459,6 +445,8 @@ @@ -459,6 +445,8 @@
459 } 445 }
460 }, 446 },
461 clearSingleSelect(){ // PUBLIC API 447 clearSingleSelect(){ // PUBLIC API
  448 + // fix #446
  449 + if (!this.multiple) this.$emit('input', '');
462 this.$emit('on-clear'); 450 this.$emit('on-clear');
463 this.hideMenu(); 451 this.hideMenu();
464 if (this.clearable) this.reset(); 452 if (this.clearable) this.reset();
@@ -467,9 +455,12 @@ @@ -467,9 +455,12 @@
467 const option = this.flatOptions.find(({componentOptions}) => componentOptions.propsData.value === value); 455 const option = this.flatOptions.find(({componentOptions}) => componentOptions.propsData.value === value);
468 if (!option) return null; 456 if (!option) return null;
469 const label = getOptionLabel(option); 457 const label = getOptionLabel(option);
  458 + // 修复多选时,选项有disabled属性,选中项仍然能删除的 bug
  459 + const disabled = option.componentOptions.propsData.disabled;
470 return { 460 return {
471 value: value, 461 value: value,
472 label: label, 462 label: label,
  463 + disabled: disabled
473 }; 464 };
474 }, 465 },
475 getInitialValue(){ 466 getInitialValue(){
@@ -725,21 +716,36 @@ @@ -725,21 +716,36 @@
725 if (value === '') this.values = []; 716 if (value === '') this.values = [];
726 else if (checkValuesNotEqual(value,publicValue,values)) { 717 else if (checkValuesNotEqual(value,publicValue,values)) {
727 this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean)); 718 this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean));
728 - this.dispatch('FormItem', 'on-form-change', this.publicValue); 719 + if (!this.multiple) this.dispatch('FormItem', 'on-form-change', this.publicValue);
729 } 720 }
730 }, 721 },
731 values(now, before){ 722 values(now, before){
732 const newValue = JSON.stringify(now); 723 const newValue = JSON.stringify(now);
733 const oldValue = JSON.stringify(before); 724 const oldValue = JSON.stringify(before);
734 // v-model is always just the value, event with labelInValue === true 725 // v-model is always just the value, event with labelInValue === true
735 - const vModelValue = (this.publicValue && this.labelInValue) ?  
736 - (this.multiple ? this.publicValue.map(({value}) => value) : this.publicValue.value) :  
737 - 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;
738 const shouldEmitInput = newValue !== oldValue && vModelValue !== this.value; 731 const shouldEmitInput = newValue !== oldValue && vModelValue !== this.value;
739 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 +
740 this.$emit('input', vModelValue); // to update v-model 746 this.$emit('input', vModelValue); // to update v-model
741 - this.$emit('on-change', this.publicValue);  
742 - this.dispatch('FormItem', 'on-form-change', this.publicValue); 747 + this.$emit('on-change', emitValue);
  748 + this.dispatch('FormItem', 'on-form-change', emitValue);
743 } 749 }
744 }, 750 },
745 query (query) { 751 query (query) {