fix:动态修改比赛时间

This commit is contained in:
2026-05-13 18:31:51 +08:00
parent c168a909db
commit 34a32b108c
3 changed files with 14 additions and 9 deletions

View File

@@ -6,8 +6,8 @@ try {
switch (envVersion) {
case "develop": // 开发版
// BASE_URL = "http://localhost:8000/api/shoot";
BASE_URL = "https://apitest.shelingxingqiu.com/api/shoot";
BASE_URL = "http://192.168.1.30:8000/api/shoot";
// BASE_URL = "https://apitest.shelingxingqiu.com/api/shoot";
break;
case "trial": // 体验版
BASE_URL = "https://apitest.shelingxingqiu.com/api/shoot";

View File

@@ -41,6 +41,8 @@ const showRoundTip = ref(false);
const isFinalShoot = ref(false);
const matchStatus = ref(undefined);
const updateRemainSecond = ref(0);
/** 当前对局每人射击时间(秒),从后端 shootTime 字段动态读取,默认 15 */
const shootTimeTotal = ref(15);
/** 对战来源类型1=好友约战2=匹配对战),用于结算页分流 */
const battleWay = ref(0);
/** 上一次处理的 ToSomeoneShoot 关键字段,用于去重过滤重复消息 */
@@ -123,6 +125,8 @@ const recoverData = (battleInfo, {force = false, arrowOnly = false} = {}) => {
}
// redPlayer 已在上方 find() 确认:不为 null 则当前射手在红队
const targetTeam = redPlayer ? 'red' : 'blue';
// 从后端消息读取本局射击时间,动态设置进度条满值与倒计时秒数(降级兜底 15s
shootTimeTotal.value = battleInfo.shootTime ?? 15;
if (force) {
// force 模式下 start.value 刚由 null 变 trueVue 异步调度渲染,
// ShootProgress2v-if="start"尚未挂载update-remain 事件会被丢弃。
@@ -130,14 +134,14 @@ const recoverData = (battleInfo, {force = false, arrowOnly = false} = {}) => {
// onAudioEnded 驱动,需在 nextTick 后直接启动。
const elapsed = (Date.now() - battleInfo.current.startTime) / 1000;
console.log(`当前轮已进行${elapsed}`);
if (elapsed > 0 && elapsed < 15) {
updateRemainSecond.value = 15 - elapsed - 0.2;
if (elapsed > 0 && elapsed < shootTimeTotal.value) {
updateRemainSecond.value = shootTimeTotal.value - elapsed - 0.2;
}
const actualRemain = updateRemainSecond.value;
nextTick(() => {
// 在 nextTick 内统一发送,确保 ShootProgress2 和 HeaderProgress 均已挂载
uni.$emit("update-tips", nextTips);
uni.$emit("update-remain", {reset: true, value: 15, team: targetTeam});
uni.$emit("update-remain", {reset: true, value: shootTimeTotal.value, team: targetTeam});
// 重置动画完成后,直接启动倒计时(无需依赖音频结束回调)
setTimeout(() => {
uni.$emit("update-remain", {stop: false, value: actualRemain, team: targetTeam});
@@ -145,8 +149,8 @@ const recoverData = (battleInfo, {force = false, arrowOnly = false} = {}) => {
});
} else {
// ToSomeoneShoot 到达时:若进度条仍在倒计时则瞬间清零再切换满值,确保视觉连贯
uni.$emit("update-remain", {zeroThenReset: true, value: 15, team: targetTeam});
updateRemainSecond.value = battleInfo.readyTime;
uni.$emit("update-remain", {zeroThenReset: true, value: shootTimeTotal.value, team: targetTeam});
updateRemainSecond.value = shootTimeTotal.value;
}
} else {
currentRound.value = battleInfo.current.round || 1;
@@ -324,6 +328,7 @@ onShow(async () => {
/>
<ShootProgress2
:tips="tips"
:total="shootTimeTotal"
:currentRound="
goldenRound > 0 ? 'gold' + goldenRound : 'round' + currentRound
"

View File

@@ -14,8 +14,8 @@ function createWebSocket(token, onMessage) {
switch (envVersion) {
case "develop": // 开发版
// url = "ws://localhost:8000/socket";
url = "wss://apitest.shelingxingqiu.com/socket";
url = "ws://192.168.1.30:8000/socket";
// url = "wss://apitest.shelingxingqiu.com/socket";
break;
case "trial": // 体验版
url = "wss://apitest.shelingxingqiu.com/socket";