fix: 增加对上场考试状态的处理,显示已结束的考试信息

This commit is contained in:
MKStoler1024 2025-01-17 04:03:24 +00:00
parent 26345cfce4
commit d1a5e5c6d8

View File

@ -60,6 +60,7 @@ document.addEventListener("DOMContentLoaded", () => {
const now = new Date(new Date().getTime() + offsetTime * 1000); const now = new Date(new Date().getTime() + offsetTime * 1000);
let currentExam = null; let currentExam = null;
let nextExam = null; let nextExam = null;
let lastExam = null;
data.examInfos.forEach(exam => { data.examInfos.forEach(exam => {
const start = new Date(exam.start); const start = new Date(exam.start);
@ -70,6 +71,9 @@ document.addEventListener("DOMContentLoaded", () => {
if (!currentExam && !nextExam && now < start) { if (!currentExam && !nextExam && now < start) {
nextExam = exam; nextExam = exam;
} }
if (now > end && (!lastExam || end > new Date(lastExam.end))) {
lastExam = exam;
}
}); });
if (currentExam) { if (currentExam) {
@ -93,6 +97,13 @@ document.addEventListener("DOMContentLoaded", () => {
statusElem.textContent = "状态: 进行中"; statusElem.textContent = "状态: 进行中";
statusElem.style.color = "#5ba838"; statusElem.style.color = "#5ba838";
} else if (lastExam && now < new Date(lastExam.end).getTime() + 60000) {
const timeSinceEnd = (now.getTime() - new Date(lastExam.end).getTime()) / 1000;
currentSubjectElem.textContent = `上场科目: ${lastExam.name}`;
examTimingElem.textContent = "";
remainingTimeElem.textContent = ``;
statusElem.textContent = "状态: 已结束";
statusElem.style.color = "red";
} else if (nextExam) { } else if (nextExam) {
const timeUntilStart = ((new Date(nextExam.start).getTime() - now.getTime()) / 1000) + 1; const timeUntilStart = ((new Date(nextExam.start).getTime() - now.getTime()) / 1000) + 1;
const remainingHours = Math.floor(timeUntilStart / 3600); const remainingHours = Math.floor(timeUntilStart / 3600);