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; }, },