电量显示走接口请求

This commit is contained in:
kron
2025-10-29 17:26:27 +08:00
parent 7036135d9c
commit f5d5475ee4
11 changed files with 30 additions and 37 deletions

View File

@@ -506,3 +506,7 @@ export const laserAimAPI = async () => {
export const laserCloseAPI = async () => { export const laserCloseAPI = async () => {
return request("POST", "/user/device/closeAim"); return request("POST", "/user/device/closeAim");
}; };
export const getDeviceBatteryAPI = async () => {
return request("GET", "/user/device/battery");
};

View File

@@ -15,10 +15,6 @@ defineProps({
type: Number, type: Number,
default: 0, default: 0,
}, },
power: {
type: Number,
default: 0,
},
goldenRound: { goldenRound: {
type: Number, type: Number,
default: 0, default: 0,
@@ -36,7 +32,7 @@ defineProps({
transform: 'scale(0.8) translateX(10px)', transform: 'scale(0.8) translateX(10px)',
}" }"
> >
<BowPower :power="power" /> <BowPower />
</view> </view>
</view> </view>
<view> <view>

View File

@@ -1,9 +1,19 @@
<script setup> <script setup>
defineProps({ import { ref, onMounted, onBeforeUnmount } from "vue";
power: { import { getDeviceBatteryAPI } from "@/apis";
type: Number,
default: 0, const power = ref(0);
}, const timer = ref(null);
onMounted(async () => {
timer.value = setInterval(async () => {
const data = await getDeviceBatteryAPI();
power.value = data.battery;
}, 1000 * 10);
});
onBeforeUnmount(() => {
clearInterval(timer.value);
}); });
</script> </script>

View File

@@ -21,10 +21,6 @@ const props = defineProps({
type: String, type: String,
default: "", default: "",
}, },
power: {
type: Number,
default: 0,
},
scores: { scores: {
type: Array, type: Array,
default: () => [], default: () => [],
@@ -118,7 +114,7 @@ onMounted(() => {
"/" + "/" +
totalRound totalRound
}}</text> }}</text>
<BowPower :power="power" /> <BowPower />
</view> </view>
<view class="target"> <view class="target">
<view v-if="stop" class="stop-sign">中场休息</view> <view v-if="stop" class="stop-sign">中场休息</view>

View File

@@ -22,7 +22,6 @@ const props = defineProps({
}, },
}); });
const arrow = ref({}); const arrow = ref({});
const power = ref(0);
const distance = ref(0); const distance = ref(0);
const debugInfo = ref(""); const debugInfo = ref("");
const showsimul = ref(false); const showsimul = ref(false);
@@ -49,7 +48,6 @@ async function onReceiveMessage(messages = []) {
messages.forEach((msg) => { messages.forEach((msg) => {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) { if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
arrow.value = msg.target; arrow.value = msg.target;
power.value = msg.target.battery;
distance.value = Number((msg.target.dst / 100).toFixed(2)); distance.value = Number((msg.target.dst / 100).toFixed(2));
debugInfo.value = msg.target; debugInfo.value = msg.target;
audioManager.play("距离合格"); audioManager.play("距离合格");
@@ -120,7 +118,7 @@ onBeforeUnmount(() => {
</view> </view>
<view class="user-row"> <view class="user-row">
<Avatar :src="user.avatar" :size="35" /> <Avatar :src="user.avatar" :size="35" />
<BowPower :power="power" /> <BowPower />
</view> </view>
</view> </view>
<view v-if="isBattle" class="ready-timer"> <view v-if="isBattle" class="ready-timer">

View File

@@ -33,7 +33,6 @@ const stepButtonTexts = [
const title = ref("新手试炼场"); const title = ref("新手试炼场");
const start = ref(false); const start = ref(false);
const practiseResult = ref({}); const practiseResult = ref({});
const power = ref(0);
const btnDisabled = ref(false); const btnDisabled = ref(false);
const practiseId = ref(""); const practiseId = ref("");
const showGuide = ref(false); const showGuide = ref(false);
@@ -66,11 +65,10 @@ async function onReceiveMessage(messages = []) {
if (scores.value.length < total) { if (scores.value.length < total) {
scores.value.push(msg.target); scores.value.push(msg.target);
} }
power.value = msg.target.battery; if (step.value === 2 && msg.target.dst / 100 >= 5) {
// if (step.value === 2 && msg.target.dst / 100 >= 5) {
btnDisabled.value = false; btnDisabled.value = false;
showGuide.value = true; showGuide.value = true;
// } }
} }
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) { if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
if (practiseId.value && practiseId.value === msg.practice.id) { if (practiseId.value && practiseId.value === msg.practice.id) {
@@ -230,7 +228,7 @@ const onClose = () => {
:style="{ marginBottom: step === 2 ? '40px' : '0' }" :style="{ marginBottom: step === 2 ? '40px' : '0' }"
> >
<Avatar :src="user.avatar" :size="35" /> <Avatar :src="user.avatar" :size="35" />
<BowPower :power="power" /> <BowPower />
</view> </view>
<BowTarget <BowTarget
v-if="step === 4" v-if="step === 4"

View File

@@ -22,7 +22,6 @@ const start = ref(false);
const startCount = ref(true); const startCount = ref(true);
const battleId = ref(""); const battleId = ref("");
const currentRound = ref(1); const currentRound = ref(1);
const power = ref(0);
const scores = ref([]); const scores = ref([]);
const tips = ref("即将开始..."); const tips = ref("即将开始...");
const players = ref([]); const players = ref([]);
@@ -120,7 +119,6 @@ async function onReceiveMessage(messages = []) {
if (!start.value) getCurrentGameAPI(); if (!start.value) getCurrentGameAPI();
if (msg.userId === user.value.id) { if (msg.userId === user.value.id) {
scores.value.push({ ...msg.target }); scores.value.push({ ...msg.target });
power.value = msg.target.battery;
} }
playersScores.value[msg.userId].push({ ...msg.target }); playersScores.value[msg.userId].push({ ...msg.target });
} }
@@ -203,7 +201,7 @@ onHide(() => {
/> />
<view v-if="start" class="user-row"> <view v-if="start" class="user-row">
<Avatar :src="user.avatar" :size="35" /> <Avatar :src="user.avatar" :size="35" />
<BowPower :power="power" /> <BowPower />
</view> </view>
<BowTarget <BowTarget
v-if="start" v-if="start"

View File

@@ -22,7 +22,6 @@ const scores = ref([]);
const total = 12; const total = 12;
const currentRound = ref(0); const currentRound = ref(0);
const practiseResult = ref({}); const practiseResult = ref({});
const power = ref(0);
const practiseId = ref(""); const practiseId = ref("");
const showGuide = ref(false); const showGuide = ref(false);
@@ -53,7 +52,6 @@ async function onReceiveMessage(messages = []) {
}, 3000); }, 3000);
} }
} }
power.value = msg.target.battery;
} }
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) { if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
if (practiseId.value && practiseId.value === msg.practice.id) { if (practiseId.value && practiseId.value === msg.practice.id) {
@@ -128,7 +126,7 @@ onBeforeUnmount(() => {
<text>还有两场坚持</text> <text>还有两场坚持</text>
<text>就是胜利💪</text> <text>就是胜利💪</text>
</BubbleTip> </BubbleTip>
<BowPower :power="power" /> <BowPower />
</view> </view>
<BowTarget <BowTarget
:totalRound="start ? total / 4 : 0" :totalRound="start ? total / 4 : 0"

View File

@@ -21,7 +21,6 @@ const start = ref(false);
const scores = ref([]); const scores = ref([]);
const total = 36; const total = 36;
const practiseResult = ref({}); const practiseResult = ref({});
const power = ref(0);
const practiseId = ref(""); const practiseId = ref("");
const showGuide = ref(false); const showGuide = ref(false);
@@ -47,7 +46,6 @@ async function onReceiveMessage(messages = []) {
}, 3000); }, 3000);
} }
} }
power.value = msg.target.battery;
} }
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) { if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
if (practiseId.value && practiseId.value === msg.practice.id) { if (practiseId.value && practiseId.value === msg.practice.id) {
@@ -115,7 +113,7 @@ onBeforeUnmount(() => {
<text>完成过半胜利</text> <text>完成过半胜利</text>
<text>在望💪</text> <text>在望💪</text>
</BubbleTip> </BubbleTip>
<BowPower :power="power" /> <BowPower />
</view> </view>
<BowTarget <BowTarget
:currentRound="scores.length" :currentRound="scores.length"

View File

@@ -337,7 +337,6 @@ onHide(() => {
<BowTarget <BowTarget
v-if="start" v-if="start"
mode="team" mode="team"
:power="start ? power : 0"
:scores="scores" :scores="scores"
:blueScores="blueScores" :blueScores="blueScores"
/> />
@@ -347,7 +346,6 @@ onHide(() => {
:redPoints="redPoints" :redPoints="redPoints"
:bluePoints="bluePoints" :bluePoints="bluePoints"
:goldenRound="goldenRound" :goldenRound="goldenRound"
:power="power"
/> />
<ScreenHint <ScreenHint
:show="showRoundTip" :show="showRoundTip"

View File

@@ -319,7 +319,6 @@ onHide(() => {
<BowTarget <BowTarget
v-if="start" v-if="start"
mode="team" mode="team"
:power="start ? power : 0"
:currentRound="scores.length" :currentRound="scores.length"
:totalRound="3" :totalRound="3"
:scores="scores" :scores="scores"