Skip to content

Commit

Permalink
Opt: room list
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyCreeper committed Oct 26, 2023
1 parent 33a0f23 commit ada011e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 45 deletions.
8 changes: 4 additions & 4 deletions src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const menuLinks = computed(() => {
{
name: "搜索",
to: "/search"
},
{
name: "房间列表",
to: "/rooms"
}
];
let links = [
Expand All @@ -37,10 +41,6 @@ const menuLinks = computed(() => {
{
name: "创建房间",
to: "/createRoom"
},
{
name: "我的房间",
to: "/cinema"
}
];
Expand Down
46 changes: 35 additions & 11 deletions src/components/RoomList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { roomListApi } from "@/services/apis/room";
import { myRoomList } from "@/services/apis/user";
import type { RoomList } from "@/types/Room";
import JoinRoom from "@/views/JoinRoom.vue";
import { roomStore } from "@/stores/room";
const props = defineProps<{
isMyRoom: boolean;
}>();
const isMyRoom = ref(false);
const __roomList = ref<RoomList[]>([]);
const JoinRoomDialog = ref(false);
const formData = ref<{
Expand Down Expand Up @@ -37,7 +35,7 @@ const sort = ref("desc");
const getRoomList = async (showMsg = false) => {
__roomList.value = [];
try {
if (props.isMyRoom) {
if (isMyRoom.value) {
await reqMyRoomList({
params: {
page: currentPage.value,
Expand All @@ -64,7 +62,7 @@ const getRoomList = async (showMsg = false) => {
});
}
if (props.isMyRoom) {
if (isMyRoom.value) {
if (myRoomList_.value && myRoomList_.value.list) {
totalItems.value = myRoomList_.value.total;
for (let i = 0; i < myRoomList_.value.list.length; i++) {
Expand Down Expand Up @@ -102,8 +100,35 @@ onMounted(() => {

<template>
<div class="card mx-auto">
<div class="card-title flex flex-wrap justify-between">
<div>房间列表({{ __roomList.length }})</div>
<div class="card-title flex flex-wrap justify-between items-center">
<div class="max-sm:mb-3">
<span
:class="
isMyRoom
? ' text-gray-700 cursor-pointer dark:text-slate-400 mr-4'
: 'border-b-2 border-slate-600 border-solid text-slate-700 dark:border-slate-200 dark:text-slate-200 mr-4'
"
@click="
isMyRoom = false;
getRoomList(false);
"
>
房间列表({{ __roomList.length }})</span
>
<span
v-if="roomStore().login"
:class="
isMyRoom
? 'border-b-2 border-slate-600 border-solid text-slate-700 dark:border-slate-200 dark:text-slate-200'
: 'text-gray-500 cursor-pointer dark:text-slate-400'
"
@click="
isMyRoom = true;
getRoomList(false);
"
>我创建的({{ __roomList.length }})</span
>
</div>
<div class="text-base -my-2">
排序方式:<el-select
v-model="order"
Expand All @@ -113,7 +138,6 @@ onMounted(() => {
>
<el-option label="房间名称" value="roomName" />
<el-option label="房间ID" value="roomId" />
<el-option label="房间人数" value="peopleNum" />
<el-option label="创建时间" value="createdAt" />
</el-select>
<button
Expand Down Expand Up @@ -144,11 +168,11 @@ onMounted(() => {
item["peopleNum"]
}}</span>
</div>
<div v-if="!props.isMyRoom" class="truncate">创建者:{{ item.creator }}</div>
<div v-if="!isMyRoom" class="truncate">创建者:{{ item.creator }}</div>
<div>创建时间:{{ new Date(item.createdAt).toLocaleString() }}</div>
</div>
<div class="flex p-2 w-full justify-between items-center">
<el-tag v-if="!props.isMyRoom" disabled :type="item.needPassword ? 'danger' : 'success'">
<el-tag v-if="!isMyRoom" disabled :type="item.needPassword ? 'danger' : 'success'">
{{ item.needPassword ? "有密码" : "无密码" }}
</el-tag>
<button class="btn btn-dense" @click="openJoinRoomDialog(item)">
Expand Down
8 changes: 4 additions & 4 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const router = createRouter({
meta: { title: "加入房间" }
},
{
path: "/cinema",
name: "selectCinema",
component: () => import("../views/MyRooms.vue"),
meta: { title: "我的房间" }
path: "/rooms",
name: "rooms",
component: () => import("../views/Rooms.vue"),
meta: { title: "房间列表" }
},
{
path: "/cinema/:roomId",
Expand Down
26 changes: 0 additions & 26 deletions src/views/MyRooms.vue

This file was deleted.

10 changes: 10 additions & 0 deletions src/views/Rooms.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup lang="ts">
import RoomList from "@/components/RoomList.vue";
</script>
<template>
<div class="text-center">
<div class="lg:w-9/12 mx-auto">
<RoomList />
</div>
</div>
</template>

0 comments on commit ada011e

Please sign in to comment.