From 439e3b0f076280311b7cd4251a95820730242780 Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期三, 07 八月 2024 10:43:33 +0800 Subject: [PATCH] 一些更新 --- src/components/CountDown/src/CountButton.vue | 85 +++++++++++++++++++----------------------- 1 files changed, 39 insertions(+), 46 deletions(-) diff --git a/src/components/CountDown/src/CountButton.vue b/src/components/CountDown/src/CountButton.vue index 1ef520e..74e45cc 100644 --- a/src/components/CountDown/src/CountButton.vue +++ b/src/components/CountDown/src/CountButton.vue @@ -3,60 +3,53 @@ {{ getButtonText }} </Button> </template> -<script lang="ts"> - import { defineComponent, ref, watchEffect, computed, unref } from 'vue'; +<script lang="ts" setup> + import { ref, watchEffect, computed, unref } from 'vue'; import { Button } from 'ant-design-vue'; import { useCountdown } from './useCountdown'; - import { isFunction } from '/@/utils/is'; - import { useI18n } from '/@/hooks/web/useI18n'; + import { isFunction } from '@/utils/is'; + import { useI18n } from '@/hooks/web/useI18n'; - const props = { + defineOptions({ name: 'CountButton' }); + + const props = defineProps({ value: { type: [Object, Number, String, Array] }, count: { type: Number, default: 60 }, beforeStartFunc: { type: Function as PropType<() => Promise<boolean>>, default: null, }, - }; - - export default defineComponent({ - name: 'CountButton', - components: { Button }, - props, - setup(props) { - const loading = ref(false); - - const { currentCount, isStart, start, reset } = useCountdown(props.count); - const { t } = useI18n(); - - const getButtonText = computed(() => { - return !unref(isStart) - ? t('component.countdown.normalText') - : t('component.countdown.sendText', [unref(currentCount)]); - }); - - watchEffect(() => { - props.value === undefined && reset(); - }); - - /** - * @description: Judge whether there is an external function before execution, and decide whether to start after execution - */ - 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 }; - }, }); + + const { t } = useI18n(); + const loading = ref(false); + const { currentCount, isStart, start, reset } = useCountdown(props.count); + + const getButtonText = computed(() => { + return !unref(isStart) + ? t('component.countdown.normalText') + : t('component.countdown.sendText', [unref(currentCount)]); + }); + + watchEffect(() => { + props.value === undefined && reset(); + }); + + /** + * @description: Judge whether there is an external function before execution, and decide whether to start after execution + */ + 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(); + } + } </script> -- Gitblit v1.9.3