UNPKG

tav-ui

Version:
57 lines (54 loc) 2.23 kB
import { defineComponent, ref, computed, unref, watchEffect, resolveComponent, openBlock, createBlock, mergeProps, withCtx, createTextVNode, toDisplayString } from 'vue'; import { Button } from 'ant-design-vue'; import { isFunction } from '../../../utils/is2.mjs'; import '../../../locales/index2.mjs'; import { useCountdown } from './useCountdown2.mjs'; import { countDownButtonProps } from './types2.mjs'; import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs'; import { tavI18n } from '../../../locales/transfer2.mjs'; const _sfc_main = defineComponent({ name: "TaCountDownButton", components: { Button }, props: countDownButtonProps, setup(props) { const loading = ref(false); const { currentCount, isStart, start, reset } = useCountdown(props.count); const getButtonText = computed(() => { return !unref(isStart) ? tavI18n("Tav.countButton.text1") : tavI18n("Tav.countButton.text2", [unref(currentCount)]); }); watchEffect(() => { props.value === void 0 && reset(); }); async function handleStart() { const { beforeStartFunc } = props; if (beforeStartFunc && isFunction(beforeStartFunc)) { loading.value = true; try { const canStart = await beforeStartFunc(); canStart && start(); } finally { loading.value = false; } } else { start(); } } return { handleStart, currentCount, loading, getButtonText, isStart }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_Button = resolveComponent("Button"); return openBlock(), createBlock(_component_Button, mergeProps(_ctx.$attrs, { disabled: _ctx.isStart, loading: _ctx.loading, onClick: _ctx.handleStart }), { default: withCtx(() => [ createTextVNode(toDisplayString(_ctx.getButtonText), 1) ]), _: 1 }, 16, ["disabled", "loading", "onClick"]); } var CountDownButton = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/tav-ui/tav-ui/packages/components/count-down/src/count-down-button.vue"]]); export { CountDownButton as default }; //# sourceMappingURL=count-down-button2.mjs.map