Skip to content

Commit

Permalink
Feat: admin delete room
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyCreeper committed May 8, 2024
1 parent 5361585 commit c25efae
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare module 'vue' {
ElForm: typeof import('element-plus/es')['ElForm']
ElFormItem: typeof import('element-plus/es')['ElFormItem']
ElIcon: typeof import('element-plus/es')['ElIcon']
ElImage: typeof import('element-plus/es')['ElImage']
ElInput: typeof import('element-plus/es')['ElInput']
ElMain: typeof import('element-plus/es')['ElMain']
ElOption: typeof import('element-plus/es')['ElOption']
Expand Down
4 changes: 2 additions & 2 deletions src/components/cinema/RoomInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ const roomUsersDrawer = ref<InstanceType<typeof RoomUsers>>();
</div>

<!-- 用户列表 -->
<RoomUsers ref="roomUsersDrawer" />
<RoomUsers v-if="isLogin" ref="roomUsersDrawer" />

<!-- 房间设置 -->
<RoomManage ref="roomManageDrawer" />
<RoomManage v-if="isLogin" ref="roomManageDrawer" />
</template>

<style lang="less" scoped>
Expand Down
16 changes: 16 additions & 0 deletions src/services/apis/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,22 @@ export const approveRoomApi = useDefineApi<
method: "POST"
});

// 删除房间
export const delRoomApi = useDefineApi<
{
headers: {
Authorization: string;
};
data: {
id: string;
};
},
any
>({
url: "/api/admin/room/delete",
method: "POST"
});

// 获取 OAuth2 设置
export const oAuth2SettingsApi = useDefineApi<
{
Expand Down
48 changes: 47 additions & 1 deletion src/views/admin/settings/RoomsManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { onMounted, ref } from "vue";
import { ElNotification, ElMessage } from "element-plus";
import { Search } from "@element-plus/icons-vue";
import { userStore } from "@/stores/user";
import { roomListApi, banRoomApi, unBanRoomApi, approveRoomApi } from "@/services/apis/admin";
import {
roomListApi,
banRoomApi,
unBanRoomApi,
approveRoomApi,
delRoomApi
} from "@/services/apis/admin";
import CopyButton from "@/components/CopyButton.vue";
import { RoomStatus, roomStatus } from "@/types/Room";
import { useTimeAgo } from "@vueuse/core";
Expand Down Expand Up @@ -108,6 +114,35 @@ const approveCreate = async (id: string) => {
}
};
// 删除房间
const { execute: reqDelRoomApi, isLoading: delRoomBtnLoading } = delRoomApi();
const deleteRoom = async (roomID: string) => {
try {
await reqDelRoomApi({
data: {
id: roomID
},
headers: { Authorization: token.value }
});
ElNotification({
title: "删除成功",
type: "success"
});
localStorage.removeItem(`room-${roomID}-token`);
localStorage.removeItem(`room-${roomID}-pwd`);
getRoomListApi();
} catch (err: any) {
console.error(err);
ElNotification({
title: "删除失败",
message: err.response?.data.error || err.message,
type: "error"
});
}
};
onMounted(async () => {
await getRoomListApi();
});
Expand Down Expand Up @@ -242,6 +277,17 @@ onMounted(async () => {
>
允许创建
</el-button>
<el-popconfirm
width="220"
confirm-button-text=""
cancel-button-text=""
title="你确定要删除这个房间吗?!"
@confirm="deleteRoom(scope.row.roomId)"
>
<template #reference>
<el-button plain type="danger" :loading="delRoomBtnLoading">删除房间</el-button>
</template>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
Expand Down

0 comments on commit c25efae

Please sign in to comment.