118 lines
5.2 KiB
HTML
118 lines
5.2 KiB
HTML
{% extends 'base.html' %}
|
|
|
|
{% block title %}模拟考试 - ExamMaster{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="card">
|
|
<div class="card-title d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<i class="fas fa-clipboard-list"></i> 模拟考试
|
|
</div>
|
|
<a href="{{ url_for('index') }}" class="btn btn-primary">
|
|
<i class="fas fa-home"></i> 返回主页
|
|
</a>
|
|
</div>
|
|
|
|
<form id="examForm" method="post" action="{{ url_for('submit_exam') }}" class="mb-4">
|
|
{% for question in questions %}
|
|
<div class="question-container mb-4">
|
|
<div class="question-header">
|
|
<span class="question-number">题目 {{ question.id }}</span>
|
|
{% if question.difficulty == '简单' %}
|
|
<span class="question-difficulty difficulty-easy">简单</span>
|
|
{% elif question.difficulty == '中等' %}
|
|
<span class="question-difficulty difficulty-medium">中等</span>
|
|
{% else %}
|
|
<span class="question-difficulty difficulty-hard">困难</span>
|
|
{% endif %}
|
|
</div>
|
|
<div class="question-stem">{{ question.stem }}</div>
|
|
<div class="options-list">
|
|
{% for opt_key, opt_val in question.options.items() %}
|
|
<div class="option-item">
|
|
<label class="option-label">
|
|
{% if question.type == '单选题' %}
|
|
<input type="radio" name="answer_{{ question.id }}" value="{{ opt_key }}" class="option-checkbox" required>
|
|
{% else %}
|
|
<input type="checkbox" name="answer_{{ question.id }}" value="{{ opt_key }}" class="option-checkbox">
|
|
{% endif %}
|
|
<span class="option-text">{{ opt_key }}. {{ opt_val }}</span>
|
|
</label>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
<button type="submit" class="btn btn-primary">提交试卷</button>
|
|
</form>
|
|
|
|
<!-- 用于显示考试结果的区域 -->
|
|
<div id="examResult" class="mt-4"></div>
|
|
</div>
|
|
|
|
{% endblock %}
|
|
|
|
{% block scripts %}
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const examForm = document.getElementById('examForm');
|
|
examForm.addEventListener('submit', function(e) {
|
|
e.preventDefault(); // 阻止表单默认提交行为
|
|
|
|
// 使用FormData获取用户选择的答案
|
|
const formData = new FormData(examForm);
|
|
|
|
// 使用fetch以POST方式提交到后端submit_exam路由
|
|
fetch(examForm.getAttribute('action'), {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// 显示考试结果在当前页面
|
|
const resultDiv = document.getElementById('examResult');
|
|
const correctCount = data.correct_count;
|
|
const total = data.total;
|
|
const score = data.score.toFixed(2);
|
|
|
|
// 使用标准样式显示结果
|
|
resultDiv.innerHTML = `
|
|
<div class="alert ${score >= 60 ? 'alert-success' : 'alert-danger'}">
|
|
<div class="d-flex align-items-center justify-content-between mb-2">
|
|
<h3 class="mb-0">考试结束</h3>
|
|
<span class="badge ${score >= 60 ? 'badge-success' : 'badge-danger'}">${score}%</span>
|
|
</div>
|
|
<div class="progress-container mb-2">
|
|
<div class="progress-header">
|
|
<span class="progress-title">得分情况</span>
|
|
<span class="progress-value">${correctCount}/${total}</span>
|
|
</div>
|
|
<div class="progress-bar-container">
|
|
<div class="progress-bar" style="width: ${score}%"></div>
|
|
</div>
|
|
</div>
|
|
<p class="mb-0">你已完成本次模拟考试,可以查看<a href="${data.result_url || '#'}">详细结果</a>。</p>
|
|
</div>`;
|
|
} else {
|
|
// 显示标准错误消息
|
|
const resultDiv = document.getElementById('examResult');
|
|
resultDiv.innerHTML = `
|
|
<div class="alert alert-danger">
|
|
<i class="fas fa-exclamation-circle"></i> 提交失败,请重试。
|
|
</div>`;
|
|
}
|
|
})
|
|
.catch(err => {
|
|
console.error("提交考试请求失败:", err);
|
|
// 显示标准错误消息
|
|
const resultDiv = document.getElementById('examResult');
|
|
resultDiv.innerHTML = `
|
|
<div class="alert alert-danger">
|
|
<i class="fas fa-exclamation-circle"></i> 提交考试请求失败,请稍后再试。
|
|
</div>`;
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
{% endblock %} |