update:代码备份
This commit is contained in:
@@ -69,6 +69,18 @@ const props = defineProps({
|
|||||||
src="@/static/app-bg7.png"
|
src="@/static/app-bg7.png"
|
||||||
mode="widthFix"
|
mode="widthFix"
|
||||||
/>
|
/>
|
||||||
|
<image
|
||||||
|
class="bg-image"
|
||||||
|
v-if="type === 9"
|
||||||
|
src="@/static/app-bg8.png"
|
||||||
|
mode="widthFix"
|
||||||
|
/>
|
||||||
|
<image
|
||||||
|
class="bg-image"
|
||||||
|
v-if="type === 10"
|
||||||
|
src="@/static/app-bg9.png"
|
||||||
|
mode="widthFix"
|
||||||
|
/>
|
||||||
<view class="bg-overlay" v-if="type === 0"></view>
|
<view class="bg-overlay" v-if="type === 0"></view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -117,13 +117,16 @@
|
|||||||
{
|
{
|
||||||
"path": "pages/mine-bow-data"
|
"path": "pages/mine-bow-data"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/training/difficulty"
|
"path": "pages/training/difficulty"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/training/index"
|
"path": "pages/training/index"
|
||||||
}
|
},
|
||||||
],
|
{
|
||||||
|
"path": "pages/training/practise-one"
|
||||||
|
}
|
||||||
|
],
|
||||||
"globalStyle": {
|
"globalStyle": {
|
||||||
"backgroundColor": "@bgColor",
|
"backgroundColor": "@bgColor",
|
||||||
"backgroundColorBottom": "@bgColorBottom",
|
"backgroundColorBottom": "@bgColorBottom",
|
||||||
|
|||||||
456
src/pages/training/components/BowTarget.vue
Normal file
456
src/pages/training/components/BowTarget.vue
Normal file
@@ -0,0 +1,456 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref, watch, onMounted, onBeforeUnmount, computed } from "vue";
|
||||||
|
import PointSwitcher from "@/components/PointSwitcher.vue";
|
||||||
|
|
||||||
|
import { MESSAGETYPES, MESSAGETYPESV2 } from "@/constants";
|
||||||
|
import { simulShootAPI } from "@/apis";
|
||||||
|
import useStore from "@/store";
|
||||||
|
import { storeToRefs } from "pinia";
|
||||||
|
const store = useStore();
|
||||||
|
const { user, device } = storeToRefs(store);
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
currentRound: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
totalRound: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
scores: {
|
||||||
|
type: Array,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
blueScores: {
|
||||||
|
type: Array,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: "solo", // solo 单排,team 双排
|
||||||
|
},
|
||||||
|
stop: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const pMode = ref(true);
|
||||||
|
const latestOne = ref(null);
|
||||||
|
const bluelatestOne = ref(null);
|
||||||
|
const prevScores = ref([]);
|
||||||
|
const prevBlueScores = ref([]);
|
||||||
|
const timer = ref(null);
|
||||||
|
const dirTimer = ref(null);
|
||||||
|
const angle = ref(null);
|
||||||
|
const circleColor = ref("");
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.scores,
|
||||||
|
(newVal) => {
|
||||||
|
if (newVal.length - prevScores.value.length === 1) {
|
||||||
|
latestOne.value = newVal[newVal.length - 1];
|
||||||
|
if (timer.value) clearTimeout(timer.value);
|
||||||
|
timer.value = setTimeout(() => {
|
||||||
|
latestOne.value = null;
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
prevScores.value = [...newVal];
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deep: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.blueScores,
|
||||||
|
(newVal) => {
|
||||||
|
if (newVal.length - prevBlueScores.value.length === 1) {
|
||||||
|
bluelatestOne.value = newVal[newVal.length - 1];
|
||||||
|
if (timer.value) clearTimeout(timer.value);
|
||||||
|
timer.value = setTimeout(() => {
|
||||||
|
bluelatestOne.value = null;
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
prevBlueScores.value = [...newVal];
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deep: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
function calcRealX(num, offset = 3.4) {
|
||||||
|
const len = 20.4 + num;
|
||||||
|
return `calc(${(len / 40.8) * 100 - offset / 2}%)`;
|
||||||
|
}
|
||||||
|
function calcRealY(num, offset = 3.4) {
|
||||||
|
const len = num < 0 ? Math.abs(num) + 20.4 : 20.4 - num;
|
||||||
|
return `calc(${(len / 40.8) * 100 - offset / 2}%)`;
|
||||||
|
}
|
||||||
|
const simulShoot = async () => {
|
||||||
|
if (device.value.deviceId) await simulShootAPI(device.value.deviceId);
|
||||||
|
};
|
||||||
|
const simulShoot2 = async () => {
|
||||||
|
if (device.value.deviceId) {
|
||||||
|
const r1 = Math.random() > 0.5 ? 0.01 : 0.02;
|
||||||
|
await simulShootAPI(device.value.deviceId, r1, r1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const env = computed(() => {
|
||||||
|
const accountInfo = uni.getAccountInfoSync();
|
||||||
|
return accountInfo.miniProgram.envVersion;
|
||||||
|
});
|
||||||
|
|
||||||
|
const arrowStyle = computed(() => {
|
||||||
|
return {
|
||||||
|
transform: `rotateX(180deg) translate(-50%, -50%) rotate(${
|
||||||
|
360 - angle.value
|
||||||
|
}deg) translateY(105%)`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
async function onReceiveMessage(message) {
|
||||||
|
if (Array.isArray(message)) return;
|
||||||
|
if (message.type === MESSAGETYPESV2.ShootResult && message.shootData) {
|
||||||
|
if (
|
||||||
|
message.shootData.playerId === user.value.id &&
|
||||||
|
!message.shootData.ring &&
|
||||||
|
message.shootData.angle >= 0
|
||||||
|
) {
|
||||||
|
angle.value = null;
|
||||||
|
setTimeout(() => {
|
||||||
|
if (props.scores[0]) {
|
||||||
|
circleColor.value =
|
||||||
|
message.shootData.playerId === props.scores[0].playerId
|
||||||
|
? "#ff4444"
|
||||||
|
: "#1840FF";
|
||||||
|
}
|
||||||
|
angle.value = message.shootData.angle;
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
uni.$on("socket-inbox", onReceiveMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (timer.value) {
|
||||||
|
clearTimeout(timer.value);
|
||||||
|
timer.value = null;
|
||||||
|
}
|
||||||
|
if (dirTimer.value) {
|
||||||
|
clearTimeout(dirTimer.value);
|
||||||
|
dirTimer.value = null;
|
||||||
|
}
|
||||||
|
uni.$off("socket-inbox", onReceiveMessage);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<view class="container">
|
||||||
|
<!-- <view class="header" v-if="totalRound > 0">
|
||||||
|
<text v-if="totalRound > 0" class="round-count">{{
|
||||||
|
(currentRound > totalRound ? totalRound : currentRound) +
|
||||||
|
"/" +
|
||||||
|
totalRound
|
||||||
|
}}</text>
|
||||||
|
</view> -->
|
||||||
|
<view class="target">
|
||||||
|
<view v-if="angle !== null" class="arrow-dir" :style="arrowStyle">
|
||||||
|
<view :style="{ background: circleColor }">
|
||||||
|
<image src="../../../static/dot-circle.png" mode="widthFix" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view v-if="stop" class="stop-sign">中场休息</view>
|
||||||
|
<view
|
||||||
|
v-if="latestOne && latestOne.ring && user.id === latestOne.playerId"
|
||||||
|
class="e-value fade-in-out"
|
||||||
|
:style="{
|
||||||
|
left: calcRealX(latestOne.ring ? latestOne.x : 0, 20),
|
||||||
|
top: calcRealY(latestOne.ring ? latestOne.y : 0, 40),
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
经验 +1
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
v-if="latestOne"
|
||||||
|
class="round-tip fade-in-out"
|
||||||
|
:style="{
|
||||||
|
left: calcRealX(latestOne.ring ? latestOne.x : 0, 28),
|
||||||
|
top: calcRealY(latestOne.ring ? latestOne.y : 0, 28),
|
||||||
|
}"
|
||||||
|
>{{ latestOne.ringX ? "X" : latestOne.ring || "未上靶"
|
||||||
|
}}<text v-if="latestOne.ring">环</text>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
v-if="
|
||||||
|
bluelatestOne &&
|
||||||
|
bluelatestOne.ring &&
|
||||||
|
user.id === bluelatestOne.playerId
|
||||||
|
"
|
||||||
|
class="e-value fade-in-out"
|
||||||
|
:style="{
|
||||||
|
left: calcRealX(bluelatestOne.ring ? bluelatestOne.x : 0, 20),
|
||||||
|
top: calcRealY(bluelatestOne.ring ? bluelatestOne.y : 0, 40),
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
经验 +1
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
v-if="bluelatestOne"
|
||||||
|
class="round-tip fade-in-out"
|
||||||
|
:style="{
|
||||||
|
left: calcRealX(bluelatestOne.ring ? bluelatestOne.x : 0, 28),
|
||||||
|
top: calcRealY(bluelatestOne.ring ? bluelatestOne.y : 0, 28),
|
||||||
|
}"
|
||||||
|
>{{ bluelatestOne.ringX ? "X" : bluelatestOne.ring || "未上靶"
|
||||||
|
}}<text v-if="bluelatestOne.ring">环</text></view
|
||||||
|
>
|
||||||
|
<block v-for="(bow, index) in scores" :key="index">
|
||||||
|
<view
|
||||||
|
v-if="bow.ring > 0"
|
||||||
|
:class="`hit ${pMode ? 'b' : 's'}-point ${
|
||||||
|
index === scores.length - 1 && latestOne ? 'pump-in' : ''
|
||||||
|
}`"
|
||||||
|
:style="{
|
||||||
|
left: calcRealX(bow.x, pMode ? '3.4' : '2'),
|
||||||
|
top: calcRealY(bow.y, pMode ? '3.4' : '2'),
|
||||||
|
backgroundColor: mode === 'solo' ? '#00bf04' : '#FF0000',
|
||||||
|
}"
|
||||||
|
><text v-if="pMode">{{ index + 1 }}</text></view
|
||||||
|
>
|
||||||
|
</block>
|
||||||
|
<block v-for="(bow, index) in blueScores" :key="index">
|
||||||
|
<view
|
||||||
|
v-if="bow.ring > 0"
|
||||||
|
:class="`hit ${pMode ? 'b' : 's'}-point ${
|
||||||
|
index === blueScores.length - 1 && bluelatestOne ? 'pump-in' : ''
|
||||||
|
}`"
|
||||||
|
:style="{
|
||||||
|
left: calcRealX(bow.x, pMode ? '3.4' : '2'),
|
||||||
|
top: calcRealY(bow.y, pMode ? '3.4' : '2'),
|
||||||
|
backgroundColor: '#1840FF',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<text v-if="pMode">{{ index + 1 }}</text>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
<image src="../../../static/bow-target.png" mode="widthFix" />
|
||||||
|
</view>
|
||||||
|
<view class="footer">
|
||||||
|
<PointSwitcher
|
||||||
|
:onChange="(val) => (pMode = val)"
|
||||||
|
:style="{ zIndex: 999 }"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
<view class="simul" v-if="env !== 'release'">
|
||||||
|
<button @click="simulShoot">模拟</button>
|
||||||
|
<button @click="simulShoot2">射箭</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.container {
|
||||||
|
width: calc(100vw - 30px);
|
||||||
|
height: calc(100vw - 30px);
|
||||||
|
padding: 0px 15px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.target {
|
||||||
|
position: relative;
|
||||||
|
margin: 10px;
|
||||||
|
width: calc(100% - 20px);
|
||||||
|
height: calc(100% - 20px);
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
.e-value {
|
||||||
|
position: absolute;
|
||||||
|
background-color: #0006;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 4px 7px;
|
||||||
|
border-radius: 5px;
|
||||||
|
z-index: 2;
|
||||||
|
width: 50px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.round-tip {
|
||||||
|
position: absolute;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 30px;
|
||||||
|
font-weight: bold;
|
||||||
|
z-index: 2;
|
||||||
|
width: 100px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.round-tip > text {
|
||||||
|
font-size: 24px;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
.target > image:last-child {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.hit {
|
||||||
|
position: absolute;
|
||||||
|
border-radius: 50%;
|
||||||
|
z-index: 1;
|
||||||
|
color: #fff;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
.s-point {
|
||||||
|
width: 4px;
|
||||||
|
height: 4px;
|
||||||
|
min-width: 4px;
|
||||||
|
min-height: 4px;
|
||||||
|
}
|
||||||
|
.b-point {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
min-width: 10px;
|
||||||
|
min-height: 10px;
|
||||||
|
border: 1px solid #fff;
|
||||||
|
z-index: 1;
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.b-point > text {
|
||||||
|
font-size: 16rpx;
|
||||||
|
color: #fff;
|
||||||
|
font-family: "DINCondensed";
|
||||||
|
/* text-align: center;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);*/
|
||||||
|
margin-top: 2rpx;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: -40px;
|
||||||
|
}
|
||||||
|
.header > image:first-child {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
.round-count {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #fed847;
|
||||||
|
top: 75px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.footer {
|
||||||
|
width: calc(100% - 20px);
|
||||||
|
padding: 0 10px;
|
||||||
|
display: flex;
|
||||||
|
margin-top: -40px;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
.footer > image {
|
||||||
|
width: 40px;
|
||||||
|
min-height: 40px;
|
||||||
|
max-height: 40px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 1px solid #fff;
|
||||||
|
}
|
||||||
|
.simul {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 20px;
|
||||||
|
margin-left: 20px;
|
||||||
|
z-index: 999;
|
||||||
|
}
|
||||||
|
.simul > button {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.stop-sign {
|
||||||
|
position: absolute;
|
||||||
|
font-size: 44px;
|
||||||
|
color: #fff9;
|
||||||
|
text-align: center;
|
||||||
|
width: 200px;
|
||||||
|
height: 60px;
|
||||||
|
left: calc(50% - 100px);
|
||||||
|
top: calc(50% - 30px);
|
||||||
|
z-index: 99;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.arrow-dir {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 52%;
|
||||||
|
left: 50%;
|
||||||
|
bottom: 50%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.arrow-dir > view {
|
||||||
|
width: 40rpx;
|
||||||
|
height: 40rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.arrow-dir > view > image {
|
||||||
|
width: 100rpx;
|
||||||
|
height: 100rpx;
|
||||||
|
transform: translate(-30%, -30%);
|
||||||
|
}
|
||||||
|
@keyframes spring-in {
|
||||||
|
0% {
|
||||||
|
transform: scale(2);
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
15% {
|
||||||
|
transform: scale(3);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
30% {
|
||||||
|
transform: scale(2);
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
45% {
|
||||||
|
transform: scale(3);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
60% {
|
||||||
|
transform: scale(2);
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
75% {
|
||||||
|
transform: scale(3);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: scale(1);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes disappear {
|
||||||
|
0% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
75% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.arrow-dir > view {
|
||||||
|
animation: disappear 3s ease forwards;
|
||||||
|
}
|
||||||
|
.arrow-dir > view > image {
|
||||||
|
animation: spring-in 3s ease forwards;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
62
src/pages/training/components/BubbleTip.vue
Normal file
62
src/pages/training/components/BubbleTip.vue
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<script setup>
|
||||||
|
const props = defineProps({
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: "normal",
|
||||||
|
},
|
||||||
|
location: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<view :class="`container ${type}`" :style="{ ...location }">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.container {
|
||||||
|
position: absolute;
|
||||||
|
color: #fff;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background-size: contain;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
font-size: 24rpx;
|
||||||
|
}
|
||||||
|
.normal {
|
||||||
|
background-image: url("../static/bubble-tip.png");
|
||||||
|
width: 157rpx;
|
||||||
|
height: 105rpx;
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-left: 30rpx;
|
||||||
|
}
|
||||||
|
.normal2 {
|
||||||
|
background-image: url("../static/bubble-tip4.png");
|
||||||
|
width: 190rpx;
|
||||||
|
height: 105rpx;
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-left: 20rpx;
|
||||||
|
top: 0;
|
||||||
|
left: 15%;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
.long {
|
||||||
|
background-image: url("../static/bubble-tip2.png");
|
||||||
|
width: 370rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
top: -50%;
|
||||||
|
left: 49%;
|
||||||
|
}
|
||||||
|
.short {
|
||||||
|
background-image: url("../static/bubble-tip3.png");
|
||||||
|
width: 300rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
top: -50%;
|
||||||
|
right: -1%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
379
src/pages/training/components/ShootProgress.vue
Normal file
379
src/pages/training/components/ShootProgress.vue
Normal file
@@ -0,0 +1,379 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref, watch, onMounted, onBeforeUnmount, computed } from "vue";
|
||||||
|
import audioManager from "@/audioManager";
|
||||||
|
import { MESSAGETYPESV2 } from "@/constants";
|
||||||
|
import { getDirectionText } from "@/util";
|
||||||
|
import Avatar from "@/components/Avatar.vue";
|
||||||
|
|
||||||
|
import useStore from "@/store";
|
||||||
|
import { storeToRefs } from "pinia";
|
||||||
|
const store = useStore();
|
||||||
|
const { user } = storeToRefs(store);
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
show: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
tips: {
|
||||||
|
type: String,
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
|
total: {
|
||||||
|
type: Number,
|
||||||
|
default: 120,
|
||||||
|
},
|
||||||
|
currentRound: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
battleId: {
|
||||||
|
type: String,
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
|
melee: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
onStop: {
|
||||||
|
type: Function,
|
||||||
|
default: () => {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const barColor = ref("#fed847");
|
||||||
|
const remain = ref(props.total);
|
||||||
|
const timer = ref(null);
|
||||||
|
const sound = ref(true);
|
||||||
|
const currentRound = ref(props.currentRound);
|
||||||
|
const currentRoundEnded = ref(false);
|
||||||
|
const halfTime = ref(false);
|
||||||
|
const wait = ref(0);
|
||||||
|
const transitionStyle = ref("all 1s linear");
|
||||||
|
|
||||||
|
const progressPercent = computed(() => {
|
||||||
|
if (!props.total) return 0;
|
||||||
|
return Math.max(0, Math.min(100, (remain.value / props.total) * 100));
|
||||||
|
});
|
||||||
|
|
||||||
|
const displayName = computed(() => {
|
||||||
|
return (
|
||||||
|
user.value?.nickName ||
|
||||||
|
user.value?.nickname ||
|
||||||
|
user.value?.name ||
|
||||||
|
"Archer"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const avatarSrc = computed(() => {
|
||||||
|
return user.value?.avatar || "/static/shooter2.png";
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.tips,
|
||||||
|
(newVal) => {
|
||||||
|
let key = "";
|
||||||
|
if (newVal.includes("红队")) key = "请红方射箭";
|
||||||
|
if (newVal.includes("蓝队")) key = "请蓝方射箭";
|
||||||
|
if (key) {
|
||||||
|
if (currentRoundEnded.value) {
|
||||||
|
currentRound.value += 1;
|
||||||
|
currentRoundEnded.value = false;
|
||||||
|
if (currentRound.value === 1) audioManager.play("第一轮");
|
||||||
|
if (currentRound.value === 2) audioManager.play("第二轮");
|
||||||
|
if (currentRound.value === 3) audioManager.play("第三轮");
|
||||||
|
if (currentRound.value === 4) audioManager.play("第四轮");
|
||||||
|
if (currentRound.value === 5) audioManager.play("第五轮");
|
||||||
|
setTimeout(() => {
|
||||||
|
audioManager.play(key);
|
||||||
|
}, 1000);
|
||||||
|
} else {
|
||||||
|
audioManager.play(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const resetTimer = (count) => {
|
||||||
|
if (timer.value) clearInterval(timer.value);
|
||||||
|
const newVal = Math.round(count);
|
||||||
|
|
||||||
|
if (newVal >= remain.value) {
|
||||||
|
transitionStyle.value = "none";
|
||||||
|
remain.value = newVal;
|
||||||
|
setTimeout(() => {
|
||||||
|
transitionStyle.value = "all 1s linear";
|
||||||
|
}, 50);
|
||||||
|
} else {
|
||||||
|
remain.value = newVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remain.value > 0) {
|
||||||
|
timer.value = setInterval(() => {
|
||||||
|
if (remain.value === 0) {
|
||||||
|
clearInterval(timer.value);
|
||||||
|
props.onStop();
|
||||||
|
}
|
||||||
|
if (remain.value > 0) remain.value--;
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.start,
|
||||||
|
(newVal) => {
|
||||||
|
if (newVal) {
|
||||||
|
resetTimer(props.total);
|
||||||
|
} else {
|
||||||
|
remain.value = 0;
|
||||||
|
clearInterval(timer.value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
immediate: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const tipContent = computed(() => {
|
||||||
|
if (halfTime.value) {
|
||||||
|
return props.battleId ? "中场休息" : `中场休息(${wait.value}秒)`;
|
||||||
|
}
|
||||||
|
return props.start && remain.value === 0 ? "时间到!" : props.tips;
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateSound = () => {
|
||||||
|
sound.value = !sound.value;
|
||||||
|
audioManager.setMuted(!sound.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function onReceiveMessage(msg) {
|
||||||
|
if (Array.isArray(msg)) return;
|
||||||
|
if (msg.type === MESSAGETYPESV2.BattleStart) {
|
||||||
|
halfTime.value = false;
|
||||||
|
audioManager.play("比赛开始");
|
||||||
|
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||||
|
audioManager.play("比赛结束", false);
|
||||||
|
} else if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||||
|
let arrow = {};
|
||||||
|
if (msg.details && Array.isArray(msg.details)) {
|
||||||
|
arrow = msg.details[msg.details.length - 1];
|
||||||
|
} else {
|
||||||
|
if (msg.shootData.playerId !== user.value.id) return;
|
||||||
|
if (msg.shootData) arrow = msg.shootData;
|
||||||
|
}
|
||||||
|
let key = [];
|
||||||
|
key.push(arrow.ring ? `${arrow.ringX ? "X" : arrow.ring}环` : "未上靶");
|
||||||
|
if (arrow.angle !== null) {
|
||||||
|
key.push(`向${getDirectionText(arrow.angle)}调整`);
|
||||||
|
}
|
||||||
|
audioManager.play(key, false);
|
||||||
|
} else if (msg.type === MESSAGETYPESV2.HalfRest) {
|
||||||
|
halfTime.value = true;
|
||||||
|
audioManager.play("中场休息");
|
||||||
|
} else if (msg.type === MESSAGETYPESV2.InvalidShot) {
|
||||||
|
uni.showToast({
|
||||||
|
title: "距离不足,无效",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
|
audioManager.play("射击无效");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const playSound = (key) => {
|
||||||
|
audioManager.play(key);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
uni.$on("update-remain", resetTimer);
|
||||||
|
uni.$on("socket-inbox", onReceiveMessage);
|
||||||
|
uni.$on("play-sound", playSound);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
uni.$off("update-remain", resetTimer);
|
||||||
|
uni.$off("socket-inbox", onReceiveMessage);
|
||||||
|
uni.$off("play-sound", playSound);
|
||||||
|
if (timer.value) clearInterval(timer.value);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<view v-if="show" class="progress-card">
|
||||||
|
<view class="progress-card__header">
|
||||||
|
<view class="progress-card__profile">
|
||||||
|
<view class="progress-card__avatar-shell">
|
||||||
|
<Avatar :src="user.avatar" :size="40" />
|
||||||
|
</view>
|
||||||
|
<text class="progress-card__name">{{ displayName }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- <button class="progress-card__sound" hover-class="none" @click="updateSound">
|
||||||
|
<image
|
||||||
|
class="progress-card__sound-icon"
|
||||||
|
:src="`/static/sound${sound ? '' : '-off'}-yellow.png`"
|
||||||
|
mode="aspectFit"
|
||||||
|
/>
|
||||||
|
</button> -->
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="progress-card__track-wrap">
|
||||||
|
<image
|
||||||
|
class="progress-card__titile"
|
||||||
|
src="../../../static/training-difficulty-design/text-icon-cgxl.png"
|
||||||
|
mode="aspectFit"
|
||||||
|
/>
|
||||||
|
<view class="progress-card__track">
|
||||||
|
<view
|
||||||
|
class="progress-card__fill"
|
||||||
|
:style="{
|
||||||
|
width: `${progressPercent}%`,
|
||||||
|
backgroundColor: barColor,
|
||||||
|
right: tips.includes('红队') ? 0 : 'unset',
|
||||||
|
transition: transitionStyle,
|
||||||
|
}"
|
||||||
|
/>
|
||||||
|
<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>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.progress-card {
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* padding: 50rpx 30rpx 0 30rpx; */
|
||||||
|
margin: 70rpx 30rpx 0 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__profile {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__avatar-shell {
|
||||||
|
width: 86rpx;
|
||||||
|
height: 86rpx;
|
||||||
|
padding: 3rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: linear-gradient(180deg, rgba(255, 209, 153, 1), rgba(162, 119, 55, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__avatar {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: block;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__name {
|
||||||
|
width: 86rpx;
|
||||||
|
color: #E7BA80;
|
||||||
|
font-size: 18rpx;
|
||||||
|
line-height: 1;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__sound {
|
||||||
|
width: 68rpx;
|
||||||
|
height: 68rpx;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: rgba(28, 24, 21, 0.72);
|
||||||
|
box-shadow: 0 8rpx 18rpx rgba(0, 0, 0, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__sound::after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__sound-icon {
|
||||||
|
width: 34rpx;
|
||||||
|
height: 34rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__track-wrap {
|
||||||
|
margin-top: -156rpx;
|
||||||
|
padding-left: 102rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__titile{
|
||||||
|
width: 260rpx;
|
||||||
|
height: 72rpx;
|
||||||
|
margin-left: 110rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__track {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 24rpx;
|
||||||
|
border-radius: 18rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #444444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__fill {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
border-radius: 18rpx;
|
||||||
|
background: linear-gradient( 133deg, #FFD19A 0%, #A17636 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__badge {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
min-width: 156rpx;
|
||||||
|
height: 40rpx;
|
||||||
|
padding: 0 24rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-radius: 999rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
/* background: rgba(164, 117, 47, 0.94); */
|
||||||
|
/* box-shadow: 0 4rpx 10rpx rgba(76, 45, 7, 0.22); */
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__badge-text {
|
||||||
|
color: #fff7de;
|
||||||
|
font-size: 18rpx;
|
||||||
|
line-height: 1;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-card__tip {
|
||||||
|
display: block;
|
||||||
|
margin-top: 16rpx;
|
||||||
|
color: rgba(255, 243, 216, 0.88);
|
||||||
|
font-size: 24rpx;
|
||||||
|
line-height: 1.4;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
196
src/pages/training/components/TestDistance.vue
Normal file
196
src/pages/training/components/TestDistance.vue
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref, onMounted, onBeforeUnmount } from "vue";
|
||||||
|
import Guide from "@/components/Guide.vue";
|
||||||
|
import BowPower from "@/components/BowPower.vue";
|
||||||
|
import Avatar from "@/components/Avatar.vue";
|
||||||
|
import audioManager from "@/audioManager";
|
||||||
|
import { simulShootAPI } from "@/apis";
|
||||||
|
import { MESSAGETYPESV2 } from "@/constants";
|
||||||
|
import useStore from "@/store";
|
||||||
|
import { storeToRefs } from "pinia";
|
||||||
|
const store = useStore();
|
||||||
|
const { user, device } = storeToRefs(store);
|
||||||
|
const props = defineProps({
|
||||||
|
guide: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
isBattle: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
count: {
|
||||||
|
type: Number,
|
||||||
|
default: 15,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const arrow = ref({});
|
||||||
|
const distance = ref(0);
|
||||||
|
const showsimul = ref(false);
|
||||||
|
const count = ref(props.count);
|
||||||
|
const timer = ref(null);
|
||||||
|
|
||||||
|
const updateTimer = (value) => {
|
||||||
|
count.value = Math.round(value);
|
||||||
|
};
|
||||||
|
onMounted(() => {
|
||||||
|
audioManager.play("请射箭测试距离");
|
||||||
|
if (props.isBattle) {
|
||||||
|
timer.value = setInterval(() => {
|
||||||
|
count.value -= 1;
|
||||||
|
if (count.value < 0) clearInterval(timer.value);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
uni.$on("update-timer", updateTimer);
|
||||||
|
});
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (timer.value) clearInterval(timer.value);
|
||||||
|
uni.$off("update-timer", updateTimer);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function onReceiveMessage(msg) {
|
||||||
|
if (Array.isArray(msg)) return;
|
||||||
|
if (msg.type === MESSAGETYPESV2.TestDistance) {
|
||||||
|
distance.value = Number((msg.shootData.distance / 100).toFixed(2));
|
||||||
|
if (distance.value >= 5) audioManager.play("距离合格");
|
||||||
|
else audioManager.play("距离不足");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const simulShoot = async () => {
|
||||||
|
if (device.value.deviceId) await simulShootAPI(device.value.deviceId);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
uni.$on("socket-inbox", onReceiveMessage);
|
||||||
|
const accountInfo = uni.getAccountInfoSync();
|
||||||
|
const envVersion = accountInfo.miniProgram.envVersion;
|
||||||
|
if (envVersion !== "release") showsimul.value = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
uni.$off("socket-inbox", onReceiveMessage);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<view class="container">
|
||||||
|
<view class="test-area">
|
||||||
|
<image
|
||||||
|
class="text-bg"
|
||||||
|
src="../../../static/training-difficulty-design/par-bg.png"
|
||||||
|
mode="widthFix"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
class="simul"
|
||||||
|
@click="simulShoot"
|
||||||
|
hover-class="none"
|
||||||
|
v-if="showsimul"
|
||||||
|
>
|
||||||
|
模拟射箭
|
||||||
|
</button>
|
||||||
|
<view class="warnning-text">
|
||||||
|
<view class="target-tip">当前靶子为<text class="text-yellow">20cm</text>全环靶,请更换靶子</view>
|
||||||
|
<block v-if="distance > 0">
|
||||||
|
<text>当前距离<text class="text-yellow">{{ distance }}</text>米</text>
|
||||||
|
<text v-if="distance >= 5">已达到距离要求</text>
|
||||||
|
<text v-else>请调整站位</text>
|
||||||
|
</block>
|
||||||
|
<block v-else>
|
||||||
|
<text>请射箭,测试站距</text>
|
||||||
|
</block>
|
||||||
|
</view>
|
||||||
|
<view class="user-row">
|
||||||
|
<Avatar :src="user.avatar" :size="35" />
|
||||||
|
<BowPower />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view v-if="isBattle" class="ready-timer">
|
||||||
|
<image src="../../../static/test-tip.png" mode="widthFix" />
|
||||||
|
<view v-if="count >= 0">
|
||||||
|
<text>具体正式比赛还有</text>
|
||||||
|
<text>{{ count }}</text>
|
||||||
|
<text>秒</text>
|
||||||
|
</view>
|
||||||
|
<view v-else> 进入中... </view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.container {
|
||||||
|
width: 100vw;
|
||||||
|
max-height: 70vh;
|
||||||
|
}
|
||||||
|
.ready-timer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
transform: translateY(-10vw);
|
||||||
|
}
|
||||||
|
.ready-timer > image:first-child {
|
||||||
|
width: 40%;
|
||||||
|
}
|
||||||
|
.ready-timer > view {
|
||||||
|
width: 80%;
|
||||||
|
height: 45px;
|
||||||
|
background-color: #545454;
|
||||||
|
border-radius: 30px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
transform: translateY(-8vw);
|
||||||
|
color: #bebebe;
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
.ready-timer > view > text:nth-child(2) {
|
||||||
|
color: #fed847;
|
||||||
|
font-size: 20px;
|
||||||
|
width: 22px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.test-area {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-bg {
|
||||||
|
width: 100%;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.warnning-text {
|
||||||
|
color: #fff;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 200rpx;
|
||||||
|
position: absolute;
|
||||||
|
top: 142rpx;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
font-size: 36rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.target-tip{
|
||||||
|
margin-bottom: 28rpx;
|
||||||
|
}
|
||||||
|
.text-yellow{
|
||||||
|
color: #FED847;
|
||||||
|
}
|
||||||
|
.simul {
|
||||||
|
position: absolute;
|
||||||
|
color: #fff;
|
||||||
|
right: 10px;
|
||||||
|
top: 30rpx;
|
||||||
|
}
|
||||||
|
.user-row{
|
||||||
|
position: absolute;
|
||||||
|
bottom: 34rpx;
|
||||||
|
left: 0rpx;
|
||||||
|
width: 100%;
|
||||||
|
padding: 0 34rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
import { computed, nextTick, ref } from "vue";
|
import { computed, nextTick, ref } from "vue";
|
||||||
import { onLoad } from "@dcloudio/uni-app";
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
import Container from "@/components/Container.vue";
|
import Container from "@/components/Container.vue";
|
||||||
|
import TargetPicker from "@/components/TargetPicker.vue";
|
||||||
import TrainingDifficultyBadge from "@/components/training/TrainingDifficultyBadge.vue";
|
import TrainingDifficultyBadge from "@/components/training/TrainingDifficultyBadge.vue";
|
||||||
import TrainingDifficultyPreviewCard from "@/components/training/TrainingDifficultyPreviewCard.vue";
|
import TrainingDifficultyPreviewCard from "@/components/training/TrainingDifficultyPreviewCard.vue";
|
||||||
import TrainingDifficultyStartButton from "@/components/training/TrainingDifficultyStartButton.vue";
|
import TrainingDifficultyStartButton from "@/components/training/TrainingDifficultyStartButton.vue";
|
||||||
@@ -41,6 +42,7 @@ const emptyDifficulty = {
|
|||||||
const modeKey = ref(defaultModeKey);
|
const modeKey = ref(defaultModeKey);
|
||||||
const unlockedDifficultyId = ref(defaultUnlockedDifficultyId);
|
const unlockedDifficultyId = ref(defaultUnlockedDifficultyId);
|
||||||
const selectedDifficultyId = ref(defaultUnlockedDifficultyId);
|
const selectedDifficultyId = ref(defaultUnlockedDifficultyId);
|
||||||
|
const showTargetPicker = ref(false);
|
||||||
const nodesScrollTop = ref(0);
|
const nodesScrollTop = ref(0);
|
||||||
const nodesScrollWithAnimation = ref(false);
|
const nodesScrollWithAnimation = ref(false);
|
||||||
|
|
||||||
@@ -318,7 +320,11 @@ const initPageState = (options = {}) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveTrainingContext = () => {
|
const resolveTargetPaperType = (target) => {
|
||||||
|
return Number(target) === 1 ? "20厘米全环靶" : "40厘米全环靶";
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveTrainingContext = (target) => {
|
||||||
const difficulty = selectedDifficulty.value;
|
const difficulty = selectedDifficulty.value;
|
||||||
|
|
||||||
if (!difficulty.id) {
|
if (!difficulty.id) {
|
||||||
@@ -330,7 +336,9 @@ const saveTrainingContext = () => {
|
|||||||
trainingTitle: pageConfig.value.title,
|
trainingTitle: pageConfig.value.title,
|
||||||
difficultyId: difficulty.id,
|
difficultyId: difficulty.id,
|
||||||
difficultyLabel: difficulty.label,
|
difficultyLabel: difficulty.label,
|
||||||
targetPaperType: difficulty.targetPaperType,
|
targetPaperType: target
|
||||||
|
? resolveTargetPaperType(target)
|
||||||
|
: difficulty.targetPaperType,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -369,6 +377,26 @@ const handleStart = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openTargetPicker = () => {
|
||||||
|
if (!selectedDifficulty.value.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
showTargetPicker.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTargetConfirm = (target) => {
|
||||||
|
showTargetPicker.value = false;
|
||||||
|
saveTrainingContext(target);
|
||||||
|
// uni.showToast({
|
||||||
|
// title: `${selectedDifficulty.value.title} 即将开始`,
|
||||||
|
// icon: "none",
|
||||||
|
// });
|
||||||
|
|
||||||
|
uni.navigateTo({
|
||||||
|
url: `/pages/training/practise-one?target=${target}`,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
onLoad((options = {}) => {
|
onLoad((options = {}) => {
|
||||||
initPageState(options);
|
initPageState(options);
|
||||||
@@ -424,10 +452,15 @@ onLoad((options = {}) => {
|
|||||||
<view class="difficulty-page__start">
|
<view class="difficulty-page__start">
|
||||||
<TrainingDifficultyStartButton
|
<TrainingDifficultyStartButton
|
||||||
:text="selectedDifficulty.startText"
|
:text="selectedDifficulty.startText"
|
||||||
@click="handleStart"
|
@click="openTargetPicker"
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<TargetPicker
|
||||||
|
:show="showTargetPicker"
|
||||||
|
:onClose="() => (showTargetPicker = false)"
|
||||||
|
:onConfirm="handleTargetConfirm"
|
||||||
|
/>
|
||||||
</Container>
|
</Container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
199
src/pages/training/practise-one.vue
Normal file
199
src/pages/training/practise-one.vue
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref, onMounted, onBeforeUnmount } from "vue";
|
||||||
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
|
import Container from "@/components/Container.vue";
|
||||||
|
import ShootProgress from "./components/ShootProgress.vue";
|
||||||
|
import BowTarget from "./components/BowTarget.vue";
|
||||||
|
import ScorePanel2 from "@/components/ScorePanel2.vue";
|
||||||
|
import ScoreResult from "@/components/ScoreResult.vue";
|
||||||
|
import Avatar from "@/components/Avatar.vue";
|
||||||
|
import BowPower from "@/components/BowPower.vue";
|
||||||
|
import TestDistance from "./components/TestDistance.vue";
|
||||||
|
import BubbleTip from "./components/BubbleTip.vue";
|
||||||
|
import audioManager from "@/audioManager";
|
||||||
|
|
||||||
|
import {
|
||||||
|
createPractiseAPI,
|
||||||
|
startPractiseAPI,
|
||||||
|
endPractiseAPI,
|
||||||
|
getPractiseAPI,
|
||||||
|
} from "@/apis";
|
||||||
|
import { sharePractiseData } from "@/canvas";
|
||||||
|
import { wxShare, debounce } from "@/util";
|
||||||
|
import { MESSAGETYPESV2, roundsName } from "@/constants";
|
||||||
|
|
||||||
|
import useStore from "@/store";
|
||||||
|
import { storeToRefs } from "pinia";
|
||||||
|
const store = useStore();
|
||||||
|
const { user } = storeToRefs(store);
|
||||||
|
|
||||||
|
const start = ref(false);
|
||||||
|
const scores = ref([]);
|
||||||
|
const total = 12;
|
||||||
|
const practiseResult = ref({});
|
||||||
|
const practiseId = ref("");
|
||||||
|
const showGuide = ref(false);
|
||||||
|
const tips = ref("");
|
||||||
|
const targetType = ref(1);
|
||||||
|
|
||||||
|
onLoad((options) => {
|
||||||
|
if (options.target) {
|
||||||
|
targetType.value = Number(options.target);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const onReady = async () => {
|
||||||
|
await startPractiseAPI();
|
||||||
|
scores.value = [];
|
||||||
|
start.value = true;
|
||||||
|
audioManager.play("练习开始");
|
||||||
|
};
|
||||||
|
|
||||||
|
const onOver = async () => {
|
||||||
|
practiseResult.value = await getPractiseAPI(practiseId.value);
|
||||||
|
start.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function onReceiveMessage(msg) {
|
||||||
|
if (msg.type === MESSAGETYPESV2.ShootResult) {
|
||||||
|
scores.value = msg.details;
|
||||||
|
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
|
||||||
|
// setTimeout(onOver, 1500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onComplete() {
|
||||||
|
const validArrows = (practiseResult.value.details || []).filter(
|
||||||
|
(a) => a.x !== -30 && a.y !== -30
|
||||||
|
);
|
||||||
|
if (validArrows.length === total) {
|
||||||
|
uni.navigateBack();
|
||||||
|
} else {
|
||||||
|
practiseId.value = "";
|
||||||
|
practiseResult.value = {};
|
||||||
|
start.value = false;
|
||||||
|
scores.value = [];
|
||||||
|
const result = await createPractiseAPI(total, 120);
|
||||||
|
if (result) practiseId.value = result.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onClickShare = debounce(async () => {
|
||||||
|
await sharePractiseData("shareCanvas", 2, user.value, practiseResult.value);
|
||||||
|
await wxShare("shareCanvas");
|
||||||
|
});
|
||||||
|
|
||||||
|
function onAudioEnded(s) {
|
||||||
|
if (s.indexOf("比赛结束") >= 0) {
|
||||||
|
onOver()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
// audioManager.play("第一轮");
|
||||||
|
uni.setKeepScreenOn({
|
||||||
|
keepScreenOn: true,
|
||||||
|
});
|
||||||
|
uni.$on("socket-inbox", onReceiveMessage);
|
||||||
|
uni.$on("share-image", onClickShare);
|
||||||
|
uni.$on("audioEnded", onAudioEnded);
|
||||||
|
const result = await createPractiseAPI(total, 120, targetType.value);
|
||||||
|
if (result) practiseId.value = result.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
uni.setKeepScreenOn({
|
||||||
|
keepScreenOn: false,
|
||||||
|
});
|
||||||
|
uni.$off("socket-inbox", onReceiveMessage);
|
||||||
|
uni.$off("share-image", onClickShare);
|
||||||
|
uni.$off("audioEnded", onAudioEnded);
|
||||||
|
audioManager.stopAll();
|
||||||
|
endPractiseAPI();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Container
|
||||||
|
:bgType="!start && !practiseResult.id?9:10"
|
||||||
|
:showBottom="!start && !scores.length"
|
||||||
|
>
|
||||||
|
<view>
|
||||||
|
<TestDistance v-if="!start && !practiseResult.id" />
|
||||||
|
<block v-else>
|
||||||
|
<ShootProgress
|
||||||
|
:start="start"
|
||||||
|
:onStop="onOver"
|
||||||
|
/>
|
||||||
|
<view class="user-row">
|
||||||
|
<!-- <Avatar :src="user.avatar" :size="35" /> -->
|
||||||
|
<BubbleTip v-if="showGuide" type="normal2">
|
||||||
|
<text>还有两场,坚持</text>
|
||||||
|
<text>就是胜利!💪</text>
|
||||||
|
</BubbleTip>
|
||||||
|
<!-- <BowPower /> -->
|
||||||
|
</view>
|
||||||
|
<BowTarget
|
||||||
|
:totalRound="start ? total / 4 : 0"
|
||||||
|
:currentRound="scores.length % 3"
|
||||||
|
:scores="scores"
|
||||||
|
/>
|
||||||
|
<ScorePanel2 :arrows="scores" />
|
||||||
|
<ScoreResult
|
||||||
|
v-if="practiseResult.details"
|
||||||
|
:rowCount="6"
|
||||||
|
:total="total"
|
||||||
|
:onClose="onComplete"
|
||||||
|
:result="practiseResult"
|
||||||
|
:tipSrc="`../static/${
|
||||||
|
practiseResult.details.filter(
|
||||||
|
(arrow) => arrow.x !== -30 && arrow.y !== -30
|
||||||
|
).length < total
|
||||||
|
? 'un'
|
||||||
|
: ''
|
||||||
|
}finish-tip.png`"
|
||||||
|
/>
|
||||||
|
<canvas class="share-canvas" id="shareCanvas" type="2d"></canvas>
|
||||||
|
</block>
|
||||||
|
</view>
|
||||||
|
<template #bottom>
|
||||||
|
<view class="btn-box">
|
||||||
|
<image
|
||||||
|
class="btn-box-bg"
|
||||||
|
src="../../static/training-difficulty-design/par-star.png"
|
||||||
|
mode="widthFix"
|
||||||
|
/>
|
||||||
|
<button class="btn" @click="onReady">准备好了,开始练习</button>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
</Container>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.btn-box{
|
||||||
|
width: 488rpx;
|
||||||
|
height: 234rpx;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 130rpx;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
.btn-box-bg{
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.btn{
|
||||||
|
width: 330rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
line-height: 70rpx;
|
||||||
|
background: #FED847;
|
||||||
|
border-radius: 44rpx;
|
||||||
|
text-align: center;
|
||||||
|
color: #000000;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
bottom: -36rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
BIN
src/static/app-bg8.png
Normal file
BIN
src/static/app-bg8.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 376 KiB |
BIN
src/static/app-bg9.png
Normal file
BIN
src/static/app-bg9.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 189 KiB |
BIN
src/static/training-difficulty-design/par-bg.png
Normal file
BIN
src/static/training-difficulty-design/par-bg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 141 KiB |
BIN
src/static/training-difficulty-design/par-icon.png
Normal file
BIN
src/static/training-difficulty-design/par-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
BIN
src/static/training-difficulty-design/par-star.png
Normal file
BIN
src/static/training-difficulty-design/par-star.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
BIN
src/static/training-difficulty-design/text-icon-cgxl.png
Normal file
BIN
src/static/training-difficulty-design/text-icon-cgxl.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Reference in New Issue
Block a user