调试重新进入比赛

This commit is contained in:
kron
2025-07-03 21:13:55 +08:00
parent 18ce93b12f
commit 79c869a3f3
7 changed files with 68 additions and 20 deletions

View File

@@ -11,24 +11,27 @@ function request(method, url, data = {}) {
}, },
data, data,
success: (res) => { success: (res) => {
if (res.data.code === 0) resolve(res.data.data); if (res.data) {
const { code, data, message } = res.data;
if (code === 0) resolve(data);
else { else {
if (res.data.message.indexOf("登录身份已失效") !== -1) { if (message.indexOf("登录身份已失效") !== -1) {
uni.removeStorageSync("token"); uni.removeStorageSync("token");
} }
if (url.indexOf("/user/room") !== -1 && method === "GET") { if (url.indexOf("/user/room") !== -1 && method === "GET") {
resolve({}); resolve({});
return; return;
} }
if (res.data.message === "ERROR_BATTLE_GAMING") { if (message === "ERROR_BATTLE_GAMING") {
resolve({}); resolve({});
return; return;
} }
uni.showToast({ uni.showToast({
title: res.data.message, title: message,
icon: "none", icon: "none",
}); });
} }
}
}, },
fail: (err) => { fail: (err) => {
reject(err); reject(err);
@@ -277,3 +280,8 @@ export const isGamingAPI = async () => {
const result = await request("GET", "/user/isGaming"); const result = await request("GET", "/user/isGaming");
return result.gaming || false; return result.gaming || false;
}; };
export const getCurrentGameAPI = async () => {
const result = await request("GET", "/user/join/battle");
return result.currentGame || {};
};

View File

@@ -18,7 +18,7 @@ const roomNumber = ref("");
const createRoom = async () => { const createRoom = async () => {
const isGaming = await isGamingAPI(); const isGaming = await isGamingAPI();
if (isGaming) { if (isGaming) {
uni.$showHint("当前正在对战中"); uni.$showHint(1);
return; return;
} }
if (loading.value === true) return; if (loading.value === true) return;

View File

@@ -17,6 +17,7 @@ export const MESSAGETYPES = {
RoomDestroy: 3617539277, RoomDestroy: 3617539277,
SomeoneComplete: 2921416944, SomeoneComplete: 2921416944,
HalfTimeOver: 388606440, HalfTimeOver: 388606440,
BackToGame: 1899960424,
}; };
export const topThreeColors = ["#FFD947", "#D2D2D2", "#FFA515"]; export const topThreeColors = ["#FFD947", "#D2D2D2", "#FFA515"];

View File

@@ -54,6 +54,21 @@ const halfTimeTip = ref(false);
const total = ref(90); const total = ref(90);
onLoad(async (options) => { onLoad(async (options) => {
if (options.battleId) {
const battleInfo = uni.getStorageSync(`battle-${options.battleId}`);
console.log("----battleInfo", battleInfo);
if (battleInfo) {
battleId.value = battleInfo.id;
start.value = true;
redTeam.value = battleInfo.redTeam;
blueTeam.value = battleInfo.blueTeam;
currentRound.value = battleInfo.currentRound;
bluePoints.value = battleInfo.blueScore;
redPoints.value = battleInfo.redScore;
totalRounds.value = battleInfo.maxRound;
roundResults.value = battleInfo.roundResults;
}
}
if (options.roomNumber) { if (options.roomNumber) {
roomNumber.value = options.roomNumber; roomNumber.value = options.roomNumber;
const result = await getRoomAPI(options.roomNumber); const result = await getRoomAPI(options.roomNumber);

View File

@@ -19,7 +19,7 @@ const roomNumber = ref("");
const enterRoom = debounce(async () => { const enterRoom = debounce(async () => {
const isGaming = await isGamingAPI(); const isGaming = await isGamingAPI();
if (isGaming) { if (isGaming) {
uni.$showHint("当前正在对战中"); uni.$showHint(1);
return; return;
} }
if (!roomNumber.value) { if (!roomNumber.value) {

View File

@@ -75,7 +75,7 @@ const toTeamMatchPage = async (gameType, teamSize) => {
} }
const isGaming = await isGamingAPI(); const isGaming = await isGamingAPI();
if (isGaming) { if (isGaming) {
uni.$showHint("当前正在对战中"); uni.$showHint(1);
return; return;
} }
uni.navigateTo({ uni.navigateTo({
@@ -92,7 +92,7 @@ const toMeleeMatchPage = async (gameType, teamSize) => {
} }
const isGaming = await isGamingAPI(); const isGaming = await isGamingAPI();
if (isGaming) { if (isGaming) {
uni.$showHint("当前正在对战中"); uni.$showHint(1);
return; return;
} }
uni.navigateTo({ uni.navigateTo({

View File

@@ -1,3 +1,4 @@
import { MESSAGETYPES } from "@/constants";
let socket = null; let socket = null;
let heartbeatInterval = null; let heartbeatInterval = null;
let reconnectCount = 0; let reconnectCount = 0;
@@ -32,6 +33,29 @@ function createWebSocket(token, onMessage) {
uni.onSocketMessage((res) => { uni.onSocketMessage((res) => {
const data = JSON.parse(res.data); const data = JSON.parse(res.data);
if (onMessage) onMessage(data.data.updates); if (onMessage) onMessage(data.data.updates);
const msg = data.data.updates[0];
if (msg && msg.constructor === MESSAGETYPES.BackToGame) {
const { battleInfo } = msg;
uni.setStorageSync(`battle-${battleInfo.id}`, battleInfo);
// 约战
if (battleInfo.config.battleMode === 1) {
uni.navigateTo({
url: `/pages/team-match?battleId=${battleInfo.id}`,
});
}
// 排位
if (battleInfo.config.battleMode === 2) {
if (battleInfo.config.mode === 1) {
uni.navigateTo({
url: `/pages/team-match?battleId=${battleInfo.id}`,
});
} else if (battleInfo.config.mode === 2) {
uni.navigateTo({
url: `/pages/melee-match?battleId=${battleInfo.id}`,
});
}
}
}
}); });
// 错误处理 // 错误处理