diff --git a/src/apis.js b/src/apis.js index b9a2395..3ad5f3c 100644 --- a/src/apis.js +++ b/src/apis.js @@ -83,6 +83,10 @@ export const getRoomAPI = (number) => { return request("GET", `/user/room?number=${number}`); }; +export const joinRoomAPI = (number) => { + return request("POST", `/user/room/join`, { number }); +}; + export const destroyRoomAPI = (roomNumber) => { return request("POST", "/user/room/destroyRoom", { roomNumber, @@ -177,6 +181,37 @@ export const simulShootAPI = (device_id, x, y) => { return request("POST", "/index/arrow", data); }; -export const getBattleListAPI = (battleType) => { - return request("POST", "/user/battle/list", { battleType }); +export const getBattleListAPI = async (page, battleType) => { + const data = []; + const result = await request("POST", "/user/battle/details/list", { + page, + battleType, + modeType: 0, + }); + (result.Battles || []).forEach((item) => { + let name = ""; + if (item.battleStats.mode === 1) { + name = `${item.playerStats.length / 2}V${item.playerStats.length / 2}`; + } + if (item.battleStats.mode === 2) { + name = `${item.playerStats.length}人大乱斗`; + } + data.push({ + name, + battleId: item.battleStats.battleId, + mode: item.battleStats.mode, + createdAt: item.battleStats.createdAt, + gameEndAt: item.battleStats.gameEndAt, + players: item.playerStats + .map((p) => p.playerBattleStats) + .sort((a, b) => b.totalScore - a.totalScore), + }); + }); + return data; +}; + +export const getBattleDetailAPI = (id) => { + return request("POST", "/user/battle/detail", { + id, + }); }; diff --git a/src/pages/match-detail.vue b/src/pages/match-detail.vue index fe26d70..8b42512 100644 --- a/src/pages/match-detail.vue +++ b/src/pages/match-detail.vue @@ -4,9 +4,8 @@ import { onLoad } from "@dcloudio/uni-app"; import Container from "@/components/Container.vue"; import BattleHeader from "@/components/BattleHeader.vue"; import Avatar from "@/components/Avatar.vue"; +import { getBattleDetailAPI } from "@/apis"; -const id = ref(""); -const type = ref(""); const data = { blueTeam: { name: "选手1", @@ -44,9 +43,11 @@ const result = ref([ }, ]); -onLoad((options) => { - type.value = options.type; - id.value = options.id; +onLoad(async (options) => { + if (options.id) { + const result = await getBattleDetailAPI(options.id); + console.log(11111, result); + } }); diff --git a/src/pages/my-growth.vue b/src/pages/my-growth.vue index 7fb8ff8..c6729ca 100644 --- a/src/pages/my-growth.vue +++ b/src/pages/my-growth.vue @@ -7,14 +7,22 @@ import { getBattleListAPI, getPractiseResultListAPI } from "@/apis"; import { ref } from "vue"; const selectedIndex = ref(0); +const matchPage = ref(1); +const matchList = ref([]); const practiseList = ref([]); +const battlePage = ref(1); +const battleList = ref([]); const handleSelect = async (index) => { if (index === 0) { - const result = await getBattleListAPI(1); + const result = await getBattleListAPI(matchPage.value, 2); + matchList.value = result.list; + matchPage.value += 1; } if (index === 1) { - const result = await getBattleListAPI(2); + // const result = await getBattleListAPI(battlePage.value, 1); + // battleList.value = result.list; + // battlePage.value += 1; } if (index === 2) { const result = await getPractiseResultListAPI(); @@ -23,13 +31,15 @@ const handleSelect = async (index) => { selectedIndex.value = index; }; -const toMatchDetail = () => { +const toMatchDetail = (id) => { uni.navigateTo({ - url: "/pages/match-detail", + url: `/pages/match-detail?id=${id}`, }); }; onMounted(async () => { - const result = await getBattleListAPI(2); + const result = await getBattleListAPI(matchPage.value, 2); + matchList.value = result; + matchPage.value += 1; }); @@ -53,57 +63,51 @@ onMounted(async () => { - + - 1V1 - 2025.01.21 14:09:23 + {{ item.name }} + {{ item.createdAt }} - - - - 选手1 - - - - - 选手2 + + + + {{ p.name }} + - - - - 5v5 - 2025.01.21 14:09:23 - - - - - - 选手1 - - - - 选手2 - - - - 选手3 - - - - 选手4 - - - - 选手5 + + + + {{ p.name }} +