mirror of
https://hub.gitmirror.com/https://github.com/ExamAware/ExamShowboard-Legacy.git
synced 2025-04-29 08:06:32 +00:00
Update ExamList.vue
This commit is contained in:
parent
821e735de1
commit
8ef0cf534c
@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-card class="mx-auto" max-width="600">
|
<v-card class="mx-auto" max-width="600" flat>
|
||||||
<v-container fluid>
|
<v-container fluid class="pa-0">
|
||||||
<v-row justify="center">
|
<v-row justify="center" class="ma-0">
|
||||||
<v-col cols="12">
|
<v-col cols="12" class="pa-0">
|
||||||
<v-data-table
|
<v-data-table
|
||||||
:items="groupedExams"
|
:items="groupedExams"
|
||||||
:headers="headers"
|
:headers="headers"
|
||||||
@ -11,16 +11,19 @@
|
|||||||
dense
|
dense
|
||||||
class="text-h5"
|
class="text-h5"
|
||||||
>
|
>
|
||||||
<template #item="{ item, index }">
|
<template #item="{ item }">
|
||||||
<tr :style="{ lineHeight: '2.5rem' }">
|
<tr :style="{ lineHeight: '2.0rem' }">
|
||||||
<td v-if="item.showDate" class="text-h5 date-column" :rowspan="item.rowspan">
|
<td v-if="item.showDate" class="text-h5 date-column" :rowspan="item.rowspan">
|
||||||
{{ item.date }}<br />{{ item.period }}
|
{{ item.date }}<br>{{ item.period }}
|
||||||
</td>
|
|
||||||
<td :class="['text-h5', 'subject-column', getStatusClass(item)]">
|
|
||||||
{{ item.name }}
|
|
||||||
</td>
|
</td>
|
||||||
|
<td class="text-h5 subject-column">{{ item.name }}</td>
|
||||||
<td class="text-h5 time-column">{{ formatTime(item.start) }}</td>
|
<td class="text-h5 time-column">{{ formatTime(item.start) }}</td>
|
||||||
<td class="text-h5 time-column">{{ formatTime(item.end) }}</td>
|
<td class="text-h5 time-column">{{ formatTime(item.end) }}</td>
|
||||||
|
<td class="status-column">
|
||||||
|
<v-chip :color="getStatusColor(item)" dark class="exam-status-chip">
|
||||||
|
{{ getStatusText(item) }}
|
||||||
|
</v-chip>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</template>
|
</template>
|
||||||
<template #header.date>
|
<template #header.date>
|
||||||
@ -35,6 +38,9 @@
|
|||||||
<template #header.end>
|
<template #header.end>
|
||||||
<span class="text-h5 font-weight-bold">结束</span>
|
<span class="text-h5 font-weight-bold">结束</span>
|
||||||
</template>
|
</template>
|
||||||
|
<template #header.status>
|
||||||
|
<span class="text-h5 font-weight-bold">状态</span>
|
||||||
|
</template>
|
||||||
</v-data-table>
|
</v-data-table>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@ -44,98 +50,87 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, computed, onMounted, onUnmounted } from 'vue';
|
import { reactive, computed, onMounted, onUnmounted } from 'vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
exam: {
|
exam: {
|
||||||
type: Array as () => any[],
|
type: Array as () => any[],
|
||||||
default: () => []
|
default: () => []
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
exams: props.exam
|
exams: props.exam
|
||||||
});
|
});
|
||||||
|
|
||||||
function formatPeriod(isoString: string): string {
|
function formatPeriod(isoString: string): string {
|
||||||
const hour = new Date(isoString).getHours();
|
const hour = new Date(isoString).getHours();
|
||||||
if (hour < 12) return '上午';
|
if (hour < 12) return '上午';
|
||||||
else if (hour < 18) return '下午';
|
else if (hour < 18) return '下午';
|
||||||
else return '晚上';
|
else return '晚上';
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupedExams = computed(() => {
|
const groupedExams = computed(() => {
|
||||||
const grouped = [];
|
const grouped = [];
|
||||||
let currentDate = '';
|
let currentDate = '';
|
||||||
let currentPeriod = '';
|
let currentPeriod = '';
|
||||||
|
|
||||||
sortedExams.value.forEach((exam, index) => {
|
sortedExams.value.forEach((exam, index) => {
|
||||||
const examDate =
|
const examDate = new Date(exam.start).toLocaleDateString('zh-CN', {
|
||||||
new Date(exam.start)
|
month: 'numeric',
|
||||||
.toLocaleDateString('zh-CN', {
|
day: 'numeric'
|
||||||
month: 'numeric',
|
}).replace('/', '月') + '日';
|
||||||
day: 'numeric'
|
|
||||||
})
|
|
||||||
.replace('/', '月') + '日';
|
|
||||||
const period = formatPeriod(exam.start);
|
const period = formatPeriod(exam.start);
|
||||||
|
|
||||||
const showDate = examDate !== currentDate || period !== currentPeriod;
|
const showDate = examDate !== currentDate || period !== currentPeriod;
|
||||||
|
|
||||||
if (showDate) {
|
if (showDate) {
|
||||||
currentDate = examDate;
|
currentDate = examDate;
|
||||||
currentPeriod = period;
|
currentPeriod = period;
|
||||||
|
const rowspan = sortedExams.value.filter(e =>
|
||||||
const rowspan = sortedExams.value.filter(
|
new Date(e.start).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' }).replace('/', '月') + '日' === currentDate &&
|
||||||
(e) =>
|
formatPeriod(e.start) === currentPeriod
|
||||||
new Date(e.start)
|
|
||||||
.toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' })
|
|
||||||
.replace('/', '月') +
|
|
||||||
'日' ===
|
|
||||||
currentDate && formatPeriod(e.start) === currentPeriod
|
|
||||||
).length;
|
).length;
|
||||||
|
|
||||||
grouped.push({ ...exam, date: examDate, period, showDate, rowspan });
|
grouped.push({ ...exam, date: examDate, period, showDate, rowspan });
|
||||||
} else {
|
} else {
|
||||||
grouped.push({ ...exam, date: examDate, period, showDate: false });
|
grouped.push({ ...exam, date: examDate, period, showDate: false });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return grouped;
|
return grouped;
|
||||||
});
|
});
|
||||||
|
|
||||||
const headers = [
|
const headers = [
|
||||||
{ text: '日期', value: 'date', sortable: false, align: 'center' },
|
{ text: '日期', value: 'date', sortable: false, align: 'center' },
|
||||||
{ text: '科目', value: 'name', align: 'center' },
|
{ text: '科目', value: 'name', align: 'center' },
|
||||||
{ text: '开始', value: 'start', sortable: false, align: 'center' },
|
{ text: '开始', value: 'start', sortable: false, align: 'center' },
|
||||||
{ text: '结束', value: 'end', sortable: false, align: 'center' }
|
{ text: '结束', value: 'end', sortable: false, align: 'center' },
|
||||||
|
{ text: '状态', value: 'status', sortable: false, align: 'center' }
|
||||||
];
|
];
|
||||||
|
|
||||||
const formatTime = (isoString: string) => {
|
const formatTime = (isoString: string) => {
|
||||||
const date = new Date(isoString);
|
const date = new Date(isoString);
|
||||||
return `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
|
return `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
|
||||||
};
|
};
|
||||||
|
function getStatusColor(item: any): string {
|
||||||
function getStatusClass(item: any): string {
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const startTime = new Date(item.start);
|
const startTime = new Date(item.start);
|
||||||
const endTime = new Date(item.end);
|
const endTime = new Date(item.end);
|
||||||
|
if (now < startTime) return 'orange';
|
||||||
if (now < startTime) return 'status-upcoming';
|
else if (now >= startTime && now <= endTime) return 'green';
|
||||||
else if (now >= startTime && now <= endTime) return 'status-ongoing';
|
else return 'red';
|
||||||
else return 'status-ended';
|
}
|
||||||
|
function getStatusText(item: any): string {
|
||||||
|
const now = new Date();
|
||||||
|
const startTime = new Date(item.start);
|
||||||
|
const endTime = new Date(item.end);
|
||||||
|
if (now < startTime) {
|
||||||
|
return '未开始';
|
||||||
|
} else if (now >= startTime && now <= endTime) {
|
||||||
|
return '进行中';
|
||||||
|
} else {
|
||||||
|
return '已结束';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortedExams = computed(() => {
|
const sortedExams = computed(() => {
|
||||||
return state.exams.sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime());
|
return state.exams.sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime());
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
state.exams = state.exams.map((exam) => ({
|
state.exams = state.exams.map((exam) => ({
|
||||||
...exam,
|
...exam,
|
||||||
status: getStatusClass(exam)
|
status: getStatusText(exam)
|
||||||
}));
|
}));
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
});
|
});
|
||||||
@ -152,44 +147,34 @@ onMounted(() => {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.v-card {
|
.exam-status-chip {
|
||||||
overflow-x: auto;
|
font-size: 1.5rem !important;
|
||||||
max-width: 100%; /* 防止表格超出边界 */
|
text-align: center;
|
||||||
padding-right: 8px; /* 调整右边距 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 列样式 */
|
/* 列样式 */
|
||||||
.date-column,
|
.date-column,
|
||||||
.subject-column,
|
.subject-column,
|
||||||
.time-column {
|
.time-column,
|
||||||
|
.status-column {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding-left: 4px;
|
padding: 5px 2px;
|
||||||
padding-right: 4px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.date-column {
|
.date-column {
|
||||||
width: 100px;
|
width: 60px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.subject-column {
|
.subject-column {
|
||||||
width: 140px;
|
width: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.time-column {
|
.time-column {
|
||||||
width: 80px;
|
width: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 状态样式 */
|
.status-column {
|
||||||
.status-upcoming {
|
width: 60px;
|
||||||
color: orange;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-ongoing {
|
|
||||||
color: #00ff00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-ended {
|
|
||||||
color: red;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user