pref: 绑定设备、匹配pk

This commit is contained in:
2026-04-28 08:59:16 +08:00
parent 8c48216a75
commit f07facd98b
7 changed files with 137 additions and 95 deletions

View File

@@ -3,8 +3,6 @@ import { ref, onMounted, onBeforeUnmount } from "vue";
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import Matching from "@/components/Matching.vue";
import RoundEndTip from "@/components/RoundEndTip.vue";
import TestDistance from "@/components/TestDistance.vue";
import { matchGameAPI } from "@/apis";
import { MESSAGETYPESV2 } from "@/constants";
@@ -17,6 +15,13 @@ async function stopMatch() {
uni.$showHint(3);
}
async function cancelMatch() {
if (gameType.value && teamSize.value) {
await matchGameAPI(false, gameType.value, teamSize.value);
}
uni.navigateBack()
}
async function onReceiveMessage(msg) {
if (msg.type === MESSAGETYPESV2.MatchSuccess) {
matchSuccess.value = true;
@@ -46,6 +51,7 @@ onMounted(() => {
keepScreenOn: true,
});
uni.$on("socket-inbox", onReceiveMessage);
uni.$on("cancelMatching", cancelMatch);
});
onBeforeUnmount(() => {
@@ -53,9 +59,7 @@ onBeforeUnmount(() => {
keepScreenOn: false,
});
uni.$off("socket-inbox", onReceiveMessage);
if (gameType.value && teamSize.value && !matchSuccess.value) {
matchGameAPI(false, gameType.value, teamSize.value);
}
uni.$off("cancelMatching", cancelMatch);
});
onShow(async () => {
@@ -65,9 +69,7 @@ onShow(async () => {
});
onHide(() => {
if (gameType.value && teamSize.value && !matchSuccess.value) {
matchGameAPI(false, gameType.value, teamSize.value);
}
});
</script>