fix:优化重新进入比赛页面箭数展示逻辑

This commit is contained in:
2026-05-13 10:10:38 +08:00
parent 47fe964c31
commit 996472953a
4 changed files with 35 additions and 23 deletions

View File

@@ -176,7 +176,7 @@ function onNewRound(msg, prevRound) {
isFinalShoot.value = msg.current.goldRound;
// 决金箭轮每人只射一箭,重置箭数显示为 (0/1)
if (msg.current.goldRound) {
uni.$emit("update-shot", { currentShot: 0, totalShot: 1 });
store.updateShotInfo(0, 1);
}
// 用传入的 prevRound捕获时刻的旧轮次展示结算 Tip与进度条 currentRound 解耦
roundTipRound.value = prevRound;
@@ -228,6 +228,8 @@ async function onReceiveMessage(msg) {
onLoad(async (options) => {
if (options.battleId) battleId.value = options.battleId;
// 重置箭数,防止因 Pinia 保留上一场比赛的旧值而错误展示
store.updateShotInfo(0, 0);
// uni.enableAlertBeforeUnload({
// message: "离开比赛可能导致比赛失败,是否继续?",
// success: (res) => {
@@ -263,9 +265,15 @@ onShow(async () => {
url: `/pages/friend-battle-result?battleId=${result.matchId}`,
});
} else {
// shootNumber 来自后端,恢复状态时同步 totalShot防止 BattleStart 不重新推送导致显示错误
if (result.shootNumber) {
uni.$emit("update-shot", { currentShot: 0, totalShot: result.shootNumber });
if (result.status !== 0) {
// 比赛进行中,从后端恢复箭数(测距阶段不展示)
if (result.shootNumber) {
// current.index 为 0 基的当前箭序号0=第一箭),+1 后作为 currentShot 展示
store.updateShotInfo((result.current?.index ?? 0) + 1, result.shootNumber);
}
} else {
// 测距阶段重置箭数,防止 ImmediateWatcher 读取 Pinia 保留的旧值
store.updateShotInfo(0, 0);
}
recoverData(result, {force: true});
}