完善比赛异常结束逻辑

This commit is contained in:
kron
2025-07-29 11:04:19 +08:00
parent 9d6bcde9ba
commit da2de8685d
2 changed files with 27 additions and 23 deletions

View File

@@ -38,7 +38,6 @@ function request(method, url, data = {}) {
if (message === "BIND_DEVICE") { if (message === "BIND_DEVICE") {
resolve({ binded: true }); resolve({ binded: true });
return; return;
} }
if (message === "ERROR_ORDER_UNPAY") { if (message === "ERROR_ORDER_UNPAY") {
uni.showToast({ uni.showToast({
@@ -65,17 +64,17 @@ function request(method, url, data = {}) {
// 统一的错误处理函数 // 统一的错误处理函数
function handleRequestError(err, url) { function handleRequestError(err, url) {
console.log('请求失败:', { err, url }); console.log("请求失败:", { err, url });
// 根据错误类型显示不同提示 // 根据错误类型显示不同提示
if (err.errMsg) { if (err.errMsg) {
if (err.errMsg.includes('timeout')) { if (err.errMsg.includes("timeout")) {
showCustomToast("请求超时,请稍后重试", "timeout"); showCustomToast("请求超时,请稍后重试", "timeout");
} else if (err.errMsg.includes('fail')) { } else if (err.errMsg.includes("fail")) {
// 检查网络状态 // 检查网络状态
uni.getNetworkType({ uni.getNetworkType({
success: (res) => { success: (res) => {
if (res.networkType === 'none') { if (res.networkType === "none") {
showCustomToast("网络连接已断开,请检查网络设置", "network"); showCustomToast("网络连接已断开,请检查网络设置", "network");
} else { } else {
showCustomToast("服务器连接失败,请稍后重试", "server"); showCustomToast("服务器连接失败,请稍后重试", "server");
@@ -83,7 +82,7 @@ function handleRequestError(err, url) {
}, },
fail: () => { fail: () => {
showCustomToast("网络异常,请检查网络连接", "unknown"); showCustomToast("网络异常,请检查网络连接", "unknown");
} },
}); });
} else { } else {
showCustomToast("请求失败,请稍后重试", "general"); showCustomToast("请求失败,请稍后重试", "general");
@@ -98,21 +97,21 @@ function showCustomToast(message, type) {
const config = { const config = {
title: message, title: message,
icon: "none", icon: "none",
duration: 3000 duration: 3000,
}; };
// 根据错误类型可以添加不同的处理逻辑 // 根据错误类型可以添加不同的处理逻辑
switch (type) { switch (type) {
case 'timeout': case "timeout":
config.duration = 4000; // 超时提示显示更久 config.duration = 4000; // 超时提示显示更久
break; break;
case 'network': case "network":
config.duration = 5000; // 网络问题提示显示更久 config.duration = 5000; // 网络问题提示显示更久
break; break;
default: default:
break; break;
} }
uni.showToast(config); uni.showToast(config);
} }
@@ -228,6 +227,7 @@ export const getGameAPI = async (battleId) => {
const result = await request("POST", "/user/battle/detail", { const result = await request("POST", "/user/battle/detail", {
id: battleId, id: battleId,
}); });
if (!result.battleStats) return {};
const { const {
battleStats = {}, battleStats = {},
playerStats = {}, playerStats = {},

View File

@@ -1,5 +1,5 @@
import websocket from "@/websocket"; import websocket from "@/websocket";
import { isGamingAPI } from "@/apis"; import { isGamingAPI, getGameAPI } from "@/apis";
export const formatTimestamp = (timestamp) => { export const formatTimestamp = (timestamp) => {
const date = new Date(timestamp * 1000); const date = new Date(timestamp * 1000);
@@ -269,16 +269,20 @@ export const wxShare = async () => {
export const isGameEnded = async (battleId) => { export const isGameEnded = async (battleId) => {
const isGaming = await isGamingAPI(); const isGaming = await isGamingAPI();
if (!isGaming) { if (!isGaming) {
// uni.showToast({ const result = await getGameAPI(battleId);
// title: "比赛已结束", if (result.mode) {
// icon: "none", uni.redirectTo({
// }); url: `/pages/battle-result?battleId=${battleId}`,
// setTimeout(() => { });
// uni.navigateBack(); } else {
// }, 1000); uni.showToast({
uni.redirectTo({ title: "比赛已结束",
url: `/pages/battle-result?battleId=${battleId}`, icon: "none",
}); });
setTimeout(() => {
uni.navigateBack();
}, 1000);
}
} }
return !isGaming; return !isGaming;
}; };