update:新增调瞄通信,优化首页
This commit is contained in:
+19
@@ -493,6 +493,25 @@ export const laserAimAPI = async () => {
|
||||
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 () => {
|
||||
return request("POST", "/user/device/closeAim");
|
||||
};
|
||||
|
||||
@@ -43,9 +43,13 @@ function handleTabClick(index) {
|
||||
|
||||
<style scoped>
|
||||
.footer {
|
||||
height: 120px;
|
||||
/* height: 120px; */
|
||||
height: 190rpx;
|
||||
width: 100vw;
|
||||
position: relative;
|
||||
/* position: relative; */
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<script setup>
|
||||
import { ref, onMounted, onBeforeUnmount } from "vue";
|
||||
import { onShow, onHide } from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import SButton from "@/components/SButton.vue";
|
||||
|
||||
import { laserAimAPI, laserCloseAPI } from "@/apis";
|
||||
import { aimRenewAPI, laserAimAPI, laserCloseAPI } from "@/apis";
|
||||
import { MESSAGETYPES } from "@/constants";
|
||||
// import audioManager from "@/audioManager";
|
||||
|
||||
@@ -23,8 +24,56 @@ const guides = [
|
||||
];
|
||||
|
||||
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 () => {
|
||||
stopAimSession(false);
|
||||
await laserCloseAPI();
|
||||
uni.navigateBack();
|
||||
};
|
||||
@@ -39,14 +88,26 @@ function onReceiveMessage(messages = []) {
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
await laserAimAPI();
|
||||
onShow(() => {
|
||||
pageVisible = true;
|
||||
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);
|
||||
await laserCloseAPI();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
+7
-3
@@ -510,6 +510,7 @@ onShareTimeline(() => {
|
||||
</view>
|
||||
<Signin :show="showModal" :onClose="() => (showModal = false)"/>
|
||||
</view>
|
||||
<view class="foot-space"></view>
|
||||
<AppFooter/>
|
||||
</Container>
|
||||
</template>
|
||||
@@ -517,9 +518,12 @@ onShareTimeline(() => {
|
||||
<style scoped>
|
||||
.container {
|
||||
width: 100%;
|
||||
height: calc(100% - 120px);
|
||||
/* height: calc(100% + 240rpx); */
|
||||
}
|
||||
.foot-space{
|
||||
width: 100%;
|
||||
height: 200rpx;
|
||||
}
|
||||
|
||||
.feature-grid {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
@@ -679,7 +683,7 @@ onShareTimeline(() => {
|
||||
|
||||
.my-data > view:nth-child(2) {
|
||||
width: 68%;
|
||||
font-size: 12px;
|
||||
font-size: 24rpx;
|
||||
color: #fff6;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
Reference in New Issue
Block a user