fix(admin): 复核页选择题选项渲染修复 + 阅卷导出 Word + 评分两位小数(R28)
针对测试人员反馈的四项: 1) 复核明细「选择题大量空白」:options 为 text 列存 JSON 字符串,原先被原样透传, 前端 v-for 对字符串逐字符迭代(op.key/op.text 皆 undefined)⇒ 每字符渲染一行。 新增 parseOptions()(仅 string 才 JSON.parse,失败降级 null)。 2) 选项与答案不随机:仅题目用 RAND() 抽题,normalizeQuestion 无 shuffle,字母无歧义。 3) 评分精度:DECIMAL(6,1) -> DECIMAL(6,2),migration 026 覆盖 17 列(与 025 同范围), lib/decimal_score.js 与 11 个 model 注释同步;汇总收敛 round2(×100/100)。 4) 阅卷导出:GET /api/admin/big-answers/:group/export?ids= 单选考生 -> 直接 .docx;多位/全部 -> 每位考生单独 .docx 打包 .zip。 路由为 3 段,注册在 :group 通配段之前。 验证:verify_big_question 51 PASS/1 FAIL(唯一 FAIL=测试人员新数据,非本次改动)、 verify_score_leak_all_channels 24/24、verify_question_no_answer_leak 4/3/0/1。
This commit is contained in:
@@ -1739,6 +1739,49 @@ class AdminController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出考生大题答卷为 Word(2026-09-28 需求:阅卷评分需将「试题 + 考生答案」导出)
|
||||
* GET /api/admin/big-answers/:group/export?ids=1,2,3
|
||||
* · 传 ids → 导出指定考生的答卷;不传 → 该组**全部已抽题**考生
|
||||
* · 命中 1 位 → 直接返回 .docx
|
||||
* · 命中多位 → 返回「每人一个独立 .docx」打包的 .zip(⛔ 不塞进同一个 Word)
|
||||
*
|
||||
* ⚠️ 与 `PUT /big-answers/:group/:uid/scores` 方法不同、段数不同,不会互相吞并。
|
||||
* ⚠️ 只调 ctx.attachment(原名):koa 自动做 RFC5987 编码;自行 encodeURIComponent 会
|
||||
* 双重编码导致中文文件名乱码(同源缺陷族,见 exportBigQuestions 注释)。
|
||||
*/
|
||||
async exportBigAnswers() {
|
||||
const { ctx, service } = this;
|
||||
if (!this._ensureAdmin()) return;
|
||||
|
||||
try {
|
||||
const { group } = ctx.params;
|
||||
if (!this._validateGroup(group)) return;
|
||||
|
||||
const result = await service.bigQuestion.exportAnswers(group, ctx.query.ids);
|
||||
|
||||
if (!result.ok) {
|
||||
const httpStatus = result.code === 'NOT_FOUND' ? 404 : 400;
|
||||
ctx.body = ctx.helper.error(httpStatus, result.message);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.set(
|
||||
'Content-Type',
|
||||
result.isZip
|
||||
? 'application/zip'
|
||||
: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||
);
|
||||
ctx.attachment(result.fileName);
|
||||
// 前端需知道本次导出了几位考生(响应体是二进制,读不到)
|
||||
ctx.set('X-Export-Count', String(result.count));
|
||||
ctx.body = result.buffer;
|
||||
} catch (err) {
|
||||
ctx.logger.error('导出考生大题答卷失败:', err);
|
||||
ctx.body = ctx.helper.error(500, '导出考生大题答卷失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增大题
|
||||
* POST /api/admin/big-questions/:group
|
||||
|
||||
Reference in New Issue
Block a user