From 32baa7279d9280472b83d3f98eec32bc3b3fd687 Mon Sep 17 00:00:00 2001 From: kron Date: Tue, 15 Jul 2025 18:14:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=94=E8=B5=9B=E7=BB=93=E6=9E=9C=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/battle-result.vue | 74 ++++++++++++++++++++++--------------- src/pages/battle-room.vue | 10 ++--- src/pages/index.vue | 7 ++-- src/pages/melee-match.vue | 19 ++++++---- src/pages/team-match.vue | 3 +- src/websocket.js | 2 +- 6 files changed, 68 insertions(+), 47 deletions(-) diff --git a/src/pages/battle-result.vue b/src/pages/battle-result.vue index 0272688..a9cb4c8 100644 --- a/src/pages/battle-result.vue +++ b/src/pages/battle-result.vue @@ -10,47 +10,61 @@ const store = useStore(); const { user } = storeToRefs(store); const { updateUser, getLvlName } = store; -const battleId = ref(""); const ifWin = ref(false); const data = ref({}); const totalPoints = ref(0); -onLoad(async (options) => { - battleId.value = options.battleId; - const result = await getGameAPI( - // options.battleId || "BATTLE-1750867490990424058-718" - options.battleId || "BATTLE-1752563964391008873-624" - ); - data.value = result; - if (result.mode === 1 && result.redPlayers[user.value.id]) { - totalPoints.value = result.redPlayers[user.value.id].totalScore; - ifWin.value = result.winner === 0; - } - if (result.mode === 1 && result.bluePlayers[user.value.id]) { - totalPoints.value = result.bluePlayers[user.value.id].totalScore; - ifWin.value = result.winner === 1; - } - if (result.mode === 2) { - const mine = result.players.find((p) => p.playerId === user.value.id); - if (mine) totalPoints.value = mine.totalScore; - } -}); +// onLoad(async (options) => { +// battleId.value = options.battleId; +// const result = await getGameAPI( +// // options.battleId || "BATTLE-1750867490990424058-718" +// options.battleId || "BATTLE-1752563964391008873-624" +// ); +// data.value = result; +// if (result.mode === 1 && result.redPlayers[user.value.id]) { +// totalPoints.value = result.redPlayers[user.value.id].totalScore; +// ifWin.value = result.winner === 0; +// } +// if (result.mode === 1 && result.bluePlayers[user.value.id]) { +// totalPoints.value = result.bluePlayers[user.value.id].totalScore; +// ifWin.value = result.winner === 1; +// } +// if (result.mode === 2) { +// const mine = result.players.find((p) => p.playerId === user.value.id); +// if (mine) totalPoints.value = mine.totalScore; +// } +// }); + function exit() { uni.navigateBack(); } onMounted(async () => { - const result = await getHomeData(); - if (result.user) updateUser(result.user); + 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 result = await getHomeData(); + // if (result.user) updateUser(result.user); }); const checkBowData = () => { if (data.value.mode === 1) { uni.navigateTo({ - url: `/pages/team-bow-data?battleId=${battleId.value}`, + url: `/pages/team-bow-data?battleId=${data.value.id}`, }); } else if (data.value.mode === 2) { uni.navigateTo({ - url: `/pages/melee-bow-data?battleId=${battleId.value}`, + url: `/pages/melee-bow-data?battleId=${data.value.id}`, }); } }; @@ -84,14 +98,14 @@ const checkBowData = () => { { - 经验 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }} - 积分 {{ totalPoints > 0 ? "+" + totalPoints : totalPoints }} diff --git a/src/pages/battle-room.vue b/src/pages/battle-room.vue index 682435a..208db37 100644 --- a/src/pages/battle-room.vue +++ b/src/pages/battle-room.vue @@ -73,8 +73,8 @@ watch( onLoad(async (options) => { if (options.battleId) { - const battleInfo = uni.getStorageSync(`battle-${options.battleId}`); - // console.log("----battleInfo", battleInfo); + const battleInfo = uni.getStorageSync("current-battle"); + console.log("----battleInfo", battleInfo); if (battleInfo) { battleId.value = battleInfo.id; start.value = true; @@ -406,7 +406,7 @@ async function onReceiveMessage(messages = []) { tips.value = "准备下半场"; } if (msg.constructor === MESSAGETYPES.MatchOver) { - uni.setStorageSync("battle", msg.endStatus); + uni.setStorageSync("last-battle", msg.endStatus); uni.redirectTo({ url: `/pages/battle-result?battleId=${msg.id}`, }); @@ -541,10 +541,10 @@ onUnmounted(() => { :total="total" :currentRound="currentRound" :battleId="battleId" - :melee="room.battleType === 2" + :melee="players.length > 0" /> { @@ -343,12 +343,13 @@ const comingSoon = () => { .player-avatar, .more-players { - width: 80rpx; - height: 80rpx; + width: 82rpx; + height: 82rpx; border-radius: 50%; margin-right: -10px; border: 1px solid #000; position: relative; + box-sizing: border-box; } .player-avatar > image:first-child, diff --git a/src/pages/melee-match.vue b/src/pages/melee-match.vue index dde707b..43da68c 100644 --- a/src/pages/melee-match.vue +++ b/src/pages/melee-match.vue @@ -22,7 +22,7 @@ const { user } = storeToRefs(store); const gameType = ref(0); const teamSize = ref(0); const start = ref(false); -const countDown = ref(90); +const startCount = ref(false); const battleId = ref(""); const currentRound = ref(1); const power = ref(0); @@ -35,6 +35,7 @@ const playersSorted = ref([]); const playersScores = ref({}); const halfTimeTip = ref(false); const onComplete = ref(null); +const total = ref(90); watch( () => [players.value, playersScores.value], @@ -53,7 +54,7 @@ watch( onLoad(async (options) => { if (options.battleId) { - const battleInfo = uni.getStorageSync(`battle-${options.battleId}`); + const battleInfo = uni.getStorageSync("current-battle"); console.log("----battleInfo", battleInfo); if (battleInfo) { battleId.value = battleInfo.id; @@ -71,7 +72,7 @@ onLoad(async (options) => { }, 300); } else if (remain > 90 && remain <= 110) { halfTimeTip.value = true; - countDown.value = 20; + total.value = 20; tips.value = "准备下半场"; setTimeout(() => { uni.$emit("update-ramain", 110 - remain); @@ -129,11 +130,12 @@ async function onReceiveMessage(messages = []) { if (msg.id !== battleId.value) return; if (msg.constructor === MESSAGETYPES.MeleeAllReady) { start.value = true; + startCount.value = true; seq.value += 1; timerSeq.value = 0; tips.value = "请连续射出6支箭"; scores.value = []; - countDown.value = 90; + total.value = 90; } if (msg.constructor === MESSAGETYPES.ShootResult) { if (msg.userId === user.value.id) { @@ -143,11 +145,13 @@ async function onReceiveMessage(messages = []) { playersScores.value[msg.userId].push(msg.target); } if (msg.constructor === MESSAGETYPES.HalfTimeOver) { + startCount.value = false; halfTimeTip.value = true; - countDown.value = 20; + total.value = 20; tips.value = "准备下半场"; } if (msg.constructor === MESSAGETYPES.MatchOver) { + uni.setStorageSync("last-battle", msg.endStatus); uni.redirectTo({ url: `/pages/battle-result?battleId=${msg.id}`, }); @@ -192,9 +196,9 @@ onUnmounted(() => { @@ -207,6 +211,7 @@ onUnmounted(() => { :currentRound="scores.length" :totalRound="start ? 12 : 0" :scores="scores" + :stop="halfTimeTip && !startCount" /> { if (options.battleId) { - const battleInfo = uni.getStorageSync(`battle-${options.battleId}`); + const battleInfo = uni.getStorageSync("current-battle"); // console.log("----battleInfo", battleInfo); if (battleInfo) { battleId.value = battleInfo.id; @@ -203,6 +203,7 @@ async function onReceiveMessage(messages = []) { } } if (msg.constructor === MESSAGETYPES.MatchOver) { + uni.setStorageSync("last-battle", msg.endStatus); uni.redirectTo({ url: `/pages/battle-result?battleId=${msg.id}`, }); diff --git a/src/websocket.js b/src/websocket.js index bd9035b..720461c 100644 --- a/src/websocket.js +++ b/src/websocket.js @@ -38,7 +38,7 @@ function createWebSocket(token, onMessage) { if (!msg) return; if (msg.constructor === MESSAGETYPES.BackToGame) { const { battleInfo } = msg; - uni.setStorageSync(`battle-${battleInfo.id}`, battleInfo); + uni.setStorageSync("current-battle", battleInfo); // 约战 if (battleInfo.config.battleMode === 1) { uni.navigateTo({