6 changed files with 296 additions and 121 deletions
@ -1,125 +1,198 @@ |
|||||
<template> |
<template> |
||||
|
<el-card class="box-card !border-none" shadow="never"> |
||||
|
<el-button @click="addDict">添加</el-button> |
||||
<div class="schedule-container"> |
<div class="schedule-container"> |
||||
<!-- 周视图日历 --> |
<!-- 周一到周日的布局 --> |
||||
<FullCalendar |
<div v-for="(day, index) in days" :key="index" class="day-column"> |
||||
:options="calendarOptions" |
<div class="day-header">{{ day.date }}</div> |
||||
ref="fullCalendar" |
<el-table |
||||
class="calendar" |
:data="day.timeSlots" |
||||
/> |
border |
||||
|
:span-method="(data) => objectSpanMethod(day.timeSlots, data)" |
||||
<!-- 课程详情弹窗 --> |
style="width: 100%" |
||||
<el-dialog |
@cell-click="handleCellClick" |
||||
v-model="dialogVisible" |
|
||||
title="课程人员安排" |
|
||||
width="30%" |
|
||||
:before-close="handleClose" |
|
||||
> |
> |
||||
<div v-if="selectedEvent"> |
<!-- 时间列 --> |
||||
<h3>{{ selectedEvent.title }}</h3> |
<el-table-column |
||||
<p>时间:{{ selectedEvent.time }}</p> |
prop="timeRange" |
||||
<h4>参与人员:</h4> |
label="时间" |
||||
<ul> |
width="80" |
||||
<li v-for="person in selectedEvent.people" :key="person.id"> |
align="center" |
||||
{{ person.name }} - {{ person.role }} |
> |
||||
</li> |
<template #default="{ row }"> |
||||
</ul> |
<div :style="{ backgroundColor: row.color }"> |
||||
|
{{ row.timeRange }} |
||||
|
</div> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
|
||||
|
<!-- 教室列 --> |
||||
|
<el-table-column |
||||
|
v-for="(classroom, idx) in day.classrooms" |
||||
|
:key="idx" |
||||
|
:label="`教室${idx + 1}`" |
||||
|
:prop="`classroom${idx + 1}`" |
||||
|
align="center" |
||||
|
> |
||||
|
<template #default="{ row }"> |
||||
|
<div v-if="row.course && row.course.classroom === classroom"> |
||||
|
<div class="teacher-name">{{ row.course.teacher }}</div> |
||||
|
<div class="student-list"> |
||||
|
<el-tag |
||||
|
v-for="student in row.course.students" |
||||
|
:key="student" |
||||
|
size="small" |
||||
|
effect="plain" |
||||
|
> |
||||
|
{{ student }} |
||||
|
</el-tag> |
||||
</div> |
</div> |
||||
|
<div class="classroom-name"> |
||||
|
剩余空位:{{ row.course.hasnumber }} |
||||
|
</div> |
||||
|
</div> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
</el-table> |
||||
|
</div> |
||||
|
|
||||
|
<!-- 详情弹窗 --> |
||||
|
<el-dialog v-model="dialogVisible" title="课程详情"> |
||||
|
<p><strong>教师:</strong> {{ selectedCourse?.teacher }}</p> |
||||
|
<p><strong>学员:</strong> {{ selectedCourse?.students.join(', ') }}</p> |
||||
</el-dialog> |
</el-dialog> |
||||
</div> |
</div> |
||||
|
</el-card> |
||||
</template> |
</template> |
||||
|
|
||||
<script setup> |
<script setup> |
||||
import { ref } from 'vue' |
import { ref } from 'vue' |
||||
import FullCalendar from '@fullcalendar/vue3' |
|
||||
import dayGridPlugin from '@fullcalendar/daygrid' |
const days = [ |
||||
import timeGridPlugin from '@fullcalendar/timegrid' |
// 示例数据结构 |
||||
import interactionPlugin from '@fullcalendar/interaction' // 新增此行 |
{ |
||||
import zhLocale from '@fullcalendar/core/locales/zh-cn' |
date: '周一', |
||||
|
timeSlots: [ |
||||
// 模拟课程数据(替换为真实接口数据) |
|
||||
const courses = ref([ |
|
||||
{ |
{ |
||||
id: 1, |
timeRange: '9:00-10:00', |
||||
title: '数学课', |
color: '#FFA07A', |
||||
start: '2025-05-18 08:00:00', |
course: { |
||||
end: '2025-05-18 09:00:00', |
teacher: '', |
||||
people: [ |
students: [], |
||||
{ id: 1, name: '张老师', role: '主讲' }, |
classroom: '教室1', |
||||
{ id: 2, name: '李同学', role: '学生' }, |
hasnumber: 5, |
||||
|
}, |
||||
|
}, |
||||
|
// 其他时间段... |
||||
], |
], |
||||
|
classrooms: ['教室1'], // 当天可用教室列表 |
||||
}, |
}, |
||||
{ |
{ |
||||
id: 2, |
date: '周二', |
||||
title: '英语课', |
timeSlots: [ |
||||
start: '2025-05-18 10:00:00', |
{ |
||||
end: '2025-05-18 11:00:00', |
timeRange: '9:00-10:00', |
||||
people: [{ id: 3, name: '王老师', role: '主讲' }], |
color: '#FFA07A', |
||||
|
course: { |
||||
|
teacher: '张老师', |
||||
|
students: ['小明', '小红'], |
||||
|
classroom: '教室1', |
||||
|
hasnumber: 5, |
||||
}, |
}, |
||||
]) |
|
||||
|
|
||||
// 弹窗相关 |
|
||||
const dialogVisible = ref(false) |
|
||||
const selectedEvent = ref(null) |
|
||||
|
|
||||
// FullCalendar 配置 |
|
||||
const calendarOptions = ref({ |
|
||||
locale: zhLocale, |
|
||||
plugins: [ |
|
||||
dayGridPlugin, |
|
||||
timeGridPlugin, |
|
||||
interactionPlugin, // 新增此行 |
|
||||
], |
|
||||
initialView: 'timeGridWeek', // 周视图 |
|
||||
headerToolbar: { |
|
||||
left: 'prev,next today', |
|
||||
center: 'title', |
|
||||
right: 'timeGridWeek,timeGridDay', // 切换视图 |
|
||||
}, |
}, |
||||
events: courses.value, |
{ |
||||
eventClick: (info) => { |
timeRange: '11:00-12:00', |
||||
selectedEvent.value = { |
color: '#712e13', |
||||
title: info.event.title, |
course: { |
||||
time: `${info.event.start.toLocaleTimeString()} - ${info.event.end.toLocaleTimeString()}`, |
teacher: '张老师', |
||||
people: info.event.extendedProps.people, |
students: ['小明', '小红'], |
||||
} |
classroom: '教室2', |
||||
dialogVisible.value = true |
hasnumber: 5, |
||||
}, |
}, |
||||
eventContent: (arg) => { |
|
||||
// 自定义事件内容(可选) |
|
||||
return { html: `<div class="fc-event-title">${arg.event.title}</div>` } |
|
||||
}, |
}, |
||||
allDaySlot: false, // 隐藏全天时段 |
// 其他时间段... |
||||
slotDuration: '01:00', // 时间段间隔(1小时) |
], |
||||
slotLabelFormat: { |
classrooms: ['教室1', '教室2'], // 当天可用教室列表 |
||||
hour: 'numeric', |
|
||||
minute: '2-digit', |
|
||||
omitZeroMinute: false, |
|
||||
meridiem: 'short', |
|
||||
}, |
}, |
||||
}) |
] |
||||
|
|
||||
|
const dialogVisible = ref(false) |
||||
|
const selectedCourse = ref(null) |
||||
|
|
||||
|
// 合并单元格方法 |
||||
|
const objectSpanMethod = (timeSlots, { row, column, rowIndex }) => { |
||||
|
if (column.property === 'timeRange') { |
||||
|
// 获取当前时间段 |
||||
|
const current = timeSlots[rowIndex] |
||||
|
|
||||
|
// 如果当前行没有时间范围,不合并 |
||||
|
if (!current || !current.timeRange) return { rowspan: 0, colspan: 0 } |
||||
|
|
||||
|
let spanCount = 1 |
||||
|
|
||||
|
// 向下查找相同时间段的行数 |
||||
|
while (timeSlots[rowIndex + spanCount]?.timeRange === current.timeRange) { |
||||
|
spanCount++ |
||||
|
} |
||||
|
|
||||
|
// 如果是重复的,隐藏该行 |
||||
|
if ( |
||||
|
spanCount > 1 && |
||||
|
rowIndex > 0 && |
||||
|
timeSlots[rowIndex - 1]?.timeRange === current.timeRange |
||||
|
) { |
||||
|
return { rowspan: 0, colspan: 0 } |
||||
|
} |
||||
|
|
||||
|
return { rowspan: spanCount, colspan: 1 } |
||||
|
} |
||||
|
|
||||
|
return { rowspan: 1, colspan: 1 } |
||||
|
} |
||||
|
|
||||
// 关闭弹窗时重置数据 |
// 单元格点击事件 |
||||
const handleClose = () => { |
const handleCellClick = (row, column, cell, event) => { |
||||
dialogVisible.value = false |
console.log(row, column, cell, event) |
||||
selectedEvent.value = null |
if (column.property.startsWith('classroom')) { |
||||
|
selectedCourse.value = row.course |
||||
|
dialogVisible.value = true |
||||
|
} |
||||
} |
} |
||||
</script> |
</script> |
||||
|
|
||||
<style> |
<style scoped> |
||||
.schedule-container { |
.schedule-container { |
||||
padding: 20px; |
display: flex; |
||||
|
gap: 10px; |
||||
|
} |
||||
|
|
||||
|
.day-column { |
||||
|
flex: 1; |
||||
|
min-width: 200px; |
||||
|
} |
||||
|
|
||||
|
.day-header { |
||||
|
text-align: center; |
||||
|
font-weight: bold; |
||||
|
padding: 8px; |
||||
|
background-color: #f0f0f0; |
||||
|
} |
||||
|
|
||||
|
.teacher-name { |
||||
|
font-weight: bold; |
||||
|
margin-bottom: 5px; |
||||
} |
} |
||||
|
|
||||
.calendar { |
.student-list { |
||||
margin-bottom: 20px; |
margin-top: 5px; |
||||
} |
} |
||||
|
|
||||
.fc-event-title { |
.el-table__cell { |
||||
white-space: normal !important; |
display: flex; |
||||
font-size: 14px; |
align-items: center; |
||||
} |
} |
||||
|
|
||||
.fc-timegrid-event { |
.classroom-name { |
||||
cursor: pointer; |
margin-bottom: 5px; |
||||
} |
} |
||||
</style> |
</style> |
||||
|
|||||
Loading…
Reference in new issue