From 8cadc6cc178192a48039446702b3583c1d6b4331 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Tue, 18 Aug 2026 16:14:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=AE=89=E5=85=A8=E5=9F=B9=E8=AE=AD):=20?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=8B=E8=BD=BD=E5=9F=B9=E8=AE=AD=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E5=86=85=E5=AE=B9=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=85=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/TrainingWorkspacePanel.vue | 143 +++++++++++++++--- 1 file changed, 124 insertions(+), 19 deletions(-) diff --git a/frontend/src/features/chat/components/TrainingWorkspacePanel.vue b/frontend/src/features/chat/components/TrainingWorkspacePanel.vue index 8cd167c2..48ecd0f5 100644 --- a/frontend/src/features/chat/components/TrainingWorkspacePanel.vue +++ b/frontend/src/features/chat/components/TrainingWorkspacePanel.vue @@ -31,7 +31,7 @@ import FilePreviewModal from '@/shared/components/FilePreviewModal.vue'; import { useMessage } from '@/shared/composables/useMessage'; import { resolveTrainingExamPdfGuide, type TrainingGuideLike } from '@/features/chat/training/trainingWorkspace.utils'; import { getMyTrainingConfig } from '@/features/chat/api/training.api'; -import type { TrainingRecord } from '@/features/chat/training/training.types'; +import type { TrainingAnswerRecord, TrainingRecord, TrainingQuestion } from '@/features/chat/training/training.types'; import html2pdf from 'html2pdf.js'; import { getAuthHeaders } from '@/shared/utils/auth'; @@ -103,21 +103,89 @@ const handleVideoEnded = () => { const reportModalVisible = ref(false); const currentReportRecord = ref(null); -const reportQuestions = ref>({}); +const reportQuestions = ref>({}); const reportLoading = ref(false); +/** + * 将学员文本答案回填到题干中的横线位置。 + * 核心逻辑:仅替换填空题题干的连续下划线;若题干没有横线或答案为空,则保留原题干,避免改变非填空题与历史题目展示。 + * @param question - 当前题目的题库定义。 + * @param answer - 该题已保存的员工答题记录。 + * @returns 含回填答案的题干片段列表,模板按 `isAnswer` 区分答案样式。 + */ +const buildReportPromptParts = (question: TrainingQuestion | undefined, answer?: TrainingAnswerRecord) => { + const prompt = question?.prompt || ''; + const textAnswer = String(answer?.answerText || '').trim(); + if (question?.type !== 'fill' || !textAnswer || !/_{2,}/.test(prompt)) { + return [{ text: prompt, isAnswer: false }]; + } + const parts = prompt.split(/(_{2,})/g); + let answerFilled = false; + return parts.map((part) => { + if (!answerFilled && /^_{2,}$/.test(part)) { + answerFilled = true; + return { text: textAnswer, isAnswer: true }; + } + return { text: part, isAnswer: false }; + }); +}; + +/** + * 将判断题的员工答案转换为报告中的可读文本。 + * 核心逻辑:优先按 selectedOptionId 查找题库选项;历史题库没有选项时兼容 true/false、是/否等值。 + * @param question - 当前题目的题库定义。 + * @param answer - 当前题目的员工答题记录。 + * @returns 员工实际作答的答案文本;无法解析时返回原始选项 ID。 + */ +const resolveReportAnswerLabel = (question: TrainingQuestion | undefined, answer: TrainingAnswerRecord) => { + if (!question) return answer.selectedOptionId || answer.answerText || '--'; + if (question.type === 'fill' || question.type === 'essay') return answer.answerText || '--'; + return question.options?.find((option) => option.id === answer.selectedOptionId)?.label + || answer.selectedOptionId + || '--'; +}; + +/** + * 组合报告题库与实际答题记录,确保未作答题目仍出现在考试报告。 + * 核心逻辑:以当前发布题库为完整题目顺序,按题目 ID 合并答题记录;再保留历史记录中的已下线题目,避免旧考试报告丢失内容。 + * @returns 用于在线预览与 PDF 下载的完整题目及答案行。 + */ +const reportQuestionRows = computed(() => { + const answers = currentReportRecord.value?.answerDetails || []; + const answersByQuestionId = new Map(answers.map((answer) => [answer.questionId, answer])); + const configuredQuestions = Object.values(reportQuestions.value); + const configuredQuestionIds = new Set(configuredQuestions.map((question) => question.id)); + const defaultAnswer = (questionId: string): TrainingAnswerRecord => ({ + questionId, + selectedOptionId: '', + answerText: '', + correct: false, + }); + + return [ + ...configuredQuestions.map((question) => ({ + question, + answer: answersByQuestionId.get(question.id) || defaultAnswer(question.id), + })), + ...answers + .filter((answer) => !configuredQuestionIds.has(answer.questionId)) + .map((answer) => ({ question: undefined, answer })), + ]; +}); + const openReport = async (record: TrainingRecord) => { currentReportRecord.value = record; reportModalVisible.value = true; reportLoading.value = true; try { const config = await getMyTrainingConfig(record.trainingType || 'onboarding'); - const qMap: Record = {}; + const qMap: Record = {}; if (config?.resources) { - config.resources.forEach(r => { + config.resources.forEach((r) => { if (Array.isArray(r.inlineQuestions)) { - r.inlineQuestions.forEach((q: any) => { - qMap[q.id] = q; + r.inlineQuestions.forEach((q: unknown) => { + const question = q as TrainingQuestion; + qMap[question.id] = question; }); } }); @@ -1563,43 +1631,55 @@ const currentSafetyStageText = computed(() => {
-
+
{{ idx + 1 }}. - {{ reportQuestions[answer.questionId]?.prompt || `[ID: ${answer.questionId}]` }} + +
- 正确 + 正确 错误
-
+ 员工作答:{{ resolveReportAnswerLabel(row.question, row.answer) }} +
+
+ 员工作答:{{ resolveReportAnswerLabel(row.question, row.answer) }} +
+
{{ String.fromCharCode(65 + Number(optIdx)) }} {{ opt.label }}
-
-
Selected Option: {{ answer.selectedOptionId }}
+
+
员工作答:{{ resolveReportAnswerLabel(undefined, row.answer) }}
-
+
{{ $t('chat.training.hr.report.noReport') }}
@@ -1634,6 +1714,31 @@ const currentSafetyStageText = computed(() => { line-height: 1.5; } +.report-filled-answer { + display: inline-block; + min-width: 5rem; + margin: 0 0.15rem; + padding: 0 0.25rem; + border-bottom: 1px solid currentColor; + color: #2563eb; + font-weight: 700; + text-align: center; +} + +.report-answer-row { + color: #475569; + line-height: 1.6; +} + +.report-employee-answer { + color: #2563eb; + font-weight: 700; +} + +.report-essay-answer { + white-space: pre-wrap; +} + .report-question-result { flex-shrink: 0; white-space: nowrap;