mobile app admin_base admin_contests admin_dashboard chat contest_detail exam_create exam_detail exam_grade exam_list profile themes

This commit is contained in:
2026-03-07 19:07:01 +08:00
parent 2d3163a1a0
commit 86a6c7dd03
13 changed files with 656 additions and 169 deletions

View File

@@ -242,6 +242,7 @@ const SCHEDULED_END = null;
let currentIndex = 0;
let answers = {};
let tabSwitchCount = 0;
let examSubmitted = false; // 提交成功后允许离开
// ===== 图片上传 =====
function examUpload(qid) {
@@ -506,6 +507,9 @@ function doSubmit() {
body: JSON.stringify({answers})
}).then(r => r.json()).then(data => {
if (data.success) {
examSubmitted = true;
// 退出考试状态,通知好友
fetch(`/api/exams/${EXAM_ID}/exit`, { method: 'POST' }).catch(() => {});
// 清除本地存储
localStorage.removeItem(STORAGE_KEY);
localStorage.removeItem(TIMER_KEY);
@@ -523,17 +527,31 @@ function doSubmit() {
});
}
// 进入考试:标记状态并通知好友
fetch(`/api/exams/${EXAM_ID}/enter`, { method: 'POST' }).catch(() => {});
// 禁止中途退出:拦截返回按钮
history.pushState(null, '', location.href);
window.addEventListener('popstate', (e) => {
if (!examSubmitted) {
history.pushState(null, '', location.href);
alert('考试进行中,请勿离开!提交前无法退出。');
}
});
// 离开页面提醒(提交成功后允许离开)
window.addEventListener('beforeunload', (e) => {
if (!examSubmitted) {
e.preventDefault();
e.returnValue = '';
}
});
// 初始化
initAnswers();
initTimer();
initTabDetection();
showQuestion(0);
// 离开页面提醒
window.addEventListener('beforeunload', (e) => {
e.preventDefault();
e.returnValue = '';
});
</script>
{% endif %}
{% endblock %}