调试重新进入比赛
This commit is contained in:
40
src/apis.js
40
src/apis.js
@@ -11,23 +11,26 @@ function request(method, url, data = {}) {
|
|||||||
},
|
},
|
||||||
data,
|
data,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.data.code === 0) resolve(res.data.data);
|
if (res.data) {
|
||||||
else {
|
const { code, data, message } = res.data;
|
||||||
if (res.data.message.indexOf("登录身份已失效") !== -1) {
|
if (code === 0) resolve(data);
|
||||||
uni.removeStorageSync("token");
|
else {
|
||||||
|
if (message.indexOf("登录身份已失效") !== -1) {
|
||||||
|
uni.removeStorageSync("token");
|
||||||
|
}
|
||||||
|
if (url.indexOf("/user/room") !== -1 && method === "GET") {
|
||||||
|
resolve({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (message === "ERROR_BATTLE_GAMING") {
|
||||||
|
resolve({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uni.showToast({
|
||||||
|
title: message,
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (url.indexOf("/user/room") !== -1 && method === "GET") {
|
|
||||||
resolve({});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (res.data.message === "ERROR_BATTLE_GAMING") {
|
|
||||||
resolve({});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uni.showToast({
|
|
||||||
title: res.data.message,
|
|
||||||
icon: "none",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (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 || {};
|
||||||
|
};
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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"];
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
@@ -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}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 错误处理
|
// 错误处理
|
||||||
|
|||||||
Reference in New Issue
Block a user