diff --git a/src/apis.js b/src/apis.js index b017577..28e6228 100644 --- a/src/apis.js +++ b/src/apis.js @@ -417,12 +417,6 @@ export const getUserGameState = () => { return request("GET", "/user/state"); }; -export const getCurrentGameAPI = async () => { - // uni.$emit("update-header-loading", true); - // const result = await request("GET", "/user/join/battle"); - // return result.currentGame || {}; -}; - export const getPointBookConfigAPI = async () => { return request("GET", "/user/score/sheet/option"); }; @@ -554,8 +548,7 @@ export const getReadyAPI = (roomId) => { }; export const getBattleAPI = async (battleId) => { - const result = await request("POST", "/user/match/info", { + return request("POST", "/user/match/info", { id: battleId, }); - return result; }; diff --git a/src/components/BackToGame.vue b/src/components/BackToGame.vue index 703612e..9319c21 100644 --- a/src/components/BackToGame.vue +++ b/src/components/BackToGame.vue @@ -46,14 +46,14 @@ const onClick = debounce(async () => { loading.value = true; const result = await getBattleAPI(); if (result && result.matchId) { - // await uni.$checkAudio(); - if (result.way === 1) { + await uni.$checkAudio(); + if (result.mode <= 3) { uni.navigateTo({ url: `/pages/team-battle?battleId=${result.matchId}`, }); - } else if (result.way === 2) { + } else { uni.navigateTo({ - url: `/pages/melee-match?battleId=${result.matchId}`, + url: `/pages/melee-battle?battleId=${result.matchId}`, }); } return; diff --git a/src/components/Container.vue b/src/components/Container.vue index 98fed85..d3fe202 100644 --- a/src/components/Container.vue +++ b/src/components/Container.vue @@ -5,7 +5,7 @@ import AppBackground from "@/components/AppBackground.vue"; import Header from "@/components/Header.vue"; import ScreenHint from "@/components/ScreenHint.vue"; import BackToGame from "@/components/BackToGame.vue"; -import { getCurrentGameAPI, laserAimAPI } from "@/apis"; +import { laserAimAPI, getBattleAPI } from "@/apis"; import { capsuleHeight, debounce } from "@/util"; import AudioManager from "@/audioManager"; const props = defineProps({ @@ -111,15 +111,19 @@ const backToGame = debounce(async () => { try { isLoading.value = true; - const game = await getCurrentGameAPI(); - if (!game || !game.gameId) { - uni.showToast({ - title: "没有进行中的对局", - icon: "none", - }); + const result = await getBattleAPI(); + if (result && result.matchId) { + await checkAudioProgress(); + if (result.mode <= 3) { + uni.navigateTo({ + url: `/pages/team-battle?battleId=${result.matchId}`, + }); + } else { + uni.navigateTo({ + url: `/pages/melee-battle?battleId=${result.matchId}`, + }); + } } - - showHint.value = false; } catch (error) { console.error("获取当前游戏失败:", error); } finally { diff --git a/src/components/CreateRoom.vue b/src/components/CreateRoom.vue index 6a54b9a..549b9ab 100644 --- a/src/components/CreateRoom.vue +++ b/src/components/CreateRoom.vue @@ -44,6 +44,8 @@ const createRoom = debounce(async () => { url: "/pages/battle-room?roomNumber=" + result.number, }); } + } catch (error) { + console.log(error); } finally { loading.value = false; } diff --git a/src/components/Header.vue b/src/components/Header.vue index 18a61f4..3b21d81 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -56,7 +56,6 @@ const signin = () => { }; const loading = ref(false); -const showLoader = ref(false); const pointBook = ref(null); const showProgress = ref(false); const heat = ref(0); @@ -80,20 +79,12 @@ onMounted(() => { pointBook.value = uni.getStorageSync("last-point-book"); } } - if ( - currentPage.route === "pages/team-battle" || - currentPage.route === "pages/melee-match" - ) { - showLoader.value = true; - } if (currentPage.route === "pages/team-battle") { showProgress.value = true; } - uni.$on("update-header-loading", updateLoading); uni.$on("update-hot", updateHot); }); onBeforeUnmount(() => { - uni.$off("update-header-loading", updateLoading); uni.$off("update-hot", updateHot); }); @@ -161,12 +152,6 @@ onBeforeUnmount(() => { - {{ pointBook.bowType.name }} {{ pointBook.distance }} 米 @@ -230,14 +215,6 @@ onBeforeUnmount(() => { font-size: 16px; color: #fff; } -.loading { - width: 20px; - height: 20px; - margin-left: 10px; - transition: all 0.3s ease; - background-blend-mode: darken; - animation: rotate 2s linear infinite; -} .point-book-info { color: #333; position: fixed; diff --git a/src/components/PlayerScore.vue b/src/components/PlayerScore.vue index 87c0439..08931a6 100644 --- a/src/components/PlayerScore.vue +++ b/src/components/PlayerScore.vue @@ -3,7 +3,7 @@ import useStore from "@/store"; import { storeToRefs } from "pinia"; const { user } = storeToRefs(useStore()); -defineProps({ +const props = defineProps({ player: { type: Object, default: () => ({}), @@ -23,7 +23,10 @@ const rowCount = new Array(6).fill(0); :style="{ borderColor: player.id === user.id ? '#FED847' : '#fff3' }" > @@ -32,20 +35,24 @@ const rowCount = new Array(6).fill(0); - {{ scores[index] ? `${scores[index].ring}环` : "-" }} + {{ + scores[0] && scores[0][index] ? `${scores[0][index].ring}环` : "-" + }} {{ - scores[index + 6] ? `${scores[index + 6].ring}环` : "-" + scores[1] && scores[1][index] ? `${scores[0][index].ring}环` : "-" }} {{ - scores.map((s) => s.ring).reduce((last, next) => last + next, 0) + scores + .map((s) => s.reduce((last, next) => last + next.ring, 0)) + .reduce((last, next) => last + next, 0) }}环 diff --git a/src/components/PlayerScore2.vue b/src/components/PlayerScore2.vue index 1f65362..84df414 100644 --- a/src/components/PlayerScore2.vue +++ b/src/components/PlayerScore2.vue @@ -9,7 +9,7 @@ defineProps({ type: String, default: "", }, - scores: { + arrows: { type: Array, default: () => [], }, @@ -21,10 +21,6 @@ defineProps({ type: Number, default: 0, }, - totalRing: { - type: Number, - default: 0, - }, }); const rowCount = new Array(6).fill(0); @@ -60,19 +56,19 @@ const rowCount = new Array(6).fill(0); - {{ scores[index] ? `${scores[index].ring}环` : "-" }} + {{ arrows[index] ? `${arrows[index].ring}环` : "-" }} {{ - scores[index + 6] ? `${scores[index + 6].ring}环` : "-" + arrows[index + 6] ? `${arrows[index + 6].ring}环` : "-" }} - {{ totalRing }}环 + {{ arrows.reduce((last, next) => last + next.ring, 0) }}环 积分{{ totalScore }} diff --git a/src/components/PlayerSeats.vue b/src/components/PlayerSeats.vue index dd0424c..28604d4 100644 --- a/src/components/PlayerSeats.vue +++ b/src/components/PlayerSeats.vue @@ -124,15 +124,16 @@ const seats = new Array(props.total).fill(1); right: 0; } */ .player-unknow { - width: 40px; - height: 40px; + width: 84rpx; + height: 84rpx; margin: 0 24rpx; - border: 1px solid #fff3; + border: 1rpx solid #fff3; border-radius: 50%; display: flex; align-items: center; justify-content: center; background-color: #69686866; + box-sizing: border-box; } .player-unknow > image { width: 40%; diff --git a/src/components/ShootProgress.vue b/src/components/ShootProgress.vue index 2f455c4..a469745 100644 --- a/src/components/ShootProgress.vue +++ b/src/components/ShootProgress.vue @@ -1,7 +1,7 @@ + + + + diff --git a/src/pages/melee-bow-data.vue b/src/pages/melee-bow-data.vue index 21c97a0..bc2f7b1 100644 --- a/src/pages/melee-bow-data.vue +++ b/src/pages/melee-bow-data.vue @@ -4,28 +4,39 @@ import { onLoad } from "@dcloudio/uni-app"; import Container from "@/components/Container.vue"; import BowTarget from "@/components/BowTarget.vue"; import Avatar from "@/components/Avatar.vue"; -import { getGameAPI } from "@/apis"; +import { getBattleAPI } from "@/apis"; import useStore from "@/store"; import { storeToRefs } from "pinia"; -const store = useStore(); -const { user } = storeToRefs(store); -const scores = ref([]); -const currentUser = ref({}); -const data = ref({}); -const onSelect = (userId) => { - const user = data.value.players.find((p) => p.playerId === userId); - currentUser.value = user; - if (user && user.arrowHistory) { - scores.value = user.arrowHistory; - } -}; +const { user } = storeToRefs(useStore()); +const currentUser = ref({ + arrows: [], +}); +const players = ref([]); + onLoad(async (options) => { - if (options.battleId) { - const result = await getGameAPI(options.battleId); - data.value = result; - if (result.players && result.players[0]) { - onSelect(result.players[0].playerId); - } + if (!options.id) return; + const result = await getBattleAPI(options.battleId || "59090720979554304"); + players.value = result.resultList.map((item, index) => { + const plist = result.teams[0] ? result.teams[0].players : []; + const p = plist.find((p) => p.id === item.userId); + const arrows = new Array(12); + result.rounds.forEach((r, index) => { + if (r.shoots[item.userId]) { + r.shoots[item.userId].forEach((s, index2) => { + arrows[index2 + index * 6] = s; + }); + } + }); + return { + ...item, + rank: index + 1, + name: p.name, + avatar: p.avatar || "", + arrows, + }; + }); + if (players.value[0]) { + currentUser.value = players.value[0]; } }); @@ -33,22 +44,26 @@ onLoad(async (options) => {