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() {
|
handleClear() {
|
||||||
this.minDate = null;
|
this.minDate = null;
|
||||||
this.maxDate = null;
|
this.maxDate = null;
|
||||||
this.handleConfirm();
|
this.handleConfirm(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleDateInput(event, type) {
|
handleDateInput(event, type) {
|
||||||
|
@ -376,10 +376,8 @@
|
||||||
this.maxDate = val.maxDate;
|
this.maxDate = val.maxDate;
|
||||||
this.minDate = val.minDate;
|
this.minDate = val.minDate;
|
||||||
|
|
||||||
if (!close) return;
|
if (!close || this.showTime) return;
|
||||||
if (!this.showTime) {
|
this.handleConfirm();
|
||||||
this.$emit('pick', [this.minDate, this.maxDate]);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
changeToToday() {
|
changeToToday() {
|
||||||
|
@ -456,7 +454,7 @@
|
||||||
this.resetDate();
|
this.resetDate();
|
||||||
},
|
},
|
||||||
|
|
||||||
handleConfirm(visible) {
|
handleConfirm(visible = false) {
|
||||||
this.$emit('pick', [this.minDate, this.maxDate], visible);
|
this.$emit('pick', [this.minDate, this.maxDate], visible);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,7 @@
|
||||||
methods: {
|
methods: {
|
||||||
handleClear() {
|
handleClear() {
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
this.$emit('pick', '');
|
this.$emit('pick');
|
||||||
},
|
},
|
||||||
|
|
||||||
resetDate() {
|
resetDate() {
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
handleClear() {
|
handleClear() {
|
||||||
this.$emit('pick', '');
|
this.$emit('pick');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
handleClear() {
|
handleClear() {
|
||||||
this.$emit('pick', '');
|
this.$emit('pick');
|
||||||
},
|
},
|
||||||
|
|
||||||
handleCancel() {
|
handleCancel() {
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<script>
|
<script>
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Clickoutside from 'element-ui/src/utils/clickoutside';
|
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 Popper from 'element-ui/src/utils/vue-popper';
|
||||||
import Emitter from 'element-ui/src/mixins/emitter';
|
import Emitter from 'element-ui/src/mixins/emitter';
|
||||||
import ElInput from 'element-ui/packages/input';
|
import ElInput from 'element-ui/packages/input';
|
||||||
|
@ -304,10 +304,13 @@ export default {
|
||||||
|
|
||||||
if (parsedValue && this.picker) {
|
if (parsedValue && this.picker) {
|
||||||
this.picker.value = parsedValue;
|
this.picker.value = parsedValue;
|
||||||
|
} else {
|
||||||
|
this.$forceUpdate();
|
||||||
}
|
}
|
||||||
return;
|
} else {
|
||||||
|
this.picker.value = value;
|
||||||
|
this.$forceUpdate();
|
||||||
}
|
}
|
||||||
this.picker.value = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -335,10 +338,25 @@ export default {
|
||||||
this.pickerVisible = !this.pickerVisible;
|
this.pickerVisible = !this.pickerVisible;
|
||||||
} else {
|
} else {
|
||||||
this.internalValue = '';
|
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() {
|
handleClose() {
|
||||||
this.pickerVisible = false;
|
this.pickerVisible = false;
|
||||||
},
|
},
|
||||||
|
@ -418,7 +436,7 @@ export default {
|
||||||
|
|
||||||
this.picker.$on('dodestroy', this.doDestroy);
|
this.picker.$on('dodestroy', this.doDestroy);
|
||||||
this.picker.$on('pick', (date, visible = false) => {
|
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.pickerVisible = this.picker.visible = visible;
|
||||||
this.picker.resetView && this.picker.resetView();
|
this.picker.resetView && this.picker.resetView();
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,6 +8,10 @@ const newArray = function(start, end) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const equalDate = function(dateA, dateB) {
|
||||||
|
return new Date(dateA).getTime() === new Date(dateB).getTime();
|
||||||
|
};
|
||||||
|
|
||||||
export const toDate = function(date) {
|
export const toDate = function(date) {
|
||||||
date = new Date(date);
|
date = new Date(date);
|
||||||
if (isNaN(date.getTime())) return null;
|
if (isNaN(date.getTime())) return null;
|
||||||
|
|
Loading…
Reference in New Issue