diff --git a/src/apis.js b/src/apis.js index 11fce7b..8780cae 100644 --- a/src/apis.js +++ b/src/apis.js @@ -120,10 +120,37 @@ export const readyGameAPI = (battleId) => { }); }; -export const getGameAPI = (battleId) => { - return request("POST", "/user/battle/detail", { +export const getGameAPI = async (battleId) => { + const result = await request("POST", "/user/battle/detail", { id: battleId, }); + const { battleStats = {}, playerStats = {} } = result; + const data = { + winner: battleStats.winner, + redTotal: battleStats.redTotal, + blueTotal: battleStats.blueTotal, + roundsData: {}, + redPlayers: {}, + bluePlayers: {}, + }; + playerStats.forEach((item) => { + const { playerBattleStats = {}, roundRecords = [] } = item; + if (playerBattleStats.team === 0) { + data.redPlayers[playerBattleStats.playerId] = playerBattleStats; + } + if (playerBattleStats.team === 1) { + data.bluePlayers[playerBattleStats.playerId] = playerBattleStats; + } + roundRecords.forEach((round) => { + data.roundsData[round.roundNumber] = { + ...data.roundsData[round.roundNumber], + [round.playerId]: round.arrowHistory, + }; + }); + }); + console.log("game result:", result); + console.log("format data:", data); + return data; }; export const simulShootAPI = (device_id, x, y) => { diff --git a/src/components/BattleFooter.vue b/src/components/BattleFooter.vue index 0653b47..716437a 100644 --- a/src/components/BattleFooter.vue +++ b/src/components/BattleFooter.vue @@ -4,12 +4,24 @@ defineProps({ type: Array, default: () => [], }, + bluePoints: { + type: Number, + default: 0, + }, + redPoints: { + type: Number, + default: 0, + }, });