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

132 lines
2.6 KiB
Vue
Raw Normal View History

2025-05-10 16:57:36 +08:00
<script setup>
2025-05-29 23:45:44 +08:00
import { ref, watch } 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-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--;
}
}, 1000);
}
);
2025-05-29 23:45:44 +08:00
watch(
() => props.start,
(newVal, oldVal) => {
if (oldVal === false && newVal === true) {
remain.value = props.total;
2025-06-05 21:32:51 +08:00
timer.value = setInterval(() => {
2025-05-29 23:45:44 +08:00
if (remain.value > 0) {
remain.value--;
}
}, 1000);
2025-06-05 21:32:51 +08:00
} else {
if (timer.value) clearInterval(timer.value);
2025-05-10 16:57:36 +08:00
}
2025-05-29 23:45:44 +08:00
}
);
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="{
width: `${((total - remain) / total) * 100}%`,
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;
}
.container > view:first-child > button:last-child > image {
width: 50px;
}
.container > view:last-child {
z-index: -1;
width: clac(100% - 30px);
margin: 0 15px;
text-align: center;
background-color: #ffffff80;
border-radius: 20px;
margin-top: -14px;
font-size: 12px;
height: 20px;
line-height: 20px;
position: relative;
transition: all 0.5s linear;
overflow: hidden;
}
.container > view:last-child > view {
position: absolute;
height: 20px;
border-radius: 20px;
z-index: -1;
2025-06-11 23:57:17 +08:00
transition: all 0.3s linear;
2025-05-10 16:57:36 +08:00
}
.container > view:last-child > text {
z-index: 1;
}
</style>