2025-05-10 16:57:36 +08:00
|
|
|
<script setup>
|
2025-06-19 01:55:40 +08:00
|
|
|
import { ref, watch, onUnmounted } from "vue";
|
2025-05-10 16:57:36 +08:00
|
|
|
const props = defineProps({
|
2025-05-29 23:45:44 +08:00
|
|
|
start: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
2025-05-10 16:57:36 +08:00
|
|
|
tips: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: "",
|
|
|
|
|
},
|
|
|
|
|
total: {
|
|
|
|
|
type: Number,
|
2025-05-16 15:56:54 +08:00
|
|
|
default: 90,
|
2025-05-10 16:57:36 +08:00
|
|
|
},
|
2025-06-05 21:32:51 +08:00
|
|
|
seq: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 0,
|
|
|
|
|
},
|
2025-06-19 01:55:40 +08:00
|
|
|
onTimeIsUp: {
|
|
|
|
|
type: Function,
|
|
|
|
|
default: () => {},
|
|
|
|
|
},
|
2025-05-10 16:57:36 +08:00
|
|
|
});
|
2025-05-29 23:45:44 +08:00
|
|
|
|
2025-06-11 23:57:17 +08:00
|
|
|
const barColor = ref("#fed847");
|
|
|
|
|
|
2025-05-29 23:45:44 +08:00
|
|
|
const remain = ref(props.total);
|
2025-06-05 21:32:51 +08:00
|
|
|
const timer = ref(null);
|
|
|
|
|
|
2025-06-11 23:57:17 +08:00
|
|
|
watch(
|
|
|
|
|
() => props.tips,
|
|
|
|
|
(newVal) => {
|
|
|
|
|
if (newVal.includes("红队")) barColor.value = "#FF6060";
|
|
|
|
|
if (newVal.includes("蓝队")) barColor.value = "#5FADFF";
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-06-05 21:32:51 +08:00
|
|
|
watch(
|
|
|
|
|
() => props.seq,
|
|
|
|
|
() => {
|
|
|
|
|
if (timer.value) clearInterval(timer.value);
|
|
|
|
|
remain.value = props.total;
|
|
|
|
|
timer.value = setInterval(() => {
|
|
|
|
|
if (remain.value > 0) {
|
|
|
|
|
remain.value--;
|
2025-06-19 01:55:40 +08:00
|
|
|
} else {
|
|
|
|
|
props.onTimeIsUp();
|
2025-06-05 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-05-29 23:45:44 +08:00
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => props.start,
|
|
|
|
|
(newVal, oldVal) => {
|
2025-06-19 01:55:40 +08:00
|
|
|
if (newVal === false) {
|
|
|
|
|
if (timer.value) clearInterval(timer.value);
|
|
|
|
|
}
|
2025-06-25 00:09:53 +08:00
|
|
|
if (!oldVal && newVal === true) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
remain.value = props.total;
|
|
|
|
|
timer.value = setInterval(() => {
|
|
|
|
|
if (remain.value > 0) {
|
|
|
|
|
remain.value--;
|
|
|
|
|
} else {
|
|
|
|
|
props.onTimeIsUp();
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
}, 3000);
|
2025-06-05 21:32:51 +08:00
|
|
|
} else {
|
|
|
|
|
if (timer.value) clearInterval(timer.value);
|
2025-05-10 16:57:36 +08:00
|
|
|
}
|
2025-06-25 00:09:53 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
immediate: true,
|
2025-05-29 23:45:44 +08:00
|
|
|
}
|
|
|
|
|
);
|
2025-06-19 01:55:40 +08:00
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
if (timer.value) clearInterval(timer.value);
|
|
|
|
|
});
|
2025-05-10 16:57:36 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<view class="container">
|
|
|
|
|
<view>
|
|
|
|
|
<image src="../static/shooter.png" mode="widthFix" />
|
|
|
|
|
<text>{{ remain === 0 ? "射箭时间到!" : tips }}</text>
|
|
|
|
|
<button>
|
|
|
|
|
<image src="../static/sound-yellow.png" mode="widthFix" />
|
|
|
|
|
</button>
|
|
|
|
|
</view>
|
|
|
|
|
<view>
|
2025-05-16 15:56:54 +08:00
|
|
|
<view
|
|
|
|
|
:style="{
|
2025-06-19 01:55:40 +08:00
|
|
|
width: `${(remain / total) * 100}%`,
|
2025-05-16 15:56:54 +08:00
|
|
|
backgroundColor: barColor,
|
|
|
|
|
right: tips.includes('红队') ? 0 : 'unset',
|
|
|
|
|
}"
|
|
|
|
|
/>
|
2025-05-10 16:57:36 +08:00
|
|
|
<text>剩余{{ remain }}秒</text>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.container {
|
|
|
|
|
width: 100vw;
|
|
|
|
|
}
|
|
|
|
|
.container > view:first-child {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
padding: 0 15px;
|
|
|
|
|
color: #fed847;
|
|
|
|
|
z-index: 1;
|
2025-06-17 12:50:59 +08:00
|
|
|
transform: translateX(-10px);
|
2025-05-10 16:57:36 +08:00
|
|
|
}
|
|
|
|
|
.container > view:first-child > image:first-child {
|
|
|
|
|
width: 80px;
|
2025-06-18 21:30:54 +08:00
|
|
|
transform: translateX(10px);
|
2025-05-10 16:57:36 +08:00
|
|
|
}
|
|
|
|
|
.container > view:first-child > button:last-child > image {
|
|
|
|
|
width: 50px;
|
2025-06-24 13:18:03 +08:00
|
|
|
transform: translateX(10px);
|
2025-05-10 16:57:36 +08:00
|
|
|
}
|
|
|
|
|
.container > view:last-child {
|
|
|
|
|
z-index: -1;
|
|
|
|
|
width: clac(100% - 30px);
|
|
|
|
|
margin: 0 15px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
background-color: #ffffff80;
|
|
|
|
|
border-radius: 20px;
|
2025-06-28 12:03:33 +08:00
|
|
|
margin-top: -20px;
|
2025-05-10 16:57:36 +08:00
|
|
|
font-size: 12px;
|
|
|
|
|
height: 20px;
|
|
|
|
|
line-height: 20px;
|
|
|
|
|
position: relative;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
.container > view:last-child > view {
|
|
|
|
|
position: absolute;
|
|
|
|
|
height: 20px;
|
|
|
|
|
border-radius: 20px;
|
|
|
|
|
z-index: -1;
|
2025-06-19 01:55:40 +08:00
|
|
|
transition: all 1s linear;
|
2025-05-10 16:57:36 +08:00
|
|
|
}
|
|
|
|
|
.container > view:last-child > text {
|
|
|
|
|
z-index: 1;
|
2025-06-21 22:22:19 +08:00
|
|
|
color: #000;
|
2025-05-10 16:57:36 +08:00
|
|
|
}
|
|
|
|
|
</style>
|