UNPKG

tdesign-vue

Version:
204 lines (200 loc) 7.8 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, ref, computed, nextTick, onMounted, watch } from '@vue/composition-api'; import dayjs from 'dayjs'; import { c as customParseFormat } from '../../_chunks/dep-d5b67aa1.js'; import { DEFAULT_FORMAT, DEFAULT_STEPS } from '../../_common/js/time-picker/const.js'; import { panelProps } from './props.js'; import SinglePanel from './single-panel.js'; import TButton from '../../button/button.js'; import { usePrefixClass } from '../../hooks/useConfig.js'; import '../../_common/js/log/index.js'; import { useConfig } from '../../config-provider/useConfig.js'; import log from '../../_common/js/log/log.js'; import '../../_chunks/dep-d639fbd7.js'; import '../props.js'; import 'lodash-es'; import '../../_common/js/time-picker/utils.js'; import '../../loading/index.js'; import '../../loading/directive.js'; import '../../loading/plugin.js'; import 'vue'; 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/toConsumableArray'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import '../../config-provider/config-receiver.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-c44a474d.js'; import '@babel/runtime/helpers/typeof'; import '../../_chunks/dep-3c66615e.js'; import '../../config-provider/type.js'; import '../../_common/js/global-config/t.js'; import '../../utils/mixins.js'; 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'; 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 _TimePickerPanel = defineComponent({ name: "TTimePickerPanel", props: _objectSpread(_objectSpread({}, panelProps()), {}, { handleConfirmClick: Function, onChange: Function, onPick: Function, disableTime: Function }), setup: function setup(props, ctx) { var panelClassName = usePrefixClass("time-picker__panel"); var triggerScroll = ref(false); var _useConfig = useConfig("timePicker"), global = _useConfig.global; var showNowTimeBtn = computed(function () { return !!props.steps.filter(function (v) { return v > 1; }).length; }); var defaultValue = computed(function () { var isStepsSet = showNowTimeBtn.value; var formattedValue = dayjs(props.value, props.format); if (props.value && formattedValue.isValid()) { return formattedValue; } if (isStepsSet) { return dayjs().hour(0).minute(0).second(0); } return dayjs().hour(0).minute(0).second(0).format(props.format); }); var panelColUpdate = function panelColUpdate() { nextTick(function () { triggerScroll.value = true; }); }; var resetTriggerScroll = function resetTriggerScroll() { triggerScroll.value = false; }; var handleChange = function handleChange(v, e) { var _props$onPick, _props$onChange; (_props$onPick = props.onPick) === null || _props$onPick === void 0 || _props$onPick.call(props, v, e); ctx.emit("pick", v, e); (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, v); ctx.emit("change", v); }; var handlePresetClick = function handlePresetClick(presetValue) { var presetVal = typeof presetValue === "function" ? presetValue() : presetValue; if (typeof props.activeIndex === "number") { if (Array.isArray(presetVal)) { props.onChange(presetVal[props.activeIndex]); } else { log.error("TimePicker", "preset: ".concat(props.presets, " \u9884\u8BBE\u503C\u5FC5\u987B\u662F\u6570\u7EC4!")); } } else { props.onChange(presetVal); } }; onMounted(function () { panelColUpdate(); }); watch(function () { return props.isShowPanel; }, function () { panelColUpdate(); }); return { showNowTimeBtn: showNowTimeBtn, panelClassName: panelClassName, triggerScroll: triggerScroll, resetTriggerScroll: resetTriggerScroll, defaultValue: defaultValue, global: global, handleChange: handleChange, handlePresetClick: handlePresetClick }; }, render: function render() { var _this = this; var h = arguments[0]; return h("div", { "class": this.panelClassName }, [h("div", { "class": "".concat(this.panelClassName, "-section-body") }, [h(SinglePanel, { "props": _objectSpread({}, { value: dayjs(this.value, this.format).isValid() ? this.value : this.defaultValue, onChange: this.handleChange, onPick: this.onPick, format: this.format || DEFAULT_FORMAT, steps: this.steps || DEFAULT_STEPS, triggerScroll: this.triggerScroll, disableTime: this.disableTime, position: this.position, resetTriggerScroll: this.resetTriggerScroll, isShowPanel: this.isShowPanel, hideDisabledTime: this.hideDisabledTime }) })]), this.isFooterDisplay ? h("div", { "class": "".concat(this.panelClassName, "-section-footer") }, [h(TButton, { "attrs": { "theme": "primary", "variant": "base", "disabled": !this.value, "size": "small" }, "on": { "click": function click() { return _this.handleConfirmClick(_this.defaultValue); } } }, [this.global.confirm]), h("div", [!this.showNowTimeBtn ? h(TButton, { "attrs": { "theme": "primary", "variant": "text", "size": "small" }, "on": { "click": function click() { return _this.onChange(dayjs().format(_this.format)); } } }, [this.global.now]) : null, this.presets && Object.keys(this.presets).map(function (key) { return h(TButton, { "key": key, "attrs": { "theme": "primary", "size": "small", "variant": "text" }, "on": { "click": function click() { var _this$handlePresetCli; return (_this$handlePresetCli = _this.handlePresetClick) === null || _this$handlePresetCli === void 0 ? void 0 : _this$handlePresetCli.call(_this, _this.presets[key]); } } }, [key]); })])]) : null]); } }); export { _TimePickerPanel as default }; //# sourceMappingURL=time-picker-panel.js.map