UNPKG

tdesign-vue

Version:
605 lines (601 loc) 23.7 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, computed, ref, watch } from '@vue/composition-api'; import dayjs from 'dayjs'; import dateRangePickerPanelProps from './date-range-picker-panel-props.js'; import dateRangePickerProps from './date-range-picker-props.js'; import TRangePanel from './panel/RangePanel.js'; import useRangeValue from './hooks/useRangeValue.js'; import { getDefaultFormat, parseToDayjs, formatDate } from '../_common/js/date-picker/format.js'; import { subtractMonth, addMonth, extractTimeObj } from '../_common/js/date-picker/utils.js'; import { dateCorrection } from './utils.js'; import '@babel/runtime/helpers/slicedToArray'; import 'lodash-es'; import '../hooks/useConfig.js'; import '../config-provider/useConfig.js'; import '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-d2f11e9e.js'; import '@babel/runtime/helpers/typeof'; import '../_chunks/dep-05dc6583.js'; import '../_chunks/dep-62386ed0.js'; import '../config-provider/type.js'; import '../_common/js/global-config/t.js'; import './panel/PanelContent.js'; import '../_chunks/dep-e77071c7.js'; import './base/Header.js'; import '../pagination/index.js'; import '../pagination/pagination.js'; import 'tdesign-icons-vue'; import '../utils/mixins.js'; import 'vue'; import '../config-provider/config-receiver.js'; import '../input-number/index.js'; import '../input-number/input-number.js'; import '../button/index.js'; import '../button/button.js'; import '../loading/index.js'; import '../loading/directive.js'; import '../loading/plugin.js'; import '../loading/loading.js'; import '../loading/icon/gradient.js'; import '../_common/js/loading/circle-adapter.js'; import '../_common/js/utils/setStyle.js'; import '../_common/js/utils/helper.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../utils/dom.js'; import 'raf'; import '../utils/easing.js'; import '../utils/render-tnode.js'; import '@babel/runtime/helpers/readOnlyError'; import '../utils/transfer-dom.js'; import '../loading/props.js'; import '../config.js'; import '../utils/withInstall.js'; import './style/css.js'; import '../loading/type.js'; import '../button/props.js'; import '../utils/ripple.js'; import '../button/type.js'; import '../input/index.js'; import '../input/input.js'; import '../utils/helper.js'; import '../utils/event.js'; import '../input/props.js'; import '../_common/js/log/index.js'; import '../_common/js/log/log.js'; import '../input/input-group.js'; import '../utils/map-props.js'; import '../input/type.js'; import '../input-number/props.js'; import '../input-number/useInputNumber.js'; import '../hooks/useCommonClassName.js'; import '../hooks/useVModel.js'; import '../_common/js/input-number/number.js'; import '../_common/js/input-number/large-number.js'; import '../hooks/useFormDisabled.js'; import '../hooks/useGlobalIcon.js'; import '../input-number/type.js'; import '../select/index.js'; import '../select/select.js'; import '../hooks/useDefaultValue.js'; import '../hooks/tnode.js'; import '../hooks/render-tnode.js'; import '../select/props.js'; import '../popup/index.js'; import '../popup/popup.js'; import '@popperjs/core'; import '../popup/props.js'; import '../popup/container.js'; import '../popup/utils.js'; import '../popup/type.js'; import '../popup/plugin.js'; import '../tag/index.js'; import '../tag/tag.js'; import 'tinycolor2'; import '../tag/props.js'; import '../tag/check-tag.js'; import '../tag/check-tag-props.js'; import '../_common/js/common.js'; import '../hooks/index.js'; import '../hooks/slots.js'; import '../hooks/useDestroyOnClose.js'; import '../hooks/useElementLazyRender.js'; import '../_common/js/utils/observe.js'; import '../hooks/useLazyLoad.js'; import '../hooks/useResizeObserver.js'; import '../hooks/useVirtualScrollNew.js'; import '../hooks/useImagePreviewUrl.js'; import '../_common/js/upload/utils.js'; import '../hooks/useMutationObservable.js'; import '../hooks/useVariables.js'; import '../_common/js/utils/getColorTokenColor.js'; import '../tag/check-tag-group.js'; import '../tag/check-tag-group-props.js'; import '../tag/type.js'; import '../select-input/index.js'; import '../select-input/select-input.js'; import '../select-input/props.js'; import '../select-input/useSingle.js'; import '../select-input/useMultiple.js'; import '../tag-input/index.js'; import '../tag-input/tag-input.js'; import '../tag-input/props.js'; import '../tag-input/hooks/useTagScroll.js'; import '../tag-input/useTagList.js'; import '../tag-input/hooks/useHover.js'; import '../tag-input/hooks/useDragSorter.js'; import '../tag-input/type.js'; import '../tag-input/interface.js'; import '../select-input/useOverlayInnerStyle.js'; import '../select-input/type.js'; import '../common-components/fake-arrow.js'; import '../select/option.js'; import '../select/option-props.js'; import '../checkbox/index.js'; import '../checkbox/group.js'; import '../checkbox/checkbox.js'; import '../checkbox/props.js'; import '../checkbox/constants.js'; import '../checkbox/store.js'; import '@babel/runtime/helpers/classCallCheck'; import '@babel/runtime/helpers/createClass'; import '../checkbox/hooks/useKeyboardEvent.js'; import '../checkbox/checkbox-group-props.js'; import '../checkbox/type.js'; import '../select/util.js'; import '../select/select-panel.js'; import '../select/optionGroup.js'; import '../select/option-group-props.js'; import '../hooks/useVirtualScroll.js'; import '../select/hooks/useSelectOptions.js'; import '../select/type.js'; import '../input-adornment/index.js'; import '../input-adornment/input-adornment.js'; import '../input-adornment/props.js'; import '../input-adornment/type.js'; import '../pagination/props.js'; import '../pagination/pagination-mini.js'; import '../pagination/pagination-mini-props.js'; import '../pagination/type.js'; import './base/Table.js'; import './base/Cell.js'; import '../time-picker/panel/time-picker-panel.js'; import '../_chunks/dep-85392228.js'; import '../_common/js/time-picker/const.js'; import '../time-picker/panel/props.js'; import '../time-picker/props.js'; import '../time-picker/panel/single-panel.js'; import '../_common/js/time-picker/utils.js'; import '../_chunks/dep-b8e25a7f.js'; import './panel/ExtraContent.js'; import './base/Footer.js'; import './hooks/useTableData.js'; import './hooks/useDisableDate.js'; import '@babel/runtime/helpers/objectDestructuringEmpty'; import '@babel/runtime/helpers/extends'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var _DateRangePickerPanel = defineComponent({ name: "TDateRangePickerPanel", props: _objectSpread({ value: dateRangePickerProps.value, defaultValue: dateRangePickerProps.defaultValue, disabled: dateRangePickerProps.disabled, disableDate: dateRangePickerProps.disableDate, disableTime: dateRangePickerProps.disableTime, enableTimePicker: dateRangePickerProps.enableTimePicker, firstDayOfWeek: dateRangePickerProps.firstDayOfWeek, format: dateRangePickerProps.format, mode: dateRangePickerProps.mode, presets: dateRangePickerProps.presets, presetsPlacement: dateRangePickerProps.presetsPlacement, timePickerProps: dateRangePickerProps.timePickerProps, panelPreselection: dateRangePickerProps.panelPreselection }, dateRangePickerPanelProps), setup: function setup(props, _ref) { var emit = _ref.emit, attrs = _ref.attrs; var _useRangeValue = useRangeValue(props), value = _useRangeValue.value, year = _useRangeValue.year, month = _useRangeValue.month, time = _useRangeValue.time, cacheValue = _useRangeValue.cacheValue, isFirstValueSelected = _useRangeValue.isFirstValueSelected, onChange = _useRangeValue.onChange; var formatRef = computed(function () { return getDefaultFormat({ mode: props.mode, enableTimePicker: props.enableTimePicker, format: props.format }); }); var isSelected = ref(false); var isHoverCell = ref(false); var hoverValue = ref([]); var activeIndex = computed(function () { return isFirstValueSelected.value ? 1 : 0; }); watch(function () { return value.value; }, function (value2) { if (value2.length === 2 && !props.enableTimePicker) { var nextMonth = value2.map(function (v) { return parseToDayjs(v || new Date(), formatRef.value.format).month(); }); if (year.value[0] === year.value[1] && nextMonth[0] === nextMonth[1]) { nextMonth[0] === 11 ? nextMonth[0] -= 1 : nextMonth[1] += 1; } month.value = nextMonth; } }, { immediate: true }); function onCellMouseEnter(date) { isHoverCell.value = true; var nextValue = _toConsumableArray(hoverValue.value); nextValue[activeIndex.value] = formatDate(date, { format: formatRef.value.format }); hoverValue.value = nextValue; } function onCellMouseLeave() { isHoverCell.value = false; hoverValue.value = cacheValue.value; } function onCellClick(date, _ref2) { var _props$onCellClick; var e = _ref2.e; isHoverCell.value = false; isSelected.value = true; var nextValue = _toConsumableArray(cacheValue.value); nextValue[activeIndex.value] = formatDate(date, { format: formatRef.value.format }); cacheValue.value = nextValue; (_props$onCellClick = props.onCellClick) === null || _props$onCellClick === void 0 || _props$onCellClick.call(props, { e: e, partial: activeIndex.value ? "end" : "start", date: nextValue.map(function (v) { return parseToDayjs(v, formatRef.value.format).toDate(); }) }); emit("cell-click", { e: e, partial: activeIndex.value ? "end" : "start", date: nextValue.map(function (v) { return parseToDayjs(v, formatRef.value.format).toDate(); }) }); if (props.enableTimePicker) return; if (nextValue.length === 2 && isFirstValueSelected.value) { onChange === null || onChange === void 0 || onChange(formatDate(nextValue, { format: formatRef.value.format, autoSwap: true }), { dayjsValue: nextValue.map(function (v) { return parseToDayjs(v, formatRef.value.format); }), trigger: "pick" }); isFirstValueSelected.value = false; } else { isFirstValueSelected.value = true; } } function onJumperClick(_ref3) { var trigger = _ref3.trigger, partial = _ref3.partial; var partialIndex = partial === "start" ? 0 : 1; var triggerMap = { prev: "arrow-previous", next: "arrow-next" }; var monthCountMap = { date: 1, week: 1, month: 12, quarter: 12, year: 120 }; var monthCount = monthCountMap[props.mode] || 0; var current = new Date(year.value[partialIndex], month.value[partialIndex]); var next = null; if (trigger === "prev") { next = subtractMonth(current, monthCount); } else if (trigger === "current") { next = new Date(); } else if (trigger === "next") { next = addMonth(current, monthCount); } var nextYear = _toConsumableArray(year.value); nextYear[partialIndex] = next.getFullYear(); var nextMonth = _toConsumableArray(month.value); nextMonth[partialIndex] = next.getMonth(); var onlyYearSelect = ["year", "quarter", "month"].includes(props.mode); var correctedDate = dateCorrection(partialIndex, nextYear, nextMonth, onlyYearSelect); nextYear = correctedDate.nextYear; nextMonth = correctedDate.nextMonth; if (year.value.some(function (y) { return !nextYear.includes(y); })) { var _props$onYearChange; (_props$onYearChange = props.onYearChange) === null || _props$onYearChange === void 0 || _props$onYearChange.call(props, { partial: partial, year: nextYear[partialIndex], date: value.value.map(function (v) { return dayjs(v).toDate(); }), trigger: trigger === "current" ? "today" : "year-".concat(triggerMap[trigger]) }); emit("year-change", { partial: partial, year: nextYear[partialIndex], date: value.value.map(function (v) { return dayjs(v).toDate(); }), trigger: trigger === "current" ? "today" : "year-".concat(triggerMap[trigger]) }); } if (month.value.some(function (m) { return !nextMonth.includes(m); })) { var _props$onMonthChange; (_props$onMonthChange = props.onMonthChange) === null || _props$onMonthChange === void 0 || _props$onMonthChange.call(props, { partial: partial, month: nextMonth[partialIndex], date: value.value.map(function (v) { return dayjs(v).toDate(); }), trigger: trigger === "current" ? "today" : "month-".concat(triggerMap[trigger]) }); emit("month-change", { partial: partial, month: nextMonth[partialIndex], date: value.value.map(function (v) { return dayjs(v).toDate(); }), trigger: trigger === "current" ? "today" : "month-".concat(triggerMap[trigger]) }); } year.value = nextYear; month.value = nextMonth; } function onTimePickerChange(val) { var _props$onTimeChange; var _extractTimeObj = extractTimeObj(val), hours = _extractTimeObj.hours, minutes = _extractTimeObj.minutes, seconds = _extractTimeObj.seconds, milliseconds = _extractTimeObj.milliseconds, meridiem = _extractTimeObj.meridiem; var nextInputValue = _toConsumableArray(cacheValue.value); var changedInputValue = cacheValue.value[activeIndex.value]; var currentDate = !dayjs(changedInputValue, formatRef.value.format).isValid() ? dayjs().year(year.value[activeIndex.value]).month(month.value[activeIndex.value]) : dayjs(changedInputValue, formatRef.value.format); var nextHours = hours; if (/am/i.test(meridiem) && nextHours === 12) nextHours -= 12; if (/pm/i.test(meridiem) && nextHours < 12) nextHours += 12; var nextDate = currentDate.hour(nextHours).minute(minutes).second(seconds).millisecond(milliseconds).toDate(); nextInputValue[activeIndex.value] = nextDate; var nextTime = _toConsumableArray(time.value); nextTime[activeIndex.value] = val; time.value = nextTime; isSelected.value = true; cacheValue.value = formatDate(nextInputValue, { format: formatRef.value.format }); (_props$onTimeChange = props.onTimeChange) === null || _props$onTimeChange === void 0 || _props$onTimeChange.call(props, { time: val, date: value.value.map(function (v) { return dayjs(v).toDate(); }), partial: activeIndex.value ? "end" : "start", trigger: "time-hour" }); emit("time-change", { time: val, date: value.value.map(function (v) { return dayjs(v).toDate(); }), partial: activeIndex.value ? "end" : "start", trigger: "time-hour" }); } function onConfirmClick(_ref4) { var _props$onConfirm; var e = _ref4.e; var nextValue = _toConsumableArray(cacheValue.value); if (nextValue.length === 2 && isFirstValueSelected.value) { onChange === null || onChange === void 0 || onChange(formatDate(nextValue, { format: formatRef.value.format, autoSwap: true }), { dayjsValue: nextValue.map(function (v) { return parseToDayjs(v, formatRef.value.format); }), trigger: "confirm" }); year.value = nextValue.map(function (v) { return dayjs(v, formatRef.value.format).year(); }); month.value = nextValue.map(function (v) { return dayjs(v, formatRef.value.format).month(); }); isFirstValueSelected.value = false; } else { isFirstValueSelected.value = true; } (_props$onConfirm = props.onConfirm) === null || _props$onConfirm === void 0 || _props$onConfirm.call(props, { date: value.value.map(function (v) { return dayjs(v).toDate(); }), e: e }); emit("confirm", { date: value.value.map(function (v) { return dayjs(v).toDate(); }), e: e }); } function onPresetClick(preset, context) { var presetValue = preset; if (typeof preset === "function") { presetValue = preset(); } if (!Array.isArray(presetValue)) { console.error("preset: ".concat(preset, " \u9884\u8BBE\u503C\u5FC5\u987B\u662F\u6570\u7EC4!")); } else { var _props$onPresetClick; onChange === null || onChange === void 0 || onChange(formatDate(presetValue, { format: formatRef.value.format, autoSwap: true }), { dayjsValue: presetValue.map(function (p) { return parseToDayjs(p, formatRef.value.format); }), trigger: "preset" }); (_props$onPresetClick = props.onPresetClick) === null || _props$onPresetClick === void 0 || _props$onPresetClick.call(props, context); emit("preset-click", context); } } function onYearChange(nextVal, _ref5) { var _props$onYearChange2; var partial = _ref5.partial; var partialIndex = partial === "start" ? 0 : 1; if (props.enableTimePicker) partialIndex = activeIndex.value; var nextYear = _toConsumableArray(year.value); nextYear[partialIndex] = nextVal; var nextMonth = _toConsumableArray(month.value); var onlyYearSelect = ["year", "quarter", "month"].includes(props.mode); var correctedDate = dateCorrection(partialIndex, nextYear, nextMonth, onlyYearSelect); nextYear = correctedDate.nextYear; nextMonth = correctedDate.nextMonth; year.value = nextYear; if (!onlyYearSelect) month.value = nextMonth; (_props$onYearChange2 = props.onYearChange) === null || _props$onYearChange2 === void 0 || _props$onYearChange2.call(props, { partial: partial, year: nextYear[partialIndex], date: value.value.map(function (v) { return dayjs(v).toDate(); }), trigger: "year-select" }); emit("year-change", { partial: partial, year: nextYear[partialIndex], date: value.value.map(function (v) { return dayjs(v).toDate(); }), trigger: "year-select" }); } function onMonthChange(nextVal, _ref6) { var _props$onMonthChange2; var partial = _ref6.partial; var partialIndex = partial === "start" ? 0 : 1; if (props.enableTimePicker) partialIndex = activeIndex.value; var nextMonth = _toConsumableArray(month.value); nextMonth[partialIndex] = nextVal; if (year[0] === year[1]) { if (partialIndex === 0) { if (nextMonth[1] <= nextMonth[0]) { nextMonth[1] = nextMonth[0] + 1; if (nextMonth[1] === 12) { var _year$value, _year$value2; nextMonth[1] = 0; year.value = [(_year$value = year.value) === null || _year$value === void 0 ? void 0 : _year$value[0], ((_year$value2 = year.value) === null || _year$value2 === void 0 ? void 0 : _year$value2[1]) + 1]; } } } if (partialIndex === 1) { nextMonth[0] = Math.min(nextMonth[0], nextMonth[1]); if (nextMonth[0] >= nextMonth[1]) { nextMonth[0] -= 1; if (nextMonth[0] === -1) { var _year$value3, _year$value4; nextMonth[0] = 11; year.value = [((_year$value3 = year.value) === null || _year$value3 === void 0 ? void 0 : _year$value3[0]) - 1, (_year$value4 = year.value) === null || _year$value4 === void 0 ? void 0 : _year$value4[1]]; } } } } month.value = nextMonth; (_props$onMonthChange2 = props.onMonthChange) === null || _props$onMonthChange2 === void 0 || _props$onMonthChange2.call(props, { partial: partial, month: nextMonth[partialIndex], date: value.value.map(function (v) { return dayjs(v).toDate(); }), trigger: "month-select" }); emit("month-change", { partial: partial, month: nextMonth[partialIndex], date: value.value.map(function (v) { return dayjs(v).toDate(); }), trigger: "month-select" }); } function onPanelClick(context) { var _props$onPanelClick; (_props$onPanelClick = props.onPanelClick) === null || _props$onPanelClick === void 0 || _props$onPanelClick.call(props, context); emit("panel-click", context); } var panelProps = computed(function () { var _attrs$popupVisible; return { hoverValue: isHoverCell.value ? hoverValue.value : [], value: isSelected.value ? formatDate(cacheValue.value, { format: formatRef.value.format }) : value.value, activeIndex: activeIndex.value, year: year.value, month: month.value, mode: props.mode, format: formatRef.value.format, presets: props.presets, time: time.value, disableDate: props.disableDate, disableTime: props.disableTime, firstDayOfWeek: props.firstDayOfWeek, timePickerProps: props.timePickerProps, enableTimePicker: props.enableTimePicker, presetsPlacement: props.presetsPlacement, panelPreselection: props.panelPreselection, popupVisible: (_attrs$popupVisible = attrs === null || attrs === void 0 ? void 0 : attrs.popupVisible) !== null && _attrs$popupVisible !== void 0 ? _attrs$popupVisible : true, onPanelClick: onPanelClick, onCellClick: onCellClick, onCellMouseEnter: onCellMouseEnter, onCellMouseLeave: onCellMouseLeave, onJumperClick: onJumperClick, onConfirmClick: onConfirmClick, onPresetClick: onPresetClick, onYearChange: onYearChange, onMonthChange: onMonthChange, onTimePickerChange: onTimePickerChange }; }); return { panelProps: panelProps }; }, render: function render() { var h = arguments[0]; var panelProps = this.panelProps; return h(TRangePanel, { "props": _objectSpread({}, panelProps) }); } }); export { _DateRangePickerPanel as default }; //# sourceMappingURL=DateRangePickerPanel.js.map