2020-10-28 07:31:45 +00:00
|
|
|
import { CSSProperties, defineComponent, inject, nextTick } from 'vue';
|
2020-08-31 14:25:47 +00:00
|
|
|
import moment from 'moment';
|
2019-01-12 03:33:27 +00:00
|
|
|
import RangeCalendar from '../vc-calendar/src/RangeCalendar';
|
|
|
|
import VcDatePicker from '../vc-calendar/src/Picker';
|
2020-08-31 08:53:19 +00:00
|
|
|
import classNames from '../_util/classNames';
|
2020-08-14 10:24:30 +00:00
|
|
|
import shallowequal from '../_util/shallowequal';
|
2020-03-28 07:45:37 +00:00
|
|
|
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
|
2019-01-12 03:33:27 +00:00
|
|
|
import Tag from '../tag';
|
2020-09-30 02:47:18 +00:00
|
|
|
import { defaultConfigProvider } from '../config-provider';
|
2019-01-12 03:33:27 +00:00
|
|
|
import interopDefault from '../_util/interopDefault';
|
2020-10-15 05:39:17 +00:00
|
|
|
import { RangePickerProps } from './props';
|
2020-10-14 15:12:51 +00:00
|
|
|
import { hasProp, getOptionProps, getComponent } from '../_util/props-util';
|
2019-01-12 03:33:27 +00:00
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
2020-03-07 11:45:13 +00:00
|
|
|
import { formatDate } from './utils';
|
|
|
|
import InputIcon from './InputIcon';
|
2020-08-20 09:56:49 +00:00
|
|
|
import { getDataAndAriaProps } from '../_util/util';
|
2020-10-14 15:12:51 +00:00
|
|
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
2020-03-07 11:45:13 +00:00
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
type RangePickerValue =
|
|
|
|
| undefined[]
|
|
|
|
| null[]
|
|
|
|
| [moment.Moment]
|
|
|
|
| [undefined, moment.Moment]
|
|
|
|
| [moment.Moment, undefined]
|
|
|
|
| [null, moment.Moment]
|
|
|
|
| [moment.Moment, null]
|
|
|
|
| [moment.Moment, moment.Moment];
|
|
|
|
|
|
|
|
export type RangePickerPresetRange = RangePickerValue | (() => RangePickerValue);
|
|
|
|
function getShowDateFromValue(value: RangePickerValue, mode?: string | string[]) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const [start, end] = value;
|
2018-03-17 13:38:29 +00:00
|
|
|
// value could be an empty array, then we should not reset showDate
|
|
|
|
if (!start && !end) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
2020-03-07 11:45:13 +00:00
|
|
|
if (mode && mode[0] === 'month') {
|
2020-10-14 15:12:51 +00:00
|
|
|
return [start, end] as RangePickerValue;
|
2020-03-07 11:45:13 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
const newEnd = end && end.isSame(start, 'month') ? end.clone().add(1, 'month') : end;
|
2020-10-14 15:12:51 +00:00
|
|
|
return [start, newEnd] as RangePickerValue;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
function pickerValueAdapter(
|
|
|
|
value?: moment.Moment | RangePickerValue,
|
|
|
|
): RangePickerValue | undefined {
|
2018-03-17 13:38:29 +00:00
|
|
|
if (!value) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return value;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return [value, value.clone().add(1, 'month')];
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
function isEmptyArray(arr: any) {
|
2018-03-17 13:38:29 +00:00
|
|
|
if (Array.isArray(arr)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return arr.length === 0 || arr.every(i => !i);
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return false;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
function fixLocale(value: RangePickerValue | undefined, localeCode: string | undefined) {
|
2018-03-17 13:38:29 +00:00
|
|
|
if (!localeCode) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
if (!value || value.length === 0) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
const [start, end] = value;
|
2019-01-02 12:20:02 +00:00
|
|
|
if (start) {
|
2019-01-12 03:33:27 +00:00
|
|
|
start.locale(localeCode);
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
2019-01-02 12:20:02 +00:00
|
|
|
if (end) {
|
2019-01-12 03:33:27 +00:00
|
|
|
end.locale(localeCode);
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
export interface RangePickerState {
|
|
|
|
sValue?: RangePickerValue;
|
|
|
|
sShowDate?: RangePickerValue;
|
|
|
|
sOpen?: boolean;
|
|
|
|
sHoverValue?: RangePickerValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defineComponent({
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'ARangePicker',
|
2019-02-01 09:23:00 +00:00
|
|
|
mixins: [BaseMixin],
|
2020-07-22 09:47:08 +00:00
|
|
|
inheritAttrs: false,
|
2020-10-14 15:12:51 +00:00
|
|
|
props: initDefaultProps(RangePickerProps, {
|
2018-03-17 13:38:29 +00:00
|
|
|
allowClear: true,
|
|
|
|
showToday: false,
|
2020-03-07 11:45:13 +00:00
|
|
|
separator: '~',
|
2018-03-17 13:38:29 +00:00
|
|
|
}),
|
2020-07-22 09:47:08 +00:00
|
|
|
setup() {
|
|
|
|
return {
|
2020-09-30 02:47:18 +00:00
|
|
|
configProvider: inject('configProvider', defaultConfigProvider),
|
2020-10-14 15:12:51 +00:00
|
|
|
picker: null,
|
|
|
|
sTagPrefixCls: undefined,
|
|
|
|
sPrefixCls: '',
|
2020-07-22 09:47:08 +00:00
|
|
|
};
|
2019-04-20 04:34:24 +00:00
|
|
|
},
|
2020-10-14 15:12:51 +00:00
|
|
|
data(): RangePickerState {
|
2019-01-12 03:33:27 +00:00
|
|
|
const value = this.value || this.defaultValue || [];
|
|
|
|
const [start, end] = value;
|
2018-03-17 13:38:29 +00:00
|
|
|
if (
|
2019-01-12 03:33:27 +00:00
|
|
|
(start && !interopDefault(moment).isMoment(start)) ||
|
|
|
|
(end && !interopDefault(moment).isMoment(end))
|
2018-03-17 13:38:29 +00:00
|
|
|
) {
|
|
|
|
throw new Error(
|
|
|
|
'The value/defaultValue of RangePicker must be a moment object array after `antd@2.0`, ' +
|
2019-01-12 03:33:27 +00:00
|
|
|
'see: https://u.ant.design/date-picker-value',
|
|
|
|
);
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
const pickerValue = !value || isEmptyArray(value) ? this.defaultPickerValue : value;
|
2018-03-17 13:38:29 +00:00
|
|
|
return {
|
2020-10-14 15:12:51 +00:00
|
|
|
sValue: value as RangePickerValue,
|
2018-04-07 06:29:59 +00:00
|
|
|
sShowDate: pickerValueAdapter(pickerValue || interopDefault(moment)()),
|
2018-03-17 13:38:29 +00:00
|
|
|
sOpen: this.open,
|
|
|
|
sHoverValue: [],
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
watch: {
|
2019-01-12 03:33:27 +00:00
|
|
|
value(val) {
|
|
|
|
const value = val || [];
|
2020-10-14 15:12:51 +00:00
|
|
|
let state: RangePickerState = { sValue: value };
|
2018-09-05 13:28:54 +00:00
|
|
|
if (!shallowequal(val, this.sValue)) {
|
|
|
|
state = {
|
|
|
|
...state,
|
2020-03-07 11:45:13 +00:00
|
|
|
sShowDate: getShowDateFromValue(value, this.mode) || this.sShowDate,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
this.setState(state);
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
open(val) {
|
2019-05-28 03:37:38 +00:00
|
|
|
const state = { sOpen: val };
|
2019-04-20 04:34:24 +00:00
|
|
|
this.setState(state);
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
2019-09-10 10:57:08 +00:00
|
|
|
sOpen(val, oldVal) {
|
2020-10-28 07:31:45 +00:00
|
|
|
nextTick(() => {
|
2019-09-10 10:57:08 +00:00
|
|
|
if (!hasProp(this, 'open') && oldVal && !val) {
|
|
|
|
this.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2019-04-20 04:34:24 +00:00
|
|
|
},
|
2018-03-17 13:38:29 +00:00
|
|
|
methods: {
|
2020-10-14 15:12:51 +00:00
|
|
|
setValue(value: RangePickerValue, hidePanel?: boolean) {
|
2020-03-07 11:45:13 +00:00
|
|
|
this.handleChange(value);
|
|
|
|
if ((hidePanel || !this.showTime) && !hasProp(this, 'open')) {
|
|
|
|
this.setState({ sOpen: false });
|
|
|
|
}
|
|
|
|
},
|
2020-07-22 09:47:08 +00:00
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
savePicker(node: any) {
|
2020-07-22 09:47:08 +00:00
|
|
|
this.picker = node;
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
clearSelection(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
this.setState({ sValue: [] });
|
|
|
|
this.handleChange([]);
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
clearHoverValue() {
|
|
|
|
this.setState({ sHoverValue: [] });
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
handleChange(value: RangePickerValue) {
|
2018-03-17 13:38:29 +00:00
|
|
|
if (!hasProp(this, 'value')) {
|
|
|
|
this.setState(({ sShowDate }) => ({
|
|
|
|
sValue: value,
|
|
|
|
sShowDate: getShowDateFromValue(value) || sShowDate,
|
2019-01-12 03:33:27 +00:00
|
|
|
}));
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
2020-03-07 11:45:13 +00:00
|
|
|
if (value[0] && value[1] && value[0].diff(value[1]) > 0) {
|
|
|
|
value[1] = undefined;
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
const [start, end] = value;
|
2020-03-07 11:45:13 +00:00
|
|
|
this.$emit('change', value, [formatDate(start, this.format), formatDate(end, this.format)]);
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
handleOpenChange(open: boolean) {
|
2018-03-17 13:38:29 +00:00
|
|
|
if (!hasProp(this, 'open')) {
|
2019-01-12 03:33:27 +00:00
|
|
|
this.setState({ sOpen: open });
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (open === false) {
|
2019-01-12 03:33:27 +00:00
|
|
|
this.clearHoverValue();
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
this.$emit('openChange', open);
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
handleShowDateChange(showDate: boolean) {
|
2019-01-12 03:33:27 +00:00
|
|
|
this.setState({ sShowDate: showDate });
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
handleHoverChange(hoverValue: any) {
|
2019-01-12 03:33:27 +00:00
|
|
|
this.setState({ sHoverValue: hoverValue });
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
handleRangeMouseLeave() {
|
2018-03-17 13:38:29 +00:00
|
|
|
if (this.sOpen) {
|
2019-01-12 03:33:27 +00:00
|
|
|
this.clearHoverValue();
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
handleCalendarInputSelect(value: RangePickerValue) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const [start] = value;
|
2019-01-02 12:20:02 +00:00
|
|
|
if (!start) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
this.setState(({ sShowDate }) => ({
|
|
|
|
sValue: value,
|
|
|
|
sShowDate: getShowDateFromValue(value) || sShowDate,
|
2019-01-12 03:33:27 +00:00
|
|
|
}));
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
handleRangeClick(value: RangePickerPresetRange) {
|
2018-03-17 13:38:29 +00:00
|
|
|
if (typeof value === 'function') {
|
2019-01-12 03:33:27 +00:00
|
|
|
value = value();
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
this.setValue(value, true);
|
|
|
|
this.$emit('ok', value);
|
|
|
|
this.$emit('openChange', false);
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2020-10-14 15:12:51 +00:00
|
|
|
onMouseEnter(e: MouseEvent) {
|
2019-01-12 03:33:27 +00:00
|
|
|
this.$emit('mouseenter', e);
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2020-10-14 15:12:51 +00:00
|
|
|
onMouseLeave(e: MouseEvent) {
|
2019-01-12 03:33:27 +00:00
|
|
|
this.$emit('mouseleave', e);
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
focus() {
|
2020-07-22 09:47:08 +00:00
|
|
|
this.picker.focus();
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
blur() {
|
2020-07-22 09:47:08 +00:00
|
|
|
this.picker.blur();
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
|
2020-03-18 06:52:02 +00:00
|
|
|
renderFooter() {
|
2020-07-22 09:47:08 +00:00
|
|
|
const { ranges, $slots } = this;
|
2020-10-14 15:12:51 +00:00
|
|
|
const { sPrefixCls: prefixCls, sTagPrefixCls: tagPrefixCls } = this;
|
2020-07-22 09:47:08 +00:00
|
|
|
const renderExtraFooter = this.renderExtraFooter || $slots.renderExtraFooter;
|
2018-03-17 13:38:29 +00:00
|
|
|
if (!ranges && !renderExtraFooter) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return null;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
const customFooter = renderExtraFooter ? (
|
2019-01-12 03:33:27 +00:00
|
|
|
<div class={`${prefixCls}-footer-extra`} key="extra">
|
2020-03-07 11:45:13 +00:00
|
|
|
{typeof renderExtraFooter === 'function' ? renderExtraFooter() : renderExtraFooter}
|
2018-03-17 13:38:29 +00:00
|
|
|
</div>
|
2019-01-12 03:33:27 +00:00
|
|
|
) : null;
|
2020-03-07 11:45:13 +00:00
|
|
|
const operations =
|
|
|
|
ranges &&
|
|
|
|
Object.keys(ranges).map(range => {
|
|
|
|
const value = ranges[range];
|
|
|
|
const hoverValue = typeof value === 'function' ? value.call(this) : value;
|
|
|
|
return (
|
|
|
|
<Tag
|
|
|
|
key={range}
|
|
|
|
prefixCls={tagPrefixCls}
|
|
|
|
color="blue"
|
|
|
|
onClick={() => this.handleRangeClick(value)}
|
|
|
|
onMouseenter={() => this.setState({ sHoverValue: hoverValue })}
|
|
|
|
onMouseleave={this.handleRangeMouseLeave}
|
|
|
|
>
|
|
|
|
{range}
|
|
|
|
</Tag>
|
|
|
|
);
|
|
|
|
});
|
2019-01-12 03:33:27 +00:00
|
|
|
const rangeNode =
|
|
|
|
operations && operations.length > 0 ? (
|
|
|
|
<div class={`${prefixCls}-footer-extra ${prefixCls}-range-quick-selector`} key="range">
|
|
|
|
{operations}
|
|
|
|
</div>
|
|
|
|
) : null;
|
|
|
|
return [rangeNode, customFooter];
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2020-10-14 15:12:51 +00:00
|
|
|
const props: any = { ...getOptionProps(this), ...this.$attrs };
|
2020-07-19 15:02:34 +00:00
|
|
|
let suffixIcon = getComponent(this, 'suffixIcon');
|
2019-01-12 03:33:27 +00:00
|
|
|
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
|
|
|
|
const {
|
|
|
|
sValue: value,
|
|
|
|
sShowDate: showDate,
|
|
|
|
sHoverValue: hoverValue,
|
|
|
|
sOpen: open,
|
2020-07-22 09:47:08 +00:00
|
|
|
$slots,
|
2019-01-12 03:33:27 +00:00
|
|
|
} = this;
|
|
|
|
const {
|
2019-04-20 04:34:24 +00:00
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
tagPrefixCls: customizeTagPrefixCls,
|
2019-01-12 03:33:27 +00:00
|
|
|
popupStyle,
|
|
|
|
disabledDate,
|
|
|
|
disabledTime,
|
|
|
|
showTime,
|
|
|
|
showToday,
|
|
|
|
ranges,
|
|
|
|
locale,
|
|
|
|
localeCode,
|
|
|
|
format,
|
2020-03-07 11:45:13 +00:00
|
|
|
separator,
|
2020-04-26 08:37:15 +00:00
|
|
|
inputReadOnly,
|
2020-07-22 09:47:08 +00:00
|
|
|
style,
|
|
|
|
onCalendarChange,
|
|
|
|
onOk,
|
|
|
|
onBlur,
|
|
|
|
onFocus,
|
|
|
|
onPanelChange,
|
2019-01-12 03:33:27 +00:00
|
|
|
} = props;
|
2019-09-11 14:35:25 +00:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-04-20 04:34:24 +00:00
|
|
|
const prefixCls = getPrefixCls('calendar', customizePrefixCls);
|
|
|
|
const tagPrefixCls = getPrefixCls('tag', customizeTagPrefixCls);
|
2020-10-14 15:12:51 +00:00
|
|
|
this.sPrefixCls = prefixCls;
|
|
|
|
this.sTagPrefixCls = tagPrefixCls;
|
2019-04-20 04:34:24 +00:00
|
|
|
|
2020-07-22 09:47:08 +00:00
|
|
|
const dateRender = props.dateRender || $slots.dateRender;
|
2019-01-12 03:33:27 +00:00
|
|
|
fixLocale(value, localeCode);
|
|
|
|
fixLocale(showDate, localeCode);
|
2018-03-17 13:38:29 +00:00
|
|
|
|
|
|
|
const calendarClassName = classNames({
|
|
|
|
[`${prefixCls}-time`]: showTime,
|
|
|
|
[`${prefixCls}-range-with-ranges`]: ranges,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-03-17 13:38:29 +00:00
|
|
|
|
|
|
|
// 需要选择时间时,点击 ok 时才触发 onChange
|
|
|
|
const pickerChangeHandler = {
|
2020-07-22 09:47:08 +00:00
|
|
|
onChange: this.handleChange,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2020-10-14 15:12:51 +00:00
|
|
|
let calendarProps: any = {
|
2020-07-22 09:47:08 +00:00
|
|
|
onOk: this.handleChange,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-17 13:38:29 +00:00
|
|
|
if (props.timePicker) {
|
2020-07-22 09:47:08 +00:00
|
|
|
pickerChangeHandler.onChange = changedValue => this.handleChange(changedValue);
|
2018-03-17 13:38:29 +00:00
|
|
|
} else {
|
2020-07-22 09:47:08 +00:00
|
|
|
calendarProps = {};
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
if ('mode' in props) {
|
2020-07-22 09:47:08 +00:00
|
|
|
calendarProps.mode = props.mode;
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-07 11:45:13 +00:00
|
|
|
const startPlaceholder = Array.isArray(props.placeholder)
|
|
|
|
? props.placeholder[0]
|
|
|
|
: locale.lang.rangePlaceholder[0];
|
|
|
|
const endPlaceholder = Array.isArray(props.placeholder)
|
|
|
|
? props.placeholder[1]
|
|
|
|
: locale.lang.rangePlaceholder[1];
|
|
|
|
|
2020-07-22 09:47:08 +00:00
|
|
|
const rangeCalendarProps = {
|
|
|
|
...calendarProps,
|
|
|
|
separator,
|
|
|
|
format,
|
|
|
|
prefixCls,
|
|
|
|
renderFooter: this.renderFooter,
|
|
|
|
timePicker: props.timePicker,
|
|
|
|
disabledDate,
|
|
|
|
disabledTime,
|
|
|
|
dateInputPlaceholder: [startPlaceholder, endPlaceholder],
|
|
|
|
locale: locale.lang,
|
|
|
|
dateRender,
|
|
|
|
value: showDate,
|
|
|
|
hoverValue,
|
|
|
|
showToday,
|
|
|
|
inputReadOnly,
|
|
|
|
onChange: onCalendarChange,
|
|
|
|
onOk,
|
|
|
|
onValueChange: this.handleShowDateChange,
|
|
|
|
onHoverChange: this.handleHoverChange,
|
|
|
|
onPanelChange,
|
|
|
|
onInputSelect: this.handleCalendarInputSelect,
|
2018-03-17 13:38:29 +00:00
|
|
|
class: calendarClassName,
|
2020-07-22 09:47:08 +00:00
|
|
|
};
|
2020-11-24 10:07:45 +00:00
|
|
|
const calendar = <RangeCalendar {...rangeCalendarProps} v-slots={$slots} />;
|
2018-03-17 13:38:29 +00:00
|
|
|
|
|
|
|
// default width for showTime
|
2020-10-14 15:12:51 +00:00
|
|
|
const pickerStyle: CSSProperties = {};
|
2018-03-17 13:38:29 +00:00
|
|
|
if (props.showTime) {
|
2019-01-12 03:33:27 +00:00
|
|
|
pickerStyle.width = '350px';
|
2018-03-17 13:38:29 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
const [startValue, endValue] = value;
|
|
|
|
const clearIcon =
|
|
|
|
!props.disabled && props.allowClear && value && (startValue || endValue) ? (
|
2020-03-28 07:45:37 +00:00
|
|
|
<CloseCircleFilled class={`${prefixCls}-picker-clear`} onClick={this.clearSelection} />
|
2019-01-12 03:33:27 +00:00
|
|
|
) : null;
|
2018-03-17 13:38:29 +00:00
|
|
|
|
2020-03-07 11:45:13 +00:00
|
|
|
const inputIcon = <InputIcon suffixIcon={suffixIcon} prefixCls={prefixCls} />;
|
2018-12-08 08:47:05 +00:00
|
|
|
|
2018-03-17 13:38:29 +00:00
|
|
|
const input = ({ value: inputValue }) => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const [start, end] = inputValue;
|
2018-03-17 13:38:29 +00:00
|
|
|
return (
|
|
|
|
<span class={props.pickerInputClass}>
|
|
|
|
<input
|
|
|
|
disabled={props.disabled}
|
2020-07-17 09:13:30 +00:00
|
|
|
readonly
|
2020-03-07 11:45:13 +00:00
|
|
|
value={formatDate(start, props.format)}
|
2018-03-17 13:38:29 +00:00
|
|
|
placeholder={startPlaceholder}
|
|
|
|
class={`${prefixCls}-range-picker-input`}
|
2020-07-17 09:13:30 +00:00
|
|
|
tabindex={-1}
|
2018-03-17 13:38:29 +00:00
|
|
|
/>
|
2020-03-07 11:45:13 +00:00
|
|
|
<span class={`${prefixCls}-range-picker-separator`}> {separator} </span>
|
2018-03-17 13:38:29 +00:00
|
|
|
<input
|
|
|
|
disabled={props.disabled}
|
2020-07-17 09:13:30 +00:00
|
|
|
readonly
|
2020-03-07 11:45:13 +00:00
|
|
|
value={formatDate(end, props.format)}
|
2018-03-17 13:38:29 +00:00
|
|
|
placeholder={endPlaceholder}
|
|
|
|
class={`${prefixCls}-range-picker-input`}
|
2020-07-17 09:13:30 +00:00
|
|
|
tabindex={-1}
|
2018-03-17 13:38:29 +00:00
|
|
|
/>
|
|
|
|
{clearIcon}
|
2018-12-08 08:47:05 +00:00
|
|
|
{inputIcon}
|
2018-03-17 13:38:29 +00:00
|
|
|
</span>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
|
|
|
};
|
2020-07-22 09:47:08 +00:00
|
|
|
const vcDatePickerProps = {
|
|
|
|
...props,
|
|
|
|
...pickerChangeHandler,
|
|
|
|
calendar,
|
|
|
|
value,
|
|
|
|
open,
|
|
|
|
prefixCls: `${prefixCls}-picker-container`,
|
|
|
|
onOpenChange: this.handleOpenChange,
|
|
|
|
style: popupStyle,
|
|
|
|
};
|
2018-03-17 13:38:29 +00:00
|
|
|
return (
|
|
|
|
<span
|
2020-07-22 09:47:08 +00:00
|
|
|
ref={this.savePicker}
|
|
|
|
id={props.id}
|
|
|
|
class={classNames(props.class, props.pickerClass)}
|
2020-11-23 06:24:33 +00:00
|
|
|
style={{ ...pickerStyle, ...style }}
|
2020-07-17 09:13:30 +00:00
|
|
|
tabindex={props.disabled ? -1 : 0}
|
2020-07-22 09:47:08 +00:00
|
|
|
onFocus={onFocus}
|
|
|
|
onBlur={onBlur}
|
2018-09-05 13:28:54 +00:00
|
|
|
onMouseenter={this.onMouseEnter}
|
|
|
|
onMouseleave={this.onMouseLeave}
|
2020-08-20 09:56:49 +00:00
|
|
|
{...getDataAndAriaProps(props)}
|
2018-03-17 13:38:29 +00:00
|
|
|
>
|
2020-11-24 10:07:45 +00:00
|
|
|
<VcDatePicker {...vcDatePickerProps} v-slots={{ default: input, ...$slots }}></VcDatePicker>
|
2018-03-17 13:38:29 +00:00
|
|
|
</span>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-03-17 13:38:29 +00:00
|
|
|
},
|
2020-10-14 15:12:51 +00:00
|
|
|
});
|