Fix: guest join room
This commit is contained in:
parent
063db6c7de
commit
b4023cc0f1
|
@ -10,7 +10,6 @@ import { useTimeAgo } from "@vueuse/core";
|
|||
import { useRouter } from "vue-router";
|
||||
import { useRoomApi } from "@/hooks/useRoom";
|
||||
import { getObjValue } from "@/utils";
|
||||
import { guestJoinRoomApi } from "@/services/apis/room";
|
||||
|
||||
const router = useRouter();
|
||||
const props = defineProps<{
|
||||
|
@ -66,6 +65,11 @@ const getRoomList = async (showMsg = false) => {
|
|||
};
|
||||
|
||||
const JoinRoomDialog = ref(false);
|
||||
const JoinRoomC = ref<InstanceType<typeof JoinRoom>>();
|
||||
const openJoinRoomDialog = () => {
|
||||
JoinRoomC.value?.init();
|
||||
JoinRoomDialog.value = true;
|
||||
};
|
||||
const joinThisRoom = async (item: RoomList) => {
|
||||
if (!settings?.guestEnable && isLogin.value) {
|
||||
ElNotification({
|
||||
|
@ -86,10 +90,10 @@ const joinThisRoom = async (item: RoomList) => {
|
|||
return isLogin.value
|
||||
? info.value?.username === item.creator || !item.needPassword
|
||||
? await joinRoom(formData.value)
|
||||
: (JoinRoomDialog.value = true)
|
||||
: openJoinRoomDialog()
|
||||
: settings?.guestEnable && !item.needPassword
|
||||
? await guestJoinRoom(formData.value)
|
||||
: (JoinRoomDialog.value = true);
|
||||
: openJoinRoomDialog();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
@ -238,6 +242,6 @@ onMounted(() => {
|
|||
<span class="truncate">加入房间</span>
|
||||
</div>
|
||||
</template>
|
||||
<JoinRoom :item="formData" />
|
||||
<JoinRoom :item="formData" ref="joinRoomC" />
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { ref } from "vue";
|
||||
import { ElNotification } from "element-plus";
|
||||
import { indexStore } from "@/stores";
|
||||
import { userStore } from "@/stores/user";
|
||||
import { roomStore } from "@/stores/room";
|
||||
import router from "@/router";
|
||||
|
@ -17,35 +18,57 @@ import { strLengthLimit } from "@/utils";
|
|||
import { storeToRefs } from "pinia";
|
||||
import { RoomMemberPermission, RoomAdminPermission } from "@/types/Room";
|
||||
|
||||
const { settings } = indexStore();
|
||||
|
||||
// 获取用户信息
|
||||
const { info, token } = userStore();
|
||||
const { info, token, isLogin } = userStore();
|
||||
const { myInfo } = storeToRefs(roomStore());
|
||||
|
||||
export const useRoomApi = (roomId: string) => {
|
||||
// 检查房间状态
|
||||
const { state: thisRoomInfo, execute: reqCheckRoomApi } = checkRoomApi();
|
||||
const checkRoom = async (pwd: string) => {
|
||||
console.log(roomId, pwd);
|
||||
|
||||
try {
|
||||
await reqCheckRoomApi({
|
||||
params: {
|
||||
roomId: roomId
|
||||
}
|
||||
});
|
||||
if (thisRoomInfo.value) {
|
||||
if (!thisRoomInfo.value) return;
|
||||
|
||||
if (isLogin.value) {
|
||||
if (info.value?.username === thisRoomInfo.value.creator) {
|
||||
return await joinRoom({ roomId, password: pwd });
|
||||
}
|
||||
|
||||
if (thisRoomInfo.value.needPassword) {
|
||||
if (pwd) return await joinRoom({ roomId, password: pwd });
|
||||
} else {
|
||||
return await joinRoom({ roomId, password: pwd });
|
||||
}
|
||||
} else if (settings?.guestEnable) {
|
||||
if (thisRoomInfo.value.needPassword) {
|
||||
if (pwd) return await guestJoinRoom({ roomId, password: pwd });
|
||||
} else {
|
||||
return await guestJoinRoom({
|
||||
roomId,
|
||||
password: pwd
|
||||
});
|
||||
}
|
||||
} else {
|
||||
router.replace({
|
||||
name: "login",
|
||||
query: {
|
||||
redirect: router.currentRoute.value.fullPath
|
||||
}
|
||||
});
|
||||
throw new Error("请先登录");
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
ElNotification({
|
||||
title: "错误",
|
||||
message: err.response.data.error || err.message,
|
||||
message: err.response?.data.error || err.message,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ export const useSettings = () => {
|
|||
]);
|
||||
|
||||
const defaultUserSettings: Map<string, settingType> = new Map([
|
||||
["enable_guest", { value: false, name: "允许访客用户" }],
|
||||
["disable_user_signup", { value: false, name: "禁止用户注册" }],
|
||||
["signup_need_review", { value: false, name: "注册需要审核" }],
|
||||
["user_max_room_count", { value: 0, append: "个", name: "用户最大创建房间数" }]
|
||||
|
|
|
@ -31,12 +31,24 @@ const formData = ref<{
|
|||
roomId: (roomID.value as string) ?? "",
|
||||
password: pwd.value as string
|
||||
});
|
||||
if (props.item) formData.value = props.item;
|
||||
|
||||
const { checkRoom, joinRoom, guestJoinRoom } = useRoomApi(formData.value.roomId);
|
||||
const { joinRoom, guestJoinRoom } = useRoomApi(formData.value.roomId);
|
||||
|
||||
const init = () => {
|
||||
console.log(props.item);
|
||||
if (props.item) formData.value = props.item;
|
||||
else {
|
||||
if (roomID) formData.value.roomId = roomID.value as string;
|
||||
if (pwd) formData.value.password = pwd.value as string;
|
||||
}
|
||||
const { checkRoom } = useRoomApi(formData.value.roomId);
|
||||
if (formData.value.roomId) checkRoom(pwd.value as string);
|
||||
};
|
||||
|
||||
defineExpose({ init });
|
||||
|
||||
onMounted(() => {
|
||||
if (formData.value.roomId) checkRoom(pwd.value as string);
|
||||
init();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in New Issue