update:新增调瞄通信,优化首页

This commit is contained in:
2026-08-03 16:39:52 +08:00
parent 3ab1ad59bd
commit fac2576b65
4 changed files with 99 additions and 11 deletions
+19
View File
@@ -493,6 +493,25 @@ export const laserAimAPI = async () => {
return request("POST", "/user/device/laserAim"); return request("POST", "/user/device/laserAim");
}; };
// 调瞄续期只负责发送请求,不等待或处理响应,避免阻塞下一次续期。
export const aimRenewAPI = () => {
const token = uni.getStorageSync(
`${uni.getAccountInfoSync().miniProgram.envVersion}_token`
);
const header = {};
if (token) header.Authorization = `Bearer ${token}`;
uni.request({
url: `${BASE_URL}/user/device/aimRenew`,
method: "POST",
header,
data: {},
timeout: 10000,
success: () => {},
fail: () => {},
});
};
export const laserCloseAPI = async () => { export const laserCloseAPI = async () => {
return request("POST", "/user/device/closeAim"); return request("POST", "/user/device/closeAim");
}; };
+6 -2
View File
@@ -43,9 +43,13 @@ function handleTabClick(index) {
<style scoped> <style scoped>
.footer { .footer {
height: 120px; /* height: 120px; */
height: 190rpx;
width: 100vw; width: 100vw;
position: relative; /* position: relative; */
position: fixed;
bottom: 0;
left: 0;
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;
align-items: center; align-items: center;
+67 -6
View File
@@ -1,9 +1,10 @@
<script setup> <script setup>
import { ref, onMounted, onBeforeUnmount } from "vue"; import { ref, onMounted, onBeforeUnmount } from "vue";
import { onShow, onHide } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue"; import Container from "@/components/Container.vue";
import SButton from "@/components/SButton.vue"; import SButton from "@/components/SButton.vue";
import { laserAimAPI, laserCloseAPI } from "@/apis"; import { aimRenewAPI, laserAimAPI, laserCloseAPI } from "@/apis";
import { MESSAGETYPES } from "@/constants"; import { MESSAGETYPES } from "@/constants";
// import audioManager from "@/audioManager"; // import audioManager from "@/audioManager";
@@ -23,8 +24,56 @@ const guides = [
]; ];
const done = ref(true); const done = ref(true);
let aimRenewTimer = null;
let pageMounted = false;
let pageVisible = false;
let aimSessionVersion = 0;
const stopAimRenew = () => {
if (!aimRenewTimer) return;
clearInterval(aimRenewTimer);
aimRenewTimer = null;
};
const startAimRenew = () => {
stopAimRenew();
aimRenewTimer = setInterval(() => {
aimRenewAPI();
}, 1000);
};
const openAimSession = async (sessionVersion) => {
try {
await laserAimAPI();
} catch (error) {
return;
}
if (
!pageMounted ||
!pageVisible ||
sessionVersion !== aimSessionVersion
) {
void laserCloseAPI().catch(() => {});
return;
}
startAimRenew();
};
const stopAimSession = (closeLaser = true) => {
const wasVisible = pageVisible;
pageVisible = false;
aimSessionVersion += 1;
stopAimRenew();
if (closeLaser && wasVisible) {
void laserCloseAPI().catch(() => {});
}
};
const onComplete = async () => { const onComplete = async () => {
stopAimSession(false);
await laserCloseAPI(); await laserCloseAPI();
uni.navigateBack(); uni.navigateBack();
}; };
@@ -39,14 +88,26 @@ function onReceiveMessage(messages = []) {
}); });
} }
onMounted(async () => { onShow(() => {
uni.$on("socket-inbox", onReceiveMessage); pageVisible = true;
await laserAimAPI(); const sessionVersion = ++aimSessionVersion;
if (pageMounted) void openAimSession(sessionVersion);
}); });
onBeforeUnmount(async () => { onHide(() => {
stopAimSession();
});
onMounted(() => {
uni.$on("socket-inbox", onReceiveMessage);
pageMounted = true;
if (pageVisible) void openAimSession(aimSessionVersion);
});
onBeforeUnmount(() => {
pageMounted = false;
stopAimSession();
uni.$off("socket-inbox", onReceiveMessage); uni.$off("socket-inbox", onReceiveMessage);
await laserCloseAPI();
}); });
</script> </script>
+7 -3
View File
@@ -510,6 +510,7 @@ onShareTimeline(() => {
</view> </view>
<Signin :show="showModal" :onClose="() => (showModal = false)"/> <Signin :show="showModal" :onClose="() => (showModal = false)"/>
</view> </view>
<view class="foot-space"></view>
<AppFooter/> <AppFooter/>
</Container> </Container>
</template> </template>
@@ -517,9 +518,12 @@ onShareTimeline(() => {
<style scoped> <style scoped>
.container { .container {
width: 100%; width: 100%;
height: calc(100% - 120px); /* height: calc(100% + 240rpx); */
}
.foot-space{
width: 100%;
height: 200rpx;
} }
.feature-grid { .feature-grid {
width: 100%; width: 100%;
display: flex; display: flex;
@@ -679,7 +683,7 @@ onShareTimeline(() => {
.my-data > view:nth-child(2) { .my-data > view:nth-child(2) {
width: 68%; width: 68%;
font-size: 12px; font-size: 24rpx;
color: #fff6; color: #fff6;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;