Commit e6950886 authored by 杨奕's avatar 杨奕 Committed by baiyaaaaa

DatePicker: fix range-separator not working with more than one instances (#3378)

parent afdd45e1
...@@ -44,7 +44,6 @@ const NewPopper = { ...@@ -44,7 +44,6 @@ const NewPopper = {
beforeDestroy: Popper.beforeDestroy beforeDestroy: Popper.beforeDestroy
}; };
let RANGE_SEPARATOR = ' - ';
const DEFAULT_FORMATS = { const DEFAULT_FORMATS = {
date: 'yyyy-MM-dd', date: 'yyyy-MM-dd',
month: 'yyyy-MM', month: 'yyyy-MM',
...@@ -73,19 +72,19 @@ const DATE_FORMATTER = function(value, format) { ...@@ -73,19 +72,19 @@ const DATE_FORMATTER = function(value, format) {
const DATE_PARSER = function(text, format) { const DATE_PARSER = function(text, format) {
return parseDate(text, format); return parseDate(text, format);
}; };
const RANGE_FORMATTER = function(value, format) { const RANGE_FORMATTER = function(value, format, separator) {
if (Array.isArray(value) && value.length === 2) { if (Array.isArray(value) && value.length === 2) {
const start = value[0]; const start = value[0];
const end = value[1]; const end = value[1];
if (start && end) { if (start && end) {
return formatDate(start, format) + RANGE_SEPARATOR + formatDate(end, format); return formatDate(start, format) + separator + formatDate(end, format);
} }
} }
return ''; return '';
}; };
const RANGE_PARSER = function(text, format) { const RANGE_PARSER = function(text, format, separator) {
const array = text.split(RANGE_SEPARATOR); const array = text.split(separator);
if (array.length === 2) { if (array.length === 2) {
const range1 = array[0]; const range1 = array[0];
const range2 = array[1]; const range2 = array[1];
...@@ -306,7 +305,7 @@ export default { ...@@ -306,7 +305,7 @@ export default {
).formatter; ).formatter;
const format = DEFAULT_FORMATS[this.type]; const format = DEFAULT_FORMATS[this.type];
return formatter(value, this.format || format); return formatter(value, this.format || format, this.rangeSeparator);
}, },
set(value) { set(value) {
...@@ -316,7 +315,7 @@ export default { ...@@ -316,7 +315,7 @@ export default {
TYPE_VALUE_RESOLVER_MAP[type] || TYPE_VALUE_RESOLVER_MAP[type] ||
TYPE_VALUE_RESOLVER_MAP['default'] TYPE_VALUE_RESOLVER_MAP['default']
).parser; ).parser;
const parsedValue = parser(value, this.format || DEFAULT_FORMATS[type]); const parsedValue = parser(value, this.format || DEFAULT_FORMATS[type], this.rangeSeparator);
if (parsedValue && this.picker) { if (parsedValue && this.picker) {
this.picker.value = parsedValue; this.picker.value = parsedValue;
...@@ -330,7 +329,6 @@ export default { ...@@ -330,7 +329,6 @@ export default {
}, },
created() { created() {
RANGE_SEPARATOR = this.rangeSeparator;
// vue-popper // vue-popper
this.popperOptions = { this.popperOptions = {
boundariesPadding: 0, boundariesPadding: 0,
...@@ -428,7 +426,7 @@ export default { ...@@ -428,7 +426,7 @@ export default {
const format = DEFAULT_FORMATS.timerange; const format = DEFAULT_FORMATS.timerange;
ranges = Array.isArray(ranges) ? ranges : [ranges]; ranges = Array.isArray(ranges) ? ranges : [ranges];
this.picker.selectableRange = ranges.map(range => parser(range, format)); this.picker.selectableRange = ranges.map(range => parser(range, format, this.rangeSeparator));
} }
for (const option in options) { for (const option in options) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment