Files
shoot-miniprograms/src/components/TestDistance.vue

135 lines
3.2 KiB
Vue
Raw Normal View History

2025-07-05 14:52:41 +08:00
<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import Guide from "@/components/Guide.vue";
import BowPower from "@/components/BowPower.vue";
import Avatar from "@/components/Avatar.vue";
import { simulShootAPI } from "@/apis";
import { checkConnection } from "@/util";
import { MESSAGETYPES } 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,
},
});
const arrow = ref({});
const power = ref(0);
const distance = ref(0);
const debugInfo = ref("");
async function onReceiveMessage(messages = []) {
messages.forEach((msg) => {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
arrow.value = msg.target;
power.value = msg.target.battery;
distance.value = msg.target.dst / 100;
debugInfo.value = msg.target;
}
});
}
const simulShoot = async () => {
if (device.value.deviceId) await simulShootAPI(device.value.deviceId);
};
onMounted(() => {
checkConnection();
uni.$on("socket-inbox", onReceiveMessage);
});
onUnmounted(() => {
uni.$off("socket-inbox", onReceiveMessage);
});
</script>
<template>
<view class="container">
<Guide v-if="guide">
<view
:style="{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
paddingRight: '10px',
}"
>
<view :style="{ display: 'flex', flexDirection: 'column' }">
<text :style="{ color: '#fed847' }">请预先射几箭测试</text>
2025-07-08 20:08:25 +08:00
<text>请确保射击距离有5米</text>
2025-07-05 14:52:41 +08:00
</view>
</view>
</Guide>
2025-07-11 00:47:34 +08:00
<view class="user-row">
<Avatar :src="user.avatar" :size="35" />
<BowPower :power="power" />
</view>
2025-07-05 14:52:41 +08:00
<image
class="text-bg"
src="https://api.shelingxingqiu.com/attachment/2025-07-05/db3skuq1n9rj4fmld4.png"
mode="widthFix"
/>
2025-07-11 00:47:34 +08:00
<view class="warnning-text">
<block v-if="distance > 0">
<text>当前距离{{ distance }}</text>
<text v-if="distance >= 5">已达到距离要求</text>
<text v-else>请调整站位</text>
</block>
<block v-else>
<text>大人请射箭</text>
</block>
2025-07-05 14:52:41 +08:00
</view>
2025-07-25 16:47:07 +08:00
<!-- <view class="debug-text">{{ debugInfo }}</view> -->
2025-07-05 14:52:41 +08:00
<view>
<view class="simul" @click="simulShoot" :style="{ color: '#fff' }">
模拟射箭
</view>
</view>
</view>
</template>
<style scoped>
.container {
width: 100vw;
display: flex;
flex-direction: column;
}
.text-bg {
width: 100%;
2025-07-11 00:47:34 +08:00
transform: translateY(-50px);
2025-07-05 14:52:41 +08:00
}
.warnning-text {
2025-07-18 10:14:13 +08:00
position: absolute;
2025-07-05 14:52:41 +08:00
color: #fed847;
font-size: 30px;
display: flex;
flex-direction: column;
align-items: center;
2025-07-11 00:47:34 +08:00
width: 54vw;
2025-07-05 14:52:41 +08:00
left: calc(50% - 27vw);
2025-07-11 00:47:34 +08:00
top: 34%;
2025-07-05 14:52:41 +08:00
}
.warnning-text > text {
2025-07-07 19:01:14 +08:00
width: 60vw;
2025-07-05 14:52:41 +08:00
text-align: center;
}
.container > view:last-child {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px;
2025-07-17 09:35:30 +08:00
margin-top: -40vw;
2025-07-11 00:47:34 +08:00
position: relative;
2025-07-05 14:52:41 +08:00
}
.debug-text {
position: fixed;
left: calc(50% - 45vw);
top: 66%;
color: #fff;
font-size: 14px;
}
</style>