修复BUG

This commit is contained in:
kron
2025-09-18 09:28:14 +08:00
parent b952ea9fd0
commit 72ab9c3757
8 changed files with 96 additions and 34 deletions

View File

@@ -49,21 +49,11 @@ const props = defineProps({
const showsimul = ref(false); const showsimul = ref(false);
const latestOne = ref(null); const latestOne = ref(null);
const bluelatestOne = ref(null);
const prevScores = ref([]); const prevScores = ref([]);
const prevBlueScores = ref([]); const prevBlueScores = ref([]);
// const startCount = ref(false);
const timer = ref(null); const timer = ref(null);
// watch(
// () => props.start,
// (newVal) => {
// startCount.value = newVal;
// },
// {
// immediate: true,
// }
// );
watch( watch(
() => props.scores, () => props.scores,
(newVal) => { (newVal) => {
@@ -85,10 +75,10 @@ watch(
() => props.blueScores, () => props.blueScores,
(newVal) => { (newVal) => {
if (newVal.length - prevBlueScores.value.length === 1) { if (newVal.length - prevBlueScores.value.length === 1) {
latestOne.value = newVal[newVal.length - 1]; bluelatestOne.value = newVal[newVal.length - 1];
if (timer.value) clearTimeout(timer.value); if (timer.value) clearTimeout(timer.value);
timer.value = setTimeout(() => { timer.value = setTimeout(() => {
latestOne.value = null; bluelatestOne.value = null;
}, 1000); }, 1000);
} }
prevBlueScores.value = [...newVal]; prevBlueScores.value = [...newVal];
@@ -176,7 +166,7 @@ onMounted(() => {
<view <view
v-if="bow.ring > 0" v-if="bow.ring > 0"
:class="`hit ${ :class="`hit ${
index === blueScores.length - 1 && latestOne ? 'pump-in' : '' index === blueScores.length - 1 && bluelatestOne ? 'pump-in' : ''
}`" }`"
:style="{ :style="{
left: calcRealX(bow.x), left: calcRealX(bow.x),

View File

@@ -44,30 +44,75 @@ const props = defineProps({
const showHint = ref(false); const showHint = ref(false);
const hintType = ref(0); const hintType = ref(0);
const capsuleHeight = ref(0); const capsuleHeight = ref(0);
const isLoading = ref(false);
const showGlobalHint = (type) => { const showGlobalHint = (type) => {
hintType.value = type; hintType.value = type;
showHint.value = true; showHint.value = true;
}; };
const hideGlobalHint = () => { const hideGlobalHint = () => {
showHint.value = false; showHint.value = false;
}; };
onMounted(() => { onMounted(() => {
const menuBtnInfo = uni.getMenuButtonBoundingClientRect(); const menuBtnInfo = uni.getMenuButtonBoundingClientRect();
capsuleHeight.value = menuBtnInfo.top - 9; capsuleHeight.value = menuBtnInfo.top - 9;
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
// const pages = getCurrentPages(); // const pages = getCurrentPages();
// const currentPage = pages[pages.length - 1]; // const currentPage = pages[pages.length - 1];
// uni.setStorageSync("last-route", currentPage.route); // uni.setStorageSync("last-route", currentPage.route);
}); });
onShow(() => { onShow(() => {
uni.$showHint = showGlobalHint; uni.$showHint = showGlobalHint;
uni.$hideHint = hideGlobalHint; uni.$hideHint = hideGlobalHint;
showHint.value = false; showHint.value = false;
}); });
const backToGame = debounce(async () => { 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 = () => { const goBack = () => {
uni.navigateBack(); uni.navigateBack();
}; };
@@ -100,7 +145,13 @@ const goBack = () => {
<button hover-class="none" @click="() => (showHint = false)"> <button hover-class="none" @click="() => (showHint = false)">
不进入 不进入
</button> </button>
<button hover-class="none" @click="backToGame">进入</button> <button
hover-class="none"
@click="backToGame"
:disabled="isLoading"
>
{{ isLoading ? '加载中...' : '进入' }}
</button>
</view> </view>
</view> </view>
<view v-if="hintType === 2" class="tip-content"> <view v-if="hintType === 2" class="tip-content">
@@ -168,4 +219,10 @@ const goBack = () => {
background-color: #fed847; background-color: #fed847;
color: #000; color: #000;
} }
.tip-content > view > button:disabled {
background-color: #ccc;
color: #666;
opacity: 0.6;
}
</style> </style>

View File

@@ -37,7 +37,6 @@ onMounted(() => {
pointBook.value = uni.getStorageSync("point-book"); pointBook.value = uni.getStorageSync("point-book");
} }
if ( if (
currentPage.route === "pages/battle-room" ||
currentPage.route === "pages/team-battle" || currentPage.route === "pages/team-battle" ||
currentPage.route === "pages/melee-match" currentPage.route === "pages/melee-match"
) { ) {

View File

@@ -29,7 +29,6 @@ watch(
if (!sound.value) return; if (!sound.value) return;
if (currentRoundEnded.value) { if (currentRoundEnded.value) {
currentRound.value += 1; currentRound.value += 1;
console.log(11111, currentRound.value);
// 播放当前轮次语音 // 播放当前轮次语音
audioManager.play( audioManager.play(
`${["一", "二", "三", "四", "五"][currentRound.value - 1]}` `${["一", "二", "三", "四", "五"][currentRound.value - 1]}`
@@ -38,10 +37,7 @@ watch(
// 延迟播放队伍提示音 // 延迟播放队伍提示音
setTimeout( setTimeout(
() => { () => {
if (key) { if (key && !yourTurn.value) audioManager.play(key);
if (!yourTurn.value) audioManager.play(key);
else audioManager.play("轮到你了");
}
currentRoundEnded.value = false; currentRoundEnded.value = false;
yourTurn.value = false; yourTurn.value = false;
}, },
@@ -103,6 +99,7 @@ async function onReceiveMessage(messages = []) {
totalShot.value = 0; totalShot.value = 0;
audioManager.play("决金箭轮"); audioManager.play("决金箭轮");
tips.value = "即将开始..."; tips.value = "即将开始...";
currentRoundEnded.value = false;
} else if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) { } else if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
ended.value = true; ended.value = true;
} else if (msg.constructor === MESSAGETYPES.MatchOver) { } else if (msg.constructor === MESSAGETYPES.MatchOver) {

View File

@@ -44,6 +44,7 @@ onLoad(async (options) => {
data.value.myTeam = result.bluePlayers[myId].team; data.value.myTeam = result.bluePlayers[myId].team;
ifWin.value = result.winner === 1; ifWin.value = result.winner === 1;
} }
audioManager.play(ifWin.value ? "胜利" : "失败");
} }
if (result.mode === 2) { if (result.mode === 2) {
data.value.playerStats = result.players.map((p) => ({ data.value.playerStats = result.players.map((p) => ({
@@ -53,6 +54,9 @@ onLoad(async (options) => {
const mine = result.players.find((p) => p.playerId === myId); const mine = result.players.find((p) => p.playerId === myId);
if (mine) totalPoints.value = mine.totalScore; if (mine) totalPoints.value = mine.totalScore;
rank.value = result.players.findIndex((p) => p.playerId === myId) + 1; rank.value = result.players.findIndex((p) => p.playerId === myId) + 1;
if (rank.value > result.players.length * 0.3) {
audioManager.play("胜利");
}
} }
} else { } else {
const battleInfo = uni.getStorageSync("last-battle"); const battleInfo = uni.getStorageSync("last-battle");
@@ -77,10 +81,16 @@ onLoad(async (options) => {
if (mine) { if (mine) {
data.value.myTeam = mine.team; data.value.myTeam = mine.team;
totalPoints.value = mine.totalScore; totalPoints.value = mine.totalScore;
ifWin.value = battleInfo.mode === 1 && mine.team === battleInfo.winner; if (battleInfo.mode === 1) {
} ifWin.value = mine.team === battleInfo.winner;
}
audioManager.play(ifWin.value ? "胜利" : "失败"); audioManager.play(ifWin.value ? "胜利" : "失败");
} else {
if (rank.value > battleInfo.playerStats.length * 0.3) {
audioManager.play("胜利");
}
}
}
}
}); });
const checkBowData = () => { const checkBowData = () => {

View File

@@ -58,18 +58,25 @@ const toRankListPage = () => {
}; };
onShow(async () => { onShow(async () => {
const rankList = await getRankListAPI();
console.log("排行数据", rankList);
updateRank(rankList);
const token = uni.getStorageSync( const token = uni.getStorageSync(
`${uni.getAccountInfoSync().miniProgram.envVersion}_token` `${uni.getAccountInfoSync().miniProgram.envVersion}_token`
); );
const promises = [getRankListAPI()];
if (token) { if (token) {
const result = await getHomeData(); promises.push(getHomeData());
console.log("首页数据:", result); }
if (result.user) {
updateUser(result.user); const [rankList, homeData] = await Promise.all(promises);
if (result.user.trio <= 0) {
console.log("排行数据", rankList);
updateRank(rankList);
if (homeData) {
console.log("首页数据:", homeData);
if (homeData.user) {
updateUser(homeData.user);
if (homeData.user.trio <= 0) {
showGuide.value = true; showGuide.value = true;
setTimeout(() => { setTimeout(() => {
showGuide.value = false; showGuide.value = false;

View File

@@ -168,7 +168,7 @@ const checkBowData = () => {
borderColor: '#FF6767', borderColor: '#FF6767',
transform: `translateX(-${index * 15}px)`, transform: `translateX(-${index * 15}px)`,
}" }"
:src="src" :src="src || '../static/user-icon.png'"
:key="index" :key="index"
mode="widthFix" mode="widthFix"
/> />
@@ -210,7 +210,7 @@ const checkBowData = () => {
borderColor: '#64BAFF', borderColor: '#64BAFF',
transform: `translateX(-${index * 15}px)`, transform: `translateX(-${index * 15}px)`,
}" }"
:src="src" :src="src || '../static/user-icon.png'"
:key="index" :key="index"
mode="widthFix" mode="widthFix"
/> />

View File

@@ -16,6 +16,7 @@ import ShootProgress2 from "@/components/ShootProgress2.vue";
import { getCurrentGameAPI } from "@/apis"; import { getCurrentGameAPI } from "@/apis";
import { isGameEnded } from "@/util"; import { isGameEnded } from "@/util";
import { MESSAGETYPES, roundsName } from "@/constants"; import { MESSAGETYPES, roundsName } from "@/constants";
import audioManager from "@/audioManager";
import useStore from "@/store"; import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
const store = useStore(); const store = useStore();
@@ -182,6 +183,7 @@ async function onReceiveMessage(messages = []) {
const redPlayer = redTeam.value.find( const redPlayer = redTeam.value.find(
(item) => item.id === currentShooterId.value (item) => item.id === currentShooterId.value
); );
if (msg.userId === user.value.id) audioManager.play("轮到你了");
const nextTips = redPlayer ? "请红队射箭" : "请蓝队射箭"; const nextTips = redPlayer ? "请红队射箭" : "请蓝队射箭";
if (nextTips !== tips.value) { if (nextTips !== tips.value) {
tips.value = nextTips; tips.value = nextTips;