cl-countdown 添加 auto 参数
This commit is contained in:
@@ -33,6 +33,10 @@
|
|||||||
<cl-countdown :second="5" @done="onDone"></cl-countdown>
|
<cl-countdown :second="5" @done="onDone"></cl-countdown>
|
||||||
</demo-item>
|
</demo-item>
|
||||||
|
|
||||||
|
<demo-item :label="t('3秒后开始倒计时')">
|
||||||
|
<cl-countdown ref="countdownRef" :second="5" :auto="false"></cl-countdown>
|
||||||
|
</demo-item>
|
||||||
|
|
||||||
<demo-item :label="t('自定义样式')">
|
<demo-item :label="t('自定义样式')">
|
||||||
<cl-countdown
|
<cl-countdown
|
||||||
:hour="10"
|
:hour="10"
|
||||||
@@ -56,7 +60,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { t } from "@/locale";
|
import { t } from "@/locale";
|
||||||
import DemoItem from "../components/item.uvue";
|
import DemoItem from "../components/item.uvue";
|
||||||
import { ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import { dayUts, isDark, parseClass } from "@/cool";
|
import { dayUts, isDark, parseClass } from "@/cool";
|
||||||
import { useUi } from "@/uni_modules/cool-ui";
|
import { useUi } from "@/uni_modules/cool-ui";
|
||||||
|
|
||||||
@@ -69,4 +73,12 @@ function onDone() {
|
|||||||
message: "倒计时完成"
|
message: "倒计时完成"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const countdownRef = ref<ClCountdownComponentPublicInstance | null>(null);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
countdownRef.value!.next();
|
||||||
|
}, 3000);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, watch, nextTick, onBeforeUnmount, onBeforeMount, computed, type PropType } from "vue";
|
import { ref, watch, nextTick, computed, type PropType, onMounted, onUnmounted } from "vue";
|
||||||
import type { PassThroughProps } from "../../types";
|
import type { PassThroughProps } from "../../types";
|
||||||
import { dayUts, get, has, isEmpty, parsePt } from "@/cool";
|
import { dayUts, get, has, isEmpty, parsePt } from "@/cool";
|
||||||
|
|
||||||
@@ -71,6 +71,11 @@ const props = defineProps({
|
|||||||
datetime: {
|
datetime: {
|
||||||
type: [Date, String] as PropType<Date | string>,
|
type: [Date, String] as PropType<Date | string>,
|
||||||
default: null
|
default: null
|
||||||
|
},
|
||||||
|
// 是否自动开始倒计时
|
||||||
|
auto: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -267,10 +272,21 @@ function start(options: Options | null = null) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 开始倒计时
|
// 开始倒计时
|
||||||
|
if (props.auto) {
|
||||||
next();
|
next();
|
||||||
|
} else {
|
||||||
|
countDown();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 组件销毁前停止倒计时
|
||||||
|
onUnmounted(() => stop());
|
||||||
|
|
||||||
|
// 组件挂载前开始倒计时
|
||||||
|
onMounted(() => {
|
||||||
|
start();
|
||||||
|
|
||||||
// 监听时间单位变化,重新开始倒计时
|
// 监听时间单位变化,重新开始倒计时
|
||||||
watch(
|
watch(
|
||||||
computed(() => [props.day, props.hour, props.minute, props.second] as number[]),
|
computed(() => [props.day, props.hour, props.minute, props.second] as number[]),
|
||||||
@@ -286,17 +302,13 @@ watch(
|
|||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
});
|
||||||
// 组件销毁前停止倒计时
|
|
||||||
onBeforeUnmount(() => stop());
|
|
||||||
|
|
||||||
// 组件挂载前开始倒计时
|
|
||||||
onBeforeMount(() => start());
|
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
start,
|
start,
|
||||||
stop,
|
stop,
|
||||||
done,
|
done,
|
||||||
|
next,
|
||||||
isRunning
|
isRunning
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ export type ClCountdownProps = {
|
|||||||
minute?: number;
|
minute?: number;
|
||||||
second?: number;
|
second?: number;
|
||||||
datetime?: Date | string;
|
datetime?: Date | string;
|
||||||
|
auto?: boolean;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user