chore(删除无用组件): 抽奖活动组件

This commit is contained in:
hzj 2025-12-03 14:46:59 +08:00
parent 9bbe7fe313
commit a20b6235ff

View File

@ -1,291 +0,0 @@
<!-- Barrage.vue 优化版 -->
<template>
<div
style="position: relative; width: 100%; height: 32vw; overflow: hidden; pointer-events: none"
>
<!-- 双行弹幕轨道 -->
<div
v-for="(track, index) in visibleTracks"
:key="index"
style="position: absolute; width: 100%; height: 50px"
:style="{ top: `calc(${index} * 16vw)` }"
>
<div
v-for="item in track"
:key="item.id"
class="barrage-item"
style="
position: absolute;
border-radius: 48px;
padding: 4px;
display: flex;
align-items: center;
gap: 4px;
"
:style="getBarrageStyle(item)"
@animationend="handleAnimationEnd(item.id)"
>
<img
:src="item.avatar"
alt=""
@error="defaultAvatarUrl"
style="
width: 10vw;
border-radius: 50%;
display: block;
aspect-ratio: 1/1;
object-fit: cover;
"
/>
<div
style="
font-weight: 700;
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
"
:style="{
backgroundImage:
item.type != ''
? '-webkit-linear-gradient(180deg, #FFF9A9 26.92%, #ED7D0A 52.08%, #FFFAB5 73.08%)'
: '-webkit-linear-gradient(180deg, #A9FFA9 26.92%, #0AED47 52.08%, #B5FFC5 73.08%)',
}"
>
{{ barrageText(item) }}
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted, onUnmounted, watch } from 'vue'
import { useI18n } from 'vue-i18n'
const { locale } = useI18n()
const props = defineProps({
barrageList: {
type: Array,
required: true,
default: () => [],
},
speed: {
type: Number,
default: 80, //
},
maxItems: {
type: Number,
default: 6, //
},
loopInterval: {
type: Number,
default: 2000, // (ms)
},
})
//
const tracks = ref([[], []])
// ID
const idCounter = ref(0)
//
const currentIndex = ref(0)
//
const visibleTracks = computed(() => tracks.value.filter((track) => track.length > 0))
//
const barrageText = (item) => {
return item.prizeType == 'GOLD' || item.prizeType == 'MONEY'
? `${item.nickname} won ${item.prizeName}`
: `${item.nickname} won the ${item.prizeName}`
}
const defaultAvatarUrl = (e) => {
console.log('头像资源出错')
e.target.onerror = null //
e.target.src = new URL('/src/assets/icon/defaultAvatar.png', import.meta.url).href
}
//
const getBarrageStyle = (item) => {
const isRTL = locale.value === 'ar'
return {
animationDuration: `${item.duration}s`,
animationDelay: `${item.delay}s`,
'--start-pos': `${item.startPos}px`,
border: item.type != '' ? '0.667px solid #FFF677' : '0.667px solid #77FF87',
background:
item.type != ''
? 'linear-gradient(270deg, rgba(218, 103, 2, 0.60) -16.85%, rgba(124, 41, 0, 0.60) 82.7%)'
: 'linear-gradient(270deg, rgba(2, 218, 60, 0.60) -16.85%, rgba(0, 124, 54, 0.60) 82.7%)',
// RTL
...(isRTL
? {
right: '0',
left: 'auto',
transform: 'translateX(-100vw)',
}
: {
left: '0',
right: 'auto',
transform: 'translateX(100vw)',
}),
}
}
//
const generateBarrageProps = (item) => {
const textLength = barrageText(item).length
return {
duration: Math.max(8 - textLength * 0.2, 5) * (100 / props.speed),
startPos: Math.floor(Math.random() * 21) - 10,
}
}
//
const addToTrack = (item) => {
//
const trackIndex = tracks.value.reduce(
(minIndex, track, index) => (track.length < tracks.value[minIndex].length ? index : minIndex),
0
)
if (tracks.value[trackIndex].length < props.maxItems) {
tracks.value[trackIndex].push({
...item,
id: idCounter.value++,
delay: Math.random() * 4, // 0-4
...generateBarrageProps(item),
})
}
}
//
const cleanCompleted = () => {
tracks.value.forEach((track) => {
for (let i = track.length - 1; i >= 0; i--) {
if (track[i].completed) {
track.splice(i, 1)
}
}
})
}
//
const handleAnimationEnd = (id) => {
tracks.value.forEach((track) => {
const item = track.find((item) => item.id === id)
if (item) item.completed = true
})
}
//
const getNextBarrage = () => {
if (props.barrageList.length === 0) return null
//
const item = props.barrageList[currentIndex.value]
currentIndex.value = (currentIndex.value + 1) % props.barrageList.length
return { ...item } //
}
//
let barrageInterval = null
const startBarrage = () => {
barrageInterval = setInterval(() => {
cleanCompleted()
const nextBarrage = getNextBarrage()
if (nextBarrage) {
addToTrack(nextBarrage)
}
}, props.loopInterval)
}
onMounted(startBarrage)
onUnmounted(() => clearInterval(barrageInterval))
//
watch(
() => props.barrageList,
(newList) => {
//
currentIndex.value = 0
//
if (newList.length === 0) {
clearInterval(barrageInterval)
} else {
//
clearInterval(barrageInterval)
startBarrage()
}
},
{ deep: true }
)
</script>
<style scoped>
* {
font-family: 'SF Pro Text';
}
/* 样式保持不变(同之前版本) */
.barrage-item {
will-change: transform;
animation: moveLeft linear forwards;
}
@keyframes moveLeft {
0% {
transform: translateX(100vw);
}
100% {
transform: translateX(-100%);
}
}
/* RTL支持 - 镜像弹幕动画 */
[dir='rtl'] .barrage-item {
animation: moveRight linear forwards;
}
@keyframes moveRight {
0% {
transform: translateX(-100vw);
}
100% {
transform: translateX(100%);
}
}
@media screen and (max-width: 360px) {
* {
font-size: 10px;
}
}
@media screen and (min-width: 360px) {
* {
font-size: 16px;
}
}
@media screen and (min-width: 768px) {
* {
font-size: 24px;
}
}
@media screen and (min-width: 1024px) {
* {
font-size: 32px;
}
}
</style>