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 | 82 | import {directive as clickOutside} from 'v-click-outside-x'; |
| 83 | 83 | import TransferDom from '../../directives/transfer-dom'; |
| 84 | 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 | 86 | import {findComponentsDownward} from '../../utils/assist'; |
| 87 | 87 | import Emitter from '../../mixins/emitter'; |
| 88 | 88 | |
| ... | ... | @@ -209,6 +209,10 @@ |
| 209 | 209 | options: { |
| 210 | 210 | type: Object, |
| 211 | 211 | default: () => ({}) |
| 212 | + }, | |
| 213 | + separator: { | |
| 214 | + type: String, | |
| 215 | + default: ' - ' | |
| 212 | 216 | } |
| 213 | 217 | }, |
| 214 | 218 | data(){ |
| ... | ... | @@ -607,23 +611,23 @@ |
| 607 | 611 | const multipleParser = TYPE_VALUE_RESOLVER_MAP['multiple'].parser; |
| 608 | 612 | |
| 609 | 613 | if (val && type === 'time' && !(val instanceof Date)) { |
| 610 | - val = parser(val, format); | |
| 614 | + val = parser(val, format, this.separator); | |
| 611 | 615 | } else if (this.multiple && val) { |
| 612 | - val = multipleParser(val, format); | |
| 616 | + val = multipleParser(val, format, this.separator); | |
| 613 | 617 | } else if (isRange) { |
| 614 | 618 | if (!val){ |
| 615 | 619 | val = [null, null]; |
| 616 | 620 | } else { |
| 617 | 621 | if (typeof val === 'string') { |
| 618 | - val = parser(val, format); | |
| 622 | + val = parser(val, format, this.separator); | |
| 619 | 623 | } else if (type === 'timerange') { |
| 620 | - val = parser(val, format).map(v => v || ''); | |
| 624 | + val = parser(val, format, this.separator).map(v => v || ''); | |
| 621 | 625 | } else { |
| 622 | 626 | const [start, end] = val; |
| 623 | 627 | if (start instanceof Date && end instanceof Date){ |
| 624 | 628 | val = val.map(date => new Date(date)); |
| 625 | 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 | 631 | } else if (!start || !end){ |
| 628 | 632 | val = [null, null]; |
| 629 | 633 | } |
| ... | ... | @@ -640,13 +644,13 @@ |
| 640 | 644 | |
| 641 | 645 | if (this.multiple) { |
| 642 | 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 | 648 | } else { |
| 645 | 649 | const {formatter} = ( |
| 646 | 650 | TYPE_VALUE_RESOLVER_MAP[this.type] || |
| 647 | 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 | 656 | onPick(dates, visible = false, type) { | ... | ... |
src/components/date-picker/util.js
| ... | ... | @@ -147,7 +147,7 @@ export const DEFAULT_FORMATS = { |
| 147 | 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 | 152 | const DATE_FORMATTER = function(value, format) { |
| 153 | 153 | return formatDate(value, format); |
| ... | ... | @@ -155,7 +155,7 @@ const DATE_FORMATTER = function(value, format) { |
| 155 | 155 | const DATE_PARSER = function(text, format) { |
| 156 | 156 | return parseDate(text, format); |
| 157 | 157 | }; |
| 158 | -const RANGE_FORMATTER = function(value, format) { | |
| 158 | +const RANGE_FORMATTER = function(value, format, RANGE_SEPARATOR) { | |
| 159 | 159 | if (Array.isArray(value) && value.length === 2) { |
| 160 | 160 | const start = value[0]; |
| 161 | 161 | const end = value[1]; |
| ... | ... | @@ -168,7 +168,7 @@ const RANGE_FORMATTER = function(value, format) { |
| 168 | 168 | } |
| 169 | 169 | return ''; |
| 170 | 170 | }; |
| 171 | -const RANGE_PARSER = function(text, format) { | |
| 171 | +const RANGE_PARSER = function(text, format, RANGE_SEPARATOR) { | |
| 172 | 172 | const array = Array.isArray(text) ? text : text.split(RANGE_SEPARATOR); |
| 173 | 173 | if (array.length === 2) { |
| 174 | 174 | const range1 = array[0]; | ... | ... |