update:大乱斗优化

This commit is contained in:
2026-06-12 16:44:17 +08:00
parent 5cf243d187
commit 8b2ea24f38
2 changed files with 68 additions and 10 deletions

View File

@@ -15,6 +15,12 @@ const props = defineProps({
}); });
const rowCount = new Array(6).fill(0); const rowCount = new Array(6).fill(0);
const getRingText = (arrow) => {
if (!arrow) return "-";
if (arrow.ringX && arrow.ring) return "X环";
return arrow.ring ? `${arrow.ring}` : "-";
};
</script> </script>
<template> <template>
@@ -35,23 +41,19 @@ const rowCount = new Array(6).fill(0);
<view> <view>
<view> <view>
<view v-for="(_, index) in rowCount" :key="index"> <view v-for="(_, index) in rowCount" :key="index">
<text>{{ <text>{{ getRingText(scores[0]?.[index]) }}</text>
scores[0] && scores[0][index] ? `${scores[0][index].ring}` : "-"
}}</text>
</view> </view>
</view> </view>
<view> <view>
<view v-for="(_, index) in rowCount" :key="index"> <view v-for="(_, index) in rowCount" :key="index">
<text>{{ <text>{{ getRingText(scores[1]?.[index]) }}</text>
scores[1] && scores[1][index] ? `${scores[1][index].ring}` : "-"
}}</text>
</view> </view>
</view> </view>
</view> </view>
<text <text
>{{ >{{
scores scores
.map((s) => s.reduce((last, next) => last + next.ring, 0)) .map((s) => (s || []).reduce((last, next) => last + next.ring, 0))
.reduce((last, next) => last + next, 0) .reduce((last, next) => last + next, 0)
}}</text }}</text
> >

View File

@@ -30,11 +30,65 @@ const playersSorted = ref([]);
const playersScores = ref([]); const playersScores = ref([]);
const halfTimeTip = ref(false); const halfTimeTip = ref(false);
const halfRest = ref(false); const halfRest = ref(false);
const HALF_REST_SECONDS = 20;
const halfRestRemain = ref(HALF_REST_SECONDS);
let halfRestTimer = null;
/** 控制设备离线提示弹窗的显示状态 */ /** 控制设备离线提示弹窗的显示状态 */
const showOfflineModal = ref(false); const showOfflineModal = ref(false);
/** 记录每位玩家当前半场连续 X 环数key 为 playerId用于触发 tententen 音效 */ /** 记录每位玩家当前半场连续 X 环数key 为 playerId用于触发 tententen 音效 */
const xRingStreaks = ref({}); const xRingStreaks = ref({});
function clearHalfRestCountdown() {
if (halfRestTimer) {
clearInterval(halfRestTimer);
halfRestTimer = null;
}
}
function getHalfRestSeconds(battleInfo) {
const remainCandidates = [
battleInfo?.halfRestRemain,
battleInfo?.halfRestRemainSeconds,
battleInfo?.restRemain,
battleInfo?.restRemainSeconds,
];
for (const item of remainCandidates) {
const remain = Number(item);
if (Number.isFinite(remain) && remain > 0 && remain <= HALF_REST_SECONDS) {
return Math.ceil(remain);
}
}
const endTime = Number(battleInfo?.halfRestEndTime ?? battleInfo?.restEndTime);
if (!Number.isFinite(endTime) || endTime <= 0) return HALF_REST_SECONDS;
const timestamp = endTime < 1e12 ? endTime * 1000 : endTime;
const diffSeconds = (timestamp - Date.now()) / 1000;
if (diffSeconds > 0 && diffSeconds <= HALF_REST_SECONDS) {
return Math.ceil(diffSeconds);
}
return HALF_REST_SECONDS;
}
function startHalfRestCountdown(seconds = HALF_REST_SECONDS) {
clearHalfRestCountdown();
halfRestRemain.value = Math.max(0, Math.ceil(Number(seconds) || HALF_REST_SECONDS));
if (halfRestRemain.value <= 0) return;
halfRestTimer = setInterval(() => {
if (halfRestRemain.value <= 1) {
halfRestRemain.value = 0;
clearHalfRestCountdown();
return;
}
halfRestRemain.value -= 1;
}, 1000);
}
/** /**
* 监听设备在线状态,大乱斗比赛进行中设备离线时弹窗提示用户 * 监听设备在线状态,大乱斗比赛进行中设备离线时弹窗提示用户
*/ */
@@ -91,8 +145,7 @@ function recoverData(battleInfo, { force = false } = {}) {
halfTimeTip.value = true; halfTimeTip.value = true;
halfRest.value = true; halfRest.value = true;
tips.value = "准备下半场"; tips.value = "准备下半场";
// 剩余休息时间 startHalfRestCountdown(getHalfRestSeconds(battleInfo));
// const remain = (Date.now() - battleInfo.timeoutTime) / 1000;
setTimeout(() => { setTimeout(() => {
uni.$emit("update-remain", 0); uni.$emit("update-remain", 0);
}, 200); }, 200);
@@ -147,6 +200,7 @@ function checkAndPlayTententen(playerId, isXRing) {
async function onReceiveMessage(msg) { async function onReceiveMessage(msg) {
if (Array.isArray(msg)) return; if (Array.isArray(msg)) return;
if (msg.type === MESSAGETYPESV2.BattleStart) { if (msg.type === MESSAGETYPESV2.BattleStart) {
clearHalfRestCountdown();
halfTimeTip.value = false; halfTimeTip.value = false;
halfRest.value = false; halfRest.value = false;
recoverData(msg); recoverData(msg);
@@ -177,6 +231,7 @@ async function onReceiveMessage(msg) {
halfTimeTip.value = true; halfTimeTip.value = true;
halfRest.value = true; halfRest.value = true;
tips.value = "准备下半场"; tips.value = "准备下半场";
startHalfRestCountdown();
} else if (msg.type === MESSAGETYPESV2.BattleEnd) { } else if (msg.type === MESSAGETYPESV2.BattleEnd) {
setTimeout(() => { setTimeout(() => {
// 全部跳转到新结算页 // 全部跳转到新结算页
@@ -197,6 +252,7 @@ onBeforeUnmount(() => {
uni.setKeepScreenOn({ uni.setKeepScreenOn({
keepScreenOn: false, keepScreenOn: false,
}); });
clearHalfRestCountdown();
uni.$off("socket-inbox", onReceiveMessage); uni.$off("socket-inbox", onReceiveMessage);
audioManager.stopAll(); audioManager.stopAll();
}); });
@@ -261,7 +317,7 @@ onShow(async () => {
> >
<view class="half-time-tip"> <view class="half-time-tip">
<text>上半场结束休息一下吧:</text> <text>上半场结束休息一下吧:</text>
<text>20秒后开始下半场</text> <text>{{ halfRestRemain }}秒后开始下半场</text>
</view> </view>
</ScreenHint> </ScreenHint>
<!-- 设备离线提示弹窗 --> <!-- 设备离线提示弹窗 -->