Files
shoot-miniprograms/src/components/StartCountdown.vue

61 lines
1.2 KiB
Vue
Raw Normal View History

2025-06-19 01:55:40 +08:00
<script setup>
2025-07-05 13:12:58 +08:00
import { ref, watch, onMounted, onUnmounted } from "vue";
2025-06-19 01:55:40 +08:00
const props = defineProps({
start: {
type: Boolean,
default: false,
},
});
const count = ref(4);
const timer = ref(null);
2025-07-05 13:12:58 +08:00
const isIos = ref(true);
2025-06-19 01:55:40 +08:00
watch(
() => props.start,
(newVal) => {
if (newVal) {
if (timer.value) clearInterval(timer.value);
2025-07-05 13:12:58 +08:00
count.value = 4;
2025-06-19 01:55:40 +08:00
timer.value = setInterval(() => {
if (count.value <= 1) {
clearInterval(timer.value);
}
count.value -= 1;
}, 1000);
}
},
{
immediate: true,
}
);
2025-07-05 13:12:58 +08:00
onMounted(() => {
const deviceInfo = uni.getDeviceInfo();
isIos.value = deviceInfo.osName === "ios";
});
2025-06-19 01:55:40 +08:00
onUnmounted(() => {
if (timer.value) clearInterval(timer.value);
});
</script>
<template>
2025-07-05 14:52:41 +08:00
<view class="container" :style="{ top: `calc(50% - ${isIos ? 56 : 64}px)` }">
2025-06-19 01:55:40 +08:00
<view class="number pump-in" v-if="count === 3">3</view>
<view class="number pump-in" v-if="count === 2">2</view>
<view class="number pump-in" v-if="count === 1">1</view>
</view>
</template>
<style scoped>
.container {
2025-06-25 00:09:53 +08:00
position: absolute;
2025-06-25 18:41:30 +08:00
top: calc(50% - 64px);
2025-06-19 01:55:40 +08:00
left: calc(50% - 30px);
}
.number {
color: #fff9;
font-size: 88px;
width: 60px;
text-align: center;
}
</style>