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

View File

@@ -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>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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