Files
competition-website/src/api/exam.js
WorkBuddy e8f0195b61 chore: 前端首次基线提交
运行必须源码:src/、public/、index.html、package.json 及构建配置。
已忽略运行非必须:node_modules/、dist/、.env*。
2026-08-17 12:25:42 +08:00

93 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import request from './request'
// ==================== 考试/知识竞答 API ====================
/**
* 获取考试状态
* @param {string} group - 组别标识
* @returns {Promise} { isActive, startTime, endTime, countdown, status, submitted }
*/
export function getExamStatus(group) {
return request.get(`/exam/${group}/status`)
}
/**
* 获取考试题目列表
* 抽题数量以后台 competition_times 配置为准(choice_count / judge_count),
* 题目数量不足时自动按题库实际数量封顶,题号随实际数量自适应。
* @param {string} group - 组别标识
* @returns {Promise} 题目数组
*/
export function getQuestions(group) {
return request.get(`/exam/${group}/questions`)
}
/**
* 获取 Word 答题模板(返回文件流,前端通过 window.open 直接下载)
* @param {string} group - 组别标识
* @returns {Promise} 文件流
*/
export function getWordTemplate(group) {
return request.get(`/exam/${group}/word-template`)
}
/**
* 提交单个答案
* @param {string} group - 组别标识
* @param {array} answers - 答案数组 [{ question_uid, answer_data }]
* @returns {Promise}
*/
export function submitAnswers(group, answers) {
return request.post(`/exam/${group}/submit-answers`, { answers }, { silent: true })
}
/**
* 上传 Word 答题文件
* @param {string} group - 组别标识
* @param {FormData} formData - 包含 Word 文件的 FormData
* @returns {Promise}
*/
export function uploadWord(group, formData) {
return request.post(`/exam/${group}/upload-word`, formData, {
timeout: 60000, // 上传超时 60 秒
})
}
/**
* 删除已上传的 Word 答题文件(中职/高职组)
* @param {string} group - 组别标识
* @returns {Promise}
*/
export function deleteWord(group) {
return request.delete(`/exam/${group}/word`, { timeout: 60000 })
}
/**
* 提交全部答案(结束考试)
* @param {string} group - 组别标识
* @param {object} data - 提交数据
* @returns {Promise}
*/
export function submitAll(group, data) {
return request.post(`/exam/${group}/submit-all`, data, { silent: true })
}
/**
* 获取已有答案(考试重新进入时恢复状态)
* @param {string} group - 组别标识
* @returns {Promise} { answers: [...] }
*/
export function getAnswers(group) {
return request.get(`/exam/${group}/answers`)
}
/**
* 获取当前选手个人成绩(后端按认证用户取,group 仅作透传参数)
* GET /score
* @param {string} group - 组别标识
* @returns {Promise} 成绩详情(含答题得分/作品评分/总分)
*/
export function getScore(group) {
return request.get('/score', { params: { group } })
}