🐞 fix: 修复五子棋确认框重复弹出的bug

This commit is contained in:
Litrix2 2024-12-21 15:57:06 +08:00
parent 0d1a86661a
commit d005f06bd9

View File

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