From c1fa8b94698a131996981f95cad895a642fb739f Mon Sep 17 00:00:00 2001 From: kron Date: Wed, 16 Jul 2025 12:09:27 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/BowTarget.vue | 37 ++++++++++++++--------- src/components/ShootProgress.vue | 14 ++++----- src/pages/battle-result.vue | 36 +++++++++++----------- src/pages/battle-room.vue | 52 +++++++++++++++++++++----------- src/pages/team-match.vue | 12 ++++++++ 5 files changed, 93 insertions(+), 58 deletions(-) diff --git a/src/components/BowTarget.vue b/src/components/BowTarget.vue index db2cd48..1c71b33 100644 --- a/src/components/BowTarget.vue +++ b/src/components/BowTarget.vue @@ -48,6 +48,8 @@ const props = defineProps({ }); const latestOne = ref(null); +const prevScores = ref([]); +const prevBlueScores = ref([]); // const startCount = ref(false); const timer = ref(null); @@ -63,12 +65,15 @@ const timer = ref(null); watch( () => props.scores, - (newVal, oldVal) => { - latestOne.value = newVal[newVal.length - 1]; - if (timer.value) clearTimeout(timer.value); - timer.value = setTimeout(() => { - latestOne.value = null; - }, 1000); + (newVal) => { + if (newVal.length - prevScores.value.length === 1) { + latestOne.value = newVal[newVal.length - 1]; + if (timer.value) clearTimeout(timer.value); + timer.value = setTimeout(() => { + latestOne.value = null; + }, 1000); + } + prevScores.value = [...newVal]; }, { deep: true, @@ -78,11 +83,14 @@ watch( watch( () => props.blueScores, (newVal) => { - latestOne.value = newVal[newVal.length - 1]; - if (timer.value) clearTimeout(timer.value); - timer.value = setTimeout(() => { - latestOne.value = null; - }, 1000); + if (newVal.length - prevBlueScores.value.length === 1) { + latestOne.value = newVal[newVal.length - 1]; + if (timer.value) clearTimeout(timer.value); + timer.value = setTimeout(() => { + latestOne.value = null; + }, 1000); + } + prevBlueScores.value = [...newVal]; }, { deep: true, @@ -141,7 +149,7 @@ const simulShoot2 = async () => { 0" :class="`hit ${ - index === blueScores.length - 1 && showLatestArrow ? 'pump-in' : '' + index === blueScores.length - 1 && latestOne ? 'pump-in' : '' }`" :style="{ left: calcRealX(bow.x), @@ -240,7 +248,6 @@ const simulShoot2 = async () => { font-size: 8px; text-align: center; line-height: 10px; - transition: all 0.3s ease; box-sizing: border-box; } .hit > text { diff --git a/src/components/ShootProgress.vue b/src/components/ShootProgress.vue index f2464f3..db81b29 100644 --- a/src/components/ShootProgress.vue +++ b/src/components/ShootProgress.vue @@ -98,16 +98,12 @@ watch( watch( () => props.start, (newVal) => { - if (!newVal && timer.value) { - if (timer.value) clearInterval(timer.value); - } + if (timer.value) clearInterval(timer.value); if (newVal) { remain.value = props.total; timer.value = setInterval(() => { if (remain.value > 0) remain.value--; }, 1000); - } else { - if (timer.value) clearInterval(timer.value); } }, { @@ -118,9 +114,11 @@ watch( const updateRemain = (value) => { if (timer.value) clearInterval(timer.value); remain.value = Math.floor(value); - timer.value = setInterval(() => { - if (remain.value > 0) remain.value--; - }, 1000); + if (remain.value > 0) { + timer.value = setInterval(() => { + if (remain.value > 0) remain.value--; + }, 1000); + } }; const updateSound = () => { diff --git a/src/pages/battle-result.vue b/src/pages/battle-result.vue index a9cb4c8..2e26795 100644 --- a/src/pages/battle-result.vue +++ b/src/pages/battle-result.vue @@ -42,16 +42,17 @@ onMounted(async () => { const battleInfo = uni.getStorageSync("last-battle"); console.log("----battleInfo", battleInfo); data.value = battleInfo; - if (battleInfo.mode === 1) { - battleInfo.playerStats.forEach((p) => { - if (p.id === user.value.id) { - totalPoints.value = p.totalScore; - if (p.team === battleInfo.winner) ifWin.value = true; - } - }); - } else if (battleInfo.mode === 2) { - const mine = battleInfo.playerStats.find((p) => p.id === user.value.id); - if (mine) totalPoints.value = mine.totalScore; + const mine = battleInfo.playerStats.find((p) => p.id === user.value.id); + if (mine) { + if (battleInfo.mode === 1) { + totalPoints.value = mine.roundStats.reduce( + (last, next) => last + next.arrows.length, + 0 + ); + if (mine.team === battleInfo.winner) ifWin.value = true; + } else if (battleInfo.mode === 2) { + totalPoints.value = mine.totalScore; + } } // const result = await getHomeData(); // if (result.user) updateUser(result.user); @@ -151,7 +152,7 @@ const checkBowData = () => { :borderColor="topThreeColors[index] || ''" /> - {{ player.name }} + {{ player.name }} {{ getLvlName(player.totalScore) }} { - 经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }} - 积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }} + + 经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }} + + + 积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }} + {{ ifWin ? "你已经奔跑在通向王者的路上了!" : "失败是成功之母,儿子在等你!" @@ -350,6 +351,7 @@ const checkBowData = () => { .player-title > text:first-child { color: #fff; margin-bottom: 3px; + width: 40vw; } .player-title > text:last-child { font-size: 13px; diff --git a/src/pages/battle-room.vue b/src/pages/battle-room.vue index 0c4aaaf..fa518a8 100644 --- a/src/pages/battle-room.vue +++ b/src/pages/battle-room.vue @@ -55,6 +55,7 @@ const showModal = ref(false); const halfTimeTip = ref(false); const isFinalShoot = ref(false); const total = ref(15); +const battleType = ref(0); watch( () => [players.value, playersScores.value], @@ -77,6 +78,7 @@ onLoad(async (options) => { console.log("----battleInfo", battleInfo); if (battleInfo) { battleId.value = battleInfo.id; + battleType.value = battleInfo.config.mode; start.value = true; step.value = 3; if (battleInfo.config.mode === 1) { @@ -88,6 +90,18 @@ onLoad(async (options) => { totalRounds.value = battleInfo.maxRound; roundResults.value = battleInfo.roundResults; currentShooterId.value = battleInfo.firePlayerIndex; + setTimeout(() => { + if (battleInfo.roundResults[battleInfo.roundResults.length - 1]) { + scores.value = + battleInfo.roundResults[ + battleInfo.roundResults.length - 1 + ].redArrows; + blueScores.value = + battleInfo.roundResults[ + battleInfo.roundResults.length - 1 + ].blueArrows; + } + }, 300); if ( battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] || battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound] @@ -151,6 +165,7 @@ onLoad(async (options) => { roomNumber.value = options.roomNumber; const result = await getRoomAPI(options.roomNumber); room.value = result; + battleType.value = result.battleType; result.members.some((m) => { if (m.userInfo.id === result.creator) { owner.value = { @@ -218,10 +233,10 @@ async function onReceiveMessage(messages = []) { timerSeq.value += 1; battleId.value = msg.id; step.value = 2; - if (room.value.battleType === 1) { + if (battleType.value === 1) { redTeam.value = msg.groupUserStatus.redTeam; blueTeam.value = msg.groupUserStatus.blueTeam; - } else if (room.value.battleType === 2) { + } else if (battleType.value === 2) { players.value = [ ...msg.groupUserStatus.redTeam, ...msg.groupUserStatus.blueTeam, @@ -233,7 +248,7 @@ async function onReceiveMessage(messages = []) { } if (msg.roomNumber === roomNumber.value) { if (msg.constructor === MESSAGETYPES.UserEnterRoom) { - if (room.value.battleType === 1) { + if (battleType.value === 1) { if (msg.userId === room.value.creator) { owner.value = { id: msg.userId, @@ -248,7 +263,7 @@ async function onReceiveMessage(messages = []) { }; } } - if (room.value.battleType === 2) { + if (battleType.value === 2) { if (room.value.creator === msg.userId) { players.value[0] = { id: msg.userId, @@ -265,7 +280,7 @@ async function onReceiveMessage(messages = []) { } } if (!start.value && msg.constructor === MESSAGETYPES.UserExitRoom) { - if (room.value.battleType === 1) { + if (battleType.value === 1) { if (msg.userId === room.value.creator) { owner.value = { id: "", @@ -276,7 +291,7 @@ async function onReceiveMessage(messages = []) { }; } } - if (room.value.battleType === 2) { + if (battleType.value === 2) { players.value = players.value.filter((p) => p.id !== msg.userId); } } @@ -298,7 +313,7 @@ async function onReceiveMessage(messages = []) { scores.value = []; totalRounds.value = msg.groupUserStatus.config.maxRounds; step.value = 3; - if (room.value.battleType === 2) { + if (battleType.value === 2) { tips.value = "请在90秒内射完12支箭"; seq.value += 1; } @@ -319,7 +334,7 @@ async function onReceiveMessage(messages = []) { total.value = 90; } if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) { - if (room.value.battleType === 1) { + if (battleType.value === 1) { if (currentShooterId.value !== msg.userId) { seq.value += 1; currentShooterId.value = msg.userId; @@ -337,7 +352,7 @@ async function onReceiveMessage(messages = []) { } } if (msg.constructor === MESSAGETYPES.ShootResult) { - if (room.value.battleType === 1) { + if (battleType.value === 1) { const isRed = redTeam.value.find((item) => item.id === msg.userId); if (isRed) scores.value.push(msg.target); else blueScores.value.push(msg.target); @@ -362,7 +377,7 @@ async function onReceiveMessage(messages = []) { }); } } - if (room.value.battleType === 2) { + if (battleType.value === 2) { scores.value.push(msg.target); power.value = msg.target.battery; } @@ -370,7 +385,7 @@ async function onReceiveMessage(messages = []) { playersScores.value[msg.userId].push(msg.target); } if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) { - if (room.value.battleType === 1) { + if (battleType.value === 1) { const result = msg.preRoundResult; scores.value = []; blueScores.value = []; @@ -381,6 +396,7 @@ async function onReceiveMessage(messages = []) { redPoints.value += result.redScore; // roundResults.value = result.roundResults; currentRound.value = result.currentRound + 1; + uni.$emit("update-ramain", 0); if (result.currentRound < 5) { roundResults.value.push({ redArrows: [], @@ -468,13 +484,13 @@ onUnmounted(() => { 弓箭手们,人都到齐了吗? - 1v1比赛即将开始! - 大乱斗即将开始! + 1v1比赛即将开始! + 大乱斗即将开始! 邀请好友 - + @@ -502,19 +518,19 @@ onUnmounted(() => { 进入对战 进入大乱斗 { :currentShooterId="currentShooterId" /> { redPoints.value = battleInfo.redScore; totalRounds.value = battleInfo.maxRound; roundResults.value = battleInfo.roundResults; + setTimeout(() => { + if (battleInfo.roundResults[battleInfo.roundResults.length - 1]) { + scores.value = + battleInfo.roundResults[ + battleInfo.roundResults.length - 1 + ].redArrows; + blueScores.value = + battleInfo.roundResults[ + battleInfo.roundResults.length - 1 + ].blueArrows; + } + }, 300); if ( battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] || battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]