feat(training): 完善安全培训题库与考试交互
修复 PDF 导入判断和填空题解析,支持文本题判分、回顾改答及安全培训三级流程校验。
This commit is contained in:
1 parent
ec4ed9b67d
commit
e62e4961d4
19 files changed
+721
-48
No files matched your search
@@ -99,12 +99,39 @@ const normalizeQuestionBank = (
|
||||
return value
|
||||
.map((item, index): TrainingQuestion | null => {
|
||||
const raw = asRecord(item);
|
||||
const type: TrainingQuestion['type'] = raw.type === 'boolean' ? 'boolean' : 'single';
|
||||
const rawType = String(raw.type || 'single').trim().toLowerCase();
|
||||
const typeAliases: Record<string, TrainingQuestion['type']> = {
|
||||
single: 'single',
|
||||
choice: 'single',
|
||||
select: 'single',
|
||||
boolean: 'boolean',
|
||||
bool: 'boolean',
|
||||
judgment: 'boolean',
|
||||
judge: 'boolean',
|
||||
'判断': 'boolean',
|
||||
'判断题': 'boolean',
|
||||
'3': 'boolean',
|
||||
true_false: 'boolean',
|
||||
truefalse: 'boolean',
|
||||
fill: 'fill',
|
||||
blank: 'fill',
|
||||
fill_blank: 'fill',
|
||||
essay: 'essay',
|
||||
qa: 'essay',
|
||||
'问答': 'essay',
|
||||
'问答题': 'essay',
|
||||
'简答': 'essay',
|
||||
'简答题': 'essay',
|
||||
'4': 'essay',
|
||||
question_answer: 'essay',
|
||||
short_answer: 'essay',
|
||||
};
|
||||
const type = typeAliases[rawType] || 'single';
|
||||
const prompt = String(raw.prompt || '').trim();
|
||||
if (!prompt) return null;
|
||||
const options = type === 'boolean'
|
||||
? booleanOptions
|
||||
: normalizeQuestionOptionList(raw.options);
|
||||
: type === 'single' ? normalizeQuestionOptionList(raw.options) : [];
|
||||
if (type === 'single' && options.length < 2) return null;
|
||||
const fallbackAnswer = type === 'boolean'
|
||||
? 'true'
|
||||
@@ -115,7 +142,8 @@ const normalizeQuestionBank = (
|
||||
id: String(raw.id || '').trim() || `q${index + 1}`,
|
||||
type,
|
||||
prompt,
|
||||
answer: optionIds.includes(answer) ? answer : fallbackAnswer,
|
||||
answer: type === 'fill' || type === 'essay' ? answer : optionIds.includes(answer) ? answer : fallbackAnswer,
|
||||
scoreRatio: Number(raw.score_ratio || raw.scoreRatio || 1),
|
||||
explanation: String(raw.explanation || '').trim(),
|
||||
options,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user