Files
shoot-miniprograms/src/pages/match-page.vue

88 lines
2.1 KiB
Vue
Raw Normal View History

2025-07-28 13:54:37 +08:00
<script setup>
2025-08-25 13:47:32 +08:00
import { ref, onMounted, onBeforeUnmount } from "vue";
2025-07-28 13:54:37 +08:00
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";
2026-02-09 10:40:40 +08:00
import { MESSAGETYPESV2 } from "@/constants";
2025-07-28 13:54:37 +08:00
const gameType = ref(0);
const teamSize = ref(0);
const onComplete = ref(null);
2026-02-09 10:40:40 +08:00
const matchSuccess = ref(false);
2025-07-28 13:54:37 +08:00
async function stopMatch() {
uni.$showHint(3);
}
2026-02-09 10:40:40 +08:00
async function onReceiveMessage(msg) {
if (msg.type === MESSAGETYPESV2.MatchSuccess) {
matchSuccess.value = true;
onComplete.value = () => {
if (gameType.value == 1) {
uni.redirectTo({
url: `/pages/team-battle?battleId=${msg.id}&gameMode=2`,
});
} else if (gameType.value == 2) {
uni.redirectTo({
url: `/pages/melee-battle?battleId=${msg.id}&gameMode=2`,
});
2025-07-28 13:54:37 +08:00
}
2026-02-09 10:40:40 +08:00
};
}
2025-07-28 13:54:37 +08:00
}
onLoad(async (options) => {
if (options.gameType && options.teamSize) {
gameType.value = options.gameType;
teamSize.value = options.teamSize;
}
});
onMounted(() => {
uni.setKeepScreenOn({
keepScreenOn: true,
});
uni.$on("socket-inbox", onReceiveMessage);
});
2025-08-25 13:47:32 +08:00
onBeforeUnmount(() => {
2025-07-28 13:54:37 +08:00
uni.setKeepScreenOn({
keepScreenOn: false,
});
uni.$off("socket-inbox", onReceiveMessage);
2026-02-09 10:40:40 +08:00
if (gameType.value && teamSize.value && !matchSuccess.value) {
2025-07-28 13:54:37 +08:00
matchGameAPI(false, gameType.value, teamSize.value);
}
});
onShow(async () => {
if (gameType.value && teamSize.value) {
matchGameAPI(true, gameType.value, teamSize.value);
}
});
onHide(() => {
2026-02-09 10:40:40 +08:00
if (gameType.value && teamSize.value && !matchSuccess.value) {
2025-07-28 13:54:37 +08:00
matchGameAPI(false, gameType.value, teamSize.value);
}
});
</script>
<template>
<Container title="搜索对手..." :bgType="1" :onBack="stopMatch">
<view class="container">
<Matching :stopMatch="stopMatch" :onComplete="onComplete" />
</view>
</Container>
</template>
<style scoped>
.container {
width: 100%;
height: 100%;
}
</style>