练习结果完善

This commit is contained in:
kron
2025-05-31 14:57:25 +08:00
parent 22617212d0
commit 2a2dddfc11
6 changed files with 57 additions and 24 deletions

View File

@@ -27,11 +27,14 @@ const stepButtonTexts = [
"",
"退出新手试炼",
];
const start = ref(false);
const practiseResult = ref({});
const power = ref(0);
const onReady = async () => {
const result = await createPractiseAPI(total);
const token = uni.getStorageSync("token");
start.value = true;
websocket.createWebSocket(token, (content) => {
const messages = JSON.parse(content).data.updates || [];
messages.forEach((msg) => {
@@ -39,9 +42,14 @@ const onReady = async () => {
scores.value.push(msg.target);
if (scores.value.length === total) {
showScore.value = true;
websocket.closeWebSocket();
}
}
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
practiseResult.value = {
...msg.practice,
arrows: JSON.parse(msg.practice.arrows),
};
}
});
});
};
@@ -144,11 +152,11 @@ const onClose = () => {
v-if="step === 4"
tips="请开始连续射箭"
:total="100"
:start="true"
:start="start"
/>
<BowTarget
:avatar="user.avatarUrl"
:power="45"
:power="power"
:debug="step === 2"
v-if="step === 2 || step === 4"
:tips="step === 4 ? '' : '本次射程5.2米,已达到距离要求'"
@@ -166,7 +174,7 @@ const onClose = () => {
:show="showScore"
v-if="step === 4"
:onClose="onClose"
:scores="scores.map((s) => s.ring)"
:result="practiseResult"
/>
<SButton v-if="step !== 4" :onClick="nextStep">{{
stepButtonTexts[step]

View File

@@ -14,6 +14,8 @@ const start = ref(false);
const showScore = ref(false);
const scores = ref([]);
const total = 12;
const practiseResult = ref({});
const power = ref(0);
const onReady = async () => {
const result = await createPractiseAPI(total);
@@ -25,11 +27,17 @@ const onReady = async () => {
messages.forEach((msg) => {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
scores.value.push(msg.target);
power.value = msg.target.battery;
if (scores.value.length === total) {
showScore.value = true;
websocket.closeWebSocket();
}
}
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
practiseResult.value = {
...msg.practice,
arrows: JSON.parse(msg.practice.arrows),
};
}
});
});
};
@@ -58,7 +66,7 @@ onUnmounted(() => {
:totalRound="total"
:currentRound="scores.length + 1"
avatar="../static/avatar.png"
:power="45"
:power="power"
:scores="scores"
/>
<ScorePanel2 v-if="start" :scores="scores.map((s) => s.ring)" />
@@ -67,7 +75,7 @@ onUnmounted(() => {
:rowCount="6"
:show="showScore"
:onClose="() => (showScore = false)"
:scores="scores.map((s) => s.ring)"
:result="practiseResult"
/>
<SButton v-if="!start" :onClick="onReady">准备好了直接开始</SButton>
</view>

View File

@@ -14,6 +14,8 @@ const start = ref(false);
const showScore = ref(false);
const scores = ref([]);
const total = 36;
const practiseResult = ref({});
const power = ref(0);
const onReady = async () => {
const result = await createPractiseAPI(total);
@@ -27,9 +29,14 @@ const onReady = async () => {
scores.value.push(msg.target);
if (scores.value.length === total) {
showScore.value = true;
websocket.closeWebSocket();
}
}
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
practiseResult.value = {
...msg.practice,
arrows: JSON.parse(msg.practice.arrows),
};
}
});
});
};
@@ -41,14 +48,14 @@ onUnmounted(() => {
<template>
<view class="container">
<AppBackground type="1" />
<AppBackground :type="1" />
<Header title="个人耐力挑战" />
<ShootProgress :tips="`请连续射箭${total}支`" total="120" />
<ShootProgress :tips="`请连续射箭${total}支`" :total="120" />
<BowTarget
:totalRound="total"
:currentRound="scores.length + 1"
avatar="../static/avatar.png"
:power="45"
:power="power"
:scores="scores"
/>
<ScorePanel
@@ -62,7 +69,7 @@ onUnmounted(() => {
:rowCount="9"
:show="showScore"
:onClose="() => (showScore = false)"
:scores="scores.map((s) => s.ring)"
:result="practiseResult"
/>
<SButton v-if="!start" :onClick="onReady">准备好了直接开始</SButton>
</view>