完成新手试炼接口调试

This commit is contained in:
kron
2025-05-30 13:58:43 +08:00
parent 57b25e7805
commit 01a327e40e
9 changed files with 74 additions and 29 deletions

View File

@@ -44,7 +44,7 @@ function calcRealY(num) {
<template> <template>
<view class="container"> <view class="container">
<view class="header"> <view class="header">
<!-- <text v-if="debug" class="header-tips">大人请射箭</text> --> <text v-if="debug" class="header-tips">大人请射箭</text>
<text v-if="totalRound > 0" class="round-count">{{ <text v-if="totalRound > 0" class="round-count">{{
currentRound + "/" + totalRound currentRound + "/" + totalRound
}}</text> }}</text>
@@ -77,7 +77,6 @@ function calcRealY(num) {
} }
.target { .target {
position: relative; position: relative;
overflow: hidden;
} }
.target > image:last-child { .target > image:last-child {
width: 100%; width: 100%;
@@ -104,6 +103,7 @@ function calcRealY(num) {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
margin-bottom: 20px;
} }
.header > image:first-child { .header > image:first-child {
width: 40px; width: 40px;
@@ -127,6 +127,7 @@ function calcRealY(num) {
.footer > image { .footer > image {
width: 40px; width: 40px;
height: 40px; height: 40px;
border-radius: 50%;
} }
.container > text { .container > text {
width: 100%; width: 100%;

View File

@@ -13,7 +13,7 @@ const toBattleRoom = () => {
}; };
</script> </script>
<template> <template>
<view v-if="!warnning" class="container"> <view class="container">
<image <image
v-if="step === 1" v-if="step === 1"
src="../static/choose-battle-mode.png" src="../static/choose-battle-mode.png"

View File

@@ -13,9 +13,7 @@ import PlayersRow from "@/components/PlayersRow.vue";
const step = ref(1); const step = ref(1);
const seats = new Array(10).fill(1); const seats = new Array(10).fill(1);
const players = new Array(7).fill(1); const players = new Array(7).fill(1);
const teams = [ const teams = [{ name: "选手1", avatar: "../static/avatar.png" }];
{ name: "选手1", avatar: "../static/avatar.png" },
];
</script> </script>
<template> <template>
@@ -61,7 +59,7 @@ const teams = [
<text :style="{ color: '#fed847' }">请预先射几箭测试</text> <text :style="{ color: '#fed847' }">请预先射几箭测试</text>
<text>请确保射击距离只有5米</text> <text>请确保射击距离只有5米</text>
</view> </view>
<BowPower power="45" /> <BowPower :power="45" />
</view> </view>
</Guide> </Guide>
<BowTarget tips="本次射程5.2米,已达距离要求" /> <BowTarget tips="本次射程5.2米,已达距离要求" />
@@ -70,7 +68,7 @@ const teams = [
<view v-if="step === 3"> <view v-if="step === 3">
<ShootProgress tips="请红队射箭-第一轮" /> <ShootProgress tips="请红队射箭-第一轮" />
<PlayersRow :blueTeam="teams" :redTeam="teams" /> <PlayersRow :blueTeam="teams" :redTeam="teams" />
<BowTarget power="45" currentRound="1" totalRound="3" debug /> <BowTarget :power="45" currentRound="1" totalRound="3" debug />
<BattleFooter :blueTeam="[6, 2, 3]" :redTeam="[4, 5, 2]" /> <BattleFooter :blueTeam="[6, 2, 3]" :redTeam="[4, 5, 2]" />
</view> </view>
</view> </view>

View File

@@ -12,7 +12,7 @@ const getMyDevice = async () => {
</script> </script>
<template> <template>
<Container bgType="1" title="弓箭调试"> <Container :bgType="1" title="弓箭调试">
<!-- <Guide> <!-- <Guide>
<view class="guide-tips"> <view class="guide-tips">
<text>请预先射几箭测试</text> <text>请预先射几箭测试</text>

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref } from "vue"; import { ref, onUnmounted } from "vue";
import Guide from "@/components/Guide.vue"; import Guide from "@/components/Guide.vue";
import SButton from "@/components/SButton.vue"; import SButton from "@/components/SButton.vue";
import Swiper from "@/components/Swiper.vue"; import Swiper from "@/components/Swiper.vue";
@@ -8,8 +8,17 @@ import ShootProgress from "@/components/ShootProgress.vue";
import ScoreResult from "@/components/ScoreResult.vue"; import ScoreResult from "@/components/ScoreResult.vue";
import ScorePanel from "@/components/ScorePanel.vue"; import ScorePanel from "@/components/ScorePanel.vue";
import Container from "@/components/Container.vue"; import Container from "@/components/Container.vue";
const scores = ref(new Array(10).fill(9)); import { createPractiseAPI } from "@/apis";
import { MESSAGETYPES } from "@/constants";
import websocket from "@/websocket";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const scores = ref([]);
const step = ref(0); const step = ref(0);
const showScore = ref(false);
const total = 12;
const stepButtonTexts = [ const stepButtonTexts = [
"开始", "开始",
"进入下一个任务", "进入下一个任务",
@@ -18,6 +27,29 @@ const stepButtonTexts = [
"", "",
"退出新手试炼", "退出新手试炼",
]; ];
const onReady = async () => {
const result = await createPractiseAPI(total);
const token = uni.getStorageSync("token");
websocket.createWebSocket(token, (content) => {
const messages = JSON.parse(content).data.updates || [];
messages.forEach((msg) => {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
scores.value.push(msg.target);
if (scores.value.length === total) {
showScore.value = true;
websocket.closeWebSocket();
}
}
});
});
};
onUnmounted(() => {
websocket.closeWebSocket();
});
const nextStep = () => { const nextStep = () => {
if (step.value === 0) { if (step.value === 0) {
step.value = 1; step.value = 1;
@@ -27,18 +59,17 @@ const nextStep = () => {
step.value = 3; step.value = 3;
} else if (step.value === 3) { } else if (step.value === 3) {
step.value = 4; step.value = 4;
onReady();
} else if (step.value === 5) { } else if (step.value === 5) {
uni.navigateBack({ uni.navigateBack({
delta: 1, delta: 1,
}); });
} }
}; };
const showScore = ref(false);
setTimeout(() => {
showScore.value = true;
}, 1000);
const onClose = () => { const onClose = () => {
showScore.value = false; showScore.value = false;
websocket.closeWebSocket();
setTimeout(() => { setTimeout(() => {
step.value = 5; step.value = 5;
}, 500); }, 500);
@@ -46,10 +77,10 @@ const onClose = () => {
</script> </script>
<template> <template>
<Container bgType="1" title="新手试炼场"> <Container :bgType="1" title="新手试炼场">
<Guide v-if="step !== 4" :tall="step === 2 || step === 5"> <Guide v-if="step !== 4" :tall="step === 2 || step === 5">
<text v-if="step === 0"> <text v-if="step === 0">
hi<text :style="{ color: '#fed847' }">Rocker</text> hi<text :style="{ color: '#fed847' }">{{ user.nickName }}</text>
这是新人必刷小任务0基础小白也能快速掌握弓箭技巧和游戏规则哦~ 这是新人必刷小任务0基础小白也能快速掌握弓箭技巧和游戏规则哦~
</text> </text>
<text v-if="step === 1" <text v-if="step === 1"
@@ -109,21 +140,33 @@ const onClose = () => {
]" ]"
/> />
</view> </view>
<ShootProgress v-if="step === 4" tips="请开始连续射箭" total="10" /> <ShootProgress
v-if="step === 4"
tips="请开始连续射箭"
:total="100"
:start="true"
/>
<BowTarget <BowTarget
avatar="../static/avatar.png" :avatar="user.avatarUrl"
power="45" :power="45"
:debug="step === 2" :debug="step === 2"
v-if="step === 2 || step === 4" v-if="step === 2 || step === 4"
:tips="step === 4 ? '' : '本次射程5.2米,已达到距离要求'" :tips="step === 4 ? '' : '本次射程5.2米,已达到距离要求'"
:scores="scores"
/>
<ScorePanel
v-if="step === 4"
:total="total"
:rowCount="6"
:scores="scores.map((s) => s.ring)"
/> />
<ScorePanel v-if="step === 4" :scores="scores" :total="12" :rowCount="6" />
<ScoreResult <ScoreResult
:total="12" :total="total"
:rowCount="6" :rowCount="6"
:show="showScore" :show="showScore"
v-if="step === 4" v-if="step === 4"
:onClose="onClose" :onClose="onClose"
:scores="scores.map((s) => s.ring)"
/> />
<SButton v-if="step !== 4" :onClick="nextStep">{{ <SButton v-if="step !== 4" :onClick="nextStep">{{
stepButtonTexts[step] stepButtonTexts[step]

View File

@@ -19,7 +19,7 @@ const teams = [
<view> <view>
<ShootProgress tips="请红队射箭-第一轮" /> <ShootProgress tips="请红队射箭-第一轮" />
<PlayersRow :blueTeam="teams" :redTeam="teams" /> <PlayersRow :blueTeam="teams" :redTeam="teams" />
<BowTarget power="45" currentRound="1" totalRound="3" debug /> <BowTarget :power="45" currentRound="1" totalRound="3" debug />
<PlayerScore <PlayerScore
name="某某选手" name="某某选手"
avatar="../static/avatar.png" avatar="../static/avatar.png"

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref, onMounted, onUnmounted } from "vue"; import { ref, onUnmounted } from "vue";
import AppBackground from "@/components/AppBackground.vue"; import AppBackground from "@/components/AppBackground.vue";
import Header from "@/components/Header.vue"; import Header from "@/components/Header.vue";
import ShootProgress from "@/components/ShootProgress.vue"; import ShootProgress from "@/components/ShootProgress.vue";
@@ -20,8 +20,8 @@ const onReady = async () => {
start.value = true; start.value = true;
const token = uni.getStorageSync("token"); const token = uni.getStorageSync("token");
websocket.createWebSocket(token, (result) => { websocket.createWebSocket(token, (content) => {
const messages = JSON.parse(result).data.updates || []; const messages = JSON.parse(content).data.updates || [];
messages.forEach((msg) => { messages.forEach((msg) => {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) { if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
scores.value.push(msg.target); scores.value.push(msg.target);

View File

@@ -20,8 +20,8 @@ const onReady = async () => {
start.value = true; start.value = true;
const token = uni.getStorageSync("token"); const token = uni.getStorageSync("token");
websocket.createWebSocket(token, (result) => { websocket.createWebSocket(token, (content) => {
const messages = JSON.parse(result).data.updates || []; const messages = JSON.parse(content).data.updates || [];
messages.forEach((msg) => { messages.forEach((msg) => {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) { if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
scores.value.push(msg.target); scores.value.push(msg.target);

View File

@@ -30,7 +30,10 @@ function createWebSocket(token, onMessage) {
} }
function closeWebSocket() { function closeWebSocket() {
if (socket) socket.close(); if (socket) {
socket.close();
stopHeartbeat();
}
} }
/** /**