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

127 lines
2.8 KiB
Vue
Raw Normal View History

2025-08-13 16:44:25 +08:00
<script setup>
2025-08-15 11:23:23 +08:00
import { ref, watch, onMounted } from "vue";
2025-08-13 16:44:25 +08:00
const props = defineProps({
isRed: {
type: Boolean,
default: true,
},
team: {
type: Array,
default: () => [],
},
2025-08-14 15:24:12 +08:00
currentShooterId: {
type: Number,
default: "",
},
2025-08-13 16:44:25 +08:00
youTurn: {
type: Boolean,
default: false,
},
});
2025-08-15 11:23:23 +08:00
const players = ref({});
2025-08-14 15:24:12 +08:00
const youTurn = ref(false);
2025-08-15 11:23:23 +08:00
const firstName = ref("");
onMounted(() => {
props.team.forEach((p, index) => {
players.value[p.id] = { sort: index, ...p };
});
});
2025-08-13 16:44:25 +08:00
watch(
2025-08-14 15:24:12 +08:00
() => props.currentShooterId,
2025-08-13 16:44:25 +08:00
(newVal) => {
2025-08-15 11:23:23 +08:00
if (!newVal) return;
const index = props.team.findIndex((p) => p.id === newVal);
youTurn.value = index >= 0;
if (index >= 0) {
const newPlayers = [...props.team];
const target = newPlayers.splice(index, 1)[0];
if (target) {
newPlayers.unshift(target);
firstName.value = target.name;
newPlayers.forEach((p, index) => {
players.value[p.id] = { sort: index, ...p };
});
}
}
2025-08-14 15:24:12 +08:00
},
{ immediate: true }
2025-08-13 16:44:25 +08:00
);
</script>
<template>
<view class="container">
<view
v-for="(item, index) in team"
:key="index"
class="player"
:style="{
2025-08-15 11:23:23 +08:00
width:
(youTurn ? 40 - ((players[item.id] || {}).sort || 0) * 5 : 35) + 'px',
height:
(youTurn ? 40 - ((players[item.id] || {}).sort || 0) * 5 : 35) + 'px',
2025-08-13 16:44:25 +08:00
borderColor: isRed ? '#ff6060' : '#5fadff',
2025-08-15 11:23:23 +08:00
zIndex: team.length - ((players[item.id] || {}).sort || 0),
top: youTurn ? ((players[item.id] || {}).sort || 0) * 2 + 'px' : '6px',
left:
(isRed
? ((players[item.id] || {}).sort || 0) * 20
2025-08-22 14:51:42 +08:00
: 40 - ((players[item.id] || {}).sort || 0) * 20) + 'px',
2025-08-13 16:44:25 +08:00
}"
>
<image :src="item.avatar || '../static/user-icon.png'" mode="widthFix" />
<text
2025-08-15 11:23:23 +08:00
v-if="youTurn && ((players[item.id] || {}).sort || 0) === 0"
2025-08-13 16:44:25 +08:00
:style="{ backgroundColor: isRed ? '#ff6060' : '#5fadff' }"
>{{ isRed ? "红队" : "蓝队" }}</text
>
</view>
<text
v-if="youTurn"
class="truncate"
:style="{
color: isRed ? '#ff6060' : '#5fadff',
[isRed ? 'left' : 'right']: 0,
}"
2025-08-15 11:23:23 +08:00
>{{ firstName }}</text
2025-08-13 16:44:25 +08:00
>
</view>
</template>
<style scoped>
.container {
display: flex;
align-items: center;
position: relative;
width: 20vw;
height: 45px;
}
.container > text {
position: absolute;
font-size: 10px;
text-align: center;
width: 40px;
bottom: -12px;
}
.player {
transition: all 0.3s ease;
position: absolute;
border-radius: 50%;
overflow: hidden;
border: 1px solid;
}
.player > image {
width: 100%;
}
.player > text {
position: absolute;
font-size: 8px;
text-align: center;
width: 40px;
left: 0px;
bottom: 0px;
color: #fff;
}
</style>