Commit 4c534a7739dc9a29a10139f6d24d44a76abfd4a5
1 parent
cd8302d5
fixed #5146 , close #5157
Showing
2 changed files
with
15 additions
and
11 deletions
Show diff stats
src/components/date-picker/picker.vue
@@ -82,7 +82,7 @@ | @@ -82,7 +82,7 @@ | ||
82 | import {directive as clickOutside} from 'v-click-outside-x'; | 82 | import {directive as clickOutside} from 'v-click-outside-x'; |
83 | import TransferDom from '../../directives/transfer-dom'; | 83 | import TransferDom from '../../directives/transfer-dom'; |
84 | import { oneOf } from '../../utils/assist'; | 84 | import { oneOf } from '../../utils/assist'; |
85 | - import { DEFAULT_FORMATS, RANGE_SEPARATOR, TYPE_VALUE_RESOLVER_MAP, getDayCountOfMonth } from './util'; | 85 | + import { DEFAULT_FORMATS, TYPE_VALUE_RESOLVER_MAP, getDayCountOfMonth } from './util'; |
86 | import {findComponentsDownward} from '../../utils/assist'; | 86 | import {findComponentsDownward} from '../../utils/assist'; |
87 | import Emitter from '../../mixins/emitter'; | 87 | import Emitter from '../../mixins/emitter'; |
88 | 88 | ||
@@ -209,6 +209,10 @@ | @@ -209,6 +209,10 @@ | ||
209 | options: { | 209 | options: { |
210 | type: Object, | 210 | type: Object, |
211 | default: () => ({}) | 211 | default: () => ({}) |
212 | + }, | ||
213 | + separator: { | ||
214 | + type: String, | ||
215 | + default: ' - ' | ||
212 | } | 216 | } |
213 | }, | 217 | }, |
214 | data(){ | 218 | data(){ |
@@ -607,23 +611,23 @@ | @@ -607,23 +611,23 @@ | ||
607 | const multipleParser = TYPE_VALUE_RESOLVER_MAP['multiple'].parser; | 611 | const multipleParser = TYPE_VALUE_RESOLVER_MAP['multiple'].parser; |
608 | 612 | ||
609 | if (val && type === 'time' && !(val instanceof Date)) { | 613 | if (val && type === 'time' && !(val instanceof Date)) { |
610 | - val = parser(val, format); | 614 | + val = parser(val, format, this.separator); |
611 | } else if (this.multiple && val) { | 615 | } else if (this.multiple && val) { |
612 | - val = multipleParser(val, format); | 616 | + val = multipleParser(val, format, this.separator); |
613 | } else if (isRange) { | 617 | } else if (isRange) { |
614 | if (!val){ | 618 | if (!val){ |
615 | val = [null, null]; | 619 | val = [null, null]; |
616 | } else { | 620 | } else { |
617 | if (typeof val === 'string') { | 621 | if (typeof val === 'string') { |
618 | - val = parser(val, format); | 622 | + val = parser(val, format, this.separator); |
619 | } else if (type === 'timerange') { | 623 | } else if (type === 'timerange') { |
620 | - val = parser(val, format).map(v => v || ''); | 624 | + val = parser(val, format, this.separator).map(v => v || ''); |
621 | } else { | 625 | } else { |
622 | const [start, end] = val; | 626 | const [start, end] = val; |
623 | if (start instanceof Date && end instanceof Date){ | 627 | if (start instanceof Date && end instanceof Date){ |
624 | val = val.map(date => new Date(date)); | 628 | val = val.map(date => new Date(date)); |
625 | } else if (typeof start === 'string' && typeof end === 'string'){ | 629 | } else if (typeof start === 'string' && typeof end === 'string'){ |
626 | - val = parser(val.join(RANGE_SEPARATOR), format); | 630 | + val = parser(val.join(this.separator), format, this.separator); |
627 | } else if (!start || !end){ | 631 | } else if (!start || !end){ |
628 | val = [null, null]; | 632 | val = [null, null]; |
629 | } | 633 | } |
@@ -640,13 +644,13 @@ | @@ -640,13 +644,13 @@ | ||
640 | 644 | ||
641 | if (this.multiple) { | 645 | if (this.multiple) { |
642 | const formatter = TYPE_VALUE_RESOLVER_MAP.multiple.formatter; | 646 | const formatter = TYPE_VALUE_RESOLVER_MAP.multiple.formatter; |
643 | - return formatter(value, this.format || format); | 647 | + return formatter(value, this.format || format, this.separator); |
644 | } else { | 648 | } else { |
645 | const {formatter} = ( | 649 | const {formatter} = ( |
646 | TYPE_VALUE_RESOLVER_MAP[this.type] || | 650 | TYPE_VALUE_RESOLVER_MAP[this.type] || |
647 | TYPE_VALUE_RESOLVER_MAP['default'] | 651 | TYPE_VALUE_RESOLVER_MAP['default'] |
648 | ); | 652 | ); |
649 | - return formatter(value, this.format || format); | 653 | + return formatter(value, this.format || format, this.separator); |
650 | } | 654 | } |
651 | }, | 655 | }, |
652 | onPick(dates, visible = false, type) { | 656 | onPick(dates, visible = false, type) { |
src/components/date-picker/util.js
@@ -147,7 +147,7 @@ export const DEFAULT_FORMATS = { | @@ -147,7 +147,7 @@ export const DEFAULT_FORMATS = { | ||
147 | datetimerange: 'yyyy-MM-dd HH:mm:ss' | 147 | datetimerange: 'yyyy-MM-dd HH:mm:ss' |
148 | }; | 148 | }; |
149 | 149 | ||
150 | -export const RANGE_SEPARATOR = ' - '; | 150 | +// export const RANGE_SEPARATOR = ' - '; // use picker.vue prop separator |
151 | 151 | ||
152 | const DATE_FORMATTER = function(value, format) { | 152 | const DATE_FORMATTER = function(value, format) { |
153 | return formatDate(value, format); | 153 | return formatDate(value, format); |
@@ -155,7 +155,7 @@ const DATE_FORMATTER = function(value, format) { | @@ -155,7 +155,7 @@ const DATE_FORMATTER = function(value, format) { | ||
155 | const DATE_PARSER = function(text, format) { | 155 | const DATE_PARSER = function(text, format) { |
156 | return parseDate(text, format); | 156 | return parseDate(text, format); |
157 | }; | 157 | }; |
158 | -const RANGE_FORMATTER = function(value, format) { | 158 | +const RANGE_FORMATTER = function(value, format, RANGE_SEPARATOR) { |
159 | if (Array.isArray(value) && value.length === 2) { | 159 | if (Array.isArray(value) && value.length === 2) { |
160 | const start = value[0]; | 160 | const start = value[0]; |
161 | const end = value[1]; | 161 | const end = value[1]; |
@@ -168,7 +168,7 @@ const RANGE_FORMATTER = function(value, format) { | @@ -168,7 +168,7 @@ const RANGE_FORMATTER = function(value, format) { | ||
168 | } | 168 | } |
169 | return ''; | 169 | return ''; |
170 | }; | 170 | }; |
171 | -const RANGE_PARSER = function(text, format) { | 171 | +const RANGE_PARSER = function(text, format, RANGE_SEPARATOR) { |
172 | const array = Array.isArray(text) ? text : text.split(RANGE_SEPARATOR); | 172 | const array = Array.isArray(text) ? text : text.split(RANGE_SEPARATOR); |
173 | if (array.length === 2) { | 173 | if (array.length === 2) { |
174 | const range1 = array[0]; | 174 | const range1 = array[0]; |