加入房间逻辑完善
This commit is contained in:
@@ -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