修复BUG
This commit is contained in:
@@ -44,30 +44,75 @@ const props = defineProps({
|
||||
const showHint = ref(false);
|
||||
const hintType = ref(0);
|
||||
const capsuleHeight = ref(0);
|
||||
const isLoading = ref(false);
|
||||
|
||||
const showGlobalHint = (type) => {
|
||||
hintType.value = type;
|
||||
showHint.value = true;
|
||||
};
|
||||
|
||||
const hideGlobalHint = () => {
|
||||
showHint.value = false;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
const menuBtnInfo = uni.getMenuButtonBoundingClientRect();
|
||||
capsuleHeight.value = menuBtnInfo.top - 9;
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// const pages = getCurrentPages();
|
||||
// const currentPage = pages[pages.length - 1];
|
||||
// uni.setStorageSync("last-route", currentPage.route);
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
uni.$showHint = showGlobalHint;
|
||||
uni.$hideHint = hideGlobalHint;
|
||||
showHint.value = false;
|
||||
});
|
||||
|
||||
const backToGame = debounce(async () => {
|
||||
const result = await getCurrentGameAPI();
|
||||
if (isLoading.value) return; // 防止重复点击
|
||||
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
// 设置请求超时
|
||||
const timeoutPromise = new Promise((_, reject) => {
|
||||
setTimeout(() => reject(new Error('请求超时')), 10000); // 10秒超时
|
||||
});
|
||||
|
||||
const result = await Promise.race([
|
||||
getCurrentGameAPI(),
|
||||
timeoutPromise
|
||||
]);
|
||||
|
||||
// 处理返回结果
|
||||
if (result && result.gameId) {
|
||||
// 跳转到游戏页面
|
||||
uni.navigateTo({
|
||||
url: `/pages/battle-room?gameId=${result.gameId}`
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '没有进行中的对局',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
showHint.value = false;
|
||||
} catch (error) {
|
||||
console.error('获取当前游戏失败:', error);
|
||||
uni.showToast({
|
||||
title: error.message || '网络请求失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
const goBack = () => {
|
||||
uni.navigateBack();
|
||||
};
|
||||
@@ -100,7 +145,13 @@ const goBack = () => {
|
||||
<button hover-class="none" @click="() => (showHint = false)">
|
||||
不进入
|
||||
</button>
|
||||
<button hover-class="none" @click="backToGame">进入</button>
|
||||
<button
|
||||
hover-class="none"
|
||||
@click="backToGame"
|
||||
:disabled="isLoading"
|
||||
>
|
||||
{{ isLoading ? '加载中...' : '进入' }}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="hintType === 2" class="tip-content">
|
||||
@@ -168,4 +219,10 @@ const goBack = () => {
|
||||
background-color: #fed847;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.tip-content > view > button:disabled {
|
||||
background-color: #ccc;
|
||||
color: #666;
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user