1v1排位数据交互完善

This commit is contained in:
kron
2025-06-08 20:59:41 +08:00
parent 312906fec3
commit 80e0b07c0e
10 changed files with 232 additions and 84 deletions

View File

@@ -2,6 +2,8 @@
import { ref, onMounted, onUnmounted } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import BattleHeader from "@/components/BattleHeader.vue";
import Guide from "@/components/Guide.vue";
import BowTarget from "@/components/BowTarget.vue";
import ShootProgress from "@/components/ShootProgress.vue";
import PlayersRow from "@/components/PlayersRow.vue";
@@ -10,6 +12,10 @@ import BattleFooter from "@/components/BattleFooter.vue";
import SButton from "@/components/SButton.vue";
import { matchGameAPI, readyGameAPI } from "@/apis";
import { MESSAGETYPES, roundsName } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const gameType = ref(0);
const teamSize = ref(0);
const matching = ref(false);
@@ -31,6 +37,8 @@ const roundResults = ref([
// redArrows: [{ ring: 2 }, { ring: 3 }],
// },
]);
const redPoints = ref(0);
const bluePoints = ref(0);
onLoad((options) => {
gameType.value = options.gameType;
@@ -38,6 +46,7 @@ onLoad((options) => {
});
async function startMatch() {
if (gameType.value && teamSize.value) {
scores.value = [];
await matchGameAPI(true, gameType.value, teamSize.value);
startMatch.value = true;
}
@@ -82,6 +91,7 @@ async function onReceiveMessage(content) {
if (msg.constructor === MESSAGETYPES.AllReady) {
start.value = true;
timerSeq.value = 0;
scores.value = [];
}
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
scores.value = [];
@@ -96,6 +106,10 @@ async function onReceiveMessage(content) {
if (msg.constructor === MESSAGETYPES.ShootResult) {
scores.value = [msg.target];
}
if (msg.constructor === MESSAGETYPES.RoundPoint) {
bluePoints.value += msg.blueScore;
redPoints.value += msg.redScore;
}
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
const result = msg.preRoundResult;
scores.value = [];
@@ -108,7 +122,7 @@ async function onReceiveMessage(content) {
}
if (msg.constructor === MESSAGETYPES.MatchOver) {
uni.redirectTo({
url: "/pages/battle-result?battleId=" + msg.id,
url: `/pages/battle-result?battleId=${msg.id}&winner=${msg.endStatus.winner}`,
});
}
});
@@ -127,6 +141,16 @@ onUnmounted(() => {
<template>
<Container title="排位赛" :bgType="1">
<view class="container">
<BattleHeader v-if="!start" :redTeam="redTeam" :blueTeam="blueTeam" />
<Guide noBg v-if="!start">
<view :style="{ display: 'flex', justifyContent: 'space-between' }">
<view :style="{ display: 'flex', flexDirection: 'column' }">
<text :style="{ color: '#fed847' }">请预先射几箭测试</text>
<text>请确保射击距离只有5米</text>
</view>
<BowPower :power="45" />
</view>
</Guide>
<ShootProgress v-if="start" :tips="tips" :seq="seq" />
<PlayersRow
v-if="start"
@@ -135,7 +159,8 @@ onUnmounted(() => {
:redTeam="redTeam"
/>
<BowTarget
:power="power"
:showE="start && user.id === currentShooterId"
:power="start ? power : 0"
:currentRound="currentRound"
:totalRound="totalRounds"
:scores="scores"
@@ -148,8 +173,10 @@ onUnmounted(() => {
"
/>
<BattleFooter
v-if="roundResults.length > 0"
v-if="start"
:roundResults="roundResults"
:redPoints="redPoints"
:bluePoints="bluePoints"
/>
<Timer :seq="timerSeq" :callBack="readyToGo" />
</view>