From e70ae0add519eb58c73642a3b0b56c5a6545d9af Mon Sep 17 00:00:00 2001 From: chenlimao Date: Thu, 14 May 2026 17:58:08 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=A7=A3=E5=86=B3=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=8C=81=E4=B9=85=E5=8C=96=E7=96=AF=E7=8B=82=E8=B0=83?= =?UTF-8?q?=E7=94=A8state=E6=8E=A5=E5=8F=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/BackToGame.vue | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/BackToGame.vue b/src/components/BackToGame.vue index 9319c21..43057af 100644 --- a/src/components/BackToGame.vue +++ b/src/components/BackToGame.vue @@ -19,8 +19,12 @@ const props = defineProps({ }); const loading = ref(false); +/** 统一获取当前环境 token,用于守卫:无有效 token 时不发起接口请求 */ +const getToken = () => + uni.getStorageSync(`${uni.getAccountInfoSync().miniProgram.envVersion}_token`); + onShow(async () => { - if (user.value.id) { + if (user.value.id && getToken()) { setTimeout(async () => { const state = await getUserGameState(); updateGame(state.gaming, state.roomId); @@ -33,7 +37,8 @@ watch( async (value) => { if (!value.id) { updateGame(false, ""); - } else { + } else if (getToken()) { + // 有有效 token 时才查询在局状态,避免 token 失效时反复发起无效请求 const state = await getUserGameState(); updateGame(state.gaming, state.roomId); }