fix: 修复考试时间显示逻辑,优化剩余时间格式,调整样式

This commit is contained in:
MKStoler1024 2025-04-23 15:08:35 +00:00
parent c759f051b3
commit 70562f8563
3 changed files with 26 additions and 25 deletions

View File

@ -18,16 +18,13 @@ document.addEventListener("DOMContentLoaded", () => {
// 初始化显示状态 // 初始化显示状态
if (showPaperInfo) { if (showPaperInfo) {
currentSubjectElem.style.display = "none";
paperInfoElem.style.display = "block"; paperInfoElem.style.display = "block";
} }
// 更新显示内容 // 更新显示内容
function updateDisplay(isExamTime) { function updateDisplay(isExamTime) {
if (autoToggle) { if (autoToggle) {
// 在考试期间显示页数,其他时间显示表格
paperInfoElem.style.display = isExamTime ? "block" : "none"; paperInfoElem.style.display = isExamTime ? "block" : "none";
currentSubjectElem.style.display = "block";
} }
} }
@ -35,7 +32,6 @@ document.addEventListener("DOMContentLoaded", () => {
if (!autoToggle) { if (!autoToggle) {
showPaperInfo = !showPaperInfo; showPaperInfo = !showPaperInfo;
paperInfoElem.style.display = showPaperInfo ? "block" : "none"; paperInfoElem.style.display = showPaperInfo ? "block" : "none";
currentSubjectElem.style.display = "block";
setCookie("showPaperInfo", showPaperInfo, 365); setCookie("showPaperInfo", showPaperInfo, 365);
} }
}); });
@ -54,7 +50,7 @@ document.addEventListener("DOMContentLoaded", () => {
return Promise.resolve(); return Promise.resolve();
} catch (error) { } catch (error) {
localStorage.removeItem('localExamConfig'); localStorage.removeItem('localExamConfig');
errorSystem.show('本地配置无效,已切换至默认配置'); errorSystem.show('本地配置无效,已清除并切换至默认配置');
} }
} }
@ -109,20 +105,15 @@ document.addEventListener("DOMContentLoaded", () => {
} }
if (now > end && (!lastExam || end > new Date(lastExam.end))) { if (now > end && (!lastExam || end > new Date(lastExam.end))) {
lastExam = exam; lastExam = exam;
isnotificated = false;
} }
}); });
// 清空原有内容 // 清空原有内容
if (paperInfoElem) paperInfoElem.style.display = showPaperInfo ? "block" : "none"; if (paperInfoElem) paperInfoElem.style.display = showPaperInfo ? "block" : "none";
if (currentSubjectElem) currentSubjectElem.style.display = showPaperInfo ? "none" : "block";
if (currentExam) { if (currentExam) {
const currentStatus = `当前科目: ${currentExam.name}`; const currentStatus = `当前科目: ${currentExam.name}`;
if (!showPaperInfo) { currentSubjectElem.textContent = currentStatus;
currentSubjectElem.textContent = currentStatus;
}
currentSubjectElem.style.display = "block"; // 总是显示科目信息
paperInfoElem.style.display = showPaperInfo ? "block" : "none"; paperInfoElem.style.display = showPaperInfo ? "block" : "none";
// 加载本地存储的页数信息 // 加载本地存储的页数信息
@ -157,13 +148,17 @@ document.addEventListener("DOMContentLoaded", () => {
const remainingHours = Math.floor(remainingTime / 3600); const remainingHours = Math.floor(remainingTime / 3600);
const remainingMinutes = Math.floor((remainingTime % 3600) / 60); const remainingMinutes = Math.floor((remainingTime % 3600) / 60);
const remainingSeconds = Math.floor(remainingTime % 60); const remainingSeconds = Math.floor(remainingTime % 60);
const remainingTimeText = `${remainingHours}${remainingMinutes}${remainingSeconds}`; let remainingTimeText = '';
if (remainingHours > 0) {
remainingTimeText = `${remainingHours}${String(remainingMinutes).padStart(2, '0')}${String(remainingSeconds).padStart(2, '0')}`;
} else {
remainingTimeText = `${String(remainingMinutes).padStart(2, '0')}${String(remainingSeconds).padStart(2, '0')}`;
}
if (remainingHours === 0 && remainingMinutes <= 14) { if (remainingHours === 0 && remainingMinutes <= 14) {
if (remainingTimeElem) { if (remainingTimeElem) {
remainingTimeElem.textContent = `倒计时: ${remainingTimeText}`; remainingTimeElem.textContent = `剩余时间: ${remainingTimeText}`;
remainingTimeElem.style.color = "red"; remainingTimeElem.style.color = "#93b4f7";
remainingTimeElem.style.fontWeight = "bold"; remainingTimeElem.style.fontWeight = "normal";
} }
if (statusElem) { if (statusElem) {
statusElem.textContent = "状态: 即将结束"; statusElem.textContent = "状态: 即将结束";
@ -171,8 +166,7 @@ document.addEventListener("DOMContentLoaded", () => {
} }
// 在剩余15分钟时显示提醒 // 在剩余15分钟时显示提醒
if (isnotificated === false && remainingMinutes === 14 && remainingSeconds === 59) { if (remainingMinutes === 14 && remainingSeconds === 59) {
isnotificated = true;
const overlay = document.getElementById('reminder-overlay'); const overlay = document.getElementById('reminder-overlay');
if (overlay) { if (overlay) {
overlay.classList.add('show'); overlay.classList.add('show');
@ -193,7 +187,6 @@ document.addEventListener("DOMContentLoaded", () => {
} }
} }
} else { } else {
// 非考试时间,显示表格
updateDisplay(false); updateDisplay(false);
if (lastExam && now < new Date(lastExam.end).getTime() + 60000) { if (lastExam && now < new Date(lastExam.end).getTime() + 60000) {
if (currentSubjectElem) currentSubjectElem.textContent = `上场科目: ${lastExam.name}`; if (currentSubjectElem) currentSubjectElem.textContent = `上场科目: ${lastExam.name}`;
@ -208,7 +201,12 @@ document.addEventListener("DOMContentLoaded", () => {
const remainingHours = Math.floor(timeUntilStart / 3600); const remainingHours = Math.floor(timeUntilStart / 3600);
const remainingMinutes = Math.floor((timeUntilStart % 3600) / 60); const remainingMinutes = Math.floor((timeUntilStart % 3600) / 60);
const remainingSeconds = Math.floor(timeUntilStart % 60); const remainingSeconds = Math.floor(timeUntilStart % 60);
const remainingTimeText = `${remainingHours}${remainingMinutes}${remainingSeconds}`; let remainingTimeText = '';
if (remainingHours > 0) {
remainingTimeText = `${remainingHours}${String(remainingMinutes).padStart(2, '0')}${String(remainingSeconds).padStart(2, '0')}`;
} else {
remainingTimeText = `${String(remainingMinutes).padStart(2, '0')}${String(remainingSeconds).padStart(2, '0')}`;
}
if (timeUntilStart <= 15 * 60) { if (timeUntilStart <= 15 * 60) {
currentSubjectElem.textContent = `即将开始: ${nextExam.name}`; currentSubjectElem.textContent = `即将开始: ${nextExam.name}`;
@ -227,12 +225,16 @@ document.addEventListener("DOMContentLoaded", () => {
examTimingElem.textContent = `起止时间: ${formatTimeWithoutSeconds(new Date(nextExam.start).toLocaleTimeString('zh-CN', { hour12: false }))} - ${formatTimeWithoutSeconds(new Date(nextExam.end).toLocaleTimeString('zh-CN', { hour12: false }))}`; examTimingElem.textContent = `起止时间: ${formatTimeWithoutSeconds(new Date(nextExam.start).toLocaleTimeString('zh-CN', { hour12: false }))} - ${formatTimeWithoutSeconds(new Date(nextExam.end).toLocaleTimeString('zh-CN', { hour12: false }))}`;
} else { } else {
if (currentSubjectElem) currentSubjectElem.textContent = "考试均已结束"; if (currentSubjectElem) {
currentSubjectElem.textContent = "考试均已结束";
currentSubjectElem.style.color = "#aaaaaa";
currentSubjectElem.style.textAlign = "center";
}
if (examTimingElem) examTimingElem.textContent = ""; if (examTimingElem) examTimingElem.textContent = "";
if (remainingTimeElem) remainingTimeElem.textContent = ""; if (remainingTimeElem) remainingTimeElem.textContent = "";
if (statusElem) { if (statusElem) {
statusElem.textContent = "状态: 空闲"; statusElem.textContent = " ";
statusElem.style.color = "#3946AF"; statusElem.style.color = "#000000";
} }
} }
} }

View File

@ -83,7 +83,6 @@ body::-webkit-scrollbar {
max-width: 90%; max-width: 90%;
margin: auto; margin: auto;
background-color: #121212; background-color: #121212;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
} }
h1 { h1 {

View File

@ -31,6 +31,7 @@
<span class="material-icons">swap_horiz</span> <span class="material-icons">swap_horiz</span>
</button> </button>
<div id="current-subject"></div> <div id="current-subject"></div>
<div id="exam-timing"></div>
<div id="paper-info" style="display: none;"> <div id="paper-info" style="display: none;">
<div class="paper-count-container"> <div class="paper-count-container">
<div class="paper-input-group"> <div class="paper-input-group">
@ -89,7 +90,6 @@
</div> </div>
</div> </div>
</div> </div>
<div id="exam-timing"></div>
<div id="remaining-time"></div> <div id="remaining-time"></div>
<div id="status"></div> <div id="status"></div>
</div> </div>