|
@@ -2,7 +2,7 @@
|
|
<el-input
|
|
<el-input
|
|
class="el-date-editor"
|
|
class="el-date-editor"
|
|
:class="'el-date-editor--' + type"
|
|
:class="'el-date-editor--' + type"
|
|
- :readonly="!editable || readonly"
|
|
|
|
|
|
+ :readonly="!editable || readonly || type === 'dates'"
|
|
:disabled="pickerDisabled"
|
|
:disabled="pickerDisabled"
|
|
:size="pickerSize"
|
|
:size="pickerSize"
|
|
:name="name"
|
|
:name="name"
|
|
@@ -123,7 +123,8 @@ const HAVE_TRIGGER_TYPES = [
|
|
'year',
|
|
'year',
|
|
'daterange',
|
|
'daterange',
|
|
'timerange',
|
|
'timerange',
|
|
- 'datetimerange'
|
|
|
|
|
|
+ 'datetimerange',
|
|
|
|
+ 'dates'
|
|
];
|
|
];
|
|
const DATE_FORMATTER = function(value, format) {
|
|
const DATE_FORMATTER = function(value, format) {
|
|
if (format === 'timestamp') return value.getTime();
|
|
if (format === 'timestamp') return value.getTime();
|
|
@@ -242,6 +243,15 @@ const TYPE_VALUE_RESOLVER_MAP = {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+ dates: {
|
|
|
|
+ formatter(value, format) {
|
|
|
|
+ return value.map(date => DATE_FORMATTER(date, format));
|
|
|
|
+ },
|
|
|
|
+ parser(value, format) {
|
|
|
|
+ return (typeof value === 'string' ? value.split(', ') : value)
|
|
|
|
+ .map(date => date instanceof Date ? date : DATE_PARSER(date, format));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
};
|
|
};
|
|
const PLACEMENT_MAP = {
|
|
const PLACEMENT_MAP = {
|
|
@@ -275,8 +285,10 @@ const valueEquals = function(a, b) {
|
|
const aIsArray = a instanceof Array;
|
|
const aIsArray = a instanceof Array;
|
|
const bIsArray = b instanceof Array;
|
|
const bIsArray = b instanceof Array;
|
|
if (aIsArray && bIsArray) {
|
|
if (aIsArray && bIsArray) {
|
|
- return new Date(a[0]).getTime() === new Date(b[0]).getTime() &&
|
|
|
|
- new Date(a[1]).getTime() === new Date(b[1]).getTime();
|
|
|
|
|
|
+ if (a.length !== b.length) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return a.every((item, index) => new Date(item).getTime() === new Date(b[index]).getTime());
|
|
}
|
|
}
|
|
if (!aIsArray && !bIsArray) {
|
|
if (!aIsArray && !bIsArray) {
|
|
return new Date(a).getTime() === new Date(b).getTime();
|
|
return new Date(a).getTime() === new Date(b).getTime();
|
|
@@ -374,7 +386,7 @@ export default {
|
|
if (this.readonly || this.pickerDisabled) return;
|
|
if (this.readonly || this.pickerDisabled) return;
|
|
if (val) {
|
|
if (val) {
|
|
this.showPicker();
|
|
this.showPicker();
|
|
- this.valueOnOpen = this.value;
|
|
|
|
|
|
+ this.valueOnOpen = Array.isArray(this.value) ? [...this.value] : this.value;
|
|
} else {
|
|
} else {
|
|
this.hidePicker();
|
|
this.hidePicker();
|
|
this.emitChange(this.value);
|
|
this.emitChange(this.value);
|
|
@@ -394,6 +406,7 @@ export default {
|
|
handler(val) {
|
|
handler(val) {
|
|
if (this.picker) {
|
|
if (this.picker) {
|
|
this.picker.value = val;
|
|
this.picker.value = val;
|
|
|
|
+ this.picker.selectedDate = Array.isArray(val) ? val : [];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -449,6 +462,8 @@ export default {
|
|
return 'month';
|
|
return 'month';
|
|
} else if (this.type === 'year') {
|
|
} else if (this.type === 'year') {
|
|
return 'year';
|
|
return 'year';
|
|
|
|
+ } else if (this.type === 'dates') {
|
|
|
|
+ return 'dates';
|
|
}
|
|
}
|
|
|
|
|
|
return 'day';
|
|
return 'day';
|
|
@@ -468,8 +483,14 @@ export default {
|
|
this.userInput[0] || (formattedValue && formattedValue[0]) || '',
|
|
this.userInput[0] || (formattedValue && formattedValue[0]) || '',
|
|
this.userInput[1] || (formattedValue && formattedValue[1]) || ''
|
|
this.userInput[1] || (formattedValue && formattedValue[1]) || ''
|
|
];
|
|
];
|
|
|
|
+ } else if (this.userInput !== null) {
|
|
|
|
+ return this.userInput;
|
|
|
|
+ } else if (formattedValue) {
|
|
|
|
+ return this.type === 'dates'
|
|
|
|
+ ? formattedValue.join(', ')
|
|
|
|
+ : formattedValue;
|
|
} else {
|
|
} else {
|
|
- return this.userInput !== null ? this.userInput : formattedValue || '';
|
|
|
|
|
|
+ return '';
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -655,7 +676,18 @@ export default {
|
|
},
|
|
},
|
|
|
|
|
|
handleClose() {
|
|
handleClose() {
|
|
|
|
+ if (!this.pickerVisible) return;
|
|
this.pickerVisible = false;
|
|
this.pickerVisible = false;
|
|
|
|
+ const {
|
|
|
|
+ type,
|
|
|
|
+ valueOnOpen,
|
|
|
|
+ valueFormat,
|
|
|
|
+ rangeSeparator
|
|
|
|
+ } = this;
|
|
|
|
+ if (type === 'dates' && this.picker) {
|
|
|
|
+ this.picker.selectedDate = parseAsFormatAndType(valueOnOpen, valueFormat, type, rangeSeparator) || valueOnOpen;
|
|
|
|
+ this.emitInput(this.picker.selectedDate);
|
|
|
|
+ }
|
|
},
|
|
},
|
|
|
|
|
|
handleFieldReset(initialValue) {
|
|
handleFieldReset(initialValue) {
|
|
@@ -769,6 +801,7 @@ export default {
|
|
this.picker.selectionMode = this.selectionMode;
|
|
this.picker.selectionMode = this.selectionMode;
|
|
this.picker.unlinkPanels = this.unlinkPanels;
|
|
this.picker.unlinkPanels = this.unlinkPanels;
|
|
this.picker.arrowControl = this.arrowControl || this.timeArrowControl || false;
|
|
this.picker.arrowControl = this.arrowControl || this.timeArrowControl || false;
|
|
|
|
+ this.picker.selectedDate = Array.isArray(this.value) && this.value || [];
|
|
this.$watch('format', (format) => {
|
|
this.$watch('format', (format) => {
|
|
this.picker.format = format;
|
|
this.picker.format = format;
|
|
});
|
|
});
|
|
@@ -846,7 +879,7 @@ export default {
|
|
|
|
|
|
emitInput(val) {
|
|
emitInput(val) {
|
|
const formatted = this.formatToValue(val);
|
|
const formatted = this.formatToValue(val);
|
|
- if (!valueEquals(this.value, formatted)) {
|
|
|
|
|
|
+ if (!valueEquals(this.value, formatted) || this.type === 'dates') {
|
|
this.$emit('input', formatted);
|
|
this.$emit('input', formatted);
|
|
}
|
|
}
|
|
},
|
|
},
|