fix:解决数据持久化疯狂调用state接口问题

This commit is contained in:
2026-05-14 17:58:08 +08:00
parent fcf346905b
commit e70ae0add5

View File

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