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

@@ -57,7 +57,6 @@ const signin = () => {
const loading = ref(false);
const pointBook = ref(null);
const showProgress = ref(false);
const heat = ref(0);
/** 房间号按钮动态定位样式position: fixed根据胶囊真实位置计算脱离 flex 流避免挤压标题) */
const battleRoomBtnStyle = ref({});
@@ -82,9 +81,6 @@ onMounted(() => {
pointBook.value = uni.getStorageSync("last-point-book");
}
}
if (currentPage.route === "pages/team-battle") {
showProgress.value = true;
}
// 仅在对战房间页获取胶囊位置,按钮用 fixed 定位精确贴靠胶囊左侧(脱离 flex 流,不挤压标题)
if (currentPage.route === "pages/battle-room") {
try {
@@ -189,7 +185,7 @@ onBeforeUnmount(() => {
}}</text
>
</view>
<view v-if="showProgress" class="battle-progress">
<view v-if="currentPage === 'pages/team-battle'" class="battle-progress">
<HeaderProgress />
</view>
<!-- 对战房间:整个胶囊为分享按钮,房号从 Store 读取fixed 定位紧靠系统胶囊左侧 -->

View File

@@ -33,8 +33,8 @@ watch(
newVal.includes("你")
? "轮到你了"
: newVal.includes("红队")
? "请红方射箭"
: "请蓝方射箭"
? "请红方射箭"
: "请蓝方射箭"
);
audioManager.play(key, false);
currentRoundEnded.value = false;
@@ -93,20 +93,22 @@ const onUpdateTips = (newVal) => {
tips.value = newVal;
};
const onUpdateTotalShot = (newVal) => {
currentShot.value = newVal.currentShot;
totalShot.value = newVal.totalShot;
};
// 监听 Pinia store 中 totalShot 变化,用于比赛恢复时同步箭数(替代 uni.$emit 避免时序问题)
// 使用 immediate: true 确保组件创建时立即读取 store 当前值(解决重入时 totalShot 值不变 watch 不触发的问题)
watch(() => store.game.totalShot, (newVal) => {
if (newVal > 0) {
totalShot.value = newVal;
currentShot.value = store.game.currentShot;
}
}, { immediate: true });
onMounted(() => {
uni.$on("update-shot", onUpdateTotalShot);
uni.$on("update-tips", onUpdateTips);
uni.$on("socket-inbox", onReceiveMessage);
uni.$on("play-sound", playSound);
});
onBeforeUnmount(() => {
uni.$off("update-shot", onUpdateTotalShot);
uni.$off("socket-inbox", onReceiveMessage);
uni.$off("play-sound", playSound);
if (timer.value) clearInterval(timer.value);
@@ -118,10 +120,7 @@ onBeforeUnmount(() => {
<text>{{ (tips || "").replace(/你/g, "").replace(/重回/g, "") }}</text>
<text v-if="totalShot > 0"> ({{ currentShot }}/{{ totalShot }}) </text>
<button v-if="!!tips" hover-class="none" @click="updateSound">
<image
:src="`../static/sound${sound ? '' : '-off'}-yellow.png`"
mode="widthFix"
/>
<image :src="`../static/sound${sound ? '' : '-off'}-yellow.png`" mode="widthFix" />
</button>
</view>
</template>
@@ -135,11 +134,13 @@ onBeforeUnmount(() => {
justify-content: center;
font-weight: 500;
}
.container > button:last-child {
.container>button:last-child {
width: 36px;
height: 36px;
}
.container > button:last-child > image {
.container>button:last-child>image {
width: 36px;
min-height: 36px;
}