fix:解决数据持久化疯狂调用state接口问题
This commit is contained in:
@@ -19,8 +19,12 @@ const props = defineProps({
|
|||||||
});
|
});
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
|
||||||
|
/** 统一获取当前环境 token,用于守卫:无有效 token 时不发起接口请求 */
|
||||||
|
const getToken = () =>
|
||||||
|
uni.getStorageSync(`${uni.getAccountInfoSync().miniProgram.envVersion}_token`);
|
||||||
|
|
||||||
onShow(async () => {
|
onShow(async () => {
|
||||||
if (user.value.id) {
|
if (user.value.id && getToken()) {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const state = await getUserGameState();
|
const state = await getUserGameState();
|
||||||
updateGame(state.gaming, state.roomId);
|
updateGame(state.gaming, state.roomId);
|
||||||
@@ -33,7 +37,8 @@ watch(
|
|||||||
async (value) => {
|
async (value) => {
|
||||||
if (!value.id) {
|
if (!value.id) {
|
||||||
updateGame(false, "");
|
updateGame(false, "");
|
||||||
} else {
|
} else if (getToken()) {
|
||||||
|
// 有有效 token 时才查询在局状态,避免 token 失效时反复发起无效请求
|
||||||
const state = await getUserGameState();
|
const state = await getUserGameState();
|
||||||
updateGame(state.gaming, state.roomId);
|
updateGame(state.gaming, state.roomId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user