feat:比赛优化
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { ref, watch, onMounted, computed } from "vue";
|
||||
import { ref, watch } from "vue";
|
||||
const props = defineProps({
|
||||
isRed: {
|
||||
type: Boolean,
|
||||
@@ -10,7 +10,7 @@ const props = defineProps({
|
||||
default: () => [],
|
||||
},
|
||||
currentShooterId: {
|
||||
type: Number,
|
||||
type: [Number, String],
|
||||
default: "",
|
||||
},
|
||||
});
|
||||
@@ -30,31 +30,35 @@ const getPos = (id) => {
|
||||
return sort * 40;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
props.team.forEach((p, index) => {
|
||||
players.value[p.id] = { sort: index, ...p };
|
||||
const syncPlayers = () => {
|
||||
const nextPlayers = {};
|
||||
const shooterId = props.currentShooterId;
|
||||
const shooterIndex = props.team.findIndex(
|
||||
(p) => String(p?.id) === String(shooterId)
|
||||
);
|
||||
const nextTeam = [...props.team];
|
||||
|
||||
currentTeam.value = !!shooterId && shooterIndex >= 0;
|
||||
firstName.value = "";
|
||||
|
||||
if (currentTeam.value) {
|
||||
const target = nextTeam.splice(shooterIndex, 1)[0];
|
||||
if (target) {
|
||||
nextTeam.unshift(target);
|
||||
firstName.value = target.name || "";
|
||||
}
|
||||
}
|
||||
|
||||
nextTeam.forEach((p, index) => {
|
||||
if (p?.id) nextPlayers[p.id] = { sort: index, ...p };
|
||||
});
|
||||
});
|
||||
players.value = nextPlayers;
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.currentShooterId,
|
||||
(newVal) => {
|
||||
if (!newVal) return;
|
||||
const index = props.team.findIndex((p) => p.id === newVal);
|
||||
currentTeam.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 };
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
[() => props.team, () => props.currentShooterId],
|
||||
syncPlayers,
|
||||
{ immediate: true, deep: true }
|
||||
);
|
||||
</script>
|
||||
|
||||
@@ -70,7 +74,7 @@ watch(
|
||||
/>
|
||||
<view
|
||||
v-for="(item, index) in team"
|
||||
:key="index"
|
||||
:key="item.id || index"
|
||||
class="player"
|
||||
:style="{
|
||||
width: (isFirst(item.id) ? 80 : 60) + 'rpx',
|
||||
|
||||
Reference in New Issue
Block a user