mirror of https://github.com/ElemeFE/element
				
				
				
			DatePicker: input event is not fired when the array value is not updated, fixed #1834
							parent
							
								
									6f75ca6150
								
							
						
					
					
						commit
						a951921916
					
				| 
						 | 
				
			
			@ -293,7 +293,7 @@
 | 
			
		|||
      handleClear() {
 | 
			
		||||
        this.minDate = null;
 | 
			
		||||
        this.maxDate = null;
 | 
			
		||||
        this.handleConfirm();
 | 
			
		||||
        this.handleConfirm(false);
 | 
			
		||||
      },
 | 
			
		||||
 | 
			
		||||
      handleDateInput(event, type) {
 | 
			
		||||
| 
						 | 
				
			
			@ -376,10 +376,8 @@
 | 
			
		|||
        this.maxDate = val.maxDate;
 | 
			
		||||
        this.minDate = val.minDate;
 | 
			
		||||
 | 
			
		||||
        if (!close) return;
 | 
			
		||||
        if (!this.showTime) {
 | 
			
		||||
          this.$emit('pick', [this.minDate, this.maxDate]);
 | 
			
		||||
        }
 | 
			
		||||
        if (!close || this.showTime) return;
 | 
			
		||||
        this.handleConfirm();
 | 
			
		||||
      },
 | 
			
		||||
 | 
			
		||||
      changeToToday() {
 | 
			
		||||
| 
						 | 
				
			
			@ -456,7 +454,7 @@
 | 
			
		|||
        this.resetDate();
 | 
			
		||||
      },
 | 
			
		||||
 | 
			
		||||
      handleConfirm(visible) {
 | 
			
		||||
      handleConfirm(visible = false) {
 | 
			
		||||
        this.$emit('pick', [this.minDate, this.maxDate], visible);
 | 
			
		||||
      },
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -189,7 +189,7 @@
 | 
			
		|||
    methods: {
 | 
			
		||||
      handleClear() {
 | 
			
		||||
        this.date = new Date();
 | 
			
		||||
        this.$emit('pick', '');
 | 
			
		||||
        this.$emit('pick');
 | 
			
		||||
      },
 | 
			
		||||
 | 
			
		||||
      resetDate() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -85,7 +85,7 @@
 | 
			
		|||
      },
 | 
			
		||||
 | 
			
		||||
      handleClear() {
 | 
			
		||||
        this.$emit('pick', '');
 | 
			
		||||
        this.$emit('pick');
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -104,7 +104,7 @@
 | 
			
		|||
 | 
			
		||||
    methods: {
 | 
			
		||||
      handleClear() {
 | 
			
		||||
        this.$emit('pick', '');
 | 
			
		||||
        this.$emit('pick');
 | 
			
		||||
      },
 | 
			
		||||
 | 
			
		||||
      handleCancel() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,7 +26,7 @@
 | 
			
		|||
<script>
 | 
			
		||||
import Vue from 'vue';
 | 
			
		||||
import Clickoutside from 'element-ui/src/utils/clickoutside';
 | 
			
		||||
import { formatDate, parseDate, getWeekNumber } from './util';
 | 
			
		||||
import { formatDate, parseDate, getWeekNumber, equalDate } from './util';
 | 
			
		||||
import Popper from 'element-ui/src/utils/vue-popper';
 | 
			
		||||
import Emitter from 'element-ui/src/mixins/emitter';
 | 
			
		||||
import ElInput from 'element-ui/packages/input';
 | 
			
		||||
| 
						 | 
				
			
			@ -304,10 +304,13 @@ export default {
 | 
			
		|||
 | 
			
		||||
          if (parsedValue && this.picker) {
 | 
			
		||||
            this.picker.value = parsedValue;
 | 
			
		||||
          } else {
 | 
			
		||||
            this.$forceUpdate();
 | 
			
		||||
          }
 | 
			
		||||
          return;
 | 
			
		||||
        }
 | 
			
		||||
        } else {
 | 
			
		||||
          this.picker.value = value;
 | 
			
		||||
          this.$forceUpdate();
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
| 
						 | 
				
			
			@ -335,10 +338,25 @@ export default {
 | 
			
		|||
        this.pickerVisible = !this.pickerVisible;
 | 
			
		||||
      } else {
 | 
			
		||||
        this.internalValue = '';
 | 
			
		||||
        this.$emit('input', '');
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    dateIsUpdated(date) {
 | 
			
		||||
      let updated = true;
 | 
			
		||||
 | 
			
		||||
      if (Array.isArray(date)) {
 | 
			
		||||
        if (equalDate(this.cacheDateMin, date[0]) &&
 | 
			
		||||
          equalDate(this.cacheDateMax, date[1])) updated = false;
 | 
			
		||||
        this.cacheDateMin = date[0];
 | 
			
		||||
        this.cacheDateMax = date[1];
 | 
			
		||||
      } else {
 | 
			
		||||
        if (equalDate(this.cacheDate, date)) updated = false;
 | 
			
		||||
        this.cacheDate = date;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return updated;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    handleClose() {
 | 
			
		||||
      this.pickerVisible = false;
 | 
			
		||||
    },
 | 
			
		||||
| 
						 | 
				
			
			@ -418,7 +436,7 @@ export default {
 | 
			
		|||
 | 
			
		||||
        this.picker.$on('dodestroy', this.doDestroy);
 | 
			
		||||
        this.picker.$on('pick', (date, visible = false) => {
 | 
			
		||||
          this.$emit('input', date);
 | 
			
		||||
          if (this.dateIsUpdated(date)) this.$emit('input', date);
 | 
			
		||||
          this.pickerVisible = this.picker.visible = visible;
 | 
			
		||||
          this.picker.resetView && this.picker.resetView();
 | 
			
		||||
        });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,10 @@ const newArray = function(start, end) {
 | 
			
		|||
  return result;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const equalDate = function(dateA, dateB) {
 | 
			
		||||
  return new Date(dateA).getTime() === new Date(dateB).getTime();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const toDate = function(date) {
 | 
			
		||||
  date = new Date(date);
 | 
			
		||||
  if (isNaN(date.getTime())) return null;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue