103 lines
5.3 KiB
JavaScript
103 lines
5.3 KiB
JavaScript
// 结束默写并显示成绩
|
|
function endDictation() {
|
|
dictationStarted = false;
|
|
// 计算成绩
|
|
let correctCount = 0;
|
|
const errorDetails = [];
|
|
for (let i = 0; i < importedWords.length; i++) {
|
|
// 修复:比较用户答案和正确答案 (都是字符串)
|
|
if (userAnswers[i] === correctAnswers[i]) {
|
|
correctCount++;
|
|
} else {
|
|
// 记录错误详情 (包含翻译)
|
|
errorDetails.push({
|
|
number: i + 1,
|
|
word: correctAnswers[i], // 正确答案是英文单词字符串
|
|
translation: importedWords[i].translation, // 获取翻译
|
|
userAnswer: userAnswers[i] || '(未作答)'
|
|
});
|
|
}
|
|
}
|
|
const totalCount = importedWords.length;
|
|
const accuracy = totalCount > 0 ? Math.round((correctCount / totalCount) * 100) : 0;
|
|
// 显示成绩报告
|
|
document.getElementById('dictationArea').style.display = 'none';
|
|
document.getElementById('resultArea').style.display = 'block';
|
|
// 更新成绩显示
|
|
document.getElementById('finalScore').textContent = accuracy + '%';
|
|
document.getElementById('correctCount').textContent = correctCount;
|
|
document.getElementById('wrongCount').textContent = totalCount - correctCount;
|
|
document.getElementById('totalCount').textContent = totalCount;
|
|
|
|
// --- 从主进程获取切屏次数并更新显示 ---
|
|
// 现在使用正确的 IPC 调用
|
|
let switchCountValue = 0; // 初始化变量
|
|
const switchCountPromise = (window.electronAPI && typeof window.electronAPI.getSwitchCount === 'function')
|
|
? window.electronAPI.getSwitchCount()
|
|
: Promise.resolve(0); // 如果 API 不可用,返回 0
|
|
|
|
switchCountPromise
|
|
.then((switchCount) => {
|
|
const switchCountValue = typeof switchCount === 'number' ? switchCount : 0;
|
|
document.getElementById('switchCountFinal').textContent = switchCountValue;
|
|
console.log("成功获取主进程切屏次数:", switchCountValue); // 调试信息
|
|
})
|
|
.catch((error) => {
|
|
console.error("获取切屏次数失败:", error);
|
|
document.getElementById('switchCountFinal').textContent = '获取失败';
|
|
});
|
|
// --- 结束更新 ---
|
|
|
|
// 根据正确率显示等级
|
|
let gradeClass = '';
|
|
let gradeText = '';
|
|
if (accuracy >= 90) {
|
|
gradeClass = 'grade-a';
|
|
gradeText = 'A (优秀)';
|
|
} else if (accuracy >= 80) {
|
|
gradeClass = 'grade-b';
|
|
gradeText = 'B (良好)';
|
|
} else if (accuracy >= 70) {
|
|
gradeClass = 'grade-c';
|
|
gradeText = 'C (及格)';
|
|
} else {
|
|
gradeClass = 'grade-d';
|
|
gradeText = 'D (需要努力)';
|
|
}
|
|
const gradeBadge = document.getElementById('gradeBadge');
|
|
gradeBadge.textContent = '等级: ' + gradeText;
|
|
gradeBadge.className = 'grade-badge ' + gradeClass;
|
|
// 更新圆形进度条
|
|
const scoreCircle = document.querySelector('.score-circle');
|
|
const gradientDegree = (accuracy / 100) * 360;
|
|
scoreCircle.style.background = `conic-gradient(#7cffcb 0deg ${gradientDegree}deg, #5de6ff ${gradientDegree}deg 360deg)`;
|
|
// 显示错误详情
|
|
const errorList = document.getElementById('errorList');
|
|
errorList.innerHTML = '';
|
|
if (errorDetails.length > 0) {
|
|
errorDetails.forEach(error => {
|
|
const li = document.createElement('li');
|
|
li.className = 'error-item';
|
|
// 修改:显示翻译
|
|
li.innerHTML = `
|
|
<div class="error-number">${error.number}.</div>
|
|
<div class="error-content">
|
|
<div class="error-word">${error.word} ${error.translation ? `(${error.translation})` : ''}</div>
|
|
<div class="error-answer">您的答案: ${error.userAnswer}</div>
|
|
<div class="error-correct">
|
|
<i class="fas fa-times" style="color: #ff6b6b;"></i>
|
|
<span class="error-arrow">→</span>
|
|
<i class="fas fa-check" style="color: #7cffcb;"></i>
|
|
<span style="margin-left: 10px;">正确答案: ${error.word}</span>
|
|
</div>
|
|
</div>
|
|
`;
|
|
errorList.appendChild(li);
|
|
});
|
|
} else {
|
|
const li = document.createElement('li');
|
|
li.innerHTML = '<div style="color: #7cffcb; text-align: center; padding: 20px;"><i class="fas fa-check-circle"></i> 恭喜!全部正确!</div>';
|
|
errorList.appendChild(li);
|
|
}
|
|
}
|
|
|