update:修复日志和防抖

This commit is contained in:
2026-07-09 14:35:48 +08:00
parent f8efe4c4a4
commit 12729a1cef
5 changed files with 106 additions and 31 deletions
+13 -4
View File
@@ -15,7 +15,7 @@ import {
getReadyAPI,
kickPlayerAPI,
} from "@/apis";
import { isLimitError } from "@/util";
import { debounce, isLimitError } from "@/util";
import { MESSAGETYPES, MESSAGETYPESV2 } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -59,6 +59,7 @@ const allReady = ref(false);
const timer = ref(null);
const goBattle = ref(false);
const showLimitModal = ref(false);
const readySubmitting = ref(false);
/** 从结算页返回时为 true,跳过进场靶纸语音 */
const skipTargetAudio = ref(false);
@@ -139,17 +140,22 @@ async function refreshRoomData() {
// timer.value = setTimeout(refreshRoomData, 2000);
}
const getReady = async () => {
const getReady = debounce(async () => {
if (readySubmitting.value) return;
readySubmitting.value = true;
try {
await getReadyAPI(roomNumber.value);
ready.value = true;
} catch (error) {
if (isLimitError(error)) {
showLimitModal.value = true;
return;
}
console.log("room ready error", error);
} finally {
readySubmitting.value = false;
}
};
});
const closeLimitModal = () => {
showLimitModal.value = false;
@@ -465,7 +471,10 @@ onBeforeUnmount(() => {
<PlayerSeats v-if="room.battleType === 2" :total="room.count || 10" :players="players"
:removePlayer="removePlayer" :isOwner="owner.id === user.id" />
<view>
<SButton :disabled="!canClick" :onClick="() => $clickSound(getReady)">
<SButton
:disabled="!canClick || readySubmitting"
:onClick="() => { $clickSound(); return getReady(); }"
>
{{
allReady.value
? "即将进入对局..."
+22 -10
View File
@@ -27,6 +27,7 @@ const data = ref({});
const roomID = ref("");
const loading = ref(false);
const showLimitModal = ref(false);
const createRoomLoading = ref(false);
const isSVip = computed(() => user.value.sVip === true);
const isVip = computed(() => user.value.vip === true && !isSVip.value);
const challengeLimitText = computed(() =>
@@ -45,6 +46,7 @@ const enterRoom = debounce(async (number) => {
showModal.value = true;
return;
}
loading.value = true;
try {
const room = await getRoomAPI(number);
if (!room.number) {
@@ -63,7 +65,6 @@ const enterRoom = debounce(async (number) => {
return;
}
}
loading.value = true;
uni.navigateTo({
url: "/pages/battle-room?roomNumber=" + number,
});
@@ -71,16 +72,22 @@ const enterRoom = debounce(async (number) => {
loading.value = false;
}
});
const onCreateRoom = async () => {
const onCreateRoom = debounce(async () => {
if (createRoomLoading.value) return;
if (!canEenter(user.value, device.value, online.value)) return;
const countData = await loadDailyCount();
if (isLimitReached(countData.challenge)) {
showLimitModal.value = true;
return;
createRoomLoading.value = true;
try {
const countData = await loadDailyCount();
if (isLimitReached(countData.challenge)) {
showLimitModal.value = true;
return;
}
warnning.value = "";
showModal.value = true;
} finally {
createRoomLoading.value = false;
}
warnning.value = "";
showModal.value = true;
};
});
const closeLimitModal = () => {
showLimitModal.value = false;
@@ -208,7 +215,12 @@ onLoad(async (options) => {
<view v-if="challengeLimitText" class="pp-text">
{{ challengeLimitText }}
</view>
<SButton width="80%" :rounded="30" :onClick="() => $clickSound(onCreateRoom)">
<SButton
width="80%"
:rounded="30"
:disabled="createRoomLoading"
:onClick="() => { $clickSound(); return onCreateRoom(); }"
>
创建约战房
</SButton>
</view>
+23 -1
View File
@@ -13,7 +13,11 @@ import TestDistance from "@/components/TestDistance.vue";
import SModal from "@/components/SModal.vue";
import audioManager from "@/audioManager";
import { getBattleAPI, laserCloseAPI } from "@/apis";
import { closeMatchWebSocket, connectMatchWebSocket } from "@/matchWebsocket";
import {
closeMatchWebSocket,
connectMatchWebSocket,
MATCH_WS_AUDIO_ACK_EVENT,
} from "@/matchWebsocket";
import { MESSAGETYPESV2 } from "@/constants";
import { takeMatchReturnSnapshot } from "@/utils/matchReturn";
import useStore from "@/store";
@@ -172,6 +176,23 @@ function closeBattleServer(reason) {
closeMatchWebSocket({ reason });
}
function notifyMatchAudioAck(message) {
if (
message?.sequence === undefined ||
message?.sequence === null ||
message?.sequence === ""
) {
return;
}
uni.$emit(MATCH_WS_AUDIO_ACK_EVENT, {
matchId: message.matchId || battleId.value,
sequence: message.sequence,
matchWsType: message.matchWsType,
matchWsTypeName: message.matchWsTypeName,
});
}
/**
* 监听设备在线状态,大乱斗比赛进行中设备离线时弹窗提示用户
*/
@@ -346,6 +367,7 @@ async function onReceiveMessage(msg) {
startHalfRestCountdown();
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
battleEnded = true;
notifyMatchAudioAck(msg);
setTimeout(() => {
// 全部跳转到新结算页
uni.redirectTo({