Files
shoot-miniprograms/src/components/CreateRoom.vue

125 lines
2.8 KiB
Vue
Raw Normal View History

2025-05-16 15:56:54 +08:00
<script setup>
import { ref } from "vue";
import SButton from "@/components/SButton.vue";
import { joinRoomAPI, createRoomAPI } from "@/apis";
import { debounce } from "@/util";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user, game } = storeToRefs(store);
2025-05-30 16:14:17 +08:00
const props = defineProps({
onConfirm: {
type: Function,
default: () => {},
},
});
2025-05-16 15:56:54 +08:00
const battleMode = ref(1);
2025-05-30 16:14:17 +08:00
const loading = ref(false);
const roomNumber = ref("");
2025-05-16 15:56:54 +08:00
const createRoom = debounce(async () => {
if (game.value.inBattle) {
2025-07-03 21:13:55 +08:00
uni.$showHint(1);
2025-07-02 17:16:56 +08:00
return;
}
2025-05-30 16:14:17 +08:00
if (loading.value === true) return;
loading.value = true;
2025-08-14 15:24:12 +08:00
let size = 2;
if (battleMode.value === 2) size = 10;
if (battleMode.value === 3) size = 4;
if (battleMode.value === 4) size = 6;
try {
const result = await createRoomAPI(
battleMode.value === 2 ? 2 : 1,
battleMode.value === 2 ? 10 : size
);
if (result.number) {
props.onConfirm();
await joinRoomAPI(result.number);
uni.navigateTo({
url: "/pages/battle-room?roomNumber=" + result.number,
});
}
} finally {
loading.value = false;
}
});
2025-05-16 15:56:54 +08:00
</script>
<template>
2025-05-30 13:58:43 +08:00
<view class="container">
<image src="../static/choose-battle-mode.png" mode="widthFix" />
<view class="create-options">
2025-05-16 15:56:54 +08:00
<view
:class="{ 'battle-btn': true, 'battle-choosen': battleMode === 1 }"
@click="() => (battleMode = 1)"
>
<text>对抗模式1V1</text>
</view>
2025-08-12 18:33:39 +08:00
<view
:class="{ 'battle-btn': true, 'battle-choosen': battleMode === 3 }"
@click="() => (battleMode = 3)"
>
2025-05-16 15:56:54 +08:00
<text>对抗模式2V2</text>
</view>
2025-08-12 18:33:39 +08:00
<view
:class="{ 'battle-btn': true, 'battle-choosen': battleMode === 4 }"
@click="() => (battleMode = 4)"
>
2025-05-16 15:56:54 +08:00
<text>对抗模式3V3</text>
</view>
2025-11-06 09:38:19 +08:00
<view
:class="{ 'battle-btn': true, 'battle-choosen': battleMode === 2 }"
@click="() => (battleMode = 2)"
>
<text>乱斗模式3-10</text>
</view>
2025-05-16 15:56:54 +08:00
</view>
<SButton :onClick="createRoom">创建房间</SButton>
2025-05-16 15:56:54 +08:00
</view>
</template>
<style scoped>
.container {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.container > image:first-child {
width: 45%;
margin: 5px 0;
}
.create-options {
width: 100%;
padding: 0 10px;
display: flex;
flex-wrap: wrap;
2025-07-25 09:59:54 +08:00
gap: 12px;
2025-05-16 15:56:54 +08:00
justify-content: center;
margin-bottom: 15px;
}
.battle-btn {
width: 45%;
height: 55px;
text-align: center;
border-radius: 10px;
2025-07-25 09:59:54 +08:00
border: 2rpx solid #fff3;
box-sizing: border-box;
2025-05-16 15:56:54 +08:00
color: #fff;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.battle-choosen {
color: #fed847;
2025-07-25 09:59:54 +08:00
border: 4rpx solid #fff3;
2025-05-16 15:56:54 +08:00
border-color: #fed847;
}
</style>