feat(training): 完善安全培训题库与考试交互
修复 PDF 导入判断和填空题解析,支持文本题判分、回顾改答及安全培训三级流程校验。
This commit is contained in:
1 parent
ec4ed9b67d
commit
e62e4961d4
19 files changed
+721
-48
No files matched your search
@@ -409,7 +409,7 @@ export const listAdminTrainingResourceCandidates = () =>
|
||||
requestJson<TrainingResourceCandidates>('/api/admin/training-configs/resource-candidates', auth());
|
||||
|
||||
export interface TrainingQuestionBankParseResult {
|
||||
question_bank: unknown[];
|
||||
question_bank: Array<{ type?: string; [key: string]: unknown }>;
|
||||
parsed_count: number;
|
||||
skipped_question_numbers: number[];
|
||||
kb_document_version_id: number;
|
||||
|
||||
@@ -141,11 +141,33 @@ const parseQuestionBank = async () => {
|
||||
}
|
||||
isParsingQuestions.value = true;
|
||||
try {
|
||||
// #region debug-point A:training-question-parse-click
|
||||
fetch('http://127.0.0.1:7788/event', { method: 'POST', body: JSON.stringify({ sessionId: 'training-pdf-question-import', runId: 'pre-fix', hypothesisId: 'A', location: 'TrainingConfigPage.vue:144', msg: '[DEBUG] Training PDF parse requested', data: { versionId: questionSourceVersionId.value }, ts: Date.now() }) }).catch(() => {});
|
||||
// #endregion
|
||||
const result = await parseAdminTrainingQuestionBank(questionSourceVersionId.value);
|
||||
// #region debug-point B:training-question-parse-result
|
||||
fetch('http://127.0.0.1:7788/event', { method: 'POST', body: JSON.stringify({ sessionId: 'training-pdf-question-import', runId: 'pre-fix', hypothesisId: 'B', location: 'TrainingConfigPage.vue:149', msg: '[DEBUG] Training PDF parse succeeded', data: { versionId: questionSourceVersionId.value, parsedCount: result.parsed_count, mode: result.extraction_mode, skipped: result.skipped_question_numbers }, ts: Date.now() }) }).catch(() => {});
|
||||
// #endregion
|
||||
// #region debug-point type-import-result
|
||||
fetch('http://127.0.0.1:7789/event', { method: 'POST', body: JSON.stringify({ sessionId: 'training-question-type-import', runId: 'pre-fix', hypothesisId: 'A', location: 'TrainingConfigPage.vue:151', msg: '[DEBUG] Training question types parsed', data: { versionId: questionSourceVersionId.value, parsedCount: result.parsed_count, skipped: result.skipped_question_numbers, types: result.question_bank.map((question) => question.type) }, ts: Date.now() }) }).catch(() => {});
|
||||
// #endregion
|
||||
const activeDocumentVersionIds = new Set(candidates.value.documents.map((document) => document.id));
|
||||
questionJsonText.value = JSON.stringify(result.question_bank, null, 2);
|
||||
// 题库由当前清洗后 PDF 解析;将配置中已失效的旧文档引用替换为该有效版本,避免保存时被后端 current/active 校验拒绝。
|
||||
questionSourceVersionId.value = result.kb_document_version_id;
|
||||
form.value.resources = form.value.resources.map((resource) => (
|
||||
resource.resource_type === 'kb_document_version'
|
||||
&& resource.kb_document_version_id
|
||||
&& !activeDocumentVersionIds.has(resource.kb_document_version_id)
|
||||
? { ...resource, kb_document_version_id: result.kb_document_version_id }
|
||||
: resource
|
||||
));
|
||||
questionParseMeta.value = { mode: result.extraction_mode, fileName: result.source_file_name, skipped: result.skipped_question_numbers };
|
||||
msg.success(t('admin.trainingConfig.messages.parseSuccess', { count: result.parsed_count }));
|
||||
} catch (error) {
|
||||
// #region debug-point C:training-question-parse-error
|
||||
fetch('http://127.0.0.1:7788/event', { method: 'POST', body: JSON.stringify({ sessionId: 'training-pdf-question-import', runId: 'pre-fix', hypothesisId: 'C', location: 'TrainingConfigPage.vue:156', msg: '[DEBUG] Training PDF parse failed', data: { versionId: questionSourceVersionId.value, error: error instanceof Error ? error.message : String(error) }, ts: Date.now() }) }).catch(() => {});
|
||||
// #endregion
|
||||
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.parseFailed'));
|
||||
} finally {
|
||||
isParsingQuestions.value = false;
|
||||
@@ -262,6 +284,9 @@ const saveConfig = async () => {
|
||||
}
|
||||
isSaving.value = true;
|
||||
try {
|
||||
// #region debug-point training-config-save-payload
|
||||
fetch('http://127.0.0.1:7790/event', { method: 'POST', body: JSON.stringify({ sessionId: 'training-config-save-validation', runId: 'pre-fix', hypothesisId: 'A', location: 'TrainingConfigPage.vue:277', msg: '[DEBUG] Training config save requested', data: { configId: selected.value.id, resources: form.value.resources.map((resource) => ({ type: resource.resource_type, guideId: resource.agent_guide_id || null, versionId: resource.kb_document_version_id || null, level: resource.training_level || null })) }, ts: Date.now() }) }).catch(() => {});
|
||||
// #endregion
|
||||
const saved = await updateAdminTrainingConfig(selected.value.id, form.value);
|
||||
await load();
|
||||
selectConfig(saved);
|
||||
|
||||
@@ -38,7 +38,9 @@ type TrainingRecordApi = {
|
||||
answer_details?: Array<{
|
||||
question_id?: string;
|
||||
selected_option_id?: string;
|
||||
answer_text?: string;
|
||||
correct?: boolean;
|
||||
score_ratio?: number;
|
||||
}>;
|
||||
completion_time?: string | null;
|
||||
updated_at?: string | null;
|
||||
@@ -122,7 +124,9 @@ function mapAnswerDetails(items?: TrainingRecordApi['answer_details']): Training
|
||||
? items.map((item) => ({
|
||||
questionId: String(item.question_id || ''),
|
||||
selectedOptionId: String(item.selected_option_id || ''),
|
||||
answerText: String(item.answer_text || ''),
|
||||
correct: Boolean(item.correct),
|
||||
scoreRatio: Number(item.score_ratio || 0),
|
||||
}))
|
||||
: [];
|
||||
}
|
||||
@@ -249,7 +253,9 @@ export async function saveMyTrainingProgress(payload: SaveTrainingProgressPayloa
|
||||
answer_details: payload.answerDetails.map((item) => ({
|
||||
question_id: item.questionId,
|
||||
selected_option_id: item.selectedOptionId,
|
||||
answer_text: item.answerText || '',
|
||||
correct: item.correct,
|
||||
score_ratio: item.scoreRatio || 0,
|
||||
})),
|
||||
join_date: payload.joinDate || undefined,
|
||||
}),
|
||||
|
||||
@@ -216,9 +216,16 @@ const expandCurrentWorkspace = () => {
|
||||
const currentAnswerLabel = computed(() => {
|
||||
const question = workspace.currentQuestion;
|
||||
if (!question) return '';
|
||||
if (question.type === 'fill' || question.type === 'essay') return workspace.answerText;
|
||||
return question.options?.find((item) => item.id === workspace.selectedOptionId)?.label || '';
|
||||
});
|
||||
|
||||
const isTextQuestion = computed(() => ['fill', 'essay'].includes(workspace.currentQuestion?.type || ''));
|
||||
const isTextFeedbackPending = computed(() => (
|
||||
workspace.currentQuestion?.type === 'essay'
|
||||
|| (workspace.currentQuestion?.type === 'fill' && !workspace.currentQuestion.answer)
|
||||
));
|
||||
|
||||
const trainingExamPdfGuide = computed(() => resolveTrainingExamPdfGuide(props.agentGuides));
|
||||
|
||||
const workspaceExpanded = ref(false);
|
||||
@@ -747,7 +754,25 @@ const currentSafetyStageText = computed(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-2.5 grid gap-2">
|
||||
<div v-if="isTextQuestion" class="mt-2.5 grid gap-2">
|
||||
<textarea
|
||||
v-model="workspace.answerText"
|
||||
:disabled="workspace.currentQuestion.type === 'essay' && workspace.answerLocked"
|
||||
:rows="workspace.currentQuestion.type === 'essay' ? 5 : 3"
|
||||
class="w-full rounded-2xl border border-default bg-white px-3.5 py-2 text-sm leading-6 text-primary outline-none transition focus:border-brand-400 focus:ring-2 focus:ring-brand-100 disabled:bg-surface-soft"
|
||||
:placeholder="$t(workspace.currentQuestion.type === 'essay' ? 'chat.training.exam.essayPlaceholder' : 'chat.training.exam.fillPlaceholder')"
|
||||
/>
|
||||
<button
|
||||
v-if="!workspace.answerLocked"
|
||||
type="button"
|
||||
:disabled="!workspace.answerText.trim()"
|
||||
class="justify-self-start rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
@click="workspace.submitTextAnswer()"
|
||||
>
|
||||
{{ $t('chat.training.exam.submitTextAnswer') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-else class="mt-2.5 grid gap-2">
|
||||
<button
|
||||
v-for="option in workspace.currentQuestion.options"
|
||||
:key="option.id"
|
||||
@@ -776,20 +801,25 @@ const currentSafetyStageText = computed(() => {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="workspace.answerLocked"
|
||||
class="mt-3 rounded-2xl border p-3"
|
||||
:class="workspace.currentFeedbackCorrect ? 'border-emerald-200 bg-emerald-50/70' : 'border-red-200 bg-red-50/70'"
|
||||
>
|
||||
<div class="flex items-center gap-2 text-sm font-semibold" :class="workspace.currentFeedbackCorrect ? 'text-emerald-700' : 'text-red-700'">
|
||||
<CheckCircle2 v-if="workspace.currentFeedbackCorrect" class="h-4 w-4" />
|
||||
<XCircle v-else class="h-4 w-4" />
|
||||
{{ workspace.currentFeedbackCorrect ? $t('chat.training.exam.correctFeedback') : $t('chat.training.exam.wrongFeedback') }}
|
||||
</div>
|
||||
<div
|
||||
v-if="workspace.answerLocked"
|
||||
class="mt-3 rounded-2xl border p-3"
|
||||
:class="isTextFeedbackPending || workspace.currentFeedbackCorrect ? 'border-emerald-200 bg-emerald-50/70' : 'border-red-200 bg-red-50/70'"
|
||||
>
|
||||
<div class="flex items-center gap-2 text-sm font-semibold" :class="isTextFeedbackPending || workspace.currentFeedbackCorrect ? 'text-emerald-700' : 'text-red-700'"">
|
||||
<CheckCircle2 v-if="isTextFeedbackPending || workspace.currentFeedbackCorrect" class="h-4 w-4" />
|
||||
<XCircle v-else class="h-4 w-4" />
|
||||
{{ isTextFeedbackPending ? $t('chat.training.exam.textAnswerRecorded') : workspace.currentFeedbackCorrect ? $t('chat.training.exam.correctFeedback') : $t('chat.training.exam.wrongFeedback') }}
|
||||
</div>
|
||||
<div class="mt-2 text-sm leading-6 text-secondary">
|
||||
{{ $t('chat.training.exam.selectedAnswer', { answer: currentAnswerLabel || '--' }) }}
|
||||
</div>
|
||||
<div class="mt-1 text-sm leading-6 text-secondary">
|
||||
<div v-if="isTextQuestion" class="mt-1 text-sm leading-6 text-secondary">
|
||||
{{ workspace.currentQuestion.type === 'fill' && workspace.currentQuestion.answer
|
||||
? $t('chat.training.exam.correctAnswer', { answer: workspace.currentQuestion.answer })
|
||||
: $t('chat.training.exam.textAnswerRecorded') }}
|
||||
</div>
|
||||
<div v-else class="mt-1 text-sm leading-6 text-secondary">
|
||||
{{ $t('chat.training.exam.correctAnswer', { answer: workspace.currentQuestion.options?.find((item) => item.id === workspace.currentQuestion?.answer)?.label || '--' }) }}
|
||||
</div>
|
||||
<div class="mt-2 text-sm leading-6 text-secondary">
|
||||
@@ -1056,7 +1086,25 @@ const currentSafetyStageText = computed(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-2.5 grid gap-2">
|
||||
<div v-if="isTextQuestion" class="mt-2.5 grid gap-2">
|
||||
<textarea
|
||||
v-model="workspace.answerText"
|
||||
:disabled="workspace.currentQuestion.type === 'essay' && workspace.answerLocked"
|
||||
:rows="workspace.currentQuestion.type === 'essay' ? 5 : 3"
|
||||
class="w-full rounded-2xl border border-default bg-white px-3.5 py-2 text-sm leading-6 text-primary outline-none transition focus:border-brand-400 focus:ring-2 focus:ring-brand-100 disabled:bg-surface-soft"
|
||||
:placeholder="$t(workspace.currentQuestion.type === 'essay' ? 'chat.training.exam.essayPlaceholder' : 'chat.training.exam.fillPlaceholder')"
|
||||
/>
|
||||
<button
|
||||
v-if="workspace.currentQuestion.type === 'fill' || !workspace.answerLocked"
|
||||
type="button"
|
||||
:disabled="!workspace.answerText.trim()"
|
||||
class="justify-self-start rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
@click="workspace.submitTextAnswer()"
|
||||
>
|
||||
{{ $t('chat.training.exam.submitTextAnswer') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-else class="mt-2.5 grid gap-2">
|
||||
<button
|
||||
v-for="option in workspace.currentQuestion.options"
|
||||
:key="option.id"
|
||||
@@ -1088,17 +1136,22 @@ const currentSafetyStageText = computed(() => {
|
||||
<div
|
||||
v-if="workspace.answerLocked"
|
||||
class="mt-3 rounded-2xl border p-3"
|
||||
:class="workspace.currentFeedbackCorrect ? 'border-emerald-200 bg-emerald-50/70' : 'border-red-200 bg-red-50/70'"
|
||||
:class="isTextFeedbackPending || workspace.currentFeedbackCorrect ? 'border-emerald-200 bg-emerald-50/70' : 'border-red-200 bg-red-50/70'"
|
||||
>
|
||||
<div class="flex items-center gap-2 text-sm font-semibold" :class="workspace.currentFeedbackCorrect ? 'text-emerald-700' : 'text-red-700'">
|
||||
<CheckCircle2 v-if="workspace.currentFeedbackCorrect" class="h-4 w-4" />
|
||||
<div class="flex items-center gap-2 text-sm font-semibold" :class="isTextFeedbackPending || workspace.currentFeedbackCorrect ? 'text-emerald-700' : 'text-red-700'"">
|
||||
<CheckCircle2 v-if="isTextFeedbackPending || workspace.currentFeedbackCorrect" class="h-4 w-4" />
|
||||
<XCircle v-else class="h-4 w-4" />
|
||||
{{ workspace.currentFeedbackCorrect ? $t('chat.training.exam.correctFeedback') : $t('chat.training.exam.wrongFeedback') }}
|
||||
{{ isTextFeedbackPending ? $t('chat.training.exam.textAnswerRecorded') : workspace.currentFeedbackCorrect ? $t('chat.training.exam.correctFeedback') : $t('chat.training.exam.wrongFeedback') }}
|
||||
</div>
|
||||
<div class="mt-2 text-sm leading-6 text-secondary">
|
||||
{{ $t('chat.training.exam.selectedAnswer', { answer: currentAnswerLabel || '--' }) }}
|
||||
</div>
|
||||
<div class="mt-1 text-sm leading-6 text-secondary">
|
||||
<div v-if="isTextQuestion" class="mt-1 text-sm leading-6 text-secondary">
|
||||
{{ workspace.currentQuestion.type === 'fill' && workspace.currentQuestion.answer
|
||||
? $t('chat.training.exam.correctAnswer', { answer: workspace.currentQuestion.answer })
|
||||
: $t('chat.training.exam.textAnswerRecorded') }}
|
||||
</div>
|
||||
<div v-else class="mt-1 text-sm leading-6 text-secondary">
|
||||
{{ $t('chat.training.exam.correctAnswer', { answer: workspace.currentQuestion.options?.find((item) => item.id === workspace.currentQuestion?.answer)?.label || '--' }) }}
|
||||
</div>
|
||||
<div class="mt-2 text-sm leading-6 text-secondary">
|
||||
|
||||
@@ -84,6 +84,15 @@ const calculateTrainingScore = (correctAnswerCount: number, totalQuestionCount:
|
||||
return Math.round((correctAnswerCount / totalQuestionCount) * 100);
|
||||
};
|
||||
|
||||
/**
|
||||
* 规范填空题文本以便与题库标准答案进行即时比对。
|
||||
* 用途:忽略作答中的空格和大小写,避免 PDF 文本换行或录入格式导致本应正确的填空题被误判。
|
||||
*/
|
||||
const normalizeTextAnswer = (value: string) => value
|
||||
.normalize('NFKC')
|
||||
.replace(/[\s\u3000、,,;;。..!!??::()()【】\[\]{}"'“”‘’\-—_]+/g, '')
|
||||
.toLocaleLowerCase();
|
||||
|
||||
export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const { currentAgent, currentUser, currentGuides } = options;
|
||||
const { t, tm } = useI18n();
|
||||
@@ -114,6 +123,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
const score = ref(0);
|
||||
const attemptCount = ref(0);
|
||||
const selectedOptionId = ref('');
|
||||
const answerText = ref('');
|
||||
const answerLocked = ref(false);
|
||||
const currentFeedbackCorrect = ref(false);
|
||||
const latestExamFeedback = ref<TrainingExamTransitionFeedback | null>(null);
|
||||
@@ -203,6 +213,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
type,
|
||||
prompt: String(item.prompt || ''),
|
||||
answer: String(item.answer || ''),
|
||||
scoreRatio: Number(item.score_ratio || item.scoreRatio || 1),
|
||||
explanation: String(item.explanation || ''),
|
||||
options,
|
||||
};
|
||||
@@ -293,6 +304,14 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 校验三级安全培训资料是否已全部完成。
|
||||
* 用途:在员工端进入或提交安全考试前提供即时拦截;服务端仍会使用同一资源完成事实做最终校验。
|
||||
*/
|
||||
const isSafetyLearningComplete = () => (
|
||||
isStageCompleted('company') && isStageCompleted('department') && isStageCompleted('team')
|
||||
);
|
||||
|
||||
const safetyStepItems = computed(() => {
|
||||
const base: Array<{ id: SafetyStage extends infer U ? U : never; labelKey: string }> = [
|
||||
{ id: 'company', labelKey: 'chat.training.safety.steps.company' },
|
||||
@@ -358,6 +377,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
currentQuestionIndex.value = 0;
|
||||
score.value = 0;
|
||||
selectedOptionId.value = '';
|
||||
answerText.value = '';
|
||||
answerLocked.value = false;
|
||||
currentFeedbackCorrect.value = false;
|
||||
latestExamFeedback.value = null;
|
||||
@@ -450,8 +470,11 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
? answerRecords.value.find((item) => item.questionId === questionId)
|
||||
: null;
|
||||
selectedOptionId.value = currentAnswer?.selectedOptionId || '';
|
||||
answerText.value = currentAnswer?.answerText || '';
|
||||
answerLocked.value = Boolean(currentAnswer);
|
||||
currentFeedbackCorrect.value = Boolean(currentAnswer?.correct);
|
||||
currentFeedbackCorrect.value = currentQuestion.value?.type === 'fill' && currentQuestion.value.answer && currentAnswer?.answerText
|
||||
? normalizeTextAnswer(currentAnswer.answerText) === normalizeTextAnswer(currentQuestion.value.answer)
|
||||
: Boolean(currentAnswer?.correct);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -499,6 +522,10 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
* AI 触发时机:当三级学习全部完成,或员工在安全培训中点击“开始考试/重新考试”时调用。
|
||||
*/
|
||||
const enterSafetyExam = () => {
|
||||
if (!isSafetyLearningComplete()) {
|
||||
msg.warning(t('chat.training.errors.safetyLearningIncomplete'));
|
||||
return;
|
||||
}
|
||||
if (totalQuestionCount.value <= 0) {
|
||||
msg.warning(t('chat.training.errors.questionBankEmpty'));
|
||||
return;
|
||||
@@ -609,6 +636,8 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
hasWarnedPersistFailure.value = false;
|
||||
currentJoinDate.value = saved.joinDate || currentJoinDate.value;
|
||||
completionDate.value = saved.completionDate;
|
||||
score.value = Number(saved.score || 0);
|
||||
answerRecords.value = saved.answerDetails;
|
||||
if (isAdminViewer.value) {
|
||||
void loadAdminRecords();
|
||||
}
|
||||
@@ -796,7 +825,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
* AI 触发时机:当员工在逐题考试阶段点击右侧题号返回某题时,需要允许直接改答且不破坏“提交答卷后才结算”的流程。
|
||||
*/
|
||||
const selectAnswer = (optionId: string) => {
|
||||
if (!currentQuestion.value) return;
|
||||
if (!currentQuestion.value || currentQuestion.value.type === 'fill' || currentQuestion.value.type === 'essay') return;
|
||||
const answeredQuestion = currentQuestion.value;
|
||||
const hadExistingAnswer = answerRecords.value.some((item) => item.questionId === answeredQuestion.id);
|
||||
selectedOptionId.value = optionId;
|
||||
@@ -830,6 +859,40 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
void persistProgress();
|
||||
};
|
||||
|
||||
/**
|
||||
* 提交填空或问答题的文本作答。
|
||||
* 核心逻辑:文本题由服务端以题库标准答案或无标准答案的字数规则最终判卷;前端仅保存非空文本并推进。
|
||||
* @returns 无有效文本时不记录,否则更新当前题作答并保持既有逐题推进行为。
|
||||
*/
|
||||
const submitTextAnswer = () => {
|
||||
if (!currentQuestion.value || !['fill', 'essay'].includes(currentQuestion.value.type)) return;
|
||||
const answeredQuestion = currentQuestion.value;
|
||||
const text = answerText.value.trim();
|
||||
if (!text) return;
|
||||
const hadExistingAnswer = answerRecords.value.some((item) => item.questionId === answeredQuestion.id);
|
||||
const answerRecord: TrainingAnswerRecord = {
|
||||
questionId: answeredQuestion.id,
|
||||
selectedOptionId: '',
|
||||
answerText: text,
|
||||
correct: answeredQuestion.type === 'fill' && answeredQuestion.answer
|
||||
? normalizeTextAnswer(text) === normalizeTextAnswer(answeredQuestion.answer)
|
||||
: false,
|
||||
scoreRatio: 0,
|
||||
};
|
||||
answerLocked.value = true;
|
||||
upsertAnswerRecord(answerRecord);
|
||||
const nextScore = recalculateScoreFromAnswers(answerRecords.value);
|
||||
score.value = nextScore;
|
||||
currentFeedbackCorrect.value = answerRecord.correct;
|
||||
latestExamFeedback.value = buildExamFeedback(answeredQuestion, answerRecord, nextScore);
|
||||
if (hadExistingAnswer || currentQuestionIndex.value >= totalQuestionCount.value - 1) {
|
||||
void persistProgress();
|
||||
return;
|
||||
}
|
||||
syncExamQuestionIndex(currentQuestionIndex.value + 1);
|
||||
void persistProgress();
|
||||
};
|
||||
|
||||
/**
|
||||
* 进入下一题或结束考试。
|
||||
* AI 触发时机:当用户答完一题后,前端必须只推进一题并即时结算,保证“一题一答一反馈”的 HR 规则被严格执行。
|
||||
@@ -850,6 +913,10 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
*/
|
||||
const submitExam = () => {
|
||||
if (!examReadyToSubmit.value) return;
|
||||
if (learnerTab.value === 'safety' && !isSafetyLearningComplete()) {
|
||||
msg.warning(t('chat.training.errors.safetyLearningIncomplete'));
|
||||
return;
|
||||
}
|
||||
stage.value = 'result';
|
||||
if (learnerTab.value === 'safety') {
|
||||
safetyStage.value = 'result';
|
||||
@@ -1077,6 +1144,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
score,
|
||||
attemptCount,
|
||||
selectedOptionId,
|
||||
answerText,
|
||||
answerLocked,
|
||||
currentFeedbackCorrect,
|
||||
examReadyToSubmit,
|
||||
@@ -1109,6 +1177,7 @@ export function useTrainingWorkspace(options: UseTrainingWorkspaceOptions) {
|
||||
markVideoCompleted,
|
||||
startExam,
|
||||
selectAnswer,
|
||||
submitTextAnswer,
|
||||
syncExamQuestionIndex,
|
||||
moveToNextQuestion,
|
||||
submitExam,
|
||||
|
||||
@@ -15,7 +15,7 @@ export type SafetyStage = 'company' | 'department' | 'team' | 'exam' | 'result';
|
||||
|
||||
export type TrainingWorkspaceView = 'learner' | 'admin';
|
||||
|
||||
export type TrainingQuestionType = 'single' | 'boolean';
|
||||
export type TrainingQuestionType = 'single' | 'boolean' | 'fill' | 'essay';
|
||||
|
||||
export interface TrainingQuestionOption {
|
||||
id: string;
|
||||
@@ -27,6 +27,7 @@ export interface TrainingQuestion {
|
||||
type: TrainingQuestionType;
|
||||
prompt: string;
|
||||
answer: string;
|
||||
scoreRatio?: number;
|
||||
explanation: string;
|
||||
options?: TrainingQuestionOption[];
|
||||
}
|
||||
@@ -68,7 +69,9 @@ export interface TrainingPublishedConfig {
|
||||
export interface TrainingAnswerRecord {
|
||||
questionId: string;
|
||||
selectedOptionId: string;
|
||||
answerText?: string;
|
||||
correct: boolean;
|
||||
scoreRatio?: number;
|
||||
}
|
||||
|
||||
export interface TrainingExamTransitionFeedback {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -369,8 +369,14 @@ export function useKbWorkspaceDocuments(
|
||||
};
|
||||
|
||||
const handleSyncDocument = async (documentId: number) => {
|
||||
// #region debug-point A:sync-click
|
||||
fetch('http://127.0.0.1:7787/event', { method: 'POST', body: JSON.stringify({ sessionId: 'knowledge-base-dify-sync', runId: 'pre-fix', hypothesisId: 'A', location: 'useKbWorkspaceDocuments.ts:371', msg: '[DEBUG] Dify sync click received', data: { documentId }, ts: Date.now() }) }).catch(() => {});
|
||||
// #endregion
|
||||
syncingDocumentId.value = documentId;
|
||||
const result = await syncKbDocumentToDify(documentId);
|
||||
// #region debug-point B:sync-response
|
||||
fetch('http://127.0.0.1:7787/event', { method: 'POST', body: JSON.stringify({ sessionId: 'knowledge-base-dify-sync', runId: 'pre-fix', hypothesisId: 'B', location: 'useKbWorkspaceDocuments.ts:376', msg: '[DEBUG] Dify sync API response received', data: { documentId, ok: result.ok, error: result.error || null, jobId: result.job?.id || null, message: result.job?.message || null }, ts: Date.now() }) }).catch(() => {});
|
||||
// #endregion
|
||||
syncingDocumentId.value = null;
|
||||
|
||||
if (!result.ok) {
|
||||
|
||||
Reference in new issue
Block a user