parent
cd8302d5be
commit
4c534a7739
2 changed files with 15 additions and 11 deletions
|
@ -82,7 +82,7 @@
|
||||||
import {directive as clickOutside} from 'v-click-outside-x';
|
import {directive as clickOutside} from 'v-click-outside-x';
|
||||||
import TransferDom from '../../directives/transfer-dom';
|
import TransferDom from '../../directives/transfer-dom';
|
||||||
import { oneOf } from '../../utils/assist';
|
import { oneOf } from '../../utils/assist';
|
||||||
import { DEFAULT_FORMATS, RANGE_SEPARATOR, TYPE_VALUE_RESOLVER_MAP, getDayCountOfMonth } from './util';
|
import { DEFAULT_FORMATS, TYPE_VALUE_RESOLVER_MAP, getDayCountOfMonth } from './util';
|
||||||
import {findComponentsDownward} from '../../utils/assist';
|
import {findComponentsDownward} from '../../utils/assist';
|
||||||
import Emitter from '../../mixins/emitter';
|
import Emitter from '../../mixins/emitter';
|
||||||
|
|
||||||
|
@ -209,6 +209,10 @@
|
||||||
options: {
|
options: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({})
|
default: () => ({})
|
||||||
|
},
|
||||||
|
separator: {
|
||||||
|
type: String,
|
||||||
|
default: ' - '
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data(){
|
data(){
|
||||||
|
@ -607,23 +611,23 @@
|
||||||
const multipleParser = TYPE_VALUE_RESOLVER_MAP['multiple'].parser;
|
const multipleParser = TYPE_VALUE_RESOLVER_MAP['multiple'].parser;
|
||||||
|
|
||||||
if (val && type === 'time' && !(val instanceof Date)) {
|
if (val && type === 'time' && !(val instanceof Date)) {
|
||||||
val = parser(val, format);
|
val = parser(val, format, this.separator);
|
||||||
} else if (this.multiple && val) {
|
} else if (this.multiple && val) {
|
||||||
val = multipleParser(val, format);
|
val = multipleParser(val, format, this.separator);
|
||||||
} else if (isRange) {
|
} else if (isRange) {
|
||||||
if (!val){
|
if (!val){
|
||||||
val = [null, null];
|
val = [null, null];
|
||||||
} else {
|
} else {
|
||||||
if (typeof val === 'string') {
|
if (typeof val === 'string') {
|
||||||
val = parser(val, format);
|
val = parser(val, format, this.separator);
|
||||||
} else if (type === 'timerange') {
|
} else if (type === 'timerange') {
|
||||||
val = parser(val, format).map(v => v || '');
|
val = parser(val, format, this.separator).map(v => v || '');
|
||||||
} else {
|
} else {
|
||||||
const [start, end] = val;
|
const [start, end] = val;
|
||||||
if (start instanceof Date && end instanceof Date){
|
if (start instanceof Date && end instanceof Date){
|
||||||
val = val.map(date => new Date(date));
|
val = val.map(date => new Date(date));
|
||||||
} else if (typeof start === 'string' && typeof end === 'string'){
|
} else if (typeof start === 'string' && typeof end === 'string'){
|
||||||
val = parser(val.join(RANGE_SEPARATOR), format);
|
val = parser(val.join(this.separator), format, this.separator);
|
||||||
} else if (!start || !end){
|
} else if (!start || !end){
|
||||||
val = [null, null];
|
val = [null, null];
|
||||||
}
|
}
|
||||||
|
@ -640,13 +644,13 @@
|
||||||
|
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
const formatter = TYPE_VALUE_RESOLVER_MAP.multiple.formatter;
|
const formatter = TYPE_VALUE_RESOLVER_MAP.multiple.formatter;
|
||||||
return formatter(value, this.format || format);
|
return formatter(value, this.format || format, this.separator);
|
||||||
} else {
|
} else {
|
||||||
const {formatter} = (
|
const {formatter} = (
|
||||||
TYPE_VALUE_RESOLVER_MAP[this.type] ||
|
TYPE_VALUE_RESOLVER_MAP[this.type] ||
|
||||||
TYPE_VALUE_RESOLVER_MAP['default']
|
TYPE_VALUE_RESOLVER_MAP['default']
|
||||||
);
|
);
|
||||||
return formatter(value, this.format || format);
|
return formatter(value, this.format || format, this.separator);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onPick(dates, visible = false, type) {
|
onPick(dates, visible = false, type) {
|
||||||
|
|
|
@ -147,7 +147,7 @@ export const DEFAULT_FORMATS = {
|
||||||
datetimerange: 'yyyy-MM-dd HH:mm:ss'
|
datetimerange: 'yyyy-MM-dd HH:mm:ss'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const RANGE_SEPARATOR = ' - ';
|
// export const RANGE_SEPARATOR = ' - '; // use picker.vue prop separator
|
||||||
|
|
||||||
const DATE_FORMATTER = function(value, format) {
|
const DATE_FORMATTER = function(value, format) {
|
||||||
return formatDate(value, format);
|
return formatDate(value, format);
|
||||||
|
@ -155,7 +155,7 @@ 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, RANGE_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];
|
||||||
|
@ -168,7 +168,7 @@ const RANGE_FORMATTER = function(value, format) {
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
const RANGE_PARSER = function(text, format) {
|
const RANGE_PARSER = function(text, format, RANGE_SEPARATOR) {
|
||||||
const array = Array.isArray(text) ? text : text.split(RANGE_SEPARATOR);
|
const array = Array.isArray(text) ? text : text.split(RANGE_SEPARATOR);
|
||||||
if (array.length === 2) {
|
if (array.length === 2) {
|
||||||
const range1 = array[0];
|
const range1 = array[0];
|
||||||
|
|
Loading…
Add table
Reference in a new issue