电量显示走接口请求

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

View File

@@ -1,9 +1,19 @@
<script setup>
defineProps({
power: {
type: Number,
default: 0,
},
import { ref, onMounted, onBeforeUnmount } from "vue";
import { getDeviceBatteryAPI } from "@/apis";
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>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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