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