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

121 lines
2.6 KiB
Vue
Raw Normal View History

2025-08-13 16:44:25 +08:00
<script setup>
2025-08-25 13:47:32 +08:00
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
2025-08-13 16:44:25 +08:00
import { RoundGoldImages } from "@/constants";
const props = defineProps({
tips: {
type: String,
default: "",
},
total: {
type: Number,
default: 15,
},
currentRound: {
type: String,
default: "round1",
},
});
2025-08-15 11:23:23 +08:00
const barColor = ref("");
2025-08-14 15:24:12 +08:00
const remain = ref(15);
2025-08-13 16:44:25 +08:00
const timer = ref(null);
watch(
() => props.tips,
(newVal) => {
if (newVal.includes("红队"))
barColor.value = "linear-gradient( 180deg, #FFA0A0 0%, #FF6060 100%)";
if (newVal.includes("蓝队"))
barColor.value = "linear-gradient( 180deg, #9AB3FF 0%, #4288FF 100%)";
2025-11-10 13:43:25 +08:00
if (newVal.includes("重回")) return;
2025-08-13 16:44:25 +08:00
if (newVal.includes("红队") || newVal.includes("蓝队")) {
if (timer.value) clearInterval(timer.value);
remain.value = props.total;
timer.value = setInterval(() => {
if (remain.value > 0) remain.value--;
}, 1000);
}
},
{
immediate: true,
}
);
const updateRemain = (value) => {
2025-11-10 13:43:25 +08:00
if (Math.ceil(value) === remain.value || Math.floor(value) === remain.value)
return;
2025-08-13 16:44:25 +08:00
if (timer.value) clearInterval(timer.value);
remain.value = Math.round(value);
2025-08-14 10:50:44 +08:00
timer.value = setInterval(() => {
if (remain.value > 0) remain.value--;
}, 1000);
2025-08-13 16:44:25 +08:00
};
onMounted(() => {
uni.$on("update-ramain", updateRemain);
});
2025-08-25 13:47:32 +08:00
onBeforeUnmount(() => {
2025-08-13 16:44:25 +08:00
uni.$off("update-ramain", updateRemain);
if (timer.value) clearInterval(timer.value);
});
</script>
<template>
<view class="container">
<image :src="RoundGoldImages[props.currentRound]" mode="widthFix" />
2025-11-08 11:33:03 +08:00
<view
:style="{
justifyContent: tips.includes('红队') ? 'flex-end' : 'flex-start',
}"
>
2025-08-13 16:44:25 +08:00
<view
:style="{
width: `${(remain / total) * 100}%`,
background: barColor,
right: tips.includes('红队') ? 0 : 'unset',
}"
/>
<text>剩余{{ remain }}</text>
</view>
</view>
</template>
<style scoped>
.container {
width: 50vw;
display: flex;
flex-direction: column;
align-items: center;
}
.container > image {
2025-11-07 16:28:52 +08:00
width: 360rpx;
height: 80rpx;
2025-11-08 11:33:03 +08:00
transform: translateY(20rpx);
2025-08-13 16:44:25 +08:00
}
.container > view:last-child {
width: 100%;
text-align: center;
background-color: #444444;
border-radius: 20px;
2025-11-08 10:57:37 +08:00
height: 24rpx;
2025-08-13 16:44:25 +08:00
position: relative;
overflow: hidden;
2025-11-08 11:33:03 +08:00
display: flex;
align-items: center;
2025-08-13 16:44:25 +08:00
}
.container > view:last-child > view {
2025-11-08 10:57:37 +08:00
height: 24rpx;
2025-08-13 16:44:25 +08:00
border-radius: 15px;
transition: all 1s linear;
}
.container > view:last-child > text {
2025-11-08 10:57:37 +08:00
font-size: 18rpx;
2025-08-13 16:44:25 +08:00
color: #fff;
2025-11-08 10:57:37 +08:00
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
2025-08-13 16:44:25 +08:00
}
</style>