UNPKG

tdesign-vue

Version:
331 lines (327 loc) 13.7 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, ref, computed, toRefs, watch } from '@vue/composition-api'; import dayjs from 'dayjs'; import { c as customParseFormat } from '../_chunks/dep-655d809c.js'; import { TimeIcon } from 'tdesign-icons-vue'; import { RangeInputPopup } from '../range-input/index.js'; import _TimePickerPanel from './panel/time-picker-panel.js'; import { TIME_PICKER_EMPTY } from '../_common/js/time-picker/const.js'; import { validateInputValue, formatInputValue } from '../_common/js/time-picker/utils.js'; import props from './time-range-picker-props.js'; import { useVModel } from '../hooks/useVModel.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import { useGlobalIcon } from '../hooks/useGlobalIcon.js'; import { useFormDisabled } from '../hooks/useFormDisabled.js'; import { useConfig } from '../config-provider/useConfig.js'; import '../_chunks/dep-fdb1b253.js'; import '../range-input/range-input.js'; import '../input/index.js'; import '../input/input.js'; import '../_chunks/dep-6a4dc7bb.js'; import '@babel/runtime/helpers/toConsumableArray'; import '@babel/runtime/helpers/typeof'; import 'lodash-es'; import '../_common/js/utils/helper.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../utils/helper.js'; import '../config-provider/config-receiver.js'; import 'vue'; 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-ba613a02.js'; import '../_common/js/global-config/t.js'; import '../utils/mixins.js'; import '../utils/event.js'; import '../input/props.js'; import '../utils/render-tnode.js'; import '@babel/runtime/helpers/readOnlyError'; import '../_common/js/log/log.js'; import '../input/input-group.js'; import '../utils/map-props.js'; import '../utils/withInstall.js'; import '../range-input/props.js'; import '../hooks/tnode.js'; import '../hooks/render-tnode.js'; import '../range-input/range-input-popup.js'; import '../popup/index.js'; import '../popup/popup.js'; import '@popperjs/core'; import '../utils/dom.js'; import 'raf'; import '../utils/easing.js'; import '../_common/js/utils/setStyle.js'; import '../popup/props.js'; import '../popup/container.js'; import '../popup/utils.js'; import '../popup/plugin.js'; import '../range-input/range-input-popup-props.js'; import '../select-input/useOverlayInnerStyle.js'; import './panel/props.js'; import './props.js'; import './panel/single-panel.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 '../utils/transfer-dom.js'; import '../loading/props.js'; import '../config.js'; import '../button/props.js'; import '../utils/ripple.js'; import '../_chunks/dep-84c94da7.js'; 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; } dayjs.extend(customParseFormat); var _TimeRangePicker = defineComponent({ name: "TTimeRangePicker", props: _objectSpread(_objectSpread({}, props), {}, { rangeInputProps: Object, popupProps: Object }), setup: function setup(props2, ctx) { var componentName = usePrefixClass("time-range-picker"); var _useConfig = useConfig("timePicker"), global = _useConfig.global; var _useConfig2 = useConfig("classPrefix"), classPrefix = _useConfig2.classPrefix; var _useGlobalIcon = useGlobalIcon({ TimeIcon: TimeIcon }), TimeIcon$1 = _useGlobalIcon.TimeIcon; var _useFormDisabled = useFormDisabled(), formDisabled = _useFormDisabled.formDisabled; var currentPanelIdx = ref(void 0); var currentValue = ref(TIME_PICKER_EMPTY); var isShowPanel = ref(false); var inputClasses = computed(function () { return ["".concat(componentName.value, "__group"), _defineProperty({}, "".concat(classPrefix.value, "-is-focused"), isShowPanel.value)]; }); var isDisabled = computed(function () { return formDisabled.value || props2.disabled; }); var _toRefs = toRefs(props2), value = _toRefs.value, format = _toRefs.format; var _useVModel = useVModel(value, props2.defaultValue, props2.onChange, "change"), _useVModel2 = _slicedToArray(_useVModel, 2), innerValue = _useVModel2[0], setInnerValue = _useVModel2[1]; var handleShowPopup = function handleShowPopup(visible, context) { if (context.trigger === "trigger-element-click") { isShowPanel.value = true; return; } isShowPanel.value = visible; }; var handleClear = function handleClear(context) { var e = context.e; e.stopPropagation(); currentValue.value = TIME_PICKER_EMPTY; setInnerValue(null); }; var handleClick = function handleClick(_ref2) { var position = _ref2.position; currentPanelIdx.value = position === "first" ? 0 : 1; }; var handleTimeChange = function handleTimeChange(newValue) { if (currentPanelIdx.value === 0) { var _currentValue$value$; currentValue.value = [newValue, (_currentValue$value$ = currentValue.value[1]) !== null && _currentValue$value$ !== void 0 ? _currentValue$value$ : newValue]; } else { var _currentValue$value$2; currentValue.value = [(_currentValue$value$2 = currentValue.value[0]) !== null && _currentValue$value$2 !== void 0 ? _currentValue$value$2 : newValue, newValue]; } }; var handleInputBlur = function handleInputBlur(value2, _ref3) { var _props2$onBlur; var e = _ref3.e; if (props2.allowInput) { var isValidTime = validateInputValue(currentValue.value[currentPanelIdx.value], format.value); if (isValidTime) { var _currentValue$value$3, _currentValue$value$4; var formattedVal = formatInputValue(currentValue.value[currentPanelIdx.value], format.value); currentPanelIdx.value === 0 ? currentValue.value = [formattedVal, (_currentValue$value$3 = currentValue.value[1]) !== null && _currentValue$value$3 !== void 0 ? _currentValue$value$3 : formattedVal] : currentValue.value = [(_currentValue$value$4 = currentValue.value[0]) !== null && _currentValue$value$4 !== void 0 ? _currentValue$value$4 : formattedVal, formattedVal]; } } (_props2$onBlur = props2.onBlur) === null || _props2$onBlur === void 0 || _props2$onBlur.call(props2, { value: value2, e: e }); }; var handleInputChange = function handleInputChange(inputVal, _ref4) { var _props2$onInput; var e = _ref4.e, position = _ref4.position; currentValue.value = inputVal; (_props2$onInput = props2.onInput) === null || _props2$onInput === void 0 || _props2$onInput.call(props2, { value: innerValue.value, e: e, position: position === "first" ? "start" : "end" }); ctx.emit("input", { value: innerValue.value, e: e, position: position === "first" ? "start" : "end" }); }; var handleClickConfirm = function handleClickConfirm() { var isValidTime = !currentValue.value.find(function (v) { return !validateInputValue(v, format.value); }); if (isValidTime) setInnerValue(currentValue.value); if (props2.autoSwap) autoSwapTime(); isShowPanel.value = false; }; var handleFocus = function handleFocus(value2, _ref5) { var _props2$onFocus; var e = _ref5.e, position = _ref5.position; (_props2$onFocus = props2.onFocus) === null || _props2$onFocus === void 0 || _props2$onFocus.call(props2, { value: value2, e: e, position: position === "first" ? "start" : "end" }); ctx.emit("focus", { value: value2, e: e, position: position === "first" ? "start" : "end" }); }; var autoSwapTime = function autoSwapTime() { var _currentValue$value = _slicedToArray(currentValue.value, 2), startTime = _currentValue$value[0], endTime = _currentValue$value[1]; var startDayjs = dayjs(startTime, props2.format); var endDayjs = dayjs(endTime, props2.format); if (startDayjs.isAfter(endDayjs, "second")) { setInnerValue([currentValue.value[1], currentValue.value[0]]); } else { setInnerValue([currentValue.value[0], currentValue.value[1]]); } }; var handleOnPick = function handleOnPick(pickValue, e) { var _props2$onPick; var pickedRangeValue = []; var context = { e: e }; if (currentPanelIdx.value === 0) { var _currentValue$value$5; pickedRangeValue = [pickValue, (_currentValue$value$5 = currentValue.value[1]) !== null && _currentValue$value$5 !== void 0 ? _currentValue$value$5 : pickValue]; context = { position: "start", e: e }; } else { var _currentValue$value$6; pickedRangeValue = [(_currentValue$value$6 = currentValue.value[0]) !== null && _currentValue$value$6 !== void 0 ? _currentValue$value$6 : pickValue, pickValue]; context = { position: "end", e: e }; } (_props2$onPick = props2.onPick) === null || _props2$onPick === void 0 || _props2$onPick.call(props2, pickedRangeValue, context); ctx.emit("pick", pickedRangeValue, context); }; watch(function () { return isShowPanel.value; }, function () { var _innerValue$value; currentValue.value = isShowPanel.value ? (_innerValue$value = innerValue.value) !== null && _innerValue$value !== void 0 ? _innerValue$value : TIME_PICKER_EMPTY : TIME_PICKER_EMPTY; if (!isShowPanel.value) currentPanelIdx.value = void 0; }); return { global: global, componentName: componentName, currentValue: currentValue, currentPanelIdx: currentPanelIdx, inputClasses: inputClasses, innerValue: innerValue, isShowPanel: isShowPanel, handleInputChange: handleInputChange, handleShowPopup: handleShowPopup, handleClear: handleClear, handleFocus: handleFocus, handleOnPick: handleOnPick, handleClickConfirm: handleClickConfirm, handleClick: handleClick, handleInputBlur: handleInputBlur, handleTimeChange: handleTimeChange, TimeIcon: TimeIcon$1, isDisabled: isDisabled }; }, render: function render() { var _this$innerValue, _this = this; var h = arguments[0]; var TimeIcon = this.TimeIcon; return h("div", { "class": this.componentName }, [h(RangeInputPopup, { "props": _objectSpread({}, { onInputChange: this.handleInputChange, disabled: this.isDisabled, readonly: this.readonly, popupVisible: this.isShowPanel, inputValue: this.isShowPanel ? this.currentValue : (_this$innerValue = this.innerValue) !== null && _this$innerValue !== void 0 ? _this$innerValue : TIME_PICKER_EMPTY, popupProps: _objectSpread({ overlayInnerStyle: { width: "auto", padding: 0 }, onVisibleChange: this.handleShowPopup }, this.popupProps), status: this.status, tips: this.tips, rangeInputProps: _objectSpread({ size: this.size, borderless: this.borderless, clearable: this.clearable, "class": this.inputClasses, placeholder: this.placeholder || [this.global.placeholder, this.global.placeholder], suffixIcon: function suffixIcon() { return h(TimeIcon); }, onClear: this.handleClear, onClick: this.handleClick, onFocus: this.handleFocus, onBlur: this.handleInputBlur, readonly: this.readonly || !this.allowInput, activeIndex: this.currentPanelIdx }, this.rangeInputProps), panel: function panel() { return h(_TimePickerPanel, { "props": _objectSpread({}, { steps: _this.steps, format: _this.format, isShowPanel: _this.isShowPanel, disableTime: _this.disableTime, hideDisabledTime: _this.hideDisabledTime, isFooterDisplay: true, value: _this.currentValue[_this.currentPanelIdx || 0], onChange: _this.handleTimeChange, onPick: _this.handleOnPick, handleConfirmClick: _this.handleClickConfirm, position: _this.currentPanelIdx === 0 ? "start" : "end", activeIndex: _this.currentPanelIdx, presets: _this.presets }) }); } }) })]); } }); export { _TimeRangePicker as default }; //# sourceMappingURL=time-range-picker.js.map