加入房间逻辑完善
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
import SButton from "@/components/SButton.vue";
|
||||
import { createRoomAPI } from "@/apis";
|
||||
import { joinRoomAPI, createRoomAPI } from "@/apis";
|
||||
|
||||
const props = defineProps({
|
||||
onConfirm: {
|
||||
@@ -26,9 +26,10 @@ const createRoom = async () => {
|
||||
step.value = 2;
|
||||
loading.value = false;
|
||||
};
|
||||
const enterRoom = () => {
|
||||
const enterRoom = async () => {
|
||||
step.value = 1;
|
||||
props.onConfirm();
|
||||
await joinRoomAPI(roomNumber.value);
|
||||
uni.navigateTo({
|
||||
url: `/pages/battle-room?roomNumber=${roomNumber.value}`,
|
||||
});
|
||||
|
||||
@@ -225,7 +225,6 @@ const destroyRoom = async () => {
|
||||
};
|
||||
|
||||
const exitRoom = async () => {
|
||||
await exitRoomAPI(roomNumber.value);
|
||||
uni.navigateBack();
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,11 @@ import Guide from "@/components/Guide.vue";
|
||||
import SButton from "@/components/SButton.vue";
|
||||
import SModal from "@/components/SModal.vue";
|
||||
import CreateRoom from "@/components/CreateRoom.vue";
|
||||
import { joinRoomAPI } from "@/apis";
|
||||
import { getRoomAPI, joinRoomAPI } from "@/apis";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { user } = storeToRefs(store);
|
||||
|
||||
const showModal = ref(false);
|
||||
const warnning = ref("");
|
||||
@@ -17,8 +21,12 @@ const enterRoom = async () => {
|
||||
warnning.value = "请输入房间号";
|
||||
showModal.value = true;
|
||||
} else {
|
||||
const room = await joinRoomAPI(roomNumber.value);
|
||||
const room = await getRoomAPI(roomNumber.value);
|
||||
if (room.number) {
|
||||
const alreadyIn = room.members.find(
|
||||
(item) => item.userInfo.id === user.value.id
|
||||
);
|
||||
if (!alreadyIn) await joinRoomAPI(roomNumber.value);
|
||||
roomNumber.value = "";
|
||||
uni.navigateTo({
|
||||
url: `/pages/battle-room?roomNumber=${room.number}`,
|
||||
|
||||
Reference in New Issue
Block a user