pref: 匹配成功展示准备页面
This commit is contained in:
@@ -9,7 +9,6 @@ import { MESSAGETYPESV2 } from "@/constants";
|
||||
const gameType = ref(0);
|
||||
const teamSize = ref(0);
|
||||
const onComplete = ref(null);
|
||||
const matchSuccess = ref(false);
|
||||
|
||||
async function stopMatch() {
|
||||
uni.$showHint(3);
|
||||
@@ -24,8 +23,9 @@ async function cancelMatch() {
|
||||
|
||||
async function onReceiveMessage(msg) {
|
||||
if (msg.type === MESSAGETYPESV2.MatchSuccess) {
|
||||
matchSuccess.value = true;
|
||||
onComplete.value = () => {
|
||||
onComplete.value = () => {}
|
||||
}
|
||||
if (msg.type === MESSAGETYPESV2.AboutToStart) {
|
||||
if (gameType.value == 1) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/team-battle?battleId=${msg.id}&gameMode=2`,
|
||||
@@ -35,7 +35,6 @@ async function onReceiveMessage(msg) {
|
||||
url: `/pages/melee-battle?battleId=${msg.id}&gameMode=2`,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,20 +29,32 @@ const halfTimeTip = ref(false);
|
||||
const halfRest = ref(false);
|
||||
|
||||
function recoverData(battleInfo, { force = false } = {}) {
|
||||
if (!battleInfo) return;
|
||||
try {
|
||||
if (battleInfo.way === 1) title.value = "好友约战 - 大乱斗";
|
||||
if (battleInfo.way === 2) title.value = "排位赛 - 大乱斗";
|
||||
players.value = battleInfo.teams[0].players;
|
||||
|
||||
// 优先使用接口数据,否则使用缓存
|
||||
if (battleInfo.teams?.[0]?.players) {
|
||||
players.value = [...battleInfo.teams[0].players];
|
||||
} else {
|
||||
// 大乱斗可能存的是 players 列表
|
||||
// 这里的缓存逻辑根据 AboutToStart 消息结构可能不同,假设也是 teams[0]
|
||||
// 如果是从 match-page 过来的,match-page 只存了 teams[1] 和 [2] 给对抗模式
|
||||
// 大乱斗的匹配逻辑可能不同,暂时保持原样,只做安全保护
|
||||
players.value = [];
|
||||
}
|
||||
|
||||
start.value = battleInfo.status !== 0;
|
||||
|
||||
if (battleInfo.status === 0) {
|
||||
const readyRemain = (Date.now() - battleInfo.createTime) / 1000;
|
||||
console.log(`对局已进行${readyRemain}秒`);
|
||||
const readyRemain = (Date.now() - (battleInfo.createTime || Date.now())) / 1000;
|
||||
if (readyRemain > 0 && readyRemain < 15) {
|
||||
setTimeout(() => {
|
||||
uni.$emit("update-timer", 15 - readyRemain - 0.2);
|
||||
}, 200);
|
||||
setTimeout(() => uni.$emit("update-timer", 15 - readyRemain - 0.2), 200);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
tips.value =
|
||||
(battleInfo.rounds.length !== 2 ? "上" : "下") + "半场:请先射6箭";
|
||||
playersScores.value = battleInfo.rounds.map((r) => ({ ...r.shoots }));
|
||||
@@ -69,7 +81,7 @@ function recoverData(battleInfo, { force = false } = {}) {
|
||||
return;
|
||||
}
|
||||
if (force) {
|
||||
const remain = (Date.now() - battleInfo.current.startTime) / 1000;
|
||||
const remain = (Date.now() - (battleInfo.current?.startTime || Date.now())) / 1000;
|
||||
console.log(`当前轮已进行${remain}秒`);
|
||||
if (remain > 0 && remain < 90) {
|
||||
setTimeout(() => {
|
||||
@@ -77,6 +89,9 @@ function recoverData(battleInfo, { force = false } = {}) {
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("recoverData error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
onLoad(async (options) => {
|
||||
@@ -127,6 +142,7 @@ onBeforeUnmount(() => {
|
||||
onShow(async () => {
|
||||
if (battleId.value) {
|
||||
const result = await getBattleAPI(battleId.value);
|
||||
if (!result) return;
|
||||
if (result.status === 2) {
|
||||
uni.showToast({
|
||||
title: "比赛已结束",
|
||||
|
||||
@@ -39,12 +39,27 @@ const isFinalShoot = ref(false);
|
||||
const recoverData = (battleInfo, { force = false, arrowOnly = false } = {}) => {
|
||||
try {
|
||||
battleId.value = battleInfo.matchId;
|
||||
blueTeam.value = battleInfo.teams[1].players || [];
|
||||
redTeam.value = battleInfo.teams[2].players || [];
|
||||
|
||||
// 优先使用接口返回的队伍数据,如果没有则尝试从缓存读取(应对匹配刚完成接口未就绪的情况)
|
||||
const t1 = battleInfo.teams?.[1] || {};
|
||||
const t2 = battleInfo.teams?.[2] || {};
|
||||
|
||||
if (t1.players) blueTeam.value = [...t1.players];
|
||||
else {
|
||||
const cached = uni.getStorageSync("blue-team");
|
||||
if (cached && cached.length) blueTeam.value = cached;
|
||||
}
|
||||
|
||||
if (t2.players) redTeam.value = [...t2.players];
|
||||
else {
|
||||
const cached = uni.getStorageSync("red-team");
|
||||
if (cached && cached.length) redTeam.value = cached;
|
||||
}
|
||||
|
||||
start.value = battleInfo.status !== 0;
|
||||
|
||||
if (battleInfo.status === 0) {
|
||||
const readyRemain = (Date.now() - battleInfo.createTime) / 1000;
|
||||
console.log(`对局已进行${readyRemain}秒`);
|
||||
const readyRemain = (Date.now() - (battleInfo.createTime || Date.now())) / 1000;
|
||||
if (readyRemain > 0 && readyRemain < 15) {
|
||||
setTimeout(() => {
|
||||
uni.$emit("update-timer", 15 - readyRemain - 0.2);
|
||||
@@ -162,6 +177,7 @@ const refreshTimer = ref(null);
|
||||
onShow(async () => {
|
||||
if (battleId.value) {
|
||||
const result = await getBattleAPI(battleId.value);
|
||||
if (!result) return;
|
||||
if (result.status === 2) {
|
||||
uni.showToast({
|
||||
title: "比赛已结束",
|
||||
|
||||
Reference in New Issue
Block a user