diff --git a/src/components/BattleHeader.vue b/src/components/BattleHeader.vue index 16be7de..b7b3716 100644 --- a/src/components/BattleHeader.vue +++ b/src/components/BattleHeader.vue @@ -73,7 +73,7 @@ defineProps({ {{ player.name }} import { ref, watch, onMounted, onBeforeUnmount } from "vue"; import audioManager from "@/audioManager"; -import { MESSAGETYPES, MESSAGETYPESV2 } from "@/constants"; +import { MESSAGETYPESV2 } from "@/constants"; import { getDirectionText } from "@/util"; import useStore from "@/store"; @@ -80,7 +80,7 @@ async function onReceiveMessage(message) { title: "距离不足,无效", icon: "none", }); - audioManager.pLay("射击无效"); + audioManager.play("射击无效"); } } diff --git a/src/components/ShootProgress.vue b/src/components/ShootProgress.vue index 24ca5c4..3a84962 100644 --- a/src/components/ShootProgress.vue +++ b/src/components/ShootProgress.vue @@ -143,12 +143,12 @@ async function onReceiveMessage(msg) { } else if (msg.type === MESSAGETYPESV2.HalfRest) { halfTime.value = true; audioManager.play("中场休息"); - } else if (type === MESSAGETYPESV2.InvalidShot) { + } else if (msg.type === MESSAGETYPESV2.InvalidShot) { uni.showToast({ title: "距离不足,无效", icon: "none", }); - audioManager.pLay("射击无效"); + audioManager.play("射击无效"); } } diff --git a/src/components/Signin.vue b/src/components/Signin.vue index 0a11d6b..0805d16 100644 --- a/src/components/Signin.vue +++ b/src/components/Signin.vue @@ -87,28 +87,34 @@ const handleLogin = async () => { }); } loading.value = true; - const wxResult = await wxLogin(); - const fileManager = uni.getFileSystemManager(); - const avatarBase64 = fileManager.readFileSync(avatarUrl.value, "base64"); - const base64Url = `data:image/png;base64,${avatarBase64}`; - const result = await loginAPI( - phone.value, - nickName.value, - base64Url, - wxResult.code - ); - const data = await getHomeData(); - if (data.user) updateUser(data.user); - const devices = await getMyDevicesAPI(); - if (devices.bindings && devices.bindings.length) { - updateDevice(devices.bindings[0].deviceId, devices.bindings[0].deviceName); - try { + try { + const wxResult = await wxLogin(); + const fileManager = uni.getFileSystemManager(); + const avatarBase64 = fileManager.readFileSync(avatarUrl.value, "base64"); + const base64Url = `data:image/png;base64,${avatarBase64}`; + const result = await loginAPI( + phone.value, + nickName.value, + base64Url, + wxResult.code + ); + const data = await getHomeData(); + if (data.user) updateUser(data.user); + const devices = await getMyDevicesAPI(); + if (devices.bindings && devices.bindings.length) { + updateDevice( + devices.bindings[0].deviceId, + devices.bindings[0].deviceName + ); const data = await getDeviceBatteryAPI(); updateOnline(data.online); - } catch (error) {} + } + props.onClose(); + } catch (error) { + console.log("login error", error); + } finally { + loading.value = false; } - loading.value = false; - props.onClose(); }; const openServiceLink = () => { diff --git a/src/pages/match-detail.vue b/src/pages/match-detail.vue index c4edb42..66eb93c 100644 --- a/src/pages/match-detail.vue +++ b/src/pages/match-detail.vue @@ -16,7 +16,7 @@ const players = ref([]); onLoad(async (options) => { if (!options.battleId) return; - battleId.value = options.battleId || "60143330377469952"; + battleId.value = options.battleId || "60510101693403136"; const result = await getBattleAPI(battleId.value); data.value = result; if (result.mode > 3) { @@ -128,7 +128,7 @@ const checkBowData = (selected) => { {{ round.shoots[team].reduce((acc, cur) => acc + cur.ring, 0) }}环 - 得分 {{ round.scores[team].totalRing }} + 得分 {{ round.scores[team].score }} diff --git a/src/pages/melee-battle.vue b/src/pages/melee-battle.vue index 570c06a..c035daa 100644 --- a/src/pages/melee-battle.vue +++ b/src/pages/melee-battle.vue @@ -12,7 +12,6 @@ import ScreenHint from "@/components/ScreenHint.vue"; import TestDistance from "@/components/TestDistance.vue"; import audioManager from "@/audioManager"; import { getBattleAPI, laserCloseAPI } from "@/apis"; -import { isGameEnded } from "@/util"; import { MESSAGETYPESV2 } from "@/constants"; import useStore from "@/store"; import { storeToRefs } from "pinia"; @@ -103,9 +102,11 @@ async function onReceiveMessage(msg) { halfRest.value = true; tips.value = "准备下半场"; } else if (msg.type === MESSAGETYPESV2.BattleEnd) { - uni.redirectTo({ - url: "/pages/battle-result?battleId=" + msg.matchId, - }); + setTimeout(() => { + uni.redirectTo({ + url: "/pages/battle-result?battleId=" + msg.matchId, + }); + }, 1000); } } onMounted(async () => { diff --git a/src/pages/practise-one.vue b/src/pages/practise-one.vue index 8bb3d5b..13a03aa 100644 --- a/src/pages/practise-one.vue +++ b/src/pages/practise-one.vue @@ -21,7 +21,7 @@ import { } from "@/apis"; import { sharePractiseData } from "@/canvas"; import { wxShare, debounce } from "@/util"; -import { MESSAGETYPESV2, MESSAGETYPES, roundsName } from "@/constants"; +import { MESSAGETYPESV2, roundsName } from "@/constants"; import useStore from "@/store"; import { storeToRefs } from "pinia"; @@ -31,7 +31,6 @@ const { user } = storeToRefs(store); const start = ref(false); const scores = ref([]); const total = 12; -const currentRound = ref(0); const practiseResult = ref({}); const practiseId = ref(""); const showGuide = ref(false); @@ -39,7 +38,6 @@ const tips = ref(""); const onReady = async () => { await startPractiseAPI(); - currentRound.value = 0; scores.value = []; start.value = true; audioManager.play("练习开始"); @@ -69,7 +67,6 @@ async function onComplete() { practiseResult.value = {}; start.value = false; scores.value = []; - currentRound.value = 0; const result = await createPractiseAPI(total, 120); if (result) practiseId.value = result.id; } @@ -132,7 +129,7 @@ onBeforeUnmount(() => { diff --git a/src/pages/team-battle.vue b/src/pages/team-battle.vue index 6634a09..da5d80d 100644 --- a/src/pages/team-battle.vue +++ b/src/pages/team-battle.vue @@ -12,8 +12,7 @@ import TestDistance from "@/components/TestDistance.vue"; import TeamAvatars from "@/components/TeamAvatars.vue"; import ShootProgress2 from "@/components/ShootProgress2.vue"; import { laserCloseAPI, getBattleAPI } from "@/apis"; -import { isGameEnded, formatTimestamp } from "@/util"; -import { MESSAGETYPES, MESSAGETYPESV2, roundsName } from "@/constants"; +import { MESSAGETYPESV2 } from "@/constants"; import audioManager from "@/audioManager"; import useStore from "@/store"; import { storeToRefs } from "pinia"; @@ -128,9 +127,11 @@ async function onReceiveMessage(msg) { }, 2000); return; } - uni.redirectTo({ - url: "/pages/battle-result?battleId=" + msg.matchId, - }); + setTimeout(() => { + uni.redirectTo({ + url: "/pages/battle-result?battleId=" + msg.matchId, + }); + }, 1000); } } diff --git a/src/util.js b/src/util.js index dc628c2..fef6b9b 100644 --- a/src/util.js +++ b/src/util.js @@ -89,26 +89,26 @@ export const wxShare = async (canvasId = "shareCanvas") => { } }; -export const isGameEnded = async (battleId) => { - const state = await getUserGameState(); - if (!state.gaming) { - const result = await getGameAPI(battleId); - if (result.mode) { - uni.redirectTo({ - url: `/pages/battle-result?battleId=${battleId}`, - }); - } else { - uni.showToast({ - title: "比赛已结束", - icon: "none", - }); - setTimeout(() => { - uni.navigateBack(); - }, 1000); - } - } - return !state.gaming; -}; +// export const isGameEnded = async (battleId) => { +// const state = await getUserGameState(); +// if (!state.gaming) { +// const result = await getGameAPI(battleId); +// if (result.mode) { +// uni.redirectTo({ +// url: `/pages/battle-result?battleId=${battleId}`, +// }); +// } else { +// uni.showToast({ +// title: "比赛已结束", +// icon: "none", +// }); +// setTimeout(() => { +// uni.navigateBack(); +// }, 1000); +// } +// } +// return !state.gaming; +// }; // 获取元素尺寸和位置信息 export const getElementRect = (classname) => { diff --git a/src/websocket.js b/src/websocket.js index b2733de..49046fe 100644 --- a/src/websocket.js +++ b/src/websocket.js @@ -47,9 +47,9 @@ function createWebSocket(token, onMessage) { uni.onSocketMessage((res) => { const { data, event } = JSON.parse(res.data); if (event === "pong") return; - if (data.type && data.data) { + if (data.type) { console.log("收到消息:", getMessageTypeName(data.type), data.data); - if (onMessage) onMessage({ ...data.data, type: data.type }); + if (onMessage) onMessage({ ...(data.data || {}), type: data.type }); return; } if (onMessage && data.updates) onMessage(data.updates);