返回游戏流程完善
This commit is contained in:
@@ -1,48 +1,35 @@
|
||||
<script setup>
|
||||
import { ref, watch } from "vue";
|
||||
import { ref, watch, onMounted, onUnmounted } from "vue";
|
||||
const props = defineProps({
|
||||
seq: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
countdown: {
|
||||
type: Number,
|
||||
default: 15,
|
||||
},
|
||||
callBack: {
|
||||
type: Function,
|
||||
default: () => {},
|
||||
},
|
||||
});
|
||||
const show = ref(false);
|
||||
const count = ref(0);
|
||||
const count = ref(props.countdown);
|
||||
const timer = ref(null);
|
||||
watch(
|
||||
() => props.seq,
|
||||
() => {
|
||||
if (props.seq > 0) {
|
||||
if (show.value) return;
|
||||
if (timer.value) clearInterval(timer.value);
|
||||
count.value = props.countdown;
|
||||
show.value = true;
|
||||
timer.value = setInterval(() => {
|
||||
if (count.value === 0) {
|
||||
show.value = false;
|
||||
clearInterval(timer.value);
|
||||
props.callBack();
|
||||
} else {
|
||||
count.value -= 1;
|
||||
}
|
||||
}, 1000);
|
||||
} else {
|
||||
if (timer.value) clearInterval(timer.value);
|
||||
show.value = false;
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
}
|
||||
);
|
||||
const updateTimer = (value) => {
|
||||
count.value = Math.round(value);
|
||||
};
|
||||
onMounted(() => {
|
||||
setTimeout(() => {
|
||||
show.value = true;
|
||||
timer.value = setInterval(() => {
|
||||
if (count.value === 0) {
|
||||
show.value = false;
|
||||
clearInterval(timer.value);
|
||||
} else {
|
||||
count.value -= 1;
|
||||
}
|
||||
}, 1000);
|
||||
}, 300);
|
||||
uni.$on("update-timer", updateTimer);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
if (timer.value) clearInterval(timer.value);
|
||||
uni.$off("update-timer", updateTimer);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user