From d005f06bd9f8578e970e2ed7bb43c3977c47d406 Mon Sep 17 00:00:00 2001 From: Litrix2 Date: Sat, 21 Dec 2024 15:57:06 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=94=E5=AD=90=E6=A3=8B=E7=A1=AE=E8=AE=A4=E6=A1=86=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=BC=B9=E5=87=BA=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/GobangPlayPage.vue | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/views/GobangPlayPage.vue b/src/views/GobangPlayPage.vue index 6cb64f6..46d689a 100644 --- a/src/views/GobangPlayPage.vue +++ b/src/views/GobangPlayPage.vue @@ -245,8 +245,13 @@ import { onBeforeRouteLeave, useRoute } from 'vue-router'; const userStore = useUserStore(); const { smLess, mdLess } = storeToRefs(useMediaStore()); let canExit = false; +let confirming = false; useLogoutInterceptor(() => { + if (confirming) { + return; + } if (canExit || matchState.value !== MatchState.GAMING) return true; + confirming = true; ElMessageBox.confirm('你正在游戏中, 是否退出登录?', '警告', { confirmButtonText: '确定', cancelButtonText: '取消', @@ -255,16 +260,24 @@ useLogoutInterceptor(() => { .then((action: Action) => { if (action !== 'confirm') return; canExit = true; + confirming = false; return userStore.logout(); }) - .catch(() => {}); + .catch(() => { + confirming = false; + }); return false; }); onBeforeRouteLeave((to, _, next) => { + if (confirming) { + next(false); + return; + } if (canExit || matchState.value !== MatchState.GAMING) { next(true); return; } + confirming = true; ElMessageBox.confirm('你正在游戏中, 是否退出房间?', '警告', { confirmButtonText: '确定', cancelButtonText: '取消', @@ -273,9 +286,12 @@ onBeforeRouteLeave((to, _, next) => { .then((action: Action) => { if (action !== 'confirm') return; canExit = true; + confirming = false; router.push(to); }) - .catch(() => {}); + .catch(() => { + confirming = false; + }); next(false); }); const roomId = useRoute().params.id as RoomId | undefined; @@ -529,7 +545,7 @@ const { send } = useGobangSocket({ }, error: { PlayerJoin() { - queueMicrotask(() => router.back()); + router.back(); return false; }, },