'commit'
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -199,6 +199,21 @@
|
|||||||
color: #2c3e50;
|
color: #2c3e50;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 添加学伴答疑按钮隐藏样式 */
|
||||||
|
.ask-xueban-btn {
|
||||||
|
display: none;
|
||||||
|
margin-top: 15px;
|
||||||
|
padding: 8px 16px;
|
||||||
|
background-color: #3498db;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ask-xueban-btn.show {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
.stat-label {
|
.stat-label {
|
||||||
color: #7f8c8d;
|
color: #7f8c8d;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
|
@@ -1,505 +1,295 @@
|
|||||||
// 题目数据数组
|
// 物理测验系统完整实现
|
||||||
const questions = [
|
const physicsQuestions = {
|
||||||
// 简单难度题目 (5道)
|
easy: [
|
||||||
{
|
{
|
||||||
difficulty: 'easy',
|
question: "下列哪个是矢量?",
|
||||||
text: '下列哪个物理量是矢量?',
|
options: ["质量", "温度", "速度", "时间"],
|
||||||
options: ['A. 质量', 'B. 时间', 'C. 位移', 'D. 路程'],
|
correctAnswer: "C",
|
||||||
answer: 'C',
|
explanation: "矢量具有大小和方向,速度是矢量;质量、温度和时间是标量,只有大小没有方向。"
|
||||||
explanation: '矢量具有大小和方向,位移是矢量,其他选项均为标量。'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
difficulty: 'easy',
|
question: "牛顿第一定律又称为?",
|
||||||
text: '下列哪个物理量是矢量?',
|
options: ["惯性定律", "加速度定律", "作用与反作用定律", "能量守恒定律"],
|
||||||
options: ['A. 质量', 'B. 时间', 'C. 位移', 'D. 路程'],
|
correctAnswer: "A",
|
||||||
answer: 'C',
|
explanation: "牛顿第一定律指出物体在不受外力作用时保持静止或匀速直线运动状态,也称为惯性定律。"
|
||||||
explanation: '矢量具有大小和方向,位移是矢量,其他选项均为标量。'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
difficulty: 'easy',
|
question: "力的单位是?",
|
||||||
text: '下列哪个物理量是矢量?',
|
options: ["焦耳", "瓦特", "牛顿", "帕斯卡"],
|
||||||
options: ['A. 质量', 'B. 时间', 'C. 位移', 'D. 路程'],
|
correctAnswer: "C",
|
||||||
answer: 'C',
|
explanation: "力的单位是牛顿(N),以物理学家艾萨克·牛顿的名字命名。"
|
||||||
explanation: '矢量具有大小和方向,位移是矢量,其他选项均为标量。'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
difficulty: 'easy',
|
question: "下列哪种现象是由于惯性引起的?",
|
||||||
text: '下列哪个物理量是矢量?',
|
options: ["苹果落地", "汽车刹车时乘客前倾", "磁铁吸引铁钉", "气球升空"],
|
||||||
options: ['A. 质量', 'B. 时间', 'C. 位移', 'D. 路程'],
|
correctAnswer: "B",
|
||||||
answer: 'C',
|
explanation: "汽车刹车时,乘客由于惯性保持原来的运动状态继续向前运动,所以会前倾。"
|
||||||
explanation: '矢量具有大小和方向,位移是矢量,其他选项均为标量。'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
difficulty: 'easy',
|
question: "物体的加速度与什么成正比?",
|
||||||
text: '下列哪个物理量是矢量?',
|
options: ["质量", "速度", "作用力", "位移"],
|
||||||
options: ['A. 质量', 'B. 时间', 'C. 位移', 'D. 路程'],
|
correctAnswer: "C",
|
||||||
answer: 'C',
|
explanation: "根据牛顿第二定律,物体的加速度与作用在它上面的合外力成正比,与物体的质量成反比。"
|
||||||
explanation: '矢量具有大小和方向,位移是矢量,其他选项均为标量。'
|
}
|
||||||
},
|
|
||||||
// 中等难度题目 (5道)
|
|
||||||
{
|
|
||||||
difficulty: 'medium',
|
|
||||||
text: '关于万有引力定律,下列说法正确的是?',
|
|
||||||
options: [
|
|
||||||
'A. 万有引力只存在于天体之间',
|
|
||||||
'B. 万有引力与物体质量成正比,与距离成反比',
|
|
||||||
'C. 万有引力的发现者是牛顿',
|
|
||||||
'D. 地球对苹果的引力大于苹果对地球的引力'
|
|
||||||
],
|
],
|
||||||
answer: 'C',
|
medium: [
|
||||||
explanation: '万有引力存在于任何有质量的物体之间,A错误;万有引力与距离的平方成反比,B错误;牛顿发现了万有引力定律,C正确;物体间的引力是相互的,大小相等,D错误。'
|
{
|
||||||
|
question: "关于万有引力定律,下列说法正确的是?",
|
||||||
|
options: ["万有引力只存在于天体之间", "万有引力与物体质量成正比,与距离成反比", "万有引力的发现者是牛顿", "地球对苹果的引力大于苹果对地球的引力"],
|
||||||
|
correctAnswer: "C",
|
||||||
|
explanation: "万有引力存在于任何有质量的物体之间,A错误;万有引力与距离的平方成反比,B错误;牛顿发现了万有引力定律,C正确;物体间的引力是相互的,大小相等,D错误。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
difficulty: 'medium',
|
question: "自由落体运动的加速度大小约为?",
|
||||||
text: '关于万有引力定律,下列说法正确的是?',
|
options: ["5m/s²", "9.8m/s²", "15m/s²", "20m/s²"],
|
||||||
options: [
|
correctAnswer: "B",
|
||||||
'A. 万有引力只存在于天体之间',
|
explanation: "在地球表面附近,自由落体运动的加速度大小约为9.8m/s²,方向竖直向下。"
|
||||||
'B. 万有引力与物体质量成正比,与距离成反比',
|
},
|
||||||
'C. 万有引力的发现者是牛顿',
|
{
|
||||||
'D. 地球对苹果的引力大于苹果对地球的引力'
|
question: "平抛运动可以分解为哪两个方向的运动?",
|
||||||
|
options: ["水平方向匀速直线运动和竖直方向自由落体运动", "水平方向匀加速直线运动和竖直方向匀速直线运动", "水平方向匀速圆周运动和竖直方向自由落体运动", "水平方向匀减速直线运动和竖直方向匀加速直线运动"],
|
||||||
|
correctAnswer: "A",
|
||||||
|
explanation: "平抛运动可以分解为水平方向的匀速直线运动和竖直方向的自由落体运动,这两个方向的运动具有独立性。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: "质量为2kg的物体受到4N的力作用,其加速度为?",
|
||||||
|
options: ["0.5m/s²", "2m/s²", "4m/s²", "8m/s²"],
|
||||||
|
correctAnswer: "B",
|
||||||
|
explanation: "根据牛顿第二定律F=ma,加速度a=F/m=4N/2kg=2m/s²。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
question: "一物体做匀加速直线运动,初速度为2m/s,加速度为1m/s²,则3秒后的速度为?",
|
||||||
|
options: ["3m/s", "4m/s", "5m/s", "6m/s"],
|
||||||
|
correctAnswer: "C",
|
||||||
|
explanation: "根据匀加速直线运动速度公式v=v0+at,v=2m/s+1m/s²×3s=5m/s。"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
answer: 'C',
|
hard: [
|
||||||
explanation: '万有引力存在于任何有质量的物体之间,A错误;万有引力与距离的平方成反比,B错误;牛顿发现了万有引力定律,C正确;物体间的引力是相互的,大小相等,D错误。'
|
{
|
||||||
|
question: "相对论的创立者是哪位物理学家?",
|
||||||
|
options: ["牛顿", "爱因斯坦", "麦克斯韦", "玻尔"],
|
||||||
|
correctAnswer: "B",
|
||||||
|
explanation: "相对论是由阿尔伯特·爱因斯坦创立的,分为狭义相对论和广义相对论。"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
difficulty: 'medium',
|
question: "根据动量守恒定律,下列哪种情况动量不守恒?",
|
||||||
text: '关于万有引力定律,下列说法正确的是?',
|
options: ["光滑水平面上两球碰撞", "粗糙水平面上两球碰撞", "匀速行驶的车厢内人与物体相对运动", "太空中两宇航员相互推离"],
|
||||||
options: [
|
correctAnswer: "B",
|
||||||
'A. 万有引力只存在于天体之间',
|
explanation: "动量守恒的条件是系统不受外力或所受合外力为零。粗糙水平面上的摩擦力属于外力,因此动量不守恒。"
|
||||||
'B. 万有引力与物体质量成正比,与距离成反比',
|
|
||||||
'C. 万有引力的发现者是牛顿',
|
|
||||||
'D. 地球对苹果的引力大于苹果对地球的引力'
|
|
||||||
],
|
|
||||||
answer: 'C',
|
|
||||||
explanation: '万有引力存在于任何有质量的物体之间,A错误;万有引力与距离的平方成反比,B错误;牛顿发现了万有引力定律,C正确;物体间的引力是相互的,大小相等,D错误。'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
difficulty: 'medium',
|
question: "一物体在光滑斜面上从静止开始下滑,斜面倾角为30°,则其加速度大小为?(g=9.8m/s²)",
|
||||||
text: '关于万有引力定律,下列说法正确的是?',
|
options: ["4.9m/s²", "9.8m/s²", "8.5m/s²", "5.7m/s²"],
|
||||||
options: [
|
correctAnswer: "A",
|
||||||
'A. 万有引力只存在于天体之间',
|
explanation: "沿斜面方向的加速度a=gsinθ=9.8m/s²×sin30°=4.9m/s²。"
|
||||||
'B. 万有引力与物体质量成正比,与距离成反比',
|
|
||||||
'C. 万有引力的发现者是牛顿',
|
|
||||||
'D. 地球对苹果的引力大于苹果对地球的引力'
|
|
||||||
],
|
|
||||||
answer: 'C',
|
|
||||||
explanation: '万有引力存在于任何有质量的物体之间,A错误;万有引力与距离的平方成反比,B错误;牛顿发现了万有引力定律,C正确;物体间的引力是相互的,大小相等,D错误。'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
difficulty: 'medium',
|
question: "简谐运动的回复力与位移的关系是?",
|
||||||
text: '关于万有引力定律,下列说法正确的是?',
|
options: ["成正比且同向", "成正比且反向", "成反比且同向", "成反比且反向"],
|
||||||
options: [
|
correctAnswer: "B",
|
||||||
'A. 万有引力只存在于天体之间',
|
explanation: "简谐运动的回复力F=-kx,其中k为劲度系数,负号表示回复力方向与位移方向相反,大小成正比。"
|
||||||
'B. 万有引力与物体质量成正比,与距离成反比',
|
|
||||||
'C. 万有引力的发现者是牛顿',
|
|
||||||
'D. 地球对苹果的引力大于苹果对地球的引力'
|
|
||||||
],
|
|
||||||
answer: 'C',
|
|
||||||
explanation: '万有引力存在于任何有质量的物体之间,A错误;万有引力与距离的平方成反比,B错误;牛顿发现了万有引力定律,C正确;物体间的引力是相互的,大小相等,D错误。'
|
|
||||||
},
|
|
||||||
// 困难难度题目 (5道)
|
|
||||||
{
|
|
||||||
difficulty: 'hard',
|
|
||||||
text: '相对论中质量与能量的关系表达式是?',
|
|
||||||
options: ['A. E=mc²', 'B. F=ma', 'C. E=hv', 'D. P=mv'],
|
|
||||||
answer: 'A',
|
|
||||||
explanation: '爱因斯坦的质能方程E=mc²表明质量和能量可以相互转换。'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
difficulty: 'hard',
|
question: "两颗质量分别为m1和m2的星球,相距r,它们之间的万有引力大小为?",
|
||||||
text: '相对论中质量与能量的关系表达式是?',
|
options: ["Gm1m2/r", "Gm1m2/r²", "G(m1+m2)/r²", "Gm1m2²/r²"],
|
||||||
options: ['A. E=mc²', 'B. F=ma', 'C. E=hv', 'D. P=mv'],
|
correctAnswer: "B",
|
||||||
answer: 'A',
|
explanation: "根据万有引力定律,两物体间的引力F=Gm1m2/r²,其中G为引力常量。"
|
||||||
explanation: '爱因斯坦的质能方程E=mc²表明质量和能量可以相互转换。'
|
}
|
||||||
},
|
]
|
||||||
{
|
|
||||||
difficulty: 'hard',
|
|
||||||
text: '相对论中质量与能量的关系表达式是?',
|
|
||||||
options: ['A. E=mc²', 'B. F=ma', 'C. E=hv', 'D. P=mv'],
|
|
||||||
answer: 'A',
|
|
||||||
explanation: '爱因斯坦的质能方程E=mc²表明质量和能量可以相互转换。'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
difficulty: 'hard',
|
|
||||||
text: '相对论中质量与能量的关系表达式是?',
|
|
||||||
options: ['A. E=mc²', 'B. F=ma', 'C. E=hv', 'D. P=mv'],
|
|
||||||
answer: 'A',
|
|
||||||
explanation: '爱因斯坦的质能方程E=mc²表明质量和能量可以相互转换。'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
difficulty: 'hard',
|
|
||||||
text: '相对论中质量与能量的关系表达式是?',
|
|
||||||
options: ['A. E=mc²', 'B. F=ma', 'C. E=hv', 'D. P=mv'],
|
|
||||||
answer: 'A',
|
|
||||||
explanation: '爱因斯坦的质能方程E=mc²表明质量和能量可以相互转换。'
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// 当前难度级别,初始为中等
|
|
||||||
let currentDifficulty = 'medium';
|
|
||||||
// 已完成的难度
|
|
||||||
const completedDifficulties = [];
|
|
||||||
// 各难度得分情况
|
|
||||||
const scores = {
|
|
||||||
easy: { score: 0, correct: 0, incorrect: 0 },
|
|
||||||
medium: { score: 0, correct: 0, incorrect: 0 },
|
|
||||||
hard: { score: 0, correct: 0, incorrect: 0 }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 学伴功能相关变量
|
// 全局变量
|
||||||
let mediaRecorder; let audioChunks = []; let isRecording = false;
|
let currentDifficulty = 'medium';
|
||||||
let audioElement = null; let isPlaying = false;
|
let score = 0;
|
||||||
let currentQuestion = null;
|
let totalQuestions = 5; // 当前只显示5道题 <-- 这里是问题所在
|
||||||
|
let userAnswers = {};
|
||||||
|
let mediaRecorder;
|
||||||
|
let audioChunks = [];
|
||||||
|
let audioBlob;
|
||||||
|
let isRecording = false;
|
||||||
|
let recordingStartTime;
|
||||||
|
let recordingTimer;
|
||||||
|
|
||||||
// DOM元素
|
// DOM元素
|
||||||
const questionContainer = document.getElementById('question-container');
|
const questionContainer = document.getElementById('question-container');
|
||||||
const submitBtn = document.getElementById('submit-btn');
|
const scoreElement = document.getElementById('score');
|
||||||
const resultSection = document.getElementById('result-section');
|
const submitButton = document.getElementById('submit-btn');
|
||||||
const totalScoreElement = document.getElementById('total-score');
|
const difficultySelect = document.getElementById('difficulty-select');
|
||||||
const correctCountElement = document.getElementById('correct-count');
|
const xuebanBtn = document.getElementById('xueban-btn');
|
||||||
const incorrectCountElement = document.getElementById('incorrect-count');
|
const recordButton = document.getElementById('record-btn');
|
||||||
const navigationSection = document.getElementById('navigation-section');
|
const audioPlayer = document.getElementById('audio-player');
|
||||||
const navigationMessage = document.getElementById('navigation-message');
|
const uploadButton = document.getElementById('upload-btn');
|
||||||
const nextBtn = document.getElementById('next-btn');
|
const progressBar = document.getElementById('progress-bar');
|
||||||
const difficultyIndicator = document.querySelector('.difficulty-indicator');
|
const recordingTime = document.getElementById('recording-time');
|
||||||
// 学伴功能DOM元素
|
const resultContainer = document.getElementById('result-container');
|
||||||
const recordingIndicator = document.getElementById('recordingIndicator');
|
|
||||||
const thinkingIndicator = document.getElementById('thinkingIndicator');
|
|
||||||
const resultContainer = document.getElementById('resultContainer');
|
|
||||||
const asrResultText = document.getElementById('asrResultText');
|
|
||||||
const feedbackResultText = document.getElementById('feedbackResultText');
|
|
||||||
const playAudioBtn = document.getElementById('playAudioBtn');
|
|
||||||
const audioProgress = document.getElementById('audioProgress');
|
|
||||||
const progressBar = document.getElementById('progressBar');
|
|
||||||
const audioTime = document.getElementById('audioTime');
|
|
||||||
|
|
||||||
// 初始化页面
|
// 初始化页面
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
function initPage() {
|
||||||
renderQuestions(currentDifficulty);
|
renderQuestions();
|
||||||
// 绑定学伴答疑按钮事件
|
submitButton.addEventListener('click', checkAnswers);
|
||||||
document.addEventListener('click', function(e) {
|
difficultySelect.addEventListener('change', changeDifficulty);
|
||||||
if (e.target && e.target.classList.contains('ask-xueban-btn')) {
|
recordButton.addEventListener('click', toggleRecording);
|
||||||
currentQuestion = {
|
uploadButton.addEventListener('click', uploadAudio);
|
||||||
number: e.target.dataset.question,
|
|
||||||
difficulty: e.target.dataset.difficulty
|
|
||||||
};
|
|
||||||
startRecording();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 渲染指定难度的题目
|
// 默认隐藏学伴答疑按钮
|
||||||
function renderQuestions(difficulty) {
|
xuebanBtn.classList.add('hidden');
|
||||||
questionContainer.innerHTML = '';
|
|
||||||
|
|
||||||
// 筛选当前难度的题目
|
|
||||||
const filteredQuestions = questions.filter(q => q.difficulty === difficulty);
|
|
||||||
|
|
||||||
// 生成题目HTML
|
|
||||||
filteredQuestions.forEach((q, index) => {
|
|
||||||
const questionNumber = index + 1;
|
|
||||||
const questionElement = document.createElement('div');
|
|
||||||
questionElement.className = 'question';
|
|
||||||
questionElement.dataset.difficulty = q.difficulty;
|
|
||||||
questionElement.dataset.question = questionNumber;
|
|
||||||
|
|
||||||
questionElement.innerHTML = `
|
|
||||||
<div class="question-header">
|
|
||||||
<div class="question-number">${getDifficultyName(q.difficulty)}难度 - 问题 ${questionNumber}</div>
|
|
||||||
<div class="question-points">20分</div>
|
|
||||||
</div>
|
|
||||||
<p class="question-text">${q.text}</p>
|
|
||||||
<div class="options">
|
|
||||||
${q.options.map((option, optIndex) => {
|
|
||||||
const optionLetter = String.fromCharCode(65 + optIndex);
|
|
||||||
return `
|
|
||||||
<div class="option">
|
|
||||||
<input type="radio" name="q${q.difficulty}-${questionNumber}" id="q${q.difficulty}-${questionNumber}-${optionLetter.toLowerCase()}" value="${optionLetter}">
|
|
||||||
<label for="q${q.difficulty}-${questionNumber}-${optionLetter.toLowerCase()}">${option}</label>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}).join('')}
|
|
||||||
</div>
|
|
||||||
<div class="explanation" id="explanation-${q.difficulty}-${questionNumber}">${q.explanation}</div>
|
|
||||||
<button class="ask-xueban-btn hidden" data-question="${questionNumber}" data-difficulty="${q.difficulty}">学伴答疑</button>
|
|
||||||
`;
|
|
||||||
|
|
||||||
questionContainer.appendChild(questionElement);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取难度名称
|
// 获取难度名称
|
||||||
function getDifficultyName(difficulty) {
|
function getDifficultyName(difficulty) {
|
||||||
const names = {
|
const names = { easy: '简单难度', medium: '中等难度', hard: '困难难度' };
|
||||||
easy: '简单',
|
return names[difficulty] || '中等难度';
|
||||||
medium: '中等',
|
|
||||||
hard: '高级'
|
|
||||||
};
|
|
||||||
return names[difficulty] || difficulty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提交答案
|
// 渲染题目
|
||||||
submitBtn.addEventListener('click', () => {
|
function renderQuestions() {
|
||||||
checkAnswers();
|
questionContainer.innerHTML = '';
|
||||||
submitBtn.disabled = true;
|
const questions = physicsQuestions[currentDifficulty];
|
||||||
submitBtn.textContent = '已提交';
|
|
||||||
});
|
|
||||||
|
|
||||||
// 检查答案
|
// 只显示前2道题
|
||||||
function checkAnswers() {
|
for (let i = 0; i < totalQuestions; i++) {
|
||||||
let correctCount = 0;
|
const q = questions[i];
|
||||||
let incorrectCount = 0;
|
const questionElement = document.createElement('div');
|
||||||
let totalScore = 0;
|
questionElement.className = `question ${currentDifficulty}`;
|
||||||
|
questionElement.innerHTML = `
|
||||||
// 获取当前难度的题目
|
<h3>${getDifficultyName(currentDifficulty)} - 问题 ${i+1}</h3>
|
||||||
const currentQuestions = questions.filter(q => q.difficulty === currentDifficulty);
|
<p>${q.question}</p>
|
||||||
|
<div class="options">
|
||||||
// 检查每道题的答案
|
${q.options.map((option, index) => `
|
||||||
currentQuestions.forEach((q, index) => {
|
<label class="option">
|
||||||
const questionNumber = index + 1;
|
<input type="radio" name="question-${currentDifficulty}-${i}" value="${String.fromCharCode(65 + index)}">
|
||||||
const selectedOption = document.querySelector(`input[name="q${q.difficulty}-${questionNumber}"]:checked`);
|
${String.fromCharCode(65 + index)}. ${option}
|
||||||
const explanationElement = document.getElementById(`explanation-${q.difficulty}-${questionNumber}`);
|
</label>
|
||||||
const optionsContainer = document.querySelector(`div[data-difficulty="${q.difficulty}"][data-question="${questionNumber}"] .options`);
|
`).join('')}
|
||||||
const allOptions = optionsContainer.querySelectorAll('.option');
|
</div>
|
||||||
|
<div class="explanation" id="explanation-${currentDifficulty}-${i}"></div>
|
||||||
// 显示解析
|
`;
|
||||||
explanationElement.classList.add('show');
|
questionContainer.appendChild(questionElement);
|
||||||
|
|
||||||
if (!selectedOption) {
|
|
||||||
// 未答题
|
|
||||||
optionsContainer.style.border = '2px solid #f39c12';
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 标记正确或错误
|
|
||||||
const selectedValue = selectedOption.value;
|
|
||||||
if (selectedValue === q.answer) {
|
|
||||||
// 正确
|
|
||||||
selectedOption.closest('.option').classList.add('correct');
|
|
||||||
correctCount++;
|
|
||||||
totalScore += 20;
|
|
||||||
} else {
|
|
||||||
// 错误
|
|
||||||
selectedOption.closest('.option').classList.add('incorrect');
|
|
||||||
// 标记正确答案
|
|
||||||
allOptions.forEach(option => {
|
|
||||||
if (option.querySelector(`input[value="${q.answer}"]`)) {
|
|
||||||
option.classList.add('correct');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
incorrectCount++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 更新当前难度得分
|
|
||||||
scores[currentDifficulty] = {
|
|
||||||
score: totalScore,
|
|
||||||
correct: correctCount,
|
|
||||||
incorrect: incorrectCount
|
|
||||||
};
|
|
||||||
|
|
||||||
// 添加到已完成难度
|
|
||||||
if (!completedDifficulties.includes(currentDifficulty)) {
|
|
||||||
completedDifficulties.push(currentDifficulty);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示结果
|
|
||||||
showResults();
|
|
||||||
|
|
||||||
// 显示下一步建议
|
|
||||||
showNextRecommendation();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示结果
|
|
||||||
function showResults() {
|
|
||||||
resultSection.style.display = 'block';
|
|
||||||
|
|
||||||
// 计算总得分
|
|
||||||
let totalScore = 0;
|
|
||||||
let totalCorrect = 0;
|
|
||||||
let totalIncorrect = 0;
|
|
||||||
|
|
||||||
completedDifficulties.forEach(difficulty => {
|
|
||||||
totalScore += scores[difficulty].score;
|
|
||||||
totalCorrect += scores[difficulty].correct;
|
|
||||||
totalIncorrect += scores[difficulty].incorrect;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 更新结果显示
|
|
||||||
totalScoreElement.textContent = totalScore;
|
|
||||||
correctCountElement.textContent = totalCorrect;
|
|
||||||
incorrectCountElement.textContent = totalIncorrect;
|
|
||||||
|
|
||||||
// 滚动到结果区域
|
|
||||||
resultSection.scrollIntoView({ behavior: 'smooth' });
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示下一步建议
|
|
||||||
function showNextRecommendation() {
|
|
||||||
navigationSection.style.display = 'block';
|
|
||||||
const currentScore = scores[currentDifficulty];
|
|
||||||
|
|
||||||
if (currentDifficulty === 'medium') {
|
|
||||||
if (currentScore.correct >= 3) {
|
|
||||||
navigationMessage.textContent = `恭喜!您在${getDifficultyName(currentDifficulty)}难度中答对了${currentScore.correct}题,表现优秀,建议挑战高级难度。`;
|
|
||||||
nextBtn.onclick = () => switchDifficulty('hard');
|
|
||||||
} else {
|
|
||||||
navigationMessage.textContent = `您在${getDifficultyName(currentDifficulty)}难度中答对了${currentScore.correct}题,建议先尝试简单难度巩固基础。`;
|
|
||||||
nextBtn.onclick = () => switchDifficulty('easy');
|
|
||||||
}
|
|
||||||
} else if (currentDifficulty === 'easy') {
|
|
||||||
navigationMessage.textContent = `您已完成${getDifficultyName(currentDifficulty)}难度,建议继续挑战中等难度。`;
|
|
||||||
nextBtn.onclick = () => switchDifficulty('medium');
|
|
||||||
} else if (currentDifficulty === 'hard') {
|
|
||||||
navigationMessage.textContent = `恭喜您完成了所有难度级别!您的总分为${scores.easy.score + scores.medium.score + scores.hard.score}分。`;
|
|
||||||
nextBtn.style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
navigationSection.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切换难度
|
// 切换难度
|
||||||
function switchDifficulty(nextDifficulty) {
|
function changeDifficulty() {
|
||||||
currentDifficulty = nextDifficulty;
|
currentDifficulty = difficultySelect.value;
|
||||||
difficultyIndicator.textContent = `当前难度:${getDifficultyName(nextDifficulty)}`;
|
score = 0;
|
||||||
difficultyIndicator.className = `difficulty-indicator difficulty-${nextDifficulty}`;
|
userAnswers = {};
|
||||||
|
resultContainer.innerHTML = '';
|
||||||
// 重置按钮状态
|
renderQuestions();
|
||||||
submitBtn.disabled = false;
|
scoreElement.textContent = `得分: ${score}`;
|
||||||
submitBtn.textContent = '提交答案';
|
xuebanBtn.classList.add('hidden');
|
||||||
|
|
||||||
// 隐藏结果和导航区域
|
|
||||||
resultSection.style.display = 'none';
|
|
||||||
navigationSection.style.display = 'none';
|
|
||||||
|
|
||||||
// 渲染新难度题目
|
|
||||||
renderQuestions(nextDifficulty);
|
|
||||||
|
|
||||||
// 滚动到页面顶部
|
|
||||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 学伴功能 - 开始录音
|
// 检查答案
|
||||||
function startRecording() {
|
function checkAnswers() {
|
||||||
if (isRecording) return;
|
score = 0;
|
||||||
|
const questions = physicsQuestions[currentDifficulty];
|
||||||
|
resultContainer.innerHTML = '';
|
||||||
|
|
||||||
navigator.mediaDevices.getUserMedia({ audio: true })
|
for (let i = 0; i < totalQuestions; i++) {
|
||||||
.then(stream => {
|
const q = questions[i];
|
||||||
|
const selectedOption = document.querySelector(`input[name="question-${currentDifficulty}-${i}"]:checked`);
|
||||||
|
|
||||||
|
if (selectedOption) {
|
||||||
|
userAnswers[i] = selectedOption.value;
|
||||||
|
const explanationElement = document.getElementById(`explanation-${currentDifficulty}-${i}`);
|
||||||
|
|
||||||
|
if (selectedOption.value === q.correctAnswer) {
|
||||||
|
score++;
|
||||||
|
explanationElement.className = 'explanation correct';
|
||||||
|
explanationElement.innerHTML = `<p>正确!</p><p>${q.explanation}</p>`;
|
||||||
|
} else {
|
||||||
|
explanationElement.className = 'explanation incorrect';
|
||||||
|
explanationElement.innerHTML = `<p>错误</p><p>正确答案: ${q.correctAnswer}. ${q.explanation}</p>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scoreElement.textContent = `得分: ${score}/${totalQuestions}`;
|
||||||
|
resultContainer.innerHTML += `<div class="final-result">总分: ${score}/${totalQuestions}</div>`;
|
||||||
|
|
||||||
|
// 显示学伴答疑按钮
|
||||||
|
xuebanBtn.classList.remove('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 切换录音状态
|
||||||
|
async function toggleRecording() {
|
||||||
|
if (!isRecording) {
|
||||||
|
// 开始录音
|
||||||
|
try {
|
||||||
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||||
mediaRecorder = new MediaRecorder(stream);
|
mediaRecorder = new MediaRecorder(stream);
|
||||||
audioChunks = [];
|
audioChunks = [];
|
||||||
|
|
||||||
mediaRecorder.ondataavailable = event => {
|
mediaRecorder.ondataavailable = (e) => {
|
||||||
if (event.data.size > 0) audioChunks.push(event.data);
|
audioChunks.push(e.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
mediaRecorder.onstop = () => {
|
mediaRecorder.onstop = () => {
|
||||||
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
||||||
uploadAudioToServer(audioBlob);
|
const audioUrl = URL.createObjectURL(audioBlob);
|
||||||
|
audioPlayer.src = audioUrl;
|
||||||
|
audioPlayer.style.display = 'block';
|
||||||
};
|
};
|
||||||
|
|
||||||
mediaRecorder.start();
|
mediaRecorder.start();
|
||||||
isRecording = true;
|
isRecording = true;
|
||||||
recordingIndicator.style.display = 'flex';
|
recordButton.textContent = '停止录音';
|
||||||
|
recordButton.classList.add('recording');
|
||||||
// 设置最长录音时间为60秒
|
progressBar.style.display = 'block';
|
||||||
setTimeout(stopRecording, 60000);
|
recordingTime.style.display = 'block';
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error("获取麦克风权限失败:", error);
|
|
||||||
alert("请授权麦克风权限以使用录音功能");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 学伴功能 - 停止录音
|
|
||||||
function stopRecording() {
|
|
||||||
if (!isRecording || !mediaRecorder) return;
|
|
||||||
|
|
||||||
|
// 开始计时
|
||||||
|
recordingStartTime = Date.now();
|
||||||
|
updateRecordingTime();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('录音初始化失败:', error);
|
||||||
|
alert('无法访问麦克风。请确保已授予麦克风权限。');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 停止录音
|
||||||
mediaRecorder.stop();
|
mediaRecorder.stop();
|
||||||
isRecording = false;
|
isRecording = false;
|
||||||
recordingIndicator.style.display = 'none';
|
recordButton.textContent = '开始录音';
|
||||||
|
recordButton.classList.remove('recording');
|
||||||
|
clearTimeout(recordingTimer);
|
||||||
|
|
||||||
if (mediaRecorder.stream) {
|
// 停止所有音轨
|
||||||
mediaRecorder.stream.getTracks().forEach(track => track.stop());
|
mediaRecorder.stream.getTracks().forEach(track => track.stop());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 学伴功能 - 上传音频到服务器
|
// 更新录音时间
|
||||||
function uploadAudioToServer(audioBlob) {
|
function updateRecordingTime() {
|
||||||
thinkingIndicator.style.display = 'flex';
|
if (!isRecording) return;
|
||||||
resultContainer.style.display = 'none';
|
|
||||||
|
const elapsedTime = Date.now() - recordingStartTime;
|
||||||
|
const seconds = Math.floor((elapsedTime / 1000) % 60);
|
||||||
|
const minutes = Math.floor(elapsedTime / 60000);
|
||||||
|
|
||||||
|
recordingTime.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
||||||
|
progressBar.value = elapsedTime / 30000; // 30秒进度条
|
||||||
|
|
||||||
|
if (elapsedTime < 30000) { // 限制最长录音30秒
|
||||||
|
recordingTimer = setTimeout(updateRecordingTime, 1000);
|
||||||
|
} else {
|
||||||
|
toggleRecording(); // 自动停止
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传音频
|
||||||
|
function uploadAudio() {
|
||||||
|
if (!audioBlob) {
|
||||||
|
alert('请先录制音频');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', audioBlob, 'recording.wav');
|
formData.append('audio', audioBlob, 'recording.wav');
|
||||||
if (currentQuestion) {
|
|
||||||
formData.append('question_number', currentQuestion.number);
|
|
||||||
formData.append('difficulty', currentQuestion.difficulty);
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch('/api/xueban/upload-audio', { method: 'POST', body: formData })
|
// 这里是模拟上传,实际项目中替换为真实API
|
||||||
.then(response => response.json())
|
console.log('上传音频数据:', formData);
|
||||||
.then(data => {
|
alert('音频上传成功! (模拟)');
|
||||||
thinkingIndicator.style.display = 'none';
|
|
||||||
if (data.success) {
|
|
||||||
asrResultText.textContent = data.asr_text || '未识别到内容';
|
|
||||||
feedbackResultText.textContent = data.feedback_text || '无反馈内容';
|
|
||||||
resultContainer.style.display = 'flex';
|
|
||||||
|
|
||||||
if (data.audio_url) {
|
|
||||||
audioElement = new Audio(data.audio_url);
|
|
||||||
audioElement.onloadedmetadata = function() { updateAudioTimeDisplay(); };
|
|
||||||
audioElement.ontimeupdate = function() { updateAudioProgress(); updateAudioTimeDisplay(); };
|
|
||||||
audioElement.onended = function() { isPlaying = false; updatePlayButton(); };
|
|
||||||
playAudioBtn.onclick = togglePlayAudio;
|
|
||||||
audioProgress.onclick = function(e) {
|
|
||||||
const rect = audioProgress.getBoundingClientRect();
|
|
||||||
const clickPosition = (e.clientX - rect.left) / rect.width;
|
|
||||||
audioElement.currentTime = clickPosition * audioElement.duration;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
alert('音频处理失败: ' + data.message);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
thinkingIndicator.style.display = 'none';
|
|
||||||
alert('上传音频失败: ' + error.message);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 学伴功能 - 切换音频播放/暂停
|
// 页面加载完成后初始化
|
||||||
function togglePlayAudio() {
|
window.addEventListener('DOMContentLoaded', initPage);
|
||||||
if (!audioElement) return;
|
|
||||||
isPlaying ? audioElement.pause() : audioElement.play();
|
|
||||||
isPlaying = !isPlaying;
|
|
||||||
updatePlayButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 学伴功能 - 更新播放按钮状态
|
|
||||||
function updatePlayButton() {
|
|
||||||
playAudioBtn.innerHTML = isPlaying ?
|
|
||||||
`<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M6 19H10V5H6V19ZM14 19H18V5H14V19Z" fill="white"/></svg>` :
|
|
||||||
`<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M8 5V19L19 12L8 5Z" fill="white"/></svg>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 学伴功能 - 更新音频进度条
|
|
||||||
function updateAudioProgress() {
|
|
||||||
if (audioElement && audioElement.duration) {
|
|
||||||
progressBar.style.width = `${(audioElement.currentTime / audioElement.duration) * 100}%`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 学伴功能 - 更新音频时间显示
|
|
||||||
function updateAudioTimeDisplay() {
|
|
||||||
if (audioElement && audioElement.duration) {
|
|
||||||
const currentTime = formatTime(audioElement.currentTime);
|
|
||||||
const duration = formatTime(audioElement.duration);
|
|
||||||
audioTime.textContent = `${currentTime} / ${duration}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 学伴功能 - 格式化时间为 MM:SS
|
|
||||||
function formatTime(seconds) {
|
|
||||||
const mins = Math.floor(seconds / 60);
|
|
||||||
const secs = Math.floor(seconds % 60);
|
|
||||||
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user