Files
admin-vben5/apps/web-antd/src/views/property/roomBooking/conferenceView/index.vue

416 lines
11 KiB
Vue
Raw Normal View History

2025-06-19 16:54:36 +08:00
<script setup lang="ts">
import { ref, computed, onMounted, h } from 'vue';
import { Page } from '@vben/common-ui';
import dayjs from 'dayjs';
import type { TableColumnType } from 'ant-design-vue';
import { Radio, Select, Button, Table } from 'ant-design-vue';
2025-07-09 18:18:48 +08:00
import { getMeetName } from '#/api/property/roomBooking';
import { getAppointmentListByDate,getAppointmentListBymeetId } from '#/api/property/roomBooking/conferenceView';
2025-06-19 16:54:36 +08:00
import type { RadioChangeEvent } from 'ant-design-vue';
import type { SelectValue } from 'ant-design-vue/es/select';
2025-07-09 18:18:48 +08:00
// 会议室和预约信息的接口类型
2025-06-19 16:54:36 +08:00
interface ConferenceRoom {
id: string;
name: string;
}
interface ConferenceBooking {
id: string | number;
tbConferenceId: string | number; // 会议室ID
bookingName: string; // 预约人
deptName: string; // 部门名称
subject: string; // 会议主题
startTime: string; // 开始时间
endTime: string; // 结束时间
bookingDate: string; // 预约日期
status: number; // 状态
}
// 视图模式
const viewMode = ref<'date' | 'room'>('date');
// 会议室列表
const roomList = ref<ConferenceRoom[]>([]);
// 选中的会议室
const selectedRoom = ref<string>('');
// 选中的日期
const selectedDate = ref<string>('');
// 一周的日期
const weekDates = ref<string[]>([]);
// 预约数据
2025-07-09 18:18:48 +08:00
const bookings = ref<any[]>([]);
// 新增:表格渲染用的结构
const bookingTable = ref<Record<string, Record<string, any>>>({});
// 新增:加载状态
const loading = ref(false);
2025-06-19 16:54:36 +08:00
2025-07-09 18:18:48 +08:00
// 时间段只显示"上午" "下午"
const timeSlots = ['上午', '下午'];
2025-06-19 16:54:36 +08:00
// 生成一周日期
function generateWeekDates(): void {
const today = dayjs();
2025-07-09 18:18:48 +08:00
// 获取本周的周一
const startOfWeek = today.startOf('week');
2025-06-19 16:54:36 +08:00
const dates = Array.from({ length: 7 }, (_, i) => {
2025-07-09 18:18:48 +08:00
return startOfWeek.add(i, 'day').format('YYYY-MM-DD');
2025-06-19 16:54:36 +08:00
});
weekDates.value = dates;
selectedDate.value = dates[0] ?? '';
}
// 获取预约数据
async function fetchBookings(): Promise<void> {
2025-07-09 18:18:48 +08:00
loading.value = true;
2025-06-19 16:54:36 +08:00
try {
if (viewMode.value === 'date') {
2025-07-09 18:18:48 +08:00
const roomRes = await getMeetName();
roomList.value = ([roomRes]).map((item: any) => ({
id: item.value,
name: item.name
}));
const appointmentRes = await getAppointmentListByDate({
appointmentDate: selectedDate.value
});
bookings.value = (appointmentRes || []).map((item: any) => ({
id: item.id,
meetId: item.meetId,
name: item.name,
person: item.person,
scheduledEndtime: item.scheduledEndtime,
scheduledStarttime: item.scheduledStarttime,
unit: item.unit,
personName: item.personName,
slots: item.slots,
unitName: item.unitName,
subject: item.subject,
deptName: item.unitName,
bookingName: item.personName,
startTime: item.scheduledStarttime,
endTime: item.scheduledEndtime,
bookingDate: item.scheduledStarttime,
tbConferenceId: item.meetId,
// 兼容后续渲染
}));
// 处理为表格结构
const table: Record<string, Record<string, any>> = { '上午': {}, '下午': {} };
roomList.value.forEach(room => {
['上午', '下午'].forEach(slot => {
const booking = bookings.value.find(b => b.name === room.name && b.slots === slot);
table[slot][room.name] = booking || null;
});
});
bookingTable.value = table;
2025-06-19 16:54:36 +08:00
} else {
2025-07-09 18:18:48 +08:00
const res = await getAppointmentListBymeetId({
meetId: selectedRoom.value
2025-06-19 16:54:36 +08:00
});
2025-07-09 18:18:48 +08:00
bookings.value = (res || []).map((item: any) => ({
id: item.id,
meetId: item.meetId,
name: item.name,
person: item.person,
scheduledEndtime: item.scheduledEndtime,
scheduledStarttime: item.scheduledStarttime,
unit: item.unit,
personName: item.personName,
slots: item.slots,
unitName: item.unitName,
subject: item.subject,
deptName: item.unitName,
bookingName: item.personName,
startTime: item.scheduledStarttime,
endTime: item.scheduledEndtime,
bookingDate: item.scheduledStarttime,
tbConferenceId: item.meetId,
}));
const table: Record<string, Record<string, any>> = { '上午': {}, '下午': {} };
weekDates.value.forEach(date => {
['上午', '下午'].forEach(slot => {
const booking = bookings.value.find(b => dayjs(b.scheduledStarttime).format('YYYY-MM-DD') === date && b.slots === slot);
table[slot][date] = booking || null;
});
});
bookingTable.value = table;
2025-06-19 16:54:36 +08:00
}
2025-07-09 18:18:48 +08:00
console.log(bookingTable.value,'bookingTable.value');
2025-06-19 16:54:36 +08:00
} catch (error) {
console.error('获取预约数据失败:', error);
2025-07-09 18:18:48 +08:00
} finally {
loading.value = false;
2025-06-19 16:54:36 +08:00
}
}
// 切换视图模式
function handleViewModeChange(e: RadioChangeEvent): void {
viewMode.value = e.target.value;
if (viewMode.value === 'date') {
selectedDate.value = weekDates.value[0] ?? '';
} else {
selectedRoom.value = roomList.value[0]?.id ?? '';
}
fetchBookings();
}
// 切换日期
function handleDateChange(date: string): void {
selectedDate.value = date;
fetchBookings();
}
// 切换会议室
function handleRoomChange(value: SelectValue): void {
selectedRoom.value = value as string;
fetchBookings();
}
2025-07-09 18:18:48 +08:00
// 获取单元格预约信息(上午/下午)
2025-06-19 16:54:36 +08:00
function getCellBooking(col: string, time: string): ConferenceBooking | undefined {
2025-07-09 18:18:48 +08:00
// 判断时间属于上午还是下午
function isMorning(startTime: string) {
const hour = dayjs(startTime).hour();
return hour < 12;
}
2025-06-19 16:54:36 +08:00
if (viewMode.value === 'date') {
const room = roomList.value.find(r => r.name === col);
2025-07-09 18:18:48 +08:00
return bookings.value.find(b =>
b.tbConferenceId === room?.id &&
((time === '上午' && isMorning(b.startTime)) || (time === '下午' && !isMorning(b.startTime)))
2025-06-19 16:54:36 +08:00
);
} else {
2025-07-09 18:18:48 +08:00
return bookings.value.find(b =>
dayjs(b.bookingDate).format('YYYY-MM-DD') === col &&
((time === '上午' && isMorning(b.startTime)) || (time === '下午' && !isMorning(b.startTime)))
2025-06-19 16:54:36 +08:00
);
}
}
// 修改渲染预约单元格的函数
function renderBookingCell(booking: ConferenceBooking) {
2025-07-09 18:18:48 +08:00
return h('div',
{
class: 'booking-cell'
},
2025-06-19 16:54:36 +08:00
[
2025-07-09 18:18:48 +08:00
h('span',
{ class: 'booking-user' },
2025-06-19 16:54:36 +08:00
`预约人:${booking.bookingName}`
),
2025-07-09 18:18:48 +08:00
h('span',
{ class: 'booking-dept' },
2025-06-19 16:54:36 +08:00
`单位:${booking.deptName}`
),
2025-07-09 18:18:48 +08:00
h('span',
{ class: 'booking-subject' },
2025-06-19 16:54:36 +08:00
`主题:${booking.subject}`
)
]
);
}
2025-07-09 18:18:48 +08:00
// 随机浅色背景色生成函数
function getRandomBgColor() {
const r = Math.floor(200 + Math.random() * 55);
const g = Math.floor(200 + Math.random() * 55);
const b = Math.floor(200 + Math.random() * 55);
return {
background: `rgba(${r},${g},${b},0.5)`,
borderRadius: '6px',
padding: '60px 10px',
transition: 'background 0.3s'
};
}
2025-06-19 16:54:36 +08:00
// 表格列配置
interface TableRecord {
time: string;
key: string;
[key: string]: any;
}
2025-07-09 18:18:48 +08:00
// 会议室列补全到7个
function getFullRoomList() {
const rooms = roomList.value.slice();
const count = rooms.length;
if (viewMode.value === 'date' && count < 7) {
for (let i = count; i < 7; i++) {
rooms.push({ id: `empty_${i}`, name: '' });
}
}
return rooms;
}
2025-06-19 16:54:36 +08:00
const columns = computed<TableColumnType<TableRecord>[]>(() => {
const baseColumns: TableColumnType<TableRecord>[] = [{
title: '时间',
2025-07-09 18:18:48 +08:00
dataIndex: 'slot',
key: 'slot',
2025-06-19 16:54:36 +08:00
width: 100,
fixed: 'left' as const
}];
const dynamicColumns: TableColumnType<TableRecord>[] = viewMode.value === 'date'
2025-07-09 18:18:48 +08:00
? getFullRoomList().map(room => ({
title: room.name || ' ',
dataIndex: room.name,
key: room.name,
2025-06-19 16:54:36 +08:00
width: 200,
}))
: weekDates.value.map(date => ({
2025-07-09 18:18:48 +08:00
title: dayjs(date).format('YYYY-MM-DD'),
2025-06-19 16:54:36 +08:00
dataIndex: date,
2025-07-09 18:18:48 +08:00
key: date,
2025-06-19 16:54:36 +08:00
width: 200,
}));
return [...baseColumns, ...dynamicColumns];
});
const tableData = computed<TableRecord[]>(() => {
2025-07-09 18:18:48 +08:00
const slots = ['上午', '下午'];
return slots.map(slot => {
const row: any = { slot };
const cols = viewMode.value === 'date'
? getFullRoomList().map(room => room.name)
: weekDates.value;
cols.forEach(col => {
row[col] = bookingTable.value[slot]?.[col] || null;
});
return row;
});
2025-06-19 16:54:36 +08:00
});
onMounted(() => {
generateWeekDates();
fetchBookings();
});
</script>
<template>
<Page>
<div class="conference-view">
<!-- 顶部控制区 -->
<div class="control-panel">
<Radio.Group v-model:value="viewMode" @change="handleViewModeChange">
<Radio.Button value="date">按日期</Radio.Button>
<Radio.Button value="room">按会议室</Radio.Button>
</Radio.Group>
<Select
v-if="viewMode === 'room'"
v-model:value="selectedRoom"
class="room-select"
placeholder="请选择会议室"
@change="handleRoomChange"
>
2025-07-09 18:18:48 +08:00
<Select.Option
2025-06-19 16:54:36 +08:00
v-for="room in roomList"
:key="room.id"
:value="room.id"
>
{{ room.name }}
</Select.Option>
</Select>
</div>
2025-07-09 18:18:48 +08:00
<div v-if="viewMode === 'date'" class="date-buttons">
<Button
v-for="date in weekDates"
:key="date"
:type="date === selectedDate ? 'primary' : 'default'"
@click="handleDateChange(date)"
>
{{ dayjs(date).format('YYYY-MM-DD') }}
</Button>
</div>
2025-06-19 16:54:36 +08:00
<Table
:columns="columns"
:data-source="tableData"
:pagination="false"
bordered
:scroll="{ x: 'max-content' }"
2025-07-09 18:18:48 +08:00
:loading="loading"
tableLayout="fixed"
>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex !== 'slot'">
<div
v-if="record[column.dataIndex]"
:style="getRandomBgColor()"
>
<div>预约人{{ record[column.dataIndex].personName }}</div>
<div>单位{{ record[column.dataIndex].unitName }}</div>
</div>
<div v-else></div>
</template>
</template>
</Table>
2025-06-19 16:54:36 +08:00
</div>
</Page>
</template>
<style lang="scss" scoped>
.conference-view {
.control-panel {
margin-bottom: 16px;
display: flex;
align-items: center;
.room-select {
width: 200px;
margin-left: 16px;
}
}
2025-07-09 18:18:48 +08:00
2025-06-19 16:54:36 +08:00
.date-buttons {
margin-top: 16px;
2025-07-09 18:18:48 +08:00
display: flex;
justify-content: center;
2025-06-19 16:54:36 +08:00
:deep(.ant-btn) {
margin-right: 8px;
2025-07-09 18:18:48 +08:00
2025-06-19 16:54:36 +08:00
&:last-child {
margin-right: 0;
}
}
}
2025-07-09 18:18:48 +08:00
2025-06-19 16:54:36 +08:00
.booking-cell {
background: #e6f7ff;
padding: 8px;
border-radius: 4px;
min-height: 60px;
display: flex;
flex-direction: column;
gap: 4px;
span {
display: block;
font-size: 12px;
line-height: 1.5;
2025-07-09 18:18:48 +08:00
2025-06-19 16:54:36 +08:00
&.booking-user {
color: #1890ff;
font-weight: 500;
}
2025-07-09 18:18:48 +08:00
2025-06-19 16:54:36 +08:00
&.booking-dept {
color: #666;
}
2025-07-09 18:18:48 +08:00
2025-06-19 16:54:36 +08:00
&.booking-subject {
color: #333;
}
}
2025-07-09 18:18:48 +08:00
2025-06-19 16:54:36 +08:00
&:hover {
background: #bae7ff;
}
}
2025-07-09 18:18:48 +08:00
:deep(.ant-table-tbody > tr > td:first-child) {
padding: 10px;
height: 200px;
}
2025-06-19 16:54:36 +08:00
}
</style>