17 Commits
Author SHA1 Message Date
zhangyi 88febb92e5 update:更换语音 2026-09-15 15:44:14 +08:00
zhangyi c8533de5cf update:优化测距展示 2026-09-03 10:35:16 +08:00
zhangyi 74bfd7a327 update:优化赏金赛记录 2026-08-31 16:14:57 +08:00
zhangyi bbfa35e871 update:优化个人训练 2026-08-28 11:12:28 +08:00
zhangyi 469487ba73 update:优化新手教程 2026-08-27 17:24:25 +08:00
zhangyi b9bbaba77f update:优化新版个人训练 2026-08-26 17:23:36 +08:00
zhangyi 11eeb98b74 update:图片更新 2026-08-26 15:36:45 +08:00
zhangyi 96b64e4187 update:新增稳定训练 2026-08-26 15:23:02 +08:00
zhangyi 45bc324f70 update:优化节奏训练结算 2026-08-25 18:00:14 +08:00
zhangyi 2eba5f87d7 update:优化记录 2026-08-25 17:49:44 +08:00
zhangyi 9a06dcf942 update:对接节奏训练 2026-08-25 17:36:54 +08:00
zhangyi 35e0ee3ca0 update:优化节奏训练 2026-08-24 16:35:56 +08:00
zhangyi 59fa317c5a update: 优化个人训练 2026-08-21 15:38:01 +08:00
zhangyi 09756ae165 Merge branch 'feat-scene' into test 2026-08-20 18:09:06 +08:00
zhangyi b89c003313 update: 新增回到首页按钮 2026-08-20 18:08:49 +08:00
zhangyi 9dda58b19c Merge branch 'feat-yuyin' into test 2026-08-20 17:57:33 +08:00
zhangyi 962596e510 update:优化精准射箭语音 2026-08-20 17:57:22 +08:00
42 changed files with 1755 additions and 279 deletions
+3 -1
View File
@@ -376,9 +376,11 @@ export const readyGameAPI = (battleId) => {
});
};
export const simulShootAPI = (device_id, x, y) => {
export const simulShootAPI = (device_id, x, y, targetType = 40) => {
const data = {
device_id,
// 模拟射箭仅支持 20cm、40cm 靶纸,未传或传入无效值时默认使用 40cm。
targetType: Number(targetType) === 20 ? 20 : 40,
};
if (x !== undefined && y !== undefined) {
data.x = x;
+44 -2
View File
@@ -1,10 +1,18 @@
export const AUDIO_INTERRUPTION_BEGIN_EVENT = "audio-interruption-begin";
export const AUDIO_INTERRUPTION_END_EVENT = "audio-interruption-end";
export const RHYTHM_SHOOT_WINDOW_AUDIO_KEY = "请射箭";
export const STABILITY_START_AUDIO_KEY =
"请在计时结束前能量条达到百分百";
export const STABILITY_ENERGY_50_AUDIO_KEY = "加油!到达50%啦";
export const STABILITY_ENERGY_70_AUDIO_KEY =
"70%啦!还差一点,胜利就在眼前";
const TRAINING_START_AUDIO_KEY_MAP = Object.freeze({
base: "请于计时前完成指定环数对应箭量",
endurance: "请于计时前完成累计环数和箭量",
precision: "请射箭命中高亮区域",
rhythm: "请在读条推进到标记区间内射箭",
stability: "请在计时结束前能量条达到百分百",
});
export const getTrainingStartAudioKey = (trainingType, fallback = "") =>
@@ -23,10 +31,30 @@ export const getPrecisionShotAudioKeys = (shootData, directionText = "") => {
return ["未上靶", directionAudioKey].filter(Boolean);
}
const ringAudioKey = shootData.ringX === true ? "X环" : `${ring}环`;
// protobuf 的 false 可能不编码;只要不是明确命中,本箭就反馈未命中。
const hitAudioKey = shootData.ok === true ? "Bingo命中目标" : "未命中";
return [ringAudioKey, directionAudioKey, hitAudioKey].filter(Boolean);
return [directionAudioKey, hitAudioKey].filter(Boolean);
};
export const getRhythmShotAudioKeys = (shootData) => {
if (!shootData || typeof shootData !== "object") return [];
const ring = Number(shootData.ring);
const ringAudioKey =
Number.isFinite(ring) && ring > 0
? `${shootData.ringX ? "X" : ring}环`
: "未上靶";
// 节奏训练是否达标完全由服务端 ok 字段决定,前端不根据环数复算。
return [ringAudioKey, shootData.ok === true ? "Perfect" : "miss"];
};
export const getStabilityShotAudioKeys = (shootData) => {
if (!shootData || typeof shootData !== "object") return [];
const ring = Number(shootData.ring);
const ringAudioKey =
Number.isFinite(ring) && ring > 0
? `${shootData.ringX ? "X" : ring}环`
: "未上靶";
return [ringAudioKey];
};
export const audioFils = {
@@ -147,12 +175,26 @@ export const audioFils = {
"https://static.shelingxingqiu.com/attachment/2025-11-13/de7kzzllq0futwynso.mp3",
练习开始:
"https://static.shelingxingqiu.com/attachment/2025-11-14/de88w0lmmt43nnfmoi.mp3",
[STABILITY_START_AUDIO_KEY]:
"https://static.shelingxingqiu.com/shootaudio/%E8%AF%B7%E5%9C%A8%E8%AE%A1%E6%97%B6%E7%BB%93%E6%9D%9F%E5%89%8D%E8%83%BD%E9%87%8F%E6%9D%A1%E8%BE%BE%E5%88%B0%E7%99%BE%E5%88%86%E7%99%BE.MP3",
[STABILITY_ENERGY_50_AUDIO_KEY]:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/%E5%8A%A0%E6%B2%B9%EF%BC%81%E5%88%B0%E8%BE%BE50%25%E5%95%A6.MP3",
[STABILITY_ENERGY_70_AUDIO_KEY]:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/70%25%E5%95%A6%EF%BC%81%E8%BF%98%E5%B7%AE%E4%B8%80%E7%82%B9%EF%BC%8C%E8%83%9C%E5%88%A9%E5%B0%B1%E5%9C%A8%E7%9C%BC%E5%89%8D.MP3",
请于计时前完成指定环数对应箭量:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/%E8%AF%B7%E4%BA%8E%E8%AE%A1%E6%97%B6%E5%89%8D%E5%AE%8C%E6%88%90%E6%8C%87%E5%AE%9A%E7%8E%AF%E6%95%B0%E5%AF%B9%E5%BA%94%E7%AE%AD%E9%87%8F.MP3",
请于计时前完成累计环数和箭量:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/%E8%AF%B7%E4%BA%8E%E8%AE%A1%E6%97%B6%E5%89%8D%E5%AE%8C%E6%88%90%E7%B4%AF%E8%AE%A1%E7%8E%AF%E6%95%B0%E5%92%8C%E7%AE%AD%E9%87%8F.MP3",
请射箭命中高亮区域:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/%E8%AF%B7%E5%B0%84%E7%AE%AD%E5%91%BD%E4%B8%AD%E9%AB%98%E4%BA%AE%E5%8C%BA%E5%9F%9F.MP3",
请在读条推进到标记区间内射箭:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/%E8%AF%B7%E5%9C%A8%E8%AF%BB%E6%9D%A1%E6%8E%A8%E8%BF%9B%E5%88%B0%E6%A0%87%E8%AE%B0%E5%8C%BA%E9%97%B4%E5%86%85%E5%B0%84%E7%AE%AD.MP3",
[RHYTHM_SHOOT_WINDOW_AUDIO_KEY]:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/%E8%AF%B7%E5%B0%84%E7%AE%AD.MP3",
Perfect:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/Perfect.MP3",
miss:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/miss.MP3",
Bingo命中目标:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/Bingo%E5%91%BD%E4%B8%AD%E7%9B%AE%E6%A0%87.MP3",
未命中:
+13 -2
View File
@@ -51,6 +51,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
targetType: {
type: [Number, String],
default: 40,
},
targetRadius: {
type: Number,
default: 20,
@@ -426,12 +430,19 @@ function getExperienceTipStyle(shot) {
);
}
const simulShoot = async () => {
if (device.value.deviceId) await simulShootAPI(device.value.deviceId);
if (device.value.deviceId) {
await simulShootAPI(
device.value.deviceId,
undefined,
undefined,
props.targetType
);
}
};
const simulShoot2 = async () => {
if (device.value.deviceId) {
const r1 = Math.random() > 0.5 ? 0.01 : 0.02;
await simulShootAPI(device.value.deviceId, r1, r1);
await simulShootAPI(device.value.deviceId, r1, r1, props.targetType);
}
};
+56 -4
View File
@@ -6,11 +6,16 @@ import Avatar from "@/components/Avatar.vue";
import audioManager from "@/audioManager";
import { simulShootAPI } from "@/apis";
import { MESSAGETYPESV2 } from "@/constants";
import { getDistanceCheckAudioKey, getDistanceCheckText } from "@/util";
import {
getDistanceCheckAudioKey,
getDistanceCheckText,
getShootValidation,
} from "@/util";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user, device } = storeToRefs(store);
const emit = defineEmits(["passed"]);
const props = defineProps({
guide: {
type: Boolean,
@@ -24,6 +29,14 @@ const props = defineProps({
type: Number,
default: 15,
},
targetType: {
type: [Number, String],
default: 40,
},
autoStart: {
type: Boolean,
default: false,
},
});
const arrow = ref({});
const distance = ref(0);
@@ -31,6 +44,29 @@ const statusText = ref("");
const showsimul = ref(false);
const count = ref(props.count);
const timer = ref(null);
const autoStartPending = ref(false);
const autoStartTriggered = ref(false);
let autoStartTimer = null;
const DISTANCE_PASSED_AUDIO_KEY = "站距合格,靶纸正确";
const AUTO_START_TIMEOUT_MS = 6000;
const clearAutoStartTimer = () => {
if (!autoStartTimer) return;
clearTimeout(autoStartTimer);
autoStartTimer = null;
};
const triggerAutoStart = () => {
if (!autoStartPending.value || autoStartTriggered.value) return;
clearAutoStartTimer();
autoStartPending.value = false;
autoStartTriggered.value = true;
emit("passed");
};
const onAudioEnded = (key) => {
if (key === DISTANCE_PASSED_AUDIO_KEY) triggerAutoStart();
};
const updateTimer = (value) => {
count.value = Math.round(value);
@@ -44,26 +80,43 @@ onMounted(() => {
}, 1000);
}
uni.$on("update-timer", updateTimer);
uni.$on("audioEnded", onAudioEnded);
});
onBeforeUnmount(() => {
if (timer.value) clearInterval(timer.value);
clearAutoStartTimer();
uni.$off("update-timer", updateTimer);
uni.$off("audioEnded", onAudioEnded);
});
async function onReceiveMessage(msg) {
if (Array.isArray(msg)) return;
if (msg.type === MESSAGETYPESV2.TestDistance) {
if (autoStartPending.value || autoStartTriggered.value) return;
const rawDistance = Number(msg.shootData?.distance ?? msg.shootData?.dst);
distance.value = Number.isFinite(rawDistance)
? Number((rawDistance / 100).toFixed(2))
: 0;
statusText.value = getDistanceCheckText(msg.shootData);
audioManager.play(getDistanceCheckAudioKey(msg.shootData));
const audioKey = getDistanceCheckAudioKey(msg.shootData);
const validation = getShootValidation(msg.shootData);
if (props.autoStart && validation.distanceOk && validation.targetOk) {
autoStartPending.value = true;
autoStartTimer = setTimeout(triggerAutoStart, AUTO_START_TIMEOUT_MS);
}
audioManager.play(audioKey);
}
}
const simulShoot = async () => {
if (device.value.deviceId) await simulShootAPI(device.value.deviceId);
if (device.value.deviceId) {
await simulShootAPI(
device.value.deviceId,
undefined,
undefined,
props.targetType
);
}
};
onMounted(() => {
@@ -102,7 +155,6 @@ onBeforeUnmount(() => {
</button>
<view class="warnning-text">
<block v-if="statusText">
<text v-if="distance > 0">当前距离{{ distance }}米</text>
<text>{{ statusText }}</text>
</block>
<block v-else>
+9 -2
View File
@@ -24,13 +24,20 @@ const props = defineProps({
const getDisplayText = (arrow = {}) => {
if (!arrow) return "";
if (!arrow.ring) return "0";
if (!arrow.ring) return props.trainingType === "stability" ? "-" : "0";
return arrow.ringX ? "X" : String(arrow.ring);
};
const isFailed = (arrow = {}) => {
if (!arrow) return false;
if (props.recordMode && props.trainingType !== "precision") return false;
if (
props.recordMode &&
props.trainingType !== "precision" &&
props.trainingType !== "rhythm" &&
props.trainingType !== "stability"
) {
return false;
}
return arrow.ok !== true;
};
+210 -5
View File
@@ -16,7 +16,11 @@ import {
} from "@/util";
import {
getPrecisionShotAudioKeys,
getRhythmShotAudioKeys,
getStabilityShotAudioKeys,
getTrainingStartAudioKey,
STABILITY_ENERGY_50_AUDIO_KEY,
STABILITY_ENERGY_70_AUDIO_KEY,
} from "@/audioManager";
import {
normalizeId,
@@ -219,6 +223,13 @@ function buildPracticeSyncMessage(message) {
if (currentContext && practiceInfo.trainingType) {
currentContext.trainingType = String(practiceInfo.trainingType).trim();
}
updateStabilityEnergyContext(practiceInfo, {
fullSnapshot: true,
detectCrossing: false,
});
updateStabilityShotContext(practiceInfo, {
detectShot: false,
});
const matchId = normalizeId(
pickField(message, "matchId", "match_id") ||
practiceInfo.id ||
@@ -377,12 +388,171 @@ function getShootResultAudioKeys(shootData) {
return keys;
}
function normalizeScoreSlot(value) {
const scoreSlot = Number(value);
return Number.isFinite(scoreSlot) && scoreSlot > 0 ? scoreSlot : 0;
}
function clampEnergy(value, scoreSlot = 0) {
const energy = Number(value);
if (!Number.isFinite(energy)) return 0;
const maxEnergy = normalizeScoreSlot(scoreSlot);
return maxEnergy > 0
? Math.min(maxEnergy, Math.max(0, energy))
: Math.max(0, energy);
}
function getEnergyPercent(energy, scoreSlot) {
const maxEnergy = normalizeScoreSlot(scoreSlot);
if (!maxEnergy) return 0;
return Math.min(100, (clampEnergy(energy, maxEnergy) / maxEnergy) * 100);
}
function getStabilityArrowCount(source = {}) {
const candidates = [
Array.isArray(source.details) ? source.details.length : NaN,
Number(source.currentArrows),
Number(source.totalArrows),
].filter((value) => Number.isFinite(value) && value >= 0);
return candidates.length > 0 ? Math.max(...candidates) : null;
}
function updateStabilityShotContext(
source = {},
{ detectShot = false } = {}
) {
const trainingType = String(
source.trainingType || currentContext?.trainingType || ""
).trim();
if (trainingType !== "stability" || !currentContext) return false;
const nextArrowCount = getStabilityArrowCount(source);
if (nextArrowCount === null) return false;
const storedArrowCount = Number(currentContext.stabilityArrowCount);
const previousArrowCount = Number.isFinite(storedArrowCount)
? storedArrowCount
: 0;
const hasNewShot =
detectShot && nextArrowCount > previousArrowCount;
if (nextArrowCount >= previousArrowCount) {
currentContext.stabilityArrowCount = nextArrowCount;
}
return hasNewShot;
}
// 稳定训练的阈值语音必须和 ACK 使用同一份判定结果,避免页面播放了
// 里程碑语音但比赛服提前收到 ACK。能量跌破阈值后再次向上跨越可重复触发。
function updateStabilityEnergyContext(
source = {},
{ fullSnapshot = false, detectCrossing = false } = {}
) {
const trainingType = String(
source.trainingType || currentContext?.trainingType || ""
).trim();
if (trainingType !== "stability" || !currentContext) return "";
const hasCurrentEnergy = Object.prototype.hasOwnProperty.call(
source,
"currentEnergy"
);
if (!hasCurrentEnergy && !fullSnapshot) return "";
const previousScoreSlot = normalizeScoreSlot(
currentContext.stabilityScoreSlot
);
const nextScoreSlot =
normalizeScoreSlot(source.scoreSlot) || previousScoreSlot;
const previousEnergy = clampEnergy(
currentContext.stabilityEnergy,
previousScoreSlot
);
const nextEnergy = clampEnergy(
hasCurrentEnergy ? source.currentEnergy : 0,
nextScoreSlot
);
const previousPercent = getEnergyPercent(
previousEnergy,
previousScoreSlot || nextScoreSlot
);
const nextPercent = getEnergyPercent(nextEnergy, nextScoreSlot);
currentContext.stabilityEnergy = nextEnergy;
currentContext.stabilityScoreSlot = nextScoreSlot;
if (!detectCrossing) {
currentContext.stabilityEnergy50Armed = nextPercent < 50;
currentContext.stabilityEnergy70Armed = nextPercent < 70;
return "";
}
let energy50Armed =
typeof currentContext.stabilityEnergy50Armed === "boolean"
? currentContext.stabilityEnergy50Armed
: previousPercent < 50;
let energy70Armed =
typeof currentContext.stabilityEnergy70Armed === "boolean"
? currentContext.stabilityEnergy70Armed
: previousPercent < 70;
if (nextPercent < 50) energy50Armed = true;
if (nextPercent < 70) energy70Armed = true;
let milestoneAudioKey = "";
if (energy70Armed && nextPercent >= 70) {
milestoneAudioKey = STABILITY_ENERGY_70_AUDIO_KEY;
energy70Armed = false;
// 同一次直接跨过两个阈值时只播70%,不能在后续补播50%。
energy50Armed = false;
} else if (energy50Armed && nextPercent >= 50) {
milestoneAudioKey = STABILITY_ENERGY_50_AUDIO_KEY;
energy50Armed = false;
}
currentContext.stabilityEnergy50Armed = energy50Armed;
currentContext.stabilityEnergy70Armed = energy70Armed;
return milestoneAudioKey;
}
function getTestDistanceAudioKeys(shootData) {
if (!shootData) return [];
return [getDistanceCheckAudioKey(shootData)];
}
function attachStabilityAudioContext(message, businessMessage) {
const fullStabilitySnapshot = [
ServerMessageType.SERVER_MSG_MATCH_START,
ServerMessageType.SERVER_MSG_SHOT,
ServerMessageType.SERVER_MSG_MATCH_END,
ServerMessageType.SERVER_MSG_TIMEOUT,
ServerMessageType.SERVER_MSG_PRACTICE_END,
].includes(message.type);
const stabilityMilestoneAudioKey = updateStabilityEnergyContext(
businessMessage,
{
fullSnapshot: fullStabilitySnapshot,
detectCrossing: message.type === ServerMessageType.SERVER_MSG_SHOT,
}
);
const stabilityHasNewShot = updateStabilityShotContext(businessMessage, {
detectShot: message.type === ServerMessageType.SERVER_MSG_SHOT,
});
if (businessMessage && stabilityMilestoneAudioKey) {
businessMessage.stabilityMilestoneAudioKey = stabilityMilestoneAudioKey;
}
if (businessMessage) {
businessMessage.stabilityHasNewShot = stabilityHasNewShot;
}
}
function getAckAudioKeys(message, businessMessage) {
const stabilityMilestoneAudioKey = String(
businessMessage?.stabilityMilestoneAudioKey || ""
).trim();
const stabilityHasNewShot =
businessMessage?.stabilityHasNewShot === true;
switch (message.type) {
case ServerMessageType.SERVER_MSG_MATCH_START:
if (businessMessage?.isSecondHalfStart) return ["下半场开始"];
@@ -405,10 +575,9 @@ function getAckAudioKeys(message, businessMessage) {
) {
return [];
}
if (
(businessMessage?.trainingType || currentContext?.trainingType) ===
"precision"
) {
const trainingType =
businessMessage?.trainingType || currentContext?.trainingType;
if (trainingType === "precision") {
const shootData = businessMessage?.shootData;
const directionText =
shootData?.angle !== null && shootData?.angle !== undefined
@@ -416,6 +585,17 @@ function getAckAudioKeys(message, businessMessage) {
: "";
return getPrecisionShotAudioKeys(shootData, directionText);
}
if (trainingType === "rhythm") {
return getRhythmShotAudioKeys(businessMessage?.shootData);
}
if (trainingType === "stability") {
return [
...(stabilityHasNewShot
? getStabilityShotAudioKeys(businessMessage?.shootData)
: []),
stabilityMilestoneAudioKey,
].filter(Boolean);
}
return getShootResultAudioKeys(businessMessage?.shootData);
case ServerMessageType.SERVER_MSG_MATCH_END:
return ["比赛结束"];
@@ -680,7 +860,9 @@ function sendHeartbeatAck() {
}
function sendPracticeInfoSync() {
if (!socket || !currentContext?.matchId || !currentContext?.userId) return;
if (!socket || !currentContext?.matchId || !currentContext?.userId) {
return false;
}
const clientMessage = {
type: ClientMessageType.CLIENT_MSG_SYNC_PRACTICE_INFO,
@@ -695,6 +877,12 @@ function sendPracticeInfoSync() {
"CLIENT_MSG_SYNC_PRACTICE_INFO",
clientMessage
);
return true;
}
// 训练开始后可在不重连 WebSocket 的情况下主动刷新完整练习快照。
export function requestPracticeInfoSync() {
return sendPracticeInfoSync();
}
function sendAck({ matchId, sequence }) {
@@ -869,6 +1057,8 @@ function handleMessage(data) {
if (businessMessage?.matchId && currentContext) {
currentContext.matchId = businessMessage.matchId;
}
// 阈值事件必须先于 ACK 判断生成,确保无 sequence 的状态推送也能播放。
attachStabilityAudioContext(message, businessMessage);
queueAckAfterAudio(message, businessMessage);
emitBusinessMessage(businessMessage);
}
@@ -980,6 +1170,21 @@ export function connectMatchWebSocket(options = {}) {
trainingType:
normalizedTrainingType ||
(isSameContext ? currentContext?.trainingType || "" : ""),
stabilityEnergy: isSameContext
? currentContext?.stabilityEnergy
: undefined,
stabilityScoreSlot: isSameContext
? currentContext?.stabilityScoreSlot
: undefined,
stabilityEnergy50Armed: isSameContext
? currentContext?.stabilityEnergy50Armed
: undefined,
stabilityEnergy70Armed: isSameContext
? currentContext?.stabilityEnergy70Armed
: undefined,
stabilityArrowCount: isSameContext
? currentContext?.stabilityArrowCount
: undefined,
meleeHalfRest: isSameContext
? currentContext?.meleeHalfRest === true
: false,
+4 -2
View File
@@ -114,7 +114,7 @@ const createPractise = async (arrows) => {
const result = await createPractiseAPI(
arrows,
120,
1,
2,
device.value.deviceId
);
if (result) practiseId.value = result.id;
@@ -384,7 +384,7 @@ const getResultTipSrc = (result = {}) => {
<text>请完成以上步骤校准智能弓</text>
</view>
<ShootProgress v-if="step === 5" tips="请开始连续射箭" :start="start" />
<TestDistance v-if="step === 3" :guide="false" />
<TestDistance v-if="step === 3" :guide="false" :targetType="40" />
<view
class="user-row"
v-if="step === 5"
@@ -399,6 +399,8 @@ const getResultTipSrc = (result = {}) => {
:totalRound="step === 5 ? total : 0"
:scores="scores"
:isSvip="isSvip"
:targetType="40"
stable-shot-effect
/>
<ScorePanel
v-if="step === 5"
+6
View File
@@ -29,6 +29,7 @@ const { user, online } = storeToRefs(store);
const title = ref("");
const start = ref(null);
const battleId = ref("");
const targetType = ref(20);
/** 对战模式:1=好友约战 2=排位赛,用于结算页跳转判断 */
const way = ref(0);
const currentRound = ref(1);
@@ -254,6 +255,8 @@ watch(online, (newVal, oldVal) => {
function recoverData(battleInfo, { force = false } = {}) {
battleInfo = normalizeBattleInfo(battleInfo);
if (!battleInfo) return;
const nextTargetType = Number(battleInfo.targetType ?? battleInfo.target_type);
if ([20, 40].includes(nextTargetType)) targetType.value = nextTargetType;
if (battleInfo.status !== undefined) {
battleEnded = [2, 4].includes(Number(battleInfo.status));
}
@@ -374,6 +377,7 @@ function onMatchSocketState(event) {
}
onLoad(async (options) => {
targetType.value = 20;
const returnSnapshot = options.fromReturn ? takeMatchReturnSnapshot() : null;
skipNextRestoreOnShow = false;
if (returnSnapshot?.matchId) battleId.value = returnSnapshot.matchId;
@@ -468,6 +472,7 @@ onShow(() => {
:guide="false"
:isBattle="true"
:count="readyTime"
:targetType="targetType"
/>
<ShootProgress
:show="start"
@@ -490,6 +495,7 @@ onShow(() => {
:totalRound="12"
:scores="playersScores.map((r) => r[user.id]).flat()"
:isSvip="isCurrentUserSvip"
:targetType="targetType"
:stop="halfRest"
stable-shot-effect
/>
+1 -10
View File
@@ -13,19 +13,10 @@ const { user } = storeToRefs(store);
const arrows = ref([]);
const isSvip = ref(false);
const practiseDetail = ref({});
const trainingTypeNameMap = Object.freeze({
base: "基础训练",
endurance: "耐力训练",
precision: "精准训练",
rhythm: "节奏训练",
});
const trainingType = computed(() =>
String(practiseDetail.value.trainingType || "").trim().toLowerCase()
);
const trainingTypeName = computed(
() => trainingTypeNameMap[trainingType.value] || "自由训练"
);
const targetTypeText = computed(() => {
const targetType = Number(practiseDetail.value.targetType);
return targetType > 0 ? `${targetType}CM靶` : "";
@@ -82,7 +73,7 @@ onLoad(async (options) => {
</view> -->
<view v-if="practiseDetail.id" class="practice-meta">
<text v-if="targetTypeText">{{ targetTypeText }}</text>
<text>{{ trainingTypeName }}</text>
<text>{{ practiseDetail.trainingTypeText }}</text>
<text v-if="difficultyText">{{ difficultyText }}</text>
</view>
<view :style="{ marginBottom: '20px' }">
+1 -12
View File
@@ -15,17 +15,6 @@ const selectedIndex = ref(0);
const matchList = ref([]);
const battleList = ref([]);
const practiseList = ref([]);
const trainingTypeNameMap = Object.freeze({
base: "基础训练",
endurance: "耐力训练",
precision: "精准训练",
rhythm: "节奏训练",
});
const getTrainingTypeName = (trainingType) => {
const normalizedType = String(trainingType || "").trim().toLowerCase();
return trainingTypeNameMap[normalizedType] || "自由训练";
};
const formatPractiseTime = (value) => {
const normalizedTime = String(value || "").trim();
@@ -172,7 +161,7 @@ onLoad((options) => {
@click="() => getPractiseDetail(item.id)"
>
<text
>{{ getTrainingTypeName(item.trainingType) }}
>{{ item.trainingTypeText }}
{{ formatPractiseTime(item.createTime) }}</text
>
<image src="../static/back.png" mode="widthFix" />
+15
View File
@@ -88,6 +88,10 @@ const handleLoginSuccess = async () => {
await bindOrg();
};
const goHome = () => {
uni.reLaunch({ url: "/pages/index" });
};
onLoad((options) => {
try {
const value = decodeURIComponent(String(options?.scene || ""));
@@ -160,6 +164,11 @@ onLoad((options) => {
温馨提示:离开门店时候记得在Pad退出登录哦!
</text>
</view>
<view class="success-action">
<SButton width="600rpx" :rounded="22" :onClick="goHome">
<text>回到首页</text>
</SButton>
</view>
</view>
<view v-else-if="status === 'failed'" class="state message-state">
@@ -231,9 +240,11 @@ onLoad((options) => {
}
.login-title {
width: 600rpx;
margin: 28rpx 0 60rpx;
font-size: 40rpx;
font-weight: 500;
text-align: center;
}
.avatar-wrap {
@@ -275,6 +286,10 @@ onLoad((options) => {
line-height: 40rpx;
}
.success-action {
margin-top: 64rpx;
}
.state-title {
font-size: 38rpx;
font-weight: 600;
+24 -8
View File
@@ -1,5 +1,5 @@
<script setup>
import { ref, nextTick, onMounted, onBeforeUnmount } from "vue";
import { computed, ref, nextTick, onMounted, onBeforeUnmount } from "vue";
import { onHide, onLoad, onShow } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import ShootProgress from "@/components/ShootProgress.vue";
@@ -37,6 +37,7 @@ const store = useStore();
const { user, device } = storeToRefs(store);
const start = ref(false);
const practiceStarting = ref(false);
const scores = ref([]);
const isSvip = ref(false);
const total = 12;
@@ -46,6 +47,9 @@ const serverAddr = ref("");
const showGuide = ref(false);
const tips = ref("");
const targetType = ref(1);
const simulatorTargetType = computed(() =>
[2, 40].includes(Number(targetType.value)) ? 40 : 20
);
const sharing = ref(false);
const exiting = ref(false);
const hiddenWhileActive = ref(false);
@@ -156,12 +160,18 @@ const beginPractise = async () => {
};
const onReady = async () => {
const result = await beginPractise();
if (!result) return;
scores.value = [];
isSvip.value = false;
start.value = true;
audioManager.play("练习开始");
if (practiceStarting.value || start.value) return;
practiceStarting.value = true;
try {
const result = await beginPractise();
if (!result) return;
scores.value = [];
isSvip.value = false;
start.value = true;
audioManager.play("练习开始");
} finally {
practiceStarting.value = false;
}
};
const onOver = async (message) => {
@@ -438,7 +448,12 @@ onBeforeUnmount(() => {
:onBack="exitPractise"
>
<view>
<TestDistance v-if="!start && !practiseResult.id" />
<TestDistance
v-if="!start && !practiseResult.id"
:targetType="simulatorTargetType"
:autoStart="true"
@passed="onReady"
/>
<block v-else>
<ShootProgress
:tips="`${
@@ -466,6 +481,7 @@ onBeforeUnmount(() => {
:currentRound="scores.length % 3"
:scores="scores"
:isSvip="isSvip"
:targetType="simulatorTargetType"
stable-shot-effect
/>
<ScorePanel2 :arrows="scores" />
+24 -8
View File
@@ -1,5 +1,5 @@
<script setup>
import { ref, nextTick, onMounted, onBeforeUnmount } from "vue";
import { computed, ref, nextTick, onMounted, onBeforeUnmount } from "vue";
import { onHide, onLoad, onShow } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import ShootProgress from "@/components/ShootProgress.vue";
@@ -37,6 +37,7 @@ const store = useStore();
const { user, device } = storeToRefs(store);
const start = ref(false);
const practiceStarting = ref(false);
const scores = ref([]);
const isSvip = ref(false);
const total = 36;
@@ -45,6 +46,9 @@ const practiseId = ref("");
const serverAddr = ref("");
const showGuide = ref(false);
const targetType = ref(1);
const simulatorTargetType = computed(() =>
[2, 40].includes(Number(targetType.value)) ? 40 : 20
);
const sharing = ref(false);
const exiting = ref(false);
const hiddenWhileActive = ref(false);
@@ -155,12 +159,18 @@ const beginPractise = async () => {
};
const onReady = async () => {
const result = await beginPractise();
if (!result) return;
scores.value = [];
isSvip.value = false;
start.value = true;
audioManager.play("练习开始");
if (practiceStarting.value || start.value) return;
practiceStarting.value = true;
try {
const result = await beginPractise();
if (!result) return;
scores.value = [];
isSvip.value = false;
start.value = true;
audioManager.play("练习开始");
} finally {
practiceStarting.value = false;
}
};
const onOver = async (message) => {
@@ -452,7 +462,12 @@ onBeforeUnmount(() => {
:onBack="exitPractise"
>
<view>
<TestDistance v-if="!start && !practiseResult.id" />
<TestDistance
v-if="!start && !practiseResult.id"
:targetType="simulatorTargetType"
:autoStart="true"
@passed="onReady"
/>
<block v-else>
<ShootProgress
:tips="`请连续射${total}支箭`"
@@ -475,6 +490,7 @@ onBeforeUnmount(() => {
:totalRound="start ? total : 0"
:scores="scores"
:isSvip="isSvip"
:targetType="simulatorTargetType"
/>
<ScorePanel
v-if="start"
+13 -2
View File
@@ -55,6 +55,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
targetType: {
type: [Number, String],
default: 20,
},
targetRadius: {
type: Number,
default: 20,
@@ -422,12 +426,19 @@ function getExperienceTipStyle(shot) {
);
}
const simulShoot = async () => {
if (device.value.deviceId) await simulShootAPI(device.value.deviceId);
if (device.value.deviceId) {
await simulShootAPI(
device.value.deviceId,
undefined,
undefined,
props.targetType
);
}
};
const simulShoot2 = async () => {
if (device.value.deviceId) {
const r1 = Math.random() > 0.5 ? 0.01 : 0.02;
await simulShootAPI(device.value.deviceId, r1, r1);
await simulShootAPI(device.value.deviceId, r1, r1, props.targetType);
}
};
@@ -24,6 +24,10 @@ const props = defineProps({
type: Number,
default: 15,
},
targetType: {
type: [Number, String],
default: 20,
},
});
const arrow = ref({});
const distance = ref(0);
@@ -63,7 +67,14 @@ async function onReceiveMessage(msg) {
}
const simulShoot = async () => {
if (device.value.deviceId) await simulShootAPI(device.value.deviceId);
if (device.value.deviceId) {
await simulShootAPI(
device.value.deviceId,
undefined,
undefined,
props.targetType
);
}
};
onMounted(() => {
@@ -102,7 +113,6 @@ onBeforeUnmount(() => {
</button>
<view class="warnning-text">
<block v-if="statusText">
<text v-if="distance > 0">当前距离{{ distance }}米</text>
<text>{{ statusText }}</text>
</block>
<block v-else>
+6
View File
@@ -67,6 +67,7 @@ const COUNTDOWN_READY_EVENT = "team-battle-countdown-ready";
const start = ref(null);
const tips = ref("");
const battleId = ref("");
const targetType = ref(20);
const currentRound = ref(0);
const roundTipRound = ref(0);
const goldenRound = ref(0);
@@ -654,6 +655,8 @@ function applyBattleBase(battleInfo) {
battleInfo = normalizeBattleInfo(battleInfo);
if (!battleInfo) return;
if (battleInfo.matchId) battleId.value = battleInfo.matchId;
const nextTargetType = Number(battleInfo.targetType ?? battleInfo.target_type);
if ([20, 40].includes(nextTargetType)) targetType.value = nextTargetType;
if (battleInfo.status !== undefined) {
start.value = battleInfo.status !== 0;
matchStatus.value = battleInfo.status;
@@ -1265,6 +1268,7 @@ onLoad((options) => {
start.value = null;
tips.value = "";
battleId.value = returnSnapshot?.matchId || options.battleId || "";
targetType.value = 20;
currentRound.value = 0;
roundTipRound.value = 0;
goldenRound.value = 0;
@@ -1398,6 +1402,7 @@ onShow(() => {
:guide="false"
:isBattle="true"
:count="readyTime"
:targetType="targetType"
/>
<!-- 比赛进行中显示:左右队伍、进度条、靶面和底部比分。 -->
<view v-if="start" class="players-row">
@@ -1423,6 +1428,7 @@ onShow(() => {
:latestShotFlash="latestShotFlash"
:redTeam="redTeam"
:blueTeam="blueTeam"
:targetType="targetType"
stable-shot-effect
/>
<BattleFooter
@@ -28,6 +28,10 @@ const props = defineProps({
type: Number,
default: 0,
},
trainingType: {
type: String,
default: "",
},
});
</script>
@@ -72,6 +76,7 @@ const props = defineProps({
:rowCount="total === 12 ? 6 : 9"
:total="total"
:arrows="arrows"
:trainingType="trainingType"
:margin="total === 12 ? 4 : 1"
:fontSize="total === 12 ? 25 : 22"
/>
+13 -2
View File
@@ -56,6 +56,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
targetType: {
type: [Number, String],
default: 40,
},
coordinateRadius: {
type: Number,
default: 20,
@@ -433,12 +437,19 @@ watch(
);
const simulShoot = async () => {
if (device.value.deviceId) await simulShootAPI(device.value.deviceId);
if (device.value.deviceId) {
await simulShootAPI(
device.value.deviceId,
undefined,
undefined,
props.targetType
);
}
};
const simulShoot2 = async () => {
if (device.value.deviceId) {
const r1 = Math.random() > 0.5 ? 0.01 : 0.02;
await simulShootAPI(device.value.deviceId, r1, r1);
await simulShootAPI(device.value.deviceId, r1, r1, props.targetType);
}
};
+9 -1
View File
@@ -21,6 +21,10 @@ const props = defineProps({
type: Boolean,
default: true,
},
trainingType: {
type: String,
default: "",
},
});
const items = ref(new Array(props.total).fill(9));
const bgImages = [
@@ -34,7 +38,11 @@ const getDisplayText = (arrow) => {
};
const isLowScore = (arrow) => {
if (!arrow || arrow.ringX) return false;
if (!arrow) return false;
if (["rhythm", "stability"].includes(props.trainingType)) {
return arrow.ok !== true;
}
if (arrow.ringX) return false;
const ring = Number(arrow.ring);
return Number.isFinite(ring) && ring < 6;
};
+83 -67
View File
@@ -54,6 +54,18 @@ const showComment = ref(false);
const showBowData = ref(false);
const showUpgrade = ref(false);
const isCompleted = computed(() => props.result.completed === true);
const heroBackground = computed(() =>
isCompleted.value
? "https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/result-bg.png"
: "https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/result-bg-fail.png"
);
const titleBackground = computed(() =>
isCompleted.value
? "https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/result-t-bg.png"
: "https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/result-t-bg-fail.png"
);
const closePanel = () => {
showPanel.value = false;
setTimeout(() => {
@@ -219,6 +231,13 @@ const metricConfigs = {
deltaKeys: ["deltaStability", "delta_stability"],
deltaUnit: "",
},
{
label: "十环次数",
valueKeys: ["tenRingCount", "ten_ring_count"],
unit: "次",
deltaKeys: ["deltaTenRingCount", "delta_ten_ring_count"],
deltaUnit: "次",
},
],
rhythm: [
{
@@ -235,6 +254,39 @@ const metricConfigs = {
deltaKeys: ["deltaTotalRings", "delta_total_rings"],
deltaUnit: "环",
},
{
label: "十环次数",
valueKeys: ["tenRingCount", "ten_ring_count"],
unit: "次",
deltaKeys: ["deltaTenRingCount", "delta_ten_ring_count"],
deltaUnit: "次",
},
],
stability: [
{
label: "能量最高值",
valueKeys: ["maxEnergyPercent", "max_energy_percent"],
unit: "%",
deltaKeys: [
"deltaMaxEnergyPercent",
"delta_max_energy_percent",
],
deltaUnit: "%",
},
{
label: "达标箭数",
valueKeys: ["qualifiedArrows", "qualified_arrows"],
unit: "箭",
deltaKeys: ["deltaQualifiedArrows", "delta_qualified_arrows"],
deltaUnit: "箭",
},
{
label: "达标率",
valueKeys: ["qualifiedRate", "qualified_rate"],
unit: "%",
deltaKeys: ["deltaQualifiedRate", "delta_qualified_rate"],
deltaUnit: "%",
},
],
endurance: [
{
@@ -251,41 +303,43 @@ const metricConfigs = {
deltaKeys: ["deltaTotalRings", "delta_total_rings"],
deltaUnit: "环",
},
{
label: "平均环数",
valueKeys: ["averageRing", "average_ring"],
unit: "环",
deltaKeys: ["deltaAverageRing", "delta_average_ring"],
deltaUnit: "环",
},
],
precision: [
{
label: "共命中目标",
label: "命中目标数",
valueKeys: ["totalHits", "total_hits"],
fallback: () => 0,
unit: "次",
deltaKeys: [
"deltaTotalHits",
"delta_total_hits",
"hitCompare",
"hitDiff",
"hitDelta",
],
deltaKeys: ["deltaTotalHits", "delta_total_hits"],
deltaUnit: "次",
},
{
label: "用时",
valueKeys: ["duration", "usedTime", "shootTime", "time"],
unit: "",
deltaKeys: [
"deltaDuration",
"delta_duration",
"timeCompare",
"timeDiff",
"durationDiff",
],
deltaUnit: "",
duration: true,
label: "射箭数",
valueKeys: ["totalArrows", "total_arrows"],
unit: "箭",
deltaKeys: ["deltaTotalArrows", "delta_total_arrows"],
deltaUnit: "箭",
},
{
label: "命中率",
valueKeys: ["hitRate", "hit_rate"],
unit: "%",
deltaKeys: ["deltaHitRate", "delta_hit_rate"],
deltaUnit: "%",
},
],
};
const resultRows = computed(() => {
const configs = metricConfigs[resultTrainingType.value] || metricConfigs.precision;
const configs =
metricConfigs[resultTrainingType.value] || metricConfigs.precision;
return configs.map((config) => {
const fallback = config.fallback ? config.fallback() : 0;
const value = readMetricNumber(config.valueKeys, fallback);
@@ -314,20 +368,17 @@ const handlePrimary = () => {
retryPractice();
};
const calories = computed(
() => formatMetricNumber(readMetricNumber(["calories", "calorie", "kcal"]))
);
</script>
<template>
<view :class="['result-mask', showPanel ? 'result-mask--show' : 'result-mask--hide']">
<image class="hero-glow" src="https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/result-bg.png" mode="widthFix" />
<image class="hero-glow" :src="heroBackground" mode="widthFix" />
<view class="result-title">
<image class="result-title-bg" src="https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/result-t-bg.png" mode="widthFix" />
<image class="result-title-bg" :src="titleBackground" mode="widthFix" />
<view class="result-title-text">Lv{{ resultDifficultyLevel }}</view>
</view>
<view class="result-panel">
<view :class="['result-panel', { 'result-panel--fail': !isCompleted }]">
<view class="line-top"></view>
<view class="line-bottom"></view>
<view class="stats">
@@ -352,25 +403,6 @@ const calories = computed(
<view v-else class="stat-value">--</view>
</view>
</view>
<view class="stat-row">
<image class="stat-bg" src="https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/result-c-bg.png" mode="scaleToFill" />
<view class="stat-cell">
<text class="stat-label">消耗卡路里</text>
<view class="stat-value">
<text>{{ calories }}卡</text>
</view>
</view>
<text class="stat-equal">≈</text>
<!-- <view class="stat-divider"></view> -->
<view class="stat-cell stat-cell--compare">
<view class="stat-value">
<image v-for="index in 3" :key="index" class="rice-icon"
src="https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/result-rice.png" mode="widthFix" />
</view>
</view>
</view>
<view class="actions">
<view class="action-item" @click="() => (showBowData = true)">
<image class="action-icon" src="https://static.shelingxingqiu.com/shootmini/static/training-difficulty-design/result-icon-1.png" mode="widthFix" />
@@ -435,7 +467,7 @@ const calories = computed(
</view>
</view>
</ScreenHint>
<BowData :total="arrows.length" :arrows="result.details" :show="showBowData"
<BowData :total="details.length" :arrows="details" :show="showBowData" :trainingType="resultTrainingType"
:onClose="() => (showBowData = false)" />
<UserUpgrade :show="showUpgrade" :onClose="() => (showUpgrade = false)" :lvl="userLevel" />
</view>
@@ -517,6 +549,10 @@ const calories = computed(
position: relative;
}
.result-panel--fail {
background: rgba(34, 34, 46, 0.8);
}
.stats {
width: 100%;
margin-top: 34rpx;
@@ -610,14 +646,6 @@ const calories = computed(
transform: skewX(12deg);
}
.stat-equal{
width: 30rpx;
height: 40rpx;
color: #F3E0B9;
font-size: 30rpx;
margin-left: 10rpx;
}
.trend-icon {
width: 28rpx;
height: 42rpx;
@@ -636,18 +664,6 @@ const calories = computed(
height: 62rpx;
}
.rice-list {
width: 160rpx;
display: flex;
align-items: center;
}
.rice-icon {
width: 36rpx;
height: 34rpx;
margin-right: 14rpx;
}
.oper-box {
position: relative;
z-index: 1;
+484 -18
View File
@@ -1,6 +1,16 @@
<script setup>
import { ref, watch, onMounted, onBeforeUnmount, computed } from "vue";
import audioManager, { getTrainingStartAudioKey } from "@/audioManager";
import {
ref,
watch,
onMounted,
onBeforeUnmount,
computed,
nextTick,
} from "vue";
import audioManager, {
getTrainingStartAudioKey,
RHYTHM_SHOOT_WINDOW_AUDIO_KEY,
} from "@/audioManager";
import { MESSAGETYPESV2 } from "@/constants";
import {
getDirectionText,
@@ -39,6 +49,38 @@ const props = defineProps({
type: String,
default: "precision",
},
roundTime: {
type: Number,
default: 0,
},
shootTime: {
type: Number,
default: 0,
},
shootWindowStart: {
type: [Number, String],
default: 0,
},
inShootWindow: {
type: Boolean,
default: false,
},
serverTimestamp: {
type: [Number, String],
default: 0,
},
hitReq: {
type: Number,
default: 0,
},
energyPercent: {
type: Number,
default: 0,
},
energyReqPercent: {
type: Number,
default: 0,
},
isVip: {
type: Boolean,
default: false,
@@ -93,12 +135,100 @@ const currentRoundEnded = ref(false);
const halfTime = ref(false);
const wait = ref(0);
const transitionStyle = ref("all 1s linear");
const rhythmRemainingMs = ref(0);
const rhythmRemainingSeconds = ref(0);
const rhythmIsShootWindow = ref(false);
const rhythmTransitionStyle = ref("none");
let rhythmCountdownTimer = null;
let rhythmTransitionTimer = null;
let rhythmServerClockOffsetMs = 0;
let rhythmSyncGeneration = 0;
const isRhythmTraining = computed(() => props.trainingType === "rhythm");
const isStabilityTraining = computed(
() => props.trainingType === "stability"
);
const normalizePositiveInteger = (value) => {
const numberValue = Number(value);
return Number.isFinite(numberValue) && numberValue > 0
? Math.round(numberValue)
: 0;
};
// 服务端时间戳可能由 protobuf int64 以字符串形式下发。
const normalizeTimestamp = (value) => {
const numberValue = Number(value);
if (!Number.isFinite(numberValue) || numberValue <= 0) return 0;
return numberValue < 1e12 ? numberValue * 1000 : numberValue;
};
const validRhythmRoundTime = computed(() =>
normalizePositiveInteger(props.roundTime)
);
const validRhythmShootTime = computed(() =>
Math.min(
normalizePositiveInteger(props.shootTime),
validRhythmRoundTime.value
)
);
const validRhythmHitReq = computed(() =>
normalizePositiveInteger(props.hitReq)
);
const rhythmRoundDurationMs = computed(
() => validRhythmRoundTime.value * 1000
);
const rhythmShootDurationMs = computed(
() => validRhythmShootTime.value * 1000
);
const progressPercent = computed(() => {
if (!props.countdownEnabled || !props.total) return 0;
return Math.max(0, Math.min(100, (remain.value / props.total) * 100));
});
const stabilityEnergyPercent = computed(() =>
Math.max(0, Math.min(100, Number(props.energyPercent) || 0))
);
const stabilityEnergyReqPercent = computed(() =>
Math.max(0, Math.min(100, Number(props.energyReqPercent) || 0))
);
const stabilityEnergyReached = computed(
() =>
stabilityEnergyReqPercent.value > 0 &&
stabilityEnergyPercent.value >= stabilityEnergyReqPercent.value
);
const rhythmMarkerPercent = computed(() => {
if (!validRhythmRoundTime.value) return 0;
return Math.max(
0,
Math.min(
100,
(validRhythmShootTime.value / validRhythmRoundTime.value) * 100
)
);
});
const rhythmProgressPercent = computed(() => {
if (!rhythmRoundDurationMs.value) return 0;
return Math.max(
0,
Math.min(
100,
(rhythmRemainingMs.value / rhythmRoundDurationMs.value) * 100
)
);
});
const rhythmTitle = computed(() => {
if (!validRhythmShootTime.value) return "节奏训练";
if (!validRhythmHitReq.value) {
return `在最后的${validRhythmShootTime.value}秒内射箭`;
}
return `在最后的${validRhythmShootTime.value}秒并命中${validRhythmHitReq.value}环内`;
});
const displayName = computed(() => {
return (
user.value?.nickName ||
@@ -143,8 +273,147 @@ const clearTimer = () => {
timer.value = null;
};
const clearRhythmTimers = () => {
if (rhythmCountdownTimer) {
clearTimeout(rhythmCountdownTimer);
rhythmCountdownTimer = null;
}
if (rhythmTransitionTimer) {
clearTimeout(rhythmTransitionTimer);
rhythmTransitionTimer = null;
}
};
const getRhythmServerNow = () => Date.now() + rhythmServerClockOffsetMs;
const getRhythmRoundRemainingMs = () => {
const shootWindowStart = normalizeTimestamp(props.shootWindowStart);
if (!shootWindowStart || !rhythmRoundDurationMs.value) return 0;
const firstRoundEnd = shootWindowStart + rhythmShootDurationMs.value;
const serverNow = getRhythmServerNow();
let roundEnd = firstRoundEnd;
// 服务端锚点过期后继续按 round_time 推演下一轮,避免进度停在 0。
if (serverNow >= firstRoundEnd) {
const elapsedRounds =
Math.floor(
(serverNow - firstRoundEnd) / rhythmRoundDurationMs.value
) + 1;
roundEnd = firstRoundEnd + elapsedRounds * rhythmRoundDurationMs.value;
}
return Math.max(
0,
Math.min(rhythmRoundDurationMs.value, roundEnd - serverNow)
);
};
const updateRhythmShootWindow = (isInWindow) => {
const nextIsInWindow = Boolean(isInWindow);
const enteredShootWindow =
nextIsInWindow && !rhythmIsShootWindow.value;
rhythmIsShootWindow.value = nextIsInWindow;
// 只在进入窗口的边沿立即提示;预热和播放均为异步,不阻塞倒计时。
if (enteredShootWindow && props.start && isRhythmTraining.value) {
audioManager.play(RHYTHM_SHOOT_WINDOW_AUDIO_KEY);
}
};
// 每秒只更新一次目标宽度,实际推进交给 CSS transition,减少响应式刷新。
const scheduleRhythmCountdownStep = () => {
rhythmCountdownTimer = null;
const currentRemaining = getRhythmRoundRemainingMs();
if (currentRemaining <= 0) {
rhythmTransitionStyle.value = "none";
rhythmRemainingMs.value = 0;
rhythmRemainingSeconds.value = 0;
updateRhythmShootWindow(false);
return;
}
// 数字展示使用服务端校准后的真实剩余时间,不读取提前写入的动画目标值。
rhythmRemainingSeconds.value = Math.ceil(currentRemaining / 1000);
updateRhythmShootWindow(
currentRemaining <= rhythmShootDurationMs.value
);
// 一轮结束后先无动画恢复至 100%,再开始下一轮向左递减。
if (currentRemaining - rhythmRemainingMs.value > 1000) {
rhythmTransitionStyle.value = "none";
rhythmRemainingMs.value = currentRemaining;
rhythmTransitionTimer = setTimeout(() => {
rhythmTransitionTimer = null;
scheduleRhythmCountdownStep();
}, 50);
return;
}
const targetRemaining = Math.max(
0,
(Math.ceil(currentRemaining / 1000) - 1) * 1000
);
const stepDuration = Math.max(50, currentRemaining - targetRemaining);
rhythmTransitionStyle.value = `width ${stepDuration}ms linear`;
rhythmRemainingMs.value = targetRemaining;
rhythmCountdownTimer = setTimeout(
scheduleRhythmCountdownStep,
stepDuration
);
};
const syncRhythmCountdown = async () => {
const generation = ++rhythmSyncGeneration;
clearRhythmTimers();
if (!isRhythmTraining.value) {
rhythmTransitionStyle.value = "none";
rhythmRemainingMs.value = 0;
rhythmRemainingSeconds.value = 0;
updateRhythmShootWindow(false);
return;
}
const serverTimestamp = normalizeTimestamp(props.serverTimestamp);
rhythmServerClockOffsetMs = serverTimestamp
? serverTimestamp - Date.now()
: 0;
if (
!validRhythmRoundTime.value ||
!validRhythmShootTime.value ||
!normalizeTimestamp(props.shootWindowStart)
) {
rhythmTransitionStyle.value = "none";
rhythmRemainingMs.value = 0;
rhythmRemainingSeconds.value = 0;
updateRhythmShootWindow(false);
return;
}
rhythmTransitionStyle.value = "none";
rhythmRemainingMs.value = getRhythmRoundRemainingMs();
rhythmRemainingSeconds.value = Math.ceil(rhythmRemainingMs.value / 1000);
updateRhythmShootWindow(
rhythmRemainingMs.value > 0 &&
rhythmRemainingMs.value <= rhythmShootDurationMs.value
);
await nextTick();
if (generation !== rhythmSyncGeneration) return;
rhythmTransitionTimer = setTimeout(() => {
rhythmTransitionTimer = null;
scheduleRhythmCountdownStep();
}, 50);
};
const resetTimer = (count) => {
clearTimer();
if (isRhythmTraining.value) {
remain.value = 0;
return;
}
if (!props.countdownEnabled) {
remain.value = 0;
return;
@@ -177,9 +446,12 @@ const resetTimer = (count) => {
};
watch(
() => [props.start, props.countdownEnabled],
([started, countdownEnabled]) => {
if (started && countdownEnabled) {
() => [props.start, props.countdownEnabled, props.trainingType],
([started, countdownEnabled, trainingType]) => {
if (trainingType === "rhythm") {
clearTimer();
remain.value = 0;
} else if (started && countdownEnabled) {
resetTimer(props.total);
} else {
clearTimer();
@@ -191,6 +463,18 @@ watch(
}
);
watch(
() => [
props.trainingType,
props.roundTime,
props.shootTime,
props.shootWindowStart,
props.serverTimestamp,
],
syncRhythmCountdown,
{ immediate: true }
);
const tipContent = computed(() => {
if (halfTime.value) {
return props.battleId ? "中场休息" : `中场休息(${wait.value}秒)`;
@@ -214,7 +498,7 @@ async function onReceiveMessage(msg) {
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
audioManager.play("练习结束", false);
} else if (msg.type === MESSAGETYPESV2.ShootResult) {
// 精准训练由页面统一等待语音和飞箭结束,其他训练保持原播放链路。
// 精准和节奏训练由页面统一处理专属结果语音,其他训练保持原播放链路。
if (props.externalShootResultAudio) return;
const latestDetail =
Array.isArray(msg.details) && msg.details.length > 0
@@ -267,12 +551,66 @@ onBeforeUnmount(() => {
uni.$off("socket-inbox", onReceiveMessage);
uni.$off("play-sound", playSound);
clearTimer();
rhythmSyncGeneration += 1;
clearRhythmTimers();
});
</script>
<template>
<view v-if="show" class="progress-card">
<view class="progress-card__header">
<view
v-if="show"
:class="
isRhythmTraining
? 'rhythm-progress'
: isStabilityTraining
? 'stability-progress'
: 'progress-card'
"
>
<template v-if="isStabilityTraining">
<text class="stability-progress__time">{{ remain }}秒</text>
<view class="stability-progress__track">
<view
class="stability-progress__fill"
:class="{
'stability-progress__fill--reached': stabilityEnergyReached,
}"
:style="{ width: `${stabilityEnergyPercent}%` }"
/>
<view
class="stability-progress__marker"
:style="{ left: `${stabilityEnergyReqPercent}%` }"
/>
<text class="stability-progress__value">
{{ Math.round(stabilityEnergyPercent) }}%
</text>
</view>
</template>
<template v-else-if="isRhythmTraining">
<text class="rhythm-progress__title">{{ rhythmTitle }}</text>
<view class="rhythm-progress__track">
<view
class="rhythm-progress__fill"
:class="{
'rhythm-progress__fill--shooting': rhythmIsShootWindow,
}"
:style="{
width: `${rhythmProgressPercent}%`,
transition: rhythmTransitionStyle,
}"
/>
<view
class="rhythm-progress__marker"
:style="{ left: `${rhythmMarkerPercent}%` }"
/>
<text
v-if="rhythmRemainingSeconds > 0"
class="rhythm-progress__window-label"
>{{ rhythmRemainingSeconds }}秒</text>
</view>
</template>
<template v-else>
<view class="progress-card__header">
<view class="progress-card__profile">
<view class="progress-card__avatar-shell">
<Avatar
@@ -304,16 +642,16 @@ onBeforeUnmount(() => {
mode="aspectFit"
/>
</button> -->
</view>
</view>
<view class="progress-card__track-wrap">
<image
<view class="progress-card__track-wrap">
<image
class="progress-card__titile"
:src="trainingTitleIcon"
mode="aspectFit"
/>
<view v-if="countdownEnabled" class="progress-card__track">
<view
<view v-if="countdownEnabled" class="progress-card__track">
<view
class="progress-card__fill"
:style="{
width: `${progressPercent}%`,
@@ -321,13 +659,14 @@ onBeforeUnmount(() => {
right: tips.includes('红队') ? 0 : 'unset',
transition: transitionStyle,
}"
/>
<view class="progress-card__badge">
<text class="progress-card__badge-text">剩余{{ remain }}秒</text>
/>
<view class="progress-card__badge">
<text class="progress-card__badge-text">剩余{{ remain }}秒</text>
</view>
</view>
<!-- <text v-if="tipContent" class="progress-card__tip">{{ tipContent }}123</text> -->
</view>
<!-- <text v-if="tipContent" class="progress-card__tip">{{ tipContent }}123</text> -->
</view>
</template>
</view>
</template>
@@ -466,4 +805,131 @@ onBeforeUnmount(() => {
line-height: 1.4;
text-align: center;
}
.stability-progress {
box-sizing: border-box;
margin: 32rpx 84rpx 0;
}
.stability-progress__time {
display: block;
margin-bottom: 20rpx;
color: #ffffff;
font-size: 34rpx;
font-weight: 500;
line-height: 48rpx;
text-align: center;
}
.stability-progress__track {
position: relative;
width: 100%;
height: 24rpx;
overflow: hidden;
border-radius: 18rpx;
background: #444444;
}
.stability-progress__fill {
position: absolute;
top: 0;
bottom: 0;
left: 0;
border-radius: 18rpx;
background: linear-gradient(90deg, #87f1df 0%, #5ba8e8 100%);
transition: width 240ms linear, background 240ms ease;
}
.stability-progress__fill--reached {
background: linear-gradient(90deg, #a5df62 0%, #61c787 100%);
}
.stability-progress__marker {
position: absolute;
top: 0;
bottom: 0;
z-index: 2;
width: 4rpx;
transform: translateX(-2rpx);
background: rgba(26, 24, 22, 0.92);
}
.stability-progress__value {
position: absolute;
inset: 0;
z-index: 3;
display: flex;
align-items: center;
justify-content: center;
color: #eefaff;
font-size: 18rpx;
line-height: 24rpx;
text-align: center;
pointer-events: none;
}
.rhythm-progress {
box-sizing: border-box;
margin: 32rpx 84rpx 0;
}
.rhythm-progress__title {
display: block;
margin-bottom: 20rpx;
color: #ffffff;
font-size: 30rpx;
font-weight: 500;
line-height: 42rpx;
text-align: center;
}
.rhythm-progress__track {
position: relative;
width: 100%;
height: 24rpx;
overflow: hidden;
border-radius: 18rpx;
background: #444444;
}
.rhythm-progress__fill {
position: absolute;
top: 0;
bottom: 0;
left: 0;
border-radius: 18rpx;
background: linear-gradient(133deg, #ffd19a 0%, #a17636 100%);
}
.rhythm-progress__fill--shooting {
background: linear-gradient(90deg, #e2bd2e 0%, #fff047 100%);
}
.rhythm-progress__marker {
position: absolute;
top: 0;
bottom: 0;
z-index: 2;
width: 4rpx;
transform: translateX(-2rpx);
background: rgba(26, 24, 22, 0.9);
}
.rhythm-progress__window-label {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
z-index: 3;
display: flex;
align-items: center;
justify-content: center;
transform: translateX(-50%);
color: #fff7de;
font-size: 18rpx;
line-height: 24rpx;
text-align: center;
white-space: nowrap;
pointer-events: none;
}
</style>
+52 -4
View File
@@ -6,11 +6,16 @@ import Avatar from "@/components/Avatar.vue";
import audioManager from "@/audioManager";
import { simulShootAPI } from "@/apis";
import { MESSAGETYPESV2 } from "@/constants";
import { getDistanceCheckAudioKey, getDistanceCheckText } from "@/util";
import {
getDistanceCheckAudioKey,
getDistanceCheckText,
getShootValidation,
} from "@/util";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user, device } = storeToRefs(store);
const emit = defineEmits(["passed"]);
const props = defineProps({
guide: {
type: Boolean,
@@ -28,6 +33,10 @@ const props = defineProps({
type: [Number, String],
default: "",
},
autoStart: {
type: Boolean,
default: false,
},
});
const arrow = ref({});
const distance = ref(0);
@@ -35,6 +44,29 @@ const statusText = ref("");
const showsimul = ref(false);
const count = ref(props.count);
const timer = ref(null);
const autoStartPending = ref(false);
const autoStartTriggered = ref(false);
let autoStartTimer = null;
const DISTANCE_PASSED_AUDIO_KEY = "站距合格,靶纸正确";
const AUTO_START_TIMEOUT_MS = 6000;
const clearAutoStartTimer = () => {
if (!autoStartTimer) return;
clearTimeout(autoStartTimer);
autoStartTimer = null;
};
const triggerAutoStart = () => {
if (!autoStartPending.value || autoStartTriggered.value) return;
clearAutoStartTimer();
autoStartPending.value = false;
autoStartTriggered.value = true;
emit("passed");
};
const onAudioEnded = (key) => {
if (key === DISTANCE_PASSED_AUDIO_KEY) triggerAutoStart();
};
const updateTimer = (value) => {
count.value = Math.round(value);
@@ -48,26 +80,43 @@ onMounted(() => {
}, 1000);
}
uni.$on("update-timer", updateTimer);
uni.$on("audioEnded", onAudioEnded);
});
onBeforeUnmount(() => {
if (timer.value) clearInterval(timer.value);
clearAutoStartTimer();
uni.$off("update-timer", updateTimer);
uni.$off("audioEnded", onAudioEnded);
});
async function onReceiveMessage(msg) {
if (Array.isArray(msg)) return;
if (msg.type === MESSAGETYPESV2.TestDistance) {
if (autoStartPending.value || autoStartTriggered.value) return;
const rawDistance = Number(msg.shootData?.distance ?? msg.shootData?.dst);
distance.value = Number.isFinite(rawDistance)
? Number((rawDistance / 100).toFixed(2))
: 0;
statusText.value = getDistanceCheckText(msg.shootData);
audioManager.play(getDistanceCheckAudioKey(msg.shootData));
const audioKey = getDistanceCheckAudioKey(msg.shootData);
const validation = getShootValidation(msg.shootData);
if (props.autoStart && validation.distanceOk && validation.targetOk) {
autoStartPending.value = true;
autoStartTimer = setTimeout(triggerAutoStart, AUTO_START_TIMEOUT_MS);
}
audioManager.play(audioKey);
}
}
const simulShoot = async () => {
if (device.value.deviceId) await simulShootAPI(device.value.deviceId);
if (device.value.deviceId) {
await simulShootAPI(
device.value.deviceId,
undefined,
undefined,
props.targetType
);
}
};
onMounted(() => {
@@ -101,7 +150,6 @@ onBeforeUnmount(() => {
<view class="warnning-text">
<view class="target-tip">当前靶纸为<text class="text-yellow">{{ targetType }}cm</text>全环靶</view>
<block v-if="statusText">
<text v-if="distance > 0">当前距离<text class="text-yellow">{{ distance }}</text>米</text>
<text>{{ statusText }}</text>
</block>
<block v-else>
@@ -15,6 +15,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
showUnlockProgress: {
type: Boolean,
default: false,
},
completedProgress: {
type: Number,
default: 0,
@@ -106,6 +110,15 @@ const handleClick = () => {
<view class="difficulty-badge__label">{{ node.label }}</view>
</view>
</view>
<view
v-if="showUnlockProgress"
class="difficulty-badge__unlock-progress"
>
<view
class="difficulty-badge__unlock-progress-completed"
:style="{ width: `${progressValue}%` }"
></view>
</view>
</view>
</template>
@@ -315,6 +328,25 @@ const handleClick = () => {
overflow: hidden;
}
.difficulty-badge__unlock-progress {
position: absolute;
top: calc(100% + 30rpx);
left: 50%;
width: 120rpx;
height: 10rpx;
overflow: hidden;
border-radius: 6rpx;
background: rgba(0, 0, 0, 0.6);
transform: translateX(-50%);
pointer-events: none;
}
.difficulty-badge__unlock-progress-completed {
height: 100%;
border-radius: 6rpx;
background: rgba(255, 217, 71, 1);
}
@keyframes badge-orbit-spin {
from {
transform: translate(-50%, -50%) rotate(0deg);
@@ -13,7 +13,20 @@ const props = defineProps({
});
const previewLines = computed(() => {
return props.lines.map((line) => String(line || "").trim()).filter(Boolean);
return props.lines
.map((line) => {
const rawParts = Array.isArray(line?.parts)
? line.parts
: [{ text: line }];
const parts = rawParts
.map((part) => ({
text: String(part?.text ?? part ?? "").trim(),
}))
.filter((part) => part.text);
return { parts };
})
.filter((line) => line.parts.length > 0);
});
</script>
@@ -27,13 +40,16 @@ const previewLines = computed(() => {
<view class="difficulty-preview__content">
<text class="difficulty-preview__title">{{ title }}</text>
<view class="difficulty-preview__copy">
<text
<view
v-for="(line, index) in previewLines"
:key="`${line}-${index}`"
:key="index"
class="difficulty-preview__line"
>
{{ line }}
</text>
<text
v-for="(part, partIndex) in line.parts"
:key="partIndex"
>{{ part.text }}</text>
</view>
</view>
</view>
</view>
@@ -86,6 +102,4 @@ const previewLines = computed(() => {
.difficulty-preview__line {
display: block;
}
</style>
+66 -16
View File
@@ -13,7 +13,7 @@ import {
} from "@/apis";
// 难度页接口数据源:
// 1. 接口:GET /training/difficulty/list?type=base/endurance/precision/rhythm
// 1. 接口:GET /training/difficulty/list?type=base/endurance/precision/rhythm/stability
// 2. 当前进度:接口 user_levels / list.completed,路由参数可覆盖选中难度
const trainingDifficultyStorageKey = "training-selection";
const defaultTrainingType = "precision";
@@ -35,6 +35,10 @@ const trainingTypeMetaMap = {
key: "rhythm",
title: "节奏训练",
},
stability: {
key: "stability",
title: "稳定训练",
},
};
const routeModeTypeMap = {
basic: "base",
@@ -42,6 +46,9 @@ const routeModeTypeMap = {
endurance: "endurance",
precision: "precision",
rhythm: "rhythm",
stability: "stability",
// 兼容历史上已经分享出去的 power 深链,实际创建仍统一传 stability。
power: "stability",
};
const defaultTargetType = 1;
@@ -83,10 +90,6 @@ const checkDifficultyCompleted = (item = {}) => {
return Boolean(item.completed) || (promoteCnt > 0 && completedCnt >= promoteCnt);
};
const getDifficultyModeText = (mode) => {
return Number(mode) === 1 ? "随机区域+指定环数" : "随机区域命中";
};
const createEmptyModeConfig = (type = defaultTrainingType) => {
const meta = trainingTypeMetaMap[type] || trainingTypeMetaMap[defaultTrainingType];
@@ -107,14 +110,13 @@ const createDifficultySummary = (item = {}) => {
const timeLimit = toNumber(item.time_limit);
const hitReq = toNumber(item.hit_req);
const totalReq = toNumber(item.total_req);
const promoteCnt = toNumber(item.promote_cnt);
const energyReqPercent = toNumber(item.energy_req_percent);
const shootingTimeText =
timeLimit > 0 ? `在${timeLimit}秒内进行射箭` : "不限时进行射箭";
const enduranceTimeText =
timeLimit > 0
? `在${timeLimit}秒内完成${arrows}箭`
: `不限时完成${arrows}箭`;
const promoteText = promoteCnt > 0 ? `完成${promoteCnt}次晋级` : "";
const summaryMap = {
base: [
@@ -130,15 +132,30 @@ const createDifficultySummary = (item = {}) => {
`需要有${arrows}箭命中高亮区域`,
],
rhythm: [
desc || `间隔${timeLimit}秒射击`,
[
`${arrows}箭`,
hitReq > 0 ? `每箭${hitReq}环以上` : "上靶即可",
getDifficultyModeText(item.mode),
promoteText,
]
.filter(Boolean)
.join(" · "),
arrows > 0
? `需要在指定时间节点射出${arrows}射箭`
: "需要在指定时间节点射箭",
hitReq > 0 ? `且每箭命中${hitReq}环内` : "且每箭命中指定区域",
],
stability: [
{
parts: [
{ text: timeLimit > 0 ? "在" : "" },
{
text: timeLimit > 0 ? `${timeLimit}秒` : "不限时",
highlight: true,
},
{ text: timeLimit > 0 ? "内射箭,命中" : "射箭,命中" },
{ text: `${hitReq}环`, highlight: true },
{ text: "可获得能量" },
],
},
{
parts: [
{ text: "计时结束能量需要大于" },
{ text: `${energyReqPercent}%`, highlight: true },
],
},
],
};
@@ -612,6 +629,23 @@ const createPracticeQuery = (difficulty) => {
rhythm: {
hitReq: toNumber(difficulty.hit_req),
mode: toNumber(difficulty.mode),
roundTime: toNumber(difficulty.round_time ?? difficulty.roundTime),
shootTime: toNumber(difficulty.shoot_time ?? difficulty.shootTime),
},
stability: {
hitReq: toNumber(difficulty.hit_req),
scoreSlot: toNumber(
difficulty.score_slot ?? difficulty.scoreSlot
),
energyPerHit: toNumber(
difficulty.energy_per_hit ?? difficulty.energyPerHit
),
energyCostPerSec: toNumber(
difficulty.energy_cost_per_sec ?? difficulty.energyCostPerSec
),
energyReqPercent: toNumber(
difficulty.energy_req_percent ?? difficulty.energyReqPercent
),
},
};
@@ -645,6 +679,21 @@ const saveTrainingContext = (practice = {}) => {
difficultyLabel: difficulty.label,
targetType: defaultTargetType,
targetPaperType: difficulty.targetPaperType,
roundTime: toNumber(difficulty.round_time ?? difficulty.roundTime),
shootTime: toNumber(difficulty.shoot_time ?? difficulty.shootTime),
hitReq: toNumber(difficulty.hit_req ?? difficulty.hitReq),
scoreSlot: toNumber(
difficulty.score_slot ?? difficulty.scoreSlot
),
energyPerHit: toNumber(
difficulty.energy_per_hit ?? difficulty.energyPerHit
),
energyCostPerSec: toNumber(
difficulty.energy_cost_per_sec ?? difficulty.energyCostPerSec
),
energyReqPercent: toNumber(
difficulty.energy_req_percent ?? difficulty.energyReqPercent
),
practiceId: practice.id || "",
serverAddr: practice.serverAddr || "",
createdAt: practice.id ? Date.now() : 0,
@@ -803,6 +852,7 @@ onShow(() => {
:node="node"
:active="node.id === selectedDifficultyId"
:locked="checkDifficultyLocked(node)"
:showUnlockProgress="node.id === unlockedDifficultyId"
:completedProgress="getCompletedDifficultyProgress(node)"
@click="handleSelectDifficulty"
/>
+57 -95
View File
@@ -15,19 +15,19 @@ const trainingModeRouteMap = {
endurance: "endurance",
precision: "precision",
rhythm: "rhythm",
strength: "power",
stability: "stability",
};
const unavailableTrainingIds = new Set(["rhythm", "strength"]);
const unavailableTrainingIds = new Set();
// 训练项目卡片右侧主图标。
const trainingModeIconMap = {
base_bow:
"https://static.shelingxingqiu.com/shootmini/static/training-home/img_3.png",
bow: "https://static.shelingxingqiu.com/shootmini/static/training-home/img_4.png",
bow: "https://static.shelingxingqiu.com/shootmini/static/training-home/img_5.png",
target:
"https://static.shelingxingqiu.com/shootmini/static/training-home/img_5.png",
"https://static.shelingxingqiu.com/shootmini/static/training-home/img_4.png",
wave: "https://static.shelingxingqiu.com/shootmini/static/training-home/img_6.png",
muscle:
"https://static.shelingxingqiu.com/shootmini/static/training-home/img_6.png",
"https://static.shelingxingqiu.com/shootmini/static/training-home/img_7.png",
};
// 训练项目卡片标题图,按接口 id 映射 CDN 资源。
const trainingModeTitleImageMap = {
@@ -39,21 +39,22 @@ const trainingModeTitleImageMap = {
"https://static.shelingxingqiu.com/shootmini/static/training-home/jingzhunxunlian.png",
rhythm:
"https://static.shelingxingqiu.com/shootmini/static/training-home/jiezouxunlian.png",
strength:
"https://static.shelingxingqiu.com/shootmini/static/training-home/liliangxulian.png",
stability:
"https://static.shelingxingqiu.com/shootmini/static/training-home/wendingxunlian.png",
};
const defaultWeekDays = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];
const defaultRadarDimensions = [
{ name: "基础", score: 0 },
{ name: "精准", score: 0 },
{ name: "力量", score: 0 },
{ name: "稳定", score: 0 },
{ name: "节奏", score: 0 },
{ name: "耐力", score: 0 },
];
const radarDimensionTrainingIdMap = Object.freeze({
基础: "base",
精准: "precision",
力量: "strength",
稳定: "stability",
力量: "stability",
节奏: "rhythm",
耐力: "endurance",
});
@@ -66,7 +67,7 @@ const createDefaultTrainingData = () => ({
total_arrows: 0,
target_rate: 0,
ten_ring_count: 0,
total_calories: 0,
average_ring: 0,
},
beat_percent: 0,
radar_max: 0,
@@ -124,20 +125,20 @@ const formatValue = (value, digits = 1) => {
return String(Number(numberValue.toFixed(digits)));
};
const formatCompactCount = (value) => {
const numberValue = Number(value);
if (!Number.isFinite(numberValue)) return "--";
if (numberValue >= 10000) return `${formatValue(numberValue / 1000)}K`;
return formatValue(numberValue, 0);
};
const getLevelText = (item) => {
if (!item) return "";
const level = Number(item.current_level) || 0;
return `当前进度 LV${level} >`;
};
// 卡路里字段按需求做 K / W 缩写展示。
const getCaloriesValue = (value) => {
const numberValue = Number(value);
if (!Number.isFinite(numberValue)) return "--";
if (numberValue >= 10000) return `${formatValue(numberValue / 10000)}W`;
if (numberValue >= 1000) return `${formatValue(numberValue / 1000)}K`;
return formatValue(numberValue, 0);
};
const getAverageRingValue = (value) => formatValue(value);
const getTrainingIcon = (item = {}) =>
trainingModeIconMap[item.icon] || trainingModeIconMap.bow;
@@ -288,7 +289,7 @@ const loadPersonalTrainingData = async () => {
total_arrows: result?.stats?.total_arrows ?? 0,
target_rate: result?.stats?.target_rate ?? 0,
ten_ring_count: result?.stats?.ten_ring_count ?? 0,
total_calories: result?.stats?.total_calories ?? 0,
average_ring: result?.stats?.average_ring ?? 0,
},
beat_percent: result?.beat_percent ?? 0,
radar_max: result?.radar_max ?? 0,
@@ -418,7 +419,7 @@ onShow(async () => {
<view class="stats-value-row">
<view class="stats-value-group">
<text class="stats-value">
{{ formatValue(trainingData.stats.total_arrows, 0) }}
{{ formatCompactCount(trainingData.stats.total_arrows) }}
</text>
<text class="stats-unit">支</text>
<view class="stats-value-decoration"></view>
@@ -444,7 +445,7 @@ onShow(async () => {
<view class="stats-value-row">
<view class="stats-value-group">
<text class="stats-value">
{{ formatValue(trainingData.stats.ten_ring_count, 0) }}
{{ formatCompactCount(trainingData.stats.ten_ring_count) }}
</text>
<text class="stats-unit">支</text>
<view class="stats-value-decoration"></view>
@@ -457,13 +458,13 @@ onShow(async () => {
<view class="stats-value-row">
<view class="stats-value-group">
<text class="stats-value">
{{ getCaloriesValue(trainingData.stats.total_calories) }}
{{ getAverageRingValue(trainingData.stats.average_ring) }}
</text>
<text class="stats-unit">卡路里</text>
<text class="stats-unit">环</text>
<view class="stats-value-decoration"></view>
</view>
</view>
<text class="stats-label">共消耗</text>
<text class="stats-label">平均环数</text>
</view>
</view>
</view>
@@ -483,7 +484,7 @@ onShow(async () => {
<text class="record-sub-text">我的训练记录</text>
<image
class="record-arrow"
src="https://static.shelingxingqiu.com/shootmini/static/training-home/img_7.png"
src="https://static.shelingxingqiu.com/shootmini/static/training-home/img_right.png"
mode="widthFix"
/>
</view>
@@ -530,19 +531,26 @@ onShow(async () => {
</view>
</view>
<view class="featured-card" @click="$clickSound(openRoutineTraining)">
<image
class="featured-card-bg"
src="https://static.shelingxingqiu.com/shootmini/static/training-home/img_22.png"
mode="widthFix"
/>
<view class="featured-card-mask"></view>
<view class="featured-card-copy">
<text class="featured-card-subtitle">12箭练习</text>
</view>
</view>
<view class="mode-grid">
<view
class="mode-card"
@click="$clickSound(openRoutineTraining)"
>
<view class="mode-card-copy">
<image
class="mode-card-title-image"
src="https://static.shelingxingqiu.com/shootmini/static/training-home/ziyouxunlian.png"
mode="widthFix"
/>
<text class="mode-card-progress">无级别限制</text>
</view>
<image
class="mode-card-icon"
src="https://static.shelingxingqiu.com/shootmini/static/training-home/img_2.png"
mode="aspectFit"
/>
</view>
<view
v-for="item in visibleTrainingItems"
:key="item.id"
@@ -743,7 +751,7 @@ onShow(async () => {
.radar-section {
position: relative;
padding-top: 34rpx;
padding-top: 30rpx;
}
.record-bubble {
@@ -860,52 +868,6 @@ onShow(async () => {
width: 92rpx;
}
.featured-card {
position: relative;
width: 100%;
height: 150rpx;
margin-top: 70rpx;
border-radius: 16rpx;
overflow: hidden;
}
.featured-card-bg {
width: 100%;
}
.featured-card-mask {
position: absolute;
left: 0;
top: 0;
width: 278rpx;
height: 150rpx;
}
.featured-card-copy {
position: absolute;
left: 174rpx;
top: 58rpx;
display: flex;
flex-direction: column;
}
.featured-card-title {
display: block;
color: #895409;
font-size: 34rpx;
font-family: "AlimamaShuHeiTi-Bold", "PingFang SC", sans-serif;
font-weight: 700;
line-height: 42rpx;
}
.featured-card-subtitle {
display: block;
margin-top: 10rpx;
color: #895409;
font-size: 22rpx;
line-height: 32rpx;
}
.mode-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
@@ -915,11 +877,11 @@ onShow(async () => {
.mode-card {
position: relative;
height: 150rpx;
height: 130rpx;
box-shadow: inset 2rpx 2rpx 6rpx 0rpx rgba(255, 255, 255, 0.27);
border-radius: 16rpx;
border: 2rpx solid rgba(235, 184, 123, 0.5);
background: rgba(0, 0, 0, 0.5);
/* background: rgba(0, 0, 0, 0.5); */
overflow: hidden;
}
@@ -928,8 +890,8 @@ onShow(async () => {
left: 0;
top: 0;
width: 72rpx;
height: 34rpx;
line-height: 34rpx;
height: 28rpx;
line-height: 28rpx;
text-align: center;
font-size: 20rpx;
color: #000;
@@ -940,7 +902,7 @@ onShow(async () => {
.mode-card-copy {
position: absolute;
left: 30rpx;
top: 40rpx;
top: 32rpx;
}
.mode-card-title {
@@ -968,16 +930,16 @@ onShow(async () => {
display: block;
margin-top: 14rpx;
color: #fcce96;
font-size: 22rpx;
line-height: 32rpx;
font-size: 20rpx;
line-height: 28rpx;
opacity: 0.5;
}
.mode-card-icon {
position: absolute;
right: 12rpx;
top: 14rpx;
width: 124rpx;
height: 124rpx;
right: 18rpx;
top: 8rpx;
width: 116rpx;
height: 116rpx;
}
</style>
+462 -5
View File
@@ -12,7 +12,12 @@ import TestDistance from "./components/TestDistance.vue";
import BubbleTip from "./components/BubbleTip.vue";
import audioManager, {
getPrecisionShotAudioKeys,
getRhythmShotAudioKeys,
getStabilityShotAudioKeys,
getTrainingStartAudioKey,
RHYTHM_SHOOT_WINDOW_AUDIO_KEY,
STABILITY_ENERGY_50_AUDIO_KEY,
STABILITY_ENERGY_70_AUDIO_KEY,
} from "@/audioManager";
import {
@@ -26,12 +31,13 @@ import {
import {
connectMatchWebSocket,
closeMatchWebSocket,
requestPracticeInfoSync,
setMatchAppHideResumable,
MATCH_WS_PRACTICE_SYNC_EVENT,
MATCH_WS_STATE_EVENT,
} from "@/matchWebsocket";
import { sharePractiseData } from "@/canvas";
import { wxShare, debounce, getDirectionText } from "@/util";
import { wxShare, debounce, getDirectionText, capsuleHeight } from "@/util";
import { MESSAGETYPESV2, roundsName } from "@/constants";
import useStore from "@/store";
@@ -41,6 +47,7 @@ const { user } = storeToRefs(store);
const sound = ref(true);
const start = ref(false);
const practiceStarting = ref(false);
const pageStages = Object.freeze({
DISTANCE: "distance",
SHOOTING: "shooting",
@@ -49,6 +56,25 @@ const pageStages = Object.freeze({
});
const pageStage = ref(pageStages.LOADING);
const scores = ref([]);
// 复用金币模块的标题视觉,但保留练习页默认 Header,避免影响返回按钮。
const rhythmHeaderTitleStyle = Object.freeze({
position: "fixed",
top: `${capsuleHeight}px`,
left: "50%",
width: "430rpx",
height: "50px",
display: "flex",
alignItems: "center",
justifyContent: "center",
transform: "translateX(-50%)",
color: "#e7ba80",
fontSize: "30rpx",
lineHeight: "42rpx",
fontWeight: 500,
textAlign: "center",
whiteSpace: "nowrap",
zIndex: 20,
});
// 只在实时 ShootResult 新增一箭时递增,避免同步快照重播飞箭特效。
const shotEffectToken = ref(0);
// 可见区域每次正式提交都递增,同一区域连续刷新也能触发动效。
@@ -65,6 +91,17 @@ const tips = ref("");
const targetType = ref(defaultTargetType);
const trainingParams = ref({});
const practiceInfo = ref({});
const simulatorTargetType = computed(() => {
const currentTargetType = Number(practiceInfo.value.targetType);
if ([20, 40].includes(currentTargetType)) return currentTargetType;
return [2, 40].includes(Number(targetType.value)) ? 40 : 20;
});
const rhythmServerTimestamp = ref(0);
const rhythmFallbackWindowStart = ref(0);
const rhythmFallbackTimestamp = ref(0);
const rhythmHasActiveServerAnchor = ref(false);
// 节奏训练目标箭数以服务端 total_arrows 为准;首帧缺失时用 arrows_left 初始化并保持稳定。
const rhythmTargetArrows = ref(0);
// 服务端状态立即落到 practiceInfo,精准训练的目标区域单独延迟展示。
const visiblePrecisionTarget = ref({
randomBlock: 0,
@@ -235,6 +272,96 @@ const loadNextDifficultyState = (result = {}) => {
// time_limit 缺失或非正数都表示整局不限时。
const timeLimit = computed(() => getPositiveInteger(practiceInfo.value.timeLimit));
const hasTimeLimit = computed(() => timeLimit.value > 0);
const isRhythmTraining = computed(() => trainingType.value === "rhythm");
const isStabilityTraining = computed(
() => trainingType.value === "stability"
);
const rhythmRoundTime = computed(() =>
getPositiveInteger(practiceInfo.value.roundTime) ||
getPositiveInteger(trainingParams.value.roundTime)
);
const rhythmShootTime = computed(() =>
getPositiveInteger(practiceInfo.value.shootTime) ||
getPositiveInteger(trainingParams.value.shootTime)
);
const rhythmShootWindowStart = computed(() => {
if (rhythmHasActiveServerAnchor.value) {
return practiceInfo.value.shootWindowStart || 0;
}
return (
rhythmFallbackWindowStart.value ||
practiceInfo.value.shootWindowStart ||
0
);
});
const rhythmCountdownTimestamp = computed(() =>
rhythmHasActiveServerAnchor.value
? rhythmServerTimestamp.value
: rhythmFallbackTimestamp.value || rhythmServerTimestamp.value
);
const rhythmInShootWindow = computed(
() => practiceInfo.value.inShootWindow === true
);
const rhythmHitReq = computed(
() =>
getPositiveInteger(practiceInfo.value.hitReq) ||
getPositiveInteger(trainingParams.value.hitReq)
);
const stabilityEnergyReqPercent = computed(() =>
Math.max(
0,
Math.min(
100,
getPracticeNumber(
practiceInfo.value.energyReqPercent,
trainingParams.value.energyReqPercent
)
)
)
);
const stabilityScoreSlot = computed(() =>
Math.max(
0,
getPracticeNumber(
practiceInfo.value.scoreSlot,
trainingParams.value.scoreSlot
)
)
);
const stabilityCurrentEnergy = computed(() => {
const currentEnergy = Math.max(
0,
getPracticeNumber(practiceInfo.value.currentEnergy)
);
return stabilityScoreSlot.value > 0
? Math.min(stabilityScoreSlot.value, currentEnergy)
: currentEnergy;
});
const stabilityEnergyPercent = computed(() => {
if (stabilityScoreSlot.value <= 0) return 0;
return Math.min(
100,
(stabilityCurrentEnergy.value / stabilityScoreSlot.value) * 100
);
});
const initializeRhythmFirstRoundCountdown = () => {
rhythmHasActiveServerAnchor.value = false;
rhythmFallbackWindowStart.value = 0;
rhythmFallbackTimestamp.value = 0;
if (!isRhythmTraining.value) return;
const roundTime = rhythmRoundTime.value;
const shootTime = rhythmShootTime.value;
if (!roundTime || !shootTime || shootTime > roundTime) return;
const localNow = Date.now();
rhythmFallbackTimestamp.value = localNow;
// shootWindowStart 位于整轮最后 shootTime 秒的起点。
rhythmFallbackWindowStart.value =
localNow + (roundTime - shootTime) * 1000;
};
const precisionBlocks = computed(() => {
if (useHighlightTest.value) {
@@ -339,6 +466,62 @@ const trainingCopy = computed(() => {
};
}
if (trainingType.value === "rhythm") {
const targetArrows = getPositiveInteger(rhythmTargetArrows.value);
const arrowsLeft = Math.min(
targetArrows,
Math.max(
0,
getPracticeNumber(practiceInfo.value.arrowsLeft, targetArrows)
)
);
const completedArrows = targetArrows - arrowsLeft;
const hitReq = rhythmHitReq.value;
return {
inline: true,
details: [
{ text: "在进度条读取到高亮区间时射箭命中" },
{
text: hitReq > 0 ? `${hitReq}环内` : "指定区域",
highlight: true,
},
{ text: ",需完成" },
{ text: `(${completedArrows}/${targetArrows})`, highlight: true },
{ text: "箭" },
],
};
}
if (trainingType.value === "stability") {
const hitReq = getPracticeNumber(
practiceInfo.value.hitReq,
trainingParams.value.hitReq
);
const stabilityTimeLimit = getPracticeNumber(
practiceInfo.value.timeLimit,
trainingParams.value.timeLimit
);
return {
inline: true,
details: [
{ text: stabilityTimeLimit > 0 ? "在" : "" },
{
text: stabilityTimeLimit > 0 ? `${stabilityTimeLimit}秒` : "不限时",
highlight: true,
},
{ text: stabilityTimeLimit > 0 ? "内射箭,命中" : "射箭,命中" },
{ text: `${hitReq}环`, highlight: true },
{ text: "可获得能量,计时结束能量需要大于" },
{
text: `${stabilityEnergyReqPercent.value}%`,
highlight: true,
},
],
};
}
return null;
});
@@ -372,6 +555,22 @@ const practiceInfoFields = [
"blocks",
"randomBlock",
"randomRingArea",
"roundTime",
"shootTime",
"shootWindowStart",
"inShootWindow",
"scoreSlot",
"currentEnergy",
"energyCostPerSec",
"energyPerHit",
"energyReqPercent",
"deltaCurrentEnergy",
"maxEnergyPercent",
"qualifiedArrows",
"qualifiedRate",
"deltaMaxEnergyPercent",
"deltaQualifiedArrows",
"deltaQualifiedRate",
"timeLimit",
"completed",
"totalArrows",
@@ -380,13 +579,17 @@ const practiceInfoFields = [
"stability",
"maxCombo",
"totalHits",
"hitRate",
"deltaTotalHits",
"deltaDuration",
"deltaHitRate",
"deltaMaxCombo",
"deltaTotalRings",
"deltaTotalArrows",
"deltaAverageRing",
"deltaStability",
"tenRingCount",
"deltaTenRingCount",
"beforeExp",
"beforeLevel",
"currentExp",
@@ -407,14 +610,30 @@ const practiceResultFields = [
"stability",
"maxCombo",
"totalHits",
"hitRate",
"currentRings",
"scoreSlot",
"currentEnergy",
"energyCostPerSec",
"energyPerHit",
"energyReqPercent",
"deltaCurrentEnergy",
"maxEnergyPercent",
"qualifiedArrows",
"qualifiedRate",
"deltaMaxEnergyPercent",
"deltaQualifiedArrows",
"deltaQualifiedRate",
"deltaTotalHits",
"deltaDuration",
"deltaHitRate",
"deltaMaxCombo",
"deltaTotalRings",
"deltaTotalArrows",
"deltaAverageRing",
"deltaStability",
"tenRingCount",
"deltaTenRingCount",
"beforeExp",
"beforeLevel",
"currentExp",
@@ -424,7 +643,72 @@ const practiceResultFields = [
"details",
];
const cacheRhythmTrainingConfig = (message = {}) => {
const messageTrainingType = String(
message.trainingType ?? message.training_type ?? trainingType.value
).trim();
if (messageTrainingType !== "rhythm") return;
const roundTime = getPositiveInteger(
message.roundTime ?? message.round_time
);
const shootTime = getPositiveInteger(
message.shootTime ?? message.shoot_time
);
const hitReq = getPositiveInteger(message.hitReq ?? message.hit_req);
const nextConfig = {};
// 固定训练配置单独缓存,避免后续部分快照清空 practiceInfo 时丢失。
if (roundTime > 0) nextConfig.roundTime = roundTime;
if (shootTime > 0) nextConfig.shootTime = shootTime;
if (hitReq > 0) nextConfig.hitReq = hitReq;
if (Object.keys(nextConfig).length === 0) return;
trainingParams.value = {
...trainingParams.value,
...nextConfig,
};
// 开始后配置才到达时补建首轮本地锚点;已有服务端锚点时不重置。
if (
start.value &&
!rhythmHasActiveServerAnchor.value &&
!rhythmFallbackWindowStart.value &&
rhythmRoundTime.value > 0 &&
rhythmShootTime.value > 0
) {
initializeRhythmFirstRoundCountdown();
}
};
const cacheRhythmTargetArrows = (message = {}) => {
const messageTrainingType = String(
message.trainingType ?? message.training_type ?? trainingType.value
).trim();
if (messageTrainingType !== "rhythm") return;
const totalArrows = getPositiveInteger(
message.totalArrows ?? message.total_arrows
);
if (totalArrows > 0) {
rhythmTargetArrows.value = totalArrows;
return;
}
// 兼容服务端首帧 total_arrows 暂为 0:只初始化一次,避免剩余数递减时分母跟着变化。
if (rhythmTargetArrows.value === 0) {
rhythmTargetArrows.value = getPositiveInteger(
message.arrowsLeft ?? message.arrows_left
);
}
};
const syncPracticeInfo = (message = {}) => {
cacheRhythmTrainingConfig(message);
cacheRhythmTargetArrows(message);
const messageTrainingType = String(
message.trainingType ?? message.training_type ?? trainingType.value
).trim();
const nextInfo = practiceInfoFields.reduce((result, field) => {
if (Object.prototype.hasOwnProperty.call(message, field)) {
result[field] = message[field];
@@ -432,6 +716,24 @@ const syncPracticeInfo = (message = {}) => {
return result;
}, {});
const isStabilityEnergySnapshot =
messageTrainingType === "stability" &&
(Object.prototype.hasOwnProperty.call(message, "currentEnergy") ||
message.type === undefined ||
[
MESSAGETYPESV2.BattleStart,
MESSAGETYPESV2.ShootResult,
MESSAGETYPESV2.BattleEnd,
].includes(message.type));
if (isStabilityEnergySnapshot) {
// BattleStart/ShootResult/PracticeEnd/同步消息都是稳定训练完整快照。
// current_energy 为 0 时 protobuf 不编码,不能沿用上一份非零能量。
if (!Object.prototype.hasOwnProperty.call(nextInfo, "currentEnergy")) {
nextInfo.currentEnergy = 0;
}
}
const isPrecisionSnapshot =
(message.type === MESSAGETYPESV2.BattleStart ||
message.type === MESSAGETYPESV2.ShootResult) &&
@@ -476,6 +778,23 @@ const buildShootResultAudioKeys = (message = {}) => {
return getPrecisionShotAudioKeys(arrow, directionText);
};
const buildRhythmShootResultAudioKeys = (message = {}) => {
const latestDetail =
Array.isArray(message.details) && message.details.length > 0
? message.details[message.details.length - 1]
: null;
const arrow = message.shootData || latestDetail;
if (!arrow) return [];
if (
arrow.playerId !== undefined &&
arrow.playerId !== null &&
String(arrow.playerId) !== String(user.value?.id)
) {
return [];
}
return getRhythmShotAudioKeys(arrow);
};
const playAudioKeysAndWait = (keys) => {
const audioKeys = (Array.isArray(keys) ? keys : [keys]).filter(Boolean);
if (audioKeys.length === 0) return Promise.resolve();
@@ -701,6 +1020,16 @@ const onPracticeInfoSync = (payload = {}) => {
const snapshot = payload.practiceInfo;
if (!snapshot || typeof snapshot !== "object") return;
if (
start.value &&
(snapshot.trainingType === "rhythm" || isRhythmTraining.value) &&
Number(snapshot.shootWindowStart) > 0
) {
rhythmHasActiveServerAnchor.value = true;
}
if (payload.timestamp !== undefined && payload.timestamp !== null) {
rhythmServerTimestamp.value = payload.timestamp;
}
const shouldShowDistance =
waitingPracticeSync && pageStage.value === pageStages.LOADING;
@@ -1014,23 +1343,58 @@ onLoad((options = {}) => {
toRouteNumber(trainingContext.difficultyLevel)
),
recordId: options.recordId || "",
hitReq: toRouteNumber(options.hitReq),
hitReq: toRouteNumber(
options.hitReq,
toRouteNumber(trainingContext.hitReq)
),
totalReq: toRouteNumber(options.totalReq),
blocks: toRouteNumber(options.blocks),
mode: toRouteNumber(options.mode),
roundTime: toRouteNumber(
options.roundTime,
toRouteNumber(trainingContext.roundTime)
),
shootTime: toRouteNumber(
options.shootTime,
toRouteNumber(trainingContext.shootTime)
),
energyPerHit: toRouteNumber(
options.energyPerHit,
toRouteNumber(trainingContext.energyPerHit)
),
energyCostPerSec: toRouteNumber(
options.energyCostPerSec,
toRouteNumber(trainingContext.energyCostPerSec)
),
energyReqPercent: toRouteNumber(
options.energyReqPercent,
toRouteNumber(trainingContext.energyReqPercent)
),
scoreSlot: toRouteNumber(
options.scoreSlot,
toRouteNumber(trainingContext.scoreSlot)
),
};
practiseId.value = trainingContext.practiceId || "";
serverAddr.value = trainingContext.serverAddr || "";
const startAudioKey = getTrainingStartAudioKey(trainingParams.value.type);
const warmupKeys = [startAudioKey];
const warmupKeys = [startAudioKey, "胜利", "失败"];
if (trainingParams.value.type === "precision") {
warmupKeys.push("Bingo命中目标", "未命中");
} else if (trainingParams.value.type === "rhythm") {
warmupKeys.push(RHYTHM_SHOOT_WINDOW_AUDIO_KEY, "Perfect", "miss");
} else if (trainingParams.value.type === "stability") {
warmupKeys.push(
STABILITY_ENERGY_50_AUDIO_KEY,
STABILITY_ENERGY_70_AUDIO_KEY
);
}
void audioManager.warmKeys(warmupKeys.filter(Boolean));
});
const onReady = async () => {
if (practiceStarting.value) return;
if (
!practiseId.value ||
practiceEnded.value ||
@@ -1044,6 +1408,7 @@ const onReady = async () => {
return;
}
practiceStarting.value = true;
pageStage.value = pageStages.LOADING;
clearHighlightTestTimer();
useHighlightTest.value = false;
@@ -1054,9 +1419,12 @@ const onReady = async () => {
practiseResult.value = {};
scores.value = [];
shotEffectToken.value = 0;
initializeRhythmFirstRoundCountdown();
start.value = true;
pageStage.value = pageStages.SHOOTING;
setPracticeAppHideResumable(true);
// 先由本地锚点保证首轮立即显示,再用最新服务端快照无感校准。
requestPracticeInfoSync();
// 开始接口成功即进入正式训练,直接播放对应提示,避免依赖 BattleStart 消息。
audioManager.play(
getTrainingStartAudioKey(trainingType.value, "练习开始")
@@ -1066,6 +1434,8 @@ const onReady = async () => {
pageStage.value = pageStages.DISTANCE;
setPracticeAppHideResumable(true);
throw error;
} finally {
practiceStarting.value = false;
}
};
@@ -1088,6 +1458,7 @@ const enterPracticeResult = (result = {}) => {
clearPracticeRuntimeContext();
closePracticeConnection("training-practice-result");
pageStage.value = pageStages.RESULT;
audioManager.play(result.completed === true ? "胜利" : "失败");
return true;
};
@@ -1120,7 +1491,27 @@ const onOver = async () => {
async function onReceiveMessage(msg) {
const previousScoreLength = scores.value.length;
const incomingRhythmWindowStart = Number(msg.shootWindowStart);
const currentRhythmWindowStart = Number(rhythmShootWindowStart.value);
const shouldSyncRhythmAnchor =
start.value &&
isRhythmTraining.value &&
incomingRhythmWindowStart > 0 &&
(!rhythmHasActiveServerAnchor.value ||
incomingRhythmWindowStart !== currentRhythmWindowStart);
// 报靶消息的时间戳包含传输延迟,同一轮内不重复校时,避免秒数回跳。
if (
shouldSyncRhythmAnchor &&
msg.timestamp !== undefined &&
msg.timestamp !== null
) {
rhythmServerTimestamp.value = msg.timestamp;
}
syncPracticeInfo(msg);
if (shouldSyncRhythmAnchor) {
rhythmHasActiveServerAnchor.value = true;
}
if (msg.type === MESSAGETYPESV2.BattleStart) {
invalidateShotPresentations();
@@ -1159,6 +1550,38 @@ async function onReceiveMessage(msg) {
audioPromise,
effectPromise,
});
} else if (trainingType.value === "rhythm") {
const audioKeys = buildRhythmShootResultAudioKeys(msg);
if (audioKeys.length > 0) {
audioManager.play(audioKeys, false);
}
if (hasNewShot) {
shotEffectToken.value += 1;
}
} else if (trainingType.value === "stability") {
const hasStabilityShot =
msg.stabilityHasNewShot === true || hasNewShot;
const latestDetail =
Array.isArray(msg.details) && msg.details.length > 0
? msg.details[msg.details.length - 1]
: null;
const arrow = msg.shootData || latestDetail;
const audioKeys = hasStabilityShot
? getStabilityShotAudioKeys(arrow)
: [];
const milestoneAudioKey = String(
msg.stabilityMilestoneAudioKey || ""
).trim();
// WebSocket 管理器负责阈值判定并把同一语音 key 用于 ACK;这里按
// 环数/最高跨越阈值的顺序一次入队。
if (milestoneAudioKey) audioKeys.push(milestoneAudioKey);
if (audioKeys.length > 0) {
audioManager.play(audioKeys, false);
}
if (hasStabilityShot) {
shotEffectToken.value += 1;
}
} else if (hasNewShot) {
shotEffectToken.value += 1;
}
@@ -1205,6 +1628,11 @@ async function onRetry() {
practiseResult.value = {};
practiceEndSnapshot.value = {};
practiceInfo.value = {};
rhythmServerTimestamp.value = 0;
rhythmFallbackWindowStart.value = 0;
rhythmFallbackTimestamp.value = 0;
rhythmHasActiveServerAnchor.value = false;
rhythmTargetArrows.value = 0;
invalidateShotPresentations({ resetVisible: true });
start.value = false;
scores.value = [];
@@ -1327,11 +1755,27 @@ onBeforeUnmount(() => {
:showBottom="isDistanceStage"
:scroll="!isShootingStage"
:onBack="exitPractice"
:title="
isShootingStage
? isRhythmTraining
? '节奏训练'
: isStabilityTraining
? '稳定训练'
: ''
: ''
"
:titleStyle="
isShootingStage && (isRhythmTraining || isStabilityTraining)
? rhythmHeaderTitleStyle
: {}
"
>
<view class="practise-content">
<TestDistance
v-if="isDistanceStage"
:targetType="practiceInfo.targetType"
:targetType="simulatorTargetType"
:autoStart="true"
@passed="onReady"
/>
<view v-else-if="isShootingStage" class="shooting-layout">
<view class="shooting-fixed">
@@ -1340,9 +1784,21 @@ onBeforeUnmount(() => {
:total="timeLimit"
:countdownEnabled="hasTimeLimit"
:trainingType="trainingType"
:roundTime="rhythmRoundTime"
:shootTime="rhythmShootTime"
:shootWindowStart="rhythmShootWindowStart"
:inShootWindow="rhythmInShootWindow"
:serverTimestamp="rhythmCountdownTimestamp"
:hitReq="rhythmHitReq"
:energyPercent="stabilityEnergyPercent"
:energyReqPercent="stabilityEnergyReqPercent"
:isVip="isVip"
:isSvip="isSvip"
:externalShootResultAudio="trainingType === 'precision'"
:externalShootResultAudio="
trainingType === 'precision' ||
trainingType === 'rhythm' ||
trainingType === 'stability'
"
:onStop="onTimeLimitReached"
/>
<view class="user-row">
@@ -1358,6 +1814,7 @@ onBeforeUnmount(() => {
:currentRound="scores.length % 3"
:scores="scores"
:isSvip="isSvip"
:targetType="simulatorTargetType"
:shotEffectToken="shotEffectToken"
:showCrosshair="false"
:sectorCount="precisionBlocks"
+17 -1
View File
@@ -4,6 +4,7 @@ import Container from "@/components/Container.vue";
import UserHeader from "@/components/UserHeader.vue";
import UserItem from "@/components/UserItem.vue";
import Avatar from "@/components/Avatar.vue";
import { getMyGoldAPI } from "@/apis";
import { canEenter } from "@/util";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -29,6 +30,16 @@ const toCoinPage = () => {
url: "/pages/coin/nearby-stores",
});
};
const showCoinEntry = ref(false);
const loadCoinEntryVisibility = async () => {
showCoinEntry.value = false;
try {
const result = await getMyGoldAPI();
showCoinEntry.value = result?.hasTempBind === true;
} catch (error) {
console.error("加载金币入口状态失败", error);
}
};
const toBeVipPage = () => {
uni.navigateTo({
url: "/pages/member/be-vip",
@@ -74,6 +85,7 @@ const logout = () => {
updateUser();
};
onMounted(() => {
loadCoinEntryVisibility();
const accountInfo = uni.getAccountInfoSync();
const envVersion = accountInfo.miniProgram.envVersion;
if (envVersion !== "release") showLogout.value = true;
@@ -113,7 +125,11 @@ const buildVersion = typeof __BUILD_TIME__ !== 'undefined' ? __BUILD_TIME__ : ''
<text v-if="user.trio > 0" :style="{ color: '#259249' }">已完成</text>
<text v-else :style="{ color: '#CC311F' }">未完成</text>
</UserItem>
<UserItem title="我的金币" :onClick="toCoinPage" />
<UserItem
v-if="showCoinEntry"
title="我的金币"
:onClick="toCoinPage"
/>
<UserItem title="会员" :onClick="toBeVipPage">
<view
v-if="user.sVip === true"
Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 B

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

+1 -1
View File
File diff suppressed because one or more lines are too long
+12 -2
View File
@@ -7,8 +7,8 @@ const { Reader, Writer } = protobuf;
// 所以这里使用 minimal Reader/Writer 做静态字段解码和客户端消息编码。
// <match-schema-generated>
// 此区块由 scripts/generate-match-schema.mjs 自动生成,请勿手动修改。
// 来源:src/utils/match.min.js(sha256: a7ab92ae43e405e7)
// 协议命名空间:rpc;消息数:12;字段数:153
// 来源:src/utils/match.min.js(sha256: bece92f31bde3072)
// 协议命名空间:rpc;消息数:12;字段数:163
export const ServerMessageType = {
SERVER_MSG_UNKNOWN: 0,
@@ -196,6 +196,16 @@ const SCHEMAS = {
51: { name: "shoot_window_start", kind: "int64" },
52: { name: "in_shoot_window", kind: "bool" },
53: { name: "shoot_time", kind: "int32" },
54: { name: "ten_ring_count", kind: "int32" },
55: { name: "delta_ten_ring_count", kind: "int32" },
56: { name: "max_energy_percent", kind: "int32" },
57: { name: "qualified_arrows", kind: "int32" },
58: { name: "qualified_rate", kind: "int32" },
59: { name: "delta_max_energy_percent", kind: "int32" },
60: { name: "delta_qualified_arrows", kind: "int32" },
61: { name: "delta_qualified_rate", kind: "int32" },
62: { name: "hit_rate", kind: "int32" },
63: { name: "delta_hit_rate", kind: "int32" },
},
MatchInfo: {
1: { name: "match_id", kind: "string" },