|
|
|
|
|
<template>
|
|
|
|
|
|
<div class="training-task-toolbar">
|
|
|
|
|
|
<TrainingMaterialButton
|
|
|
|
|
|
:material-name="resolvedMaterial.name"
|
|
|
|
|
|
:material-url="resolvedMaterial.url"
|
|
|
|
|
|
:training-data-name="resolvedTrainingData.name"
|
|
|
|
|
|
:training-data-url="resolvedTrainingData.url"
|
|
|
|
|
|
:guide-manual-name="resolvedGuideManual.name"
|
|
|
|
|
|
:guide-manual-url="resolvedGuideManual.url"
|
|
|
|
|
|
:ai-manual-name="resolvedAiManual.name"
|
|
|
|
|
|
:ai-manual-url="resolvedAiManual.url"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<!-- 成绩展示:无成绩不显示;有老师评分优先显示老师评分,否则显示 AI 评分;有 AI 评分时点击可查看 AI 评分详情 -->
|
|
|
|
|
|
<template v-if="scoreVisible">
|
|
|
|
|
|
<button v-if="displayScore !== null && hasAiScore" type="button" class="task-toolbar-score" :title="scoreBadgeTitle" @click="openAiEvaluationDialog">
|
|
|
|
|
|
{{ displayScore }}<small>分</small>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<span v-else-if="displayScore !== null" class="task-toolbar-score" :title="scoreBadgeTitle">
|
|
|
|
|
|
{{ displayScore }}<small>分</small>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<el-button class="task-toolbar-button" @click="openScoreDialog">
|
|
|
|
|
|
<el-icon><View /></el-icon>查看成绩
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<!-- 保存当前进度按钮已注销
|
|
|
|
|
|
<el-button class="task-toolbar-button task-toolbar-button--save" :loading="savingProgress" @click="triggerExistingAction('save')">
|
|
|
|
|
|
<el-icon><CircleCheck /></el-icon>保存当前进度
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
-->
|
|
|
|
|
|
<el-button class="task-toolbar-button task-toolbar-button--submit" @click="triggerExistingAction('submit')">
|
|
|
|
|
|
<el-icon><CircleCheck /></el-icon>提交任务
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<el-button class="task-toolbar-button" @click="triggerExistingAction('reset')">
|
|
|
|
|
|
<el-icon><RefreshLeft /></el-icon>重新实训
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<el-button class="task-toolbar-button" :loading="exporting" @click="exportCurrentTrainingOutcome">
|
|
|
|
|
|
<el-icon><Download /></el-icon>导出实训成果
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 成绩弹窗:成绩、评语和参考答案(老师推送后展示) -->
|
|
|
|
|
|
<el-dialog v-model="scoreDialogVisible" title="实训成绩" width="560px" append-to-body class="task-score-dialog" @open="onScoreDialogOpen">
|
|
|
|
|
|
<div class="task-score-body">
|
|
|
|
|
|
<section v-if="hasTeacherScore || hasAiScore" class="task-score-cards">
|
|
|
|
|
|
<div v-if="hasTeacherScore" class="task-score-card task-score-card--teacher">
|
|
|
|
|
|
<p class="task-score-card__label">老师评分</p>
|
|
|
|
|
|
<p class="task-score-card__value">{{ formatScoreValue(teacherScore) }}<small>分</small></p>
|
|
|
|
|
|
<p v-if="teacherScoredAt" class="task-score-card__time">{{ formatScoreTime(teacherScoredAt) }}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div v-if="hasAiScore" class="task-score-card task-score-card--ai">
|
|
|
|
|
|
<p class="task-score-card__label">AI 评分</p>
|
|
|
|
|
|
<p class="task-score-card__value">{{ formatScoreValue(aiScore) }}<small>分</small></p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
<section v-if="teacherComment" class="task-score-block">
|
|
|
|
|
|
<p class="task-score-block__label">老师评语</p>
|
|
|
|
|
|
<p class="task-score-block__text">{{ teacherComment }}</p>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
<section v-if="referenceAnswerPushed" class="task-score-block">
|
|
|
|
|
|
<p class="task-score-block__label">参考答案</p>
|
|
|
|
|
|
<p class="task-score-block__text">{{ loadedTask?.referenceAnswerName || "参考答案" }}</p>
|
|
|
|
|
|
<iframe v-if="referenceAnswerPdfUrl" :src="referenceAnswerPdfUrl" class="reference-answer-frame reference-answer-frame--inline" title="参考答案预览" />
|
|
|
|
|
|
<p v-else-if="referenceAnswerLoading" class="task-score-block__text">参考答案加载中...</p>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
<el-empty v-if="!hasScoreData && !referenceAnswerPushed" description="老师还没有批阅这份实训任务" :image-size="90" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
<!-- AI 评分结果:悬浮在页面上(非弹窗) -->
|
|
|
|
|
|
<transition name="ai-eval-pop">
|
|
|
|
|
|
<div v-if="aiEvaluationFloatVisible" class="ai-evaluation-float">
|
|
|
|
|
|
<div class="ai-evaluation-float__header">
|
|
|
|
|
|
<span class="ai-evaluation-float__title">AI评分结果</span>
|
|
|
|
|
|
<button type="button" class="ai-evaluation-float__close" @click="aiEvaluationFloatVisible = false">
|
|
|
|
|
|
<el-icon><Close /></el-icon>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="ai-evaluation-float__summary">
|
|
|
|
|
|
<span class="ai-evaluation-float__label">综合评分</span>
|
|
|
|
|
|
<span class="ai-evaluation-float__score">{{ formatScoreValue(aiEvaluationScore) }}<small>/100</small></span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p v-if="aiEvaluationComment" class="ai-evaluation-float__comment">{{ aiEvaluationComment }}</p>
|
|
|
|
|
|
<div v-for="(criterion, index) in aiEvaluationCriteria" :key="index" class="ai-evaluation-float__criterion">
|
|
|
|
|
|
<p class="ai-evaluation-float__criterion-head">
|
|
|
|
|
|
<span>{{ criterion.name }}</span>
|
|
|
|
|
|
<b>{{ criterion.score }}<i>/{{ criterion.maxScore }}</i></b>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p class="ai-evaluation-float__text">{{ criterion.rationale }}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<template v-if="aiEvaluationImprovements.length">
|
|
|
|
|
|
<p class="ai-evaluation-float__label">优先改进</p>
|
|
|
|
|
|
<ul class="ai-evaluation-float__improvements">
|
|
|
|
|
|
<li v-for="(item, index) in aiEvaluationImprovements" :key="index">{{ item }}</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-empty v-if="!aiEvaluationComment && !aiEvaluationCriteria.length" description="暂无AI评价内容" :image-size="90" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</transition>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
|
|
|
|
import { CircleCheck, Close, Download, RefreshLeft, View } from "@element-plus/icons-vue";
|
|
|
|
|
|
import { ElMessage } from "element-plus";
|
|
|
|
|
|
import { getTrainingTaskByKey, previewStudentReferenceAnswer } from "@/api/trainingTask";
|
|
|
|
|
|
import { getAiTrainingEvaluation } from "@/api/aiTrainingEvaluation";
|
|
|
|
|
|
import { deleteStudentTrainingAnswer, getStudentTrainingAnswer, saveStudentTrainingAnswer } from "@/api/studentTrainingAnswer";
|
|
|
|
|
|
import { resolveTrainingTaskKey } from "@/views/training/taskKeyMap";
|
|
|
|
|
|
import TrainingMaterialButton from "@/views/components/TrainingMaterialButton.vue";
|
|
|
|
|
|
import { collectTrainingOutcomeDetails, exportTrainingOutcomePdf } from "@/utils/trainingOutcomePdf";
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
materialName: { type: String, default: "" },
|
|
|
|
|
|
materialUrl: { type: String, default: "" },
|
|
|
|
|
|
trainingDataName: { type: String, default: "" },
|
|
|
|
|
|
trainingDataUrl: { type: String, default: "" },
|
|
|
|
|
|
guideManualName: { type: String, default: "" },
|
|
|
|
|
|
guideManualUrl: { type: String, default: "" },
|
|
|
|
|
|
aiManualName: { type: String, default: "" },
|
|
|
|
|
|
aiManualUrl: { type: String, default: "" },
|
|
|
|
|
|
taskKey: { type: String, default: "" },
|
|
|
|
|
|
onSubmit: { type: Function, default: null },
|
|
|
|
|
|
onReset: { type: Function, default: null },
|
|
|
|
|
|
onExport: { type: Function, default: null },
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
const loadedMaterial = ref({
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
url: "",
|
|
|
|
|
|
trainingDataName: "",
|
|
|
|
|
|
trainingDataUrl: "",
|
|
|
|
|
|
guideManualName: "",
|
|
|
|
|
|
guideManualUrl: "",
|
|
|
|
|
|
aiManualName: "",
|
|
|
|
|
|
aiManualUrl: ""
|
|
|
|
|
|
});
|
|
|
|
|
|
const loadedTask = ref(null);
|
|
|
|
|
|
const exporting = ref(false);
|
|
|
|
|
|
const savingProgress = ref(false);
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 成绩展示状态 ==========
|
|
|
|
|
|
const scoreAnswer = ref(null);
|
|
|
|
|
|
const scoreDialogVisible = ref(false);
|
|
|
|
|
|
const referenceAnswerPdfUrl = ref("");
|
|
|
|
|
|
const referenceAnswerLoading = ref(false);
|
|
|
|
|
|
const aiEvaluationFloatVisible = ref(false);
|
|
|
|
|
|
const aiEvaluationScore = ref(null);
|
|
|
|
|
|
const aiEvaluationComment = ref("");
|
|
|
|
|
|
const aiEvaluationCriteria = ref([]);
|
|
|
|
|
|
const aiEvaluationImprovements = ref([]);
|
|
|
|
|
|
// 不同接口对同一分数的命名不一致,统一兜底取值,避免换了字段名就读不到分数
|
|
|
|
|
|
const teacherScore = computed(() => pickScore(scoreAnswer.value, ["teacherScore", "teacherTotalScore"]));
|
|
|
|
|
|
const aiScore = computed(() => pickScore(scoreAnswer.value, ["aiAssessmentScore", "aiTotalScore", "aiScore", "score", "totalScore"]));
|
|
|
|
|
|
const teacherComment = computed(() => pickText(scoreAnswer.value, ["teacherComment", "teacherComments", "comment"]));
|
|
|
|
|
|
const teacherScoredAt = computed(() => String(scoreAnswer.value?.teacherScoredAt || "").trim());
|
|
|
|
|
|
const hasTeacherScore = computed(() => teacherScore.value !== null);
|
|
|
|
|
|
const hasAiScore = computed(() => aiScore.value !== null);
|
|
|
|
|
|
const hasScoreData = computed(() => hasTeacherScore.value || hasAiScore.value || Boolean(teacherComment.value));
|
|
|
|
|
|
const scoreVisible = computed(() => hasScoreData.value);
|
|
|
|
|
|
const displayScore = computed(() => {
|
|
|
|
|
|
if (hasTeacherScore.value) return teacherScore.value;
|
|
|
|
|
|
if (hasAiScore.value) return aiScore.value;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
const scoreBadgeTitle = computed(() => "AI 评分,点击查看评分详情");
|
|
|
|
|
|
// 老师在任务配置里“推送”参考答案后,学生任务信息才会携带参考答案文件
|
|
|
|
|
|
const referenceAnswerPushed = computed(() => Boolean(loadedTask.value?.referenceAnswerUrl));
|
|
|
|
|
|
let referenceAnswerObjectUrl = "";
|
|
|
|
|
|
|
|
|
|
|
|
function onScoreDialogOpen() {
|
|
|
|
|
|
// 打开时重新拉取,保证教师刚评完的分/评语能及时看到。
|
|
|
|
|
|
loadScoreState();
|
|
|
|
|
|
if (referenceAnswerObjectUrl) {
|
|
|
|
|
|
URL.revokeObjectURL(referenceAnswerObjectUrl);
|
|
|
|
|
|
referenceAnswerObjectUrl = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
referenceAnswerPdfUrl.value = "";
|
|
|
|
|
|
if (!referenceAnswerPushed.value) return;
|
|
|
|
|
|
referenceAnswerLoading.value = true;
|
|
|
|
|
|
previewStudentReferenceAnswer(resolvedTaskKey.value).then((response) => {
|
|
|
|
|
|
const blob = response instanceof Blob ? response : new Blob([response], { type: "application/pdf" });
|
|
|
|
|
|
referenceAnswerPdfUrl.value = URL.createObjectURL(blob);
|
|
|
|
|
|
referenceAnswerPdfUrl.value = referenceAnswerObjectUrl;
|
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
ElMessage.error("参考答案加载失败,请稍后重试");
|
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
|
referenceAnswerLoading.value = false;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toScoreNumber(value) {
|
|
|
|
|
|
if (value === null || value === undefined || value === "") return null;
|
|
|
|
|
|
const num = Number(value);
|
|
|
|
|
|
return Number.isFinite(num) ? num : null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function pickScore(source, keys) {
|
|
|
|
|
|
for (const key of keys) {
|
|
|
|
|
|
const num = toScoreNumber(source?.[key]);
|
|
|
|
|
|
if (num !== null) return num;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function pickText(source, keys) {
|
|
|
|
|
|
for (const key of keys) {
|
|
|
|
|
|
const text = String(source?.[key] || "").trim();
|
|
|
|
|
|
if (text) return text;
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatScoreValue(value) {
|
|
|
|
|
|
const num = toScoreNumber(value);
|
|
|
|
|
|
if (num === null) return "--";
|
|
|
|
|
|
return num.toFixed(2).replace(/\.00$/, "").replace(/(\.\d)0$/, "$1");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatScoreTime(value) {
|
|
|
|
|
|
return String(value).replace("T", " ").slice(0, 16);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function loadScoreState() {
|
|
|
|
|
|
const scoreTaskKey = resolvedTaskKey.value;
|
|
|
|
|
|
if (!scoreTaskKey) {
|
|
|
|
|
|
scoreAnswer.value = null;
|
|
|
|
|
|
console.debug("[成绩] 当前页面未解析到 taskKey,不展示成绩:", route.path);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await getStudentTrainingAnswer(scoreTaskKey);
|
|
|
|
|
|
scoreAnswer.value = response?.data || null;
|
|
|
|
|
|
if (!scoreAnswer.value) {
|
|
|
|
|
|
console.debug(`[成绩] taskKey=${scoreTaskKey} 暂无答题记录,不展示成绩`);
|
|
|
|
|
|
} else if (!pickScore(scoreAnswer.value, ["teacherScore", "teacherTotalScore"]) &&
|
|
|
|
|
|
!pickScore(scoreAnswer.value, ["aiAssessmentScore", "aiTotalScore", "aiScore", "score", "totalScore"])) {
|
|
|
|
|
|
console.debug(`[成绩] taskKey=${scoreTaskKey} 有答题记录但无评分数据(未提交 / 未批阅 / 未 AI 评分)`);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
// 没有答题记录或接口异常时按“无成绩”处理,工具栏不显示成绩入口。
|
|
|
|
|
|
scoreAnswer.value = null;
|
|
|
|
|
|
console.debug(`[成绩] taskKey=${scoreTaskKey} 成绩加载失败,不展示成绩`, error?.message || error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function openAiEvaluationDialog() {
|
|
|
|
|
|
if (!resolvedTaskKey.value) return;
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await getAiTrainingEvaluation(resolvedTaskKey.value);
|
|
|
|
|
|
const data = response?.data || {};
|
|
|
|
|
|
let report = {};
|
|
|
|
|
|
try { report = data.assessmentReportJson ? JSON.parse(data.assessmentReportJson) : {}; } catch { report = {}; }
|
|
|
|
|
|
aiEvaluationScore.value = toScoreNumber(data.assessmentScore ?? report.score);
|
|
|
|
|
|
aiEvaluationComment.value = data.assessmentComment || report.overallComment || report.overallDiagnosis || "";
|
|
|
|
|
|
aiEvaluationCriteria.value = Array.isArray(report.criteria) ? report.criteria : [];
|
|
|
|
|
|
aiEvaluationImprovements.value = Array.isArray(report.improvements) ? report.improvements : [];
|
|
|
|
|
|
aiEvaluationFloatVisible.value = true;
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
ElMessage.error("AI评价加载失败,请稍后重试");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 点击悬浮卡片与分数徽标以外区域时收起
|
|
|
|
|
|
function onDocMouseDownForAiFloat(e) {
|
|
|
|
|
|
if (!aiEvaluationFloatVisible.value) return;
|
|
|
|
|
|
const target = e.target;
|
|
|
|
|
|
if (target.closest?.(".ai-evaluation-float") || target.closest?.(".task-toolbar-score")) return;
|
|
|
|
|
|
aiEvaluationFloatVisible.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function openScoreDialog() {
|
|
|
|
|
|
// 打开时重新拉取,保证教师刚评完的分/评语能及时看到。
|
|
|
|
|
|
loadScoreState();
|
|
|
|
|
|
scoreDialogVisible.value = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
const resolvedTaskKey = computed(() => resolveTrainingTaskKey(route, props.taskKey));
|
|
|
|
|
|
const resolvedMaterial = computed(() => ({
|
|
|
|
|
|
name: String(props.materialName || loadedMaterial.value.name || ""),
|
|
|
|
|
|
url: String(props.materialUrl || loadedMaterial.value.url || ""),
|
|
|
|
|
|
}));
|
|
|
|
|
|
const resolvedTrainingData = computed(() => ({
|
|
|
|
|
|
name: String(props.trainingDataName || loadedMaterial.value.trainingDataName || ""),
|
|
|
|
|
|
url: String(props.trainingDataUrl || loadedMaterial.value.trainingDataUrl || ""),
|
|
|
|
|
|
}));
|
|
|
|
|
|
const resolvedGuideManual = computed(() => ({
|
|
|
|
|
|
name: String(props.guideManualName || loadedMaterial.value.guideManualName || ""),
|
|
|
|
|
|
url: String(props.guideManualUrl || loadedMaterial.value.guideManualUrl || ""),
|
|
|
|
|
|
}));
|
|
|
|
|
|
const resolvedAiManual = computed(() => ({
|
|
|
|
|
|
name: String(props.aiManualName || loadedMaterial.value.aiManualName || ""),
|
|
|
|
|
|
url: String(props.aiManualUrl || loadedMaterial.value.aiManualUrl || ""),
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
loadTaskConfig();
|
|
|
|
|
|
document.addEventListener("mousedown", onDocMouseDownForAiFloat);
|
|
|
|
|
|
});
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
|
document.removeEventListener("mousedown", onDocMouseDownForAiFloat);
|
|
|
|
|
|
});
|
|
|
|
|
|
watch(resolvedTaskKey, loadTaskConfig);
|
|
|
|
|
|
|
|
|
|
|
|
async function loadTaskConfig() {
|
|
|
|
|
|
if (!resolvedTaskKey.value) return;
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await getTrainingTaskByKey(resolvedTaskKey.value);
|
|
|
|
|
|
const task = response?.data || response || {};
|
|
|
|
|
|
loadedTask.value = task;
|
|
|
|
|
|
loadedMaterial.value = {
|
|
|
|
|
|
name: String(props.materialName || task.materialName || ""),
|
|
|
|
|
|
url: String(props.materialUrl || task.materialUrl || ""),
|
|
|
|
|
|
trainingDataName: String(task.trainingDataName || ""),
|
|
|
|
|
|
trainingDataUrl: String(task.trainingDataUrl || ""),
|
|
|
|
|
|
guideManualName: String(task.guideManualName || ""),
|
|
|
|
|
|
guideManualUrl: String(task.guideManualUrl || ""),
|
|
|
|
|
|
aiManualName: String(task.aiManualName || ""),
|
|
|
|
|
|
aiManualUrl: String(task.aiManualUrl || "")
|
|
|
|
|
|
};
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// The material button keeps its unavailable state when a task has no configured case file.
|
|
|
|
|
|
loadedTask.value = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
loadScoreState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function exportCurrentTrainingOutcome() {
|
|
|
|
|
|
if (exporting.value) return;
|
|
|
|
|
|
exporting.value = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
let task = loadedTask.value;
|
|
|
|
|
|
if (!task?.taskName) {
|
|
|
|
|
|
const response = await getTrainingTaskByKey(resolvedTaskKey.value);
|
|
|
|
|
|
task = response?.data || response || null;
|
|
|
|
|
|
loadedTask.value = task;
|
|
|
|
|
|
}
|
|
|
|
|
|
let studentAnswer = null;
|
|
|
|
|
|
try {
|
|
|
|
|
|
const answerResponse = await getStudentTrainingAnswer(resolvedTaskKey.value);
|
|
|
|
|
|
studentAnswer = answerResponse?.data || null;
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// 当前页面的填写值仍可导出;已保存记录不可用时不阻塞学生下载任务说明。
|
|
|
|
|
|
}
|
|
|
|
|
|
await exportTrainingOutcomePdf({
|
|
|
|
|
|
...task,
|
|
|
|
|
|
stepDetails: collectTrainingOutcomeDetails(task, studentAnswer),
|
|
|
|
|
|
});
|
|
|
|
|
|
ElMessage.success("PDF 实训成果已开始下载");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("导出实训成果 PDF 失败", error);
|
|
|
|
|
|
ElMessage.error(error?.message || "PDF 导出失败,请稍后重试。");
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
exporting.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function triggerExistingAction(action) {
|
|
|
|
|
|
const directActions = {
|
|
|
|
|
|
submit: props.onSubmit,
|
|
|
|
|
|
reset: props.onReset,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (action === "save") {
|
|
|
|
|
|
saveProgress();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (directActions[action]) {
|
|
|
|
|
|
directActions[action]();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const labelPriority = {
|
|
|
|
|
|
submit: [[/提交任务/], [/完成实训/, /保存并完成/, /校验并完成/]],
|
|
|
|
|
|
reset: [[/重新实训/]],
|
|
|
|
|
|
export: [[/导出实训成果/]],
|
|
|
|
|
|
};
|
|
|
|
|
|
const buttons = getCurrentTaskActionButtons();
|
|
|
|
|
|
const target = labelPriority[action]
|
|
|
|
|
|
.map((matchers) => buttons.find((button) => matchers.some((matcher) => matcher.test(button.innerText || ""))))
|
|
|
|
|
|
.find(Boolean);
|
|
|
|
|
|
|
|
|
|
|
|
if (target) {
|
|
|
|
|
|
target.click();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fallbackActions = {
|
|
|
|
|
|
submit: saveLegacyTraining,
|
|
|
|
|
|
reset: resetLegacyTraining,
|
|
|
|
|
|
export: exportLegacyTraining,
|
|
|
|
|
|
};
|
|
|
|
|
|
fallbackActions[action]?.();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getCurrentTaskActionButtons() {
|
|
|
|
|
|
const shell = document.querySelector(".student-training-shell") || document;
|
|
|
|
|
|
const actionAreas = Array.from(shell.querySelectorAll(
|
|
|
|
|
|
".step-actions, .step-navigation, .footer-actions, .training-actions, .task-actions, .taskfooter, .training-step-area"
|
|
|
|
|
|
));
|
|
|
|
|
|
const candidates = actionAreas.length
|
|
|
|
|
|
? actionAreas.flatMap((area) => Array.from(area.querySelectorAll("button")))
|
|
|
|
|
|
: Array.from(shell.querySelectorAll("button"));
|
|
|
|
|
|
return Array.from(new Set(candidates))
|
|
|
|
|
|
.filter((button) => !button.closest(".training-task-toolbar") && isVisible(button) && !button.disabled);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isVisible(element) {
|
|
|
|
|
|
const style = window.getComputedStyle(element);
|
|
|
|
|
|
return style.display !== "none" && style.visibility !== "hidden" && element.getClientRects().length > 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getLegacyTrainingScope() {
|
|
|
|
|
|
return document.querySelector(".student-training-shell") || document.querySelector(".training-step-area") || document.body;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function collectLegacyFields() {
|
|
|
|
|
|
const scope = getLegacyTrainingScope();
|
|
|
|
|
|
return Array.from(scope.querySelectorAll("input, textarea, select"))
|
|
|
|
|
|
.filter((element) => !element.closest(".training-ai-sidebar") && !element.closest(".training-task-toolbar"))
|
|
|
|
|
|
.map((element, index) => ({
|
|
|
|
|
|
tag: element.tagName.toLowerCase(),
|
|
|
|
|
|
index,
|
|
|
|
|
|
type: element.type || element.tagName.toLowerCase(),
|
|
|
|
|
|
value: element.value ?? "",
|
|
|
|
|
|
checked: Boolean(element.checked),
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function saveProgress() {
|
|
|
|
|
|
if (savingProgress.value) return;
|
|
|
|
|
|
// 优先触发页面自身的保存逻辑(保留各页面的校验与状态文案)
|
|
|
|
|
|
const saveLabelPriority = [[/保存当前进度/], [/保存进度/], [/^保存$/], [/保存(?!成功|失败|中)/]];
|
|
|
|
|
|
const buttons = getCurrentTaskActionButtons();
|
|
|
|
|
|
const target = saveLabelPriority
|
|
|
|
|
|
.map((matchers) => buttons.find((button) => matchers.some((matcher) => matcher.test(button.innerText || ""))))
|
|
|
|
|
|
.find(Boolean);
|
|
|
|
|
|
if (target) {
|
|
|
|
|
|
savingProgress.value = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
target.click();
|
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
|
|
|
|
ElMessage.success("进度已保存");
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
savingProgress.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 页面没有保存按钮时保存表单快照(SAVE 不等于提交)
|
|
|
|
|
|
if (!resolvedTaskKey.value) {
|
|
|
|
|
|
ElMessage.warning("当前任务暂未配置,无法保存。");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
savingProgress.value = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 快照写入 dynamicStepAnswers 而不是 step1Answer:
|
|
|
|
|
|
* step1Answer 是新版页面自身的结构化答案(含知识自测 choiceAnswers),
|
|
|
|
|
|
* 用整页 DOM 快照覆盖会直接冲掉学生已保存的答题,导致学生端与教师端评阅都回显不出来。
|
|
|
|
|
|
*/
|
|
|
|
|
|
await saveStudentTrainingAnswer(resolvedTaskKey.value, {
|
|
|
|
|
|
saveAction: "SAVE",
|
|
|
|
|
|
currentStep: 1,
|
|
|
|
|
|
dynamicStepAnswers: JSON.stringify({
|
|
|
|
|
|
type: "legacy-training-snapshot-v3",
|
|
|
|
|
|
route: route.path,
|
|
|
|
|
|
savedAt: new Date().toISOString(),
|
|
|
|
|
|
fields: collectLegacyFields(),
|
|
|
|
|
|
}),
|
|
|
|
|
|
});
|
|
|
|
|
|
ElMessage.success("进度已保存");
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
ElMessage.error("保存失败,请稍后重试。");
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
savingProgress.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function saveLegacyTraining() {
|
|
|
|
|
|
if (!resolvedTaskKey.value) {
|
|
|
|
|
|
ElMessage.warning("当前任务暂未配置,无法提交。");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
await saveStudentTrainingAnswer(resolvedTaskKey.value, {
|
|
|
|
|
|
saveAction: "SUBMIT",
|
|
|
|
|
|
currentStep: 1,
|
|
|
|
|
|
/* 同上:快照落到 dynamicStepAnswers,避免覆盖 step1Answer 里的结构化答题 */
|
|
|
|
|
|
dynamicStepAnswers: JSON.stringify({
|
|
|
|
|
|
type: "legacy-training-snapshot-v3",
|
|
|
|
|
|
route: route.path,
|
|
|
|
|
|
savedAt: new Date().toISOString(),
|
|
|
|
|
|
fields: collectLegacyFields(),
|
|
|
|
|
|
}),
|
|
|
|
|
|
});
|
|
|
|
|
|
ElMessage.success("提交任务成功");
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
ElMessage.error("提交任务失败,请稍后重试。");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function resetLegacyTraining() {
|
|
|
|
|
|
if (!resolvedTaskKey.value) {
|
|
|
|
|
|
ElMessage.warning("当前任务暂未配置,无法重新实训。");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
await deleteStudentTrainingAnswer(resolvedTaskKey.value);
|
|
|
|
|
|
const scope = getLegacyTrainingScope();
|
|
|
|
|
|
Array.from(scope.querySelectorAll("input, textarea, select")).forEach((element) => {
|
|
|
|
|
|
if (element.closest(".training-ai-sidebar") || element.closest(".training-task-toolbar")) return;
|
|
|
|
|
|
if (element.type === "checkbox" || element.type === "radio") {
|
|
|
|
|
|
element.checked = false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
element.value = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
element.dispatchEvent(new Event("input", { bubbles: true }));
|
|
|
|
|
|
element.dispatchEvent(new Event("change", { bubbles: true }));
|
|
|
|
|
|
});
|
|
|
|
|
|
ElMessage.success("已清空全部实训步骤,可以重新开始。");
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
ElMessage.error("重新实训失败,请稍后重试。");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function exportLegacyTraining() {
|
|
|
|
|
|
const blob = new Blob([JSON.stringify(collectLegacyFields(), null, 2)], { type: "application/json;charset=utf-8" });
|
|
|
|
|
|
const link = document.createElement("a");
|
|
|
|
|
|
link.href = URL.createObjectURL(blob);
|
|
|
|
|
|
link.download = `${route.meta?.title || "实训"}-实训成果.json`;
|
|
|
|
|
|
document.body.appendChild(link);
|
|
|
|
|
|
link.click();
|
|
|
|
|
|
document.body.removeChild(link);
|
|
|
|
|
|
URL.revokeObjectURL(link.href);
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.training-task-toolbar { display:flex; flex-wrap:wrap; align-items:center; justify-content:flex-end; gap:var(--student-sp-2, 8px); }
|
|
|
|
|
|
.training-task-toolbar :deep(.material-actions) { margin-right:auto; }
|
|
|
|
|
|
.task-toolbar-button { min-height:var(--student-action-height, 34px); height:var(--student-action-height, 34px); padding:0 var(--student-sp-3, 14px); border-color:var(--student-panel-border); border-radius:var(--student-radius-sm, 6px); color:var(--student-accent); background:var(--student-card-bg); font-size:var(--student-fs-button); font-weight:600; }
|
|
|
|
|
|
.task-toolbar-button:hover { border-color:var(--student-accent-light); color:var(--student-accent-deep); background:var(--student-accent-soft); }
|
|
|
|
|
|
.task-toolbar-button--save { border-color:rgba(43,164,113,.45); color:var(--student-success); }
|
|
|
|
|
|
.task-toolbar-button--save:hover { border-color:var(--student-success); color:#1f8f62; background:#f0fbf6; }
|
|
|
|
|
|
.task-toolbar-button--submit { border-color:var(--student-accent); color:#fff; background:var(--student-accent); }
|
|
|
|
|
|
.task-toolbar-button--submit:hover { border-color:var(--student-accent-deep); color:#fff; background:var(--student-accent-deep); }
|
|
|
|
|
|
@media (max-width:768px) { .training-task-toolbar { justify-content:stretch; } .training-task-toolbar > * { flex:1 1 auto; } }
|
|
|
|
|
|
|
|
|
|
|
|
/* 成绩徽标:琥珀色,区别于蓝色系工具栏按钮 */
|
|
|
|
|
|
.task-toolbar-score {
|
|
|
|
|
|
display:inline-flex; align-items:center; gap:var(--student-sp-1, 4px); height:var(--student-action-height, 34px); padding:0 var(--student-sp-3, 14px);
|
|
|
|
|
|
border-radius:var(--student-radius-sm, 6px); background:var(--student-accent-soft);
|
|
|
|
|
|
border:1px solid var(--student-accent-light); color:var(--student-accent-deep); font-weight:700; font-size:var(--student-fs-data); line-height:1;
|
|
|
|
|
|
white-space:nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
.task-toolbar-score small { font-size: var(--student-fs-body); font-weight:600; }
|
|
|
|
|
|
|
|
|
|
|
|
/* 成绩弹窗 */
|
|
|
|
|
|
.task-score-body { display:flex; flex-direction:column; gap:var(--student-sp-4, 16px); }
|
|
|
|
|
|
.task-score-cards { display:flex; gap:var(--student-sp-3, 12px); }
|
|
|
|
|
|
.task-score-card { flex:1; border-radius:var(--student-radius-sm, 6px); padding:var(--student-sp-3, 12px) var(--student-sp-4, 16px); border:1px solid var(--student-panel-border); background:var(--student-panel-bg); }
|
|
|
|
|
|
.task-score-card--teacher { background:var(--student-accent-soft); border-color:var(--student-accent-light); }
|
|
|
|
|
|
.task-score-card--ai { background:#f0fbf6; border-color:var(--student-success); }
|
|
|
|
|
|
.task-score-card__label { margin:0 0 var(--student-sp-1, 4px); font-size:var(--student-fs-caption); color:var(--student-text-secondary); }
|
|
|
|
|
|
.task-score-card__value { margin:0; font-size:28px; font-weight:700; line-height:1.2; font-family:var(--student-font-data); }
|
|
|
|
|
|
.task-score-card--teacher .task-score-card__value { color:var(--student-accent-deep); }
|
|
|
|
|
|
.task-score-card--ai .task-score-card__value { color:var(--student-success); }
|
|
|
|
|
|
.task-score-card__value small { font-size:var(--student-fs-caption); font-weight:500; margin-left:2px; color:var(--student-text-secondary); }
|
|
|
|
|
|
.task-score-card__time { margin:var(--student-sp-2, 8px) 0 0; font-size:var(--student-fs-caption); color:var(--student-text-secondary); }
|
|
|
|
|
|
.task-score-block { border-radius:var(--student-radius-sm, 6px); border:1px solid var(--student-panel-border); background:var(--student-panel-bg); padding:var(--student-sp-3, 12px) var(--student-sp-4, 16px); }
|
|
|
|
|
|
.task-score-block__label { margin:0 0 var(--student-sp-1, 4px); font-size:var(--student-fs-caption); font-weight:600; color:var(--student-text-secondary); }
|
|
|
|
|
|
.task-score-block__text { margin:0; font-size:var(--student-fs-body); line-height:1.7; color:var(--student-text); white-space:pre-wrap; word-break:break-word; }
|
|
|
|
|
|
.reference-answer-frame { display:block; width:100%; height:70vh; border:1px solid var(--student-panel-border); border-radius:var(--student-radius-sm, 6px); background:var(--student-card-bg); }
|
|
|
|
|
|
@media (max-width:640px) { .task-score-cards { flex-direction:column; } }
|
|
|
|
|
|
|
|
|
|
|
|
/* AI 评分结果悬浮卡片(悬浮在页面上,非弹窗) */
|
|
|
|
|
|
.ai-evaluation-float { position:fixed; top:132px; right:28px; z-index:1800; width:380px; max-height:calc(100vh - 200px); overflow-y:auto; padding:16px; background:var(--student-card-bg, #ffffff); border:1px solid var(--student-panel-border); border-radius:12px; box-shadow:0 12px 32px rgba(15,23,42,.18); }
|
|
|
|
|
|
.ai-evaluation-float__header { display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; }
|
|
|
|
|
|
.ai-evaluation-float__title { font-size:var(--student-fs-body, 14px); font-weight:700; color:var(--student-text, #1f2937); }
|
|
|
|
|
|
.ai-evaluation-float__close { display:inline-flex; align-items:center; justify-content:center; padding:4px; color:var(--student-text-secondary); background:transparent; border:0; border-radius:6px; cursor:pointer; }
|
|
|
|
|
|
.ai-evaluation-float__close:hover { color:var(--student-text, #1f2937); background:var(--student-panel-bg, #f3f4f6); }
|
|
|
|
|
|
.ai-evaluation-float__summary { display:flex; align-items:flex-end; justify-content:space-between; padding:12px 14px; border:1px solid var(--student-accent-light, rgba(37,99,235,.15)); border-left:4px solid var(--student-accent, #2563eb); border-radius:8px; background:var(--student-accent-soft, #eff6ff); }
|
|
|
|
|
|
.ai-evaluation-float__label { margin:0 0 4px; font-size:var(--student-fs-caption, 12px); font-weight:600; color:var(--student-text-secondary); }
|
|
|
|
|
|
.ai-evaluation-float__score { font-size:26px; font-weight:700; line-height:1.1; color:var(--student-accent-deep, #2563eb); font-family:var(--student-font-data); }
|
|
|
|
|
|
.ai-evaluation-float__score small { font-size:var(--student-fs-caption, 12px); font-weight:500; margin-left:2px; color:var(--student-text-secondary); }
|
|
|
|
|
|
.ai-evaluation-float__comment { margin:10px 0 0; font-size:var(--student-fs-body, 14px); line-height:1.7; color:var(--student-text, #1f2937); }
|
|
|
|
|
|
.ai-evaluation-float__criterion { margin-top:12px; padding:10px 12px; border:1px solid var(--student-panel-border); border-radius:8px; background:var(--student-panel-bg); }
|
|
|
|
|
|
.ai-evaluation-float__criterion-head { display:flex; align-items:center; justify-content:space-between; gap:8px; margin:0; font-size:var(--student-fs-body, 14px); font-weight:600; color:var(--student-text, #1f2937); }
|
|
|
|
|
|
.ai-evaluation-float__criterion-head b { color:var(--student-success, #16a34a); font-weight:700; }
|
|
|
|
|
|
.ai-evaluation-float__criterion-head i { font-style:normal; font-weight:500; color:var(--student-text-secondary); }
|
|
|
|
|
|
.ai-evaluation-float__text { margin:6px 0 0; font-size:var(--student-fs-body-sm, 13px); line-height:1.7; color:var(--student-text-secondary, #4b5563); }
|
|
|
|
|
|
.ai-evaluation-float__improvements { margin:6px 0 0; padding-left:18px; }
|
|
|
|
|
|
.ai-evaluation-float__improvements li { margin-bottom:4px; font-size:var(--student-fs-body-sm, 13px); line-height:1.6; color:var(--student-text, #1f2937); }
|
|
|
|
|
|
.ai-eval-pop-enter-active, .ai-eval-pop-leave-active { transition:opacity .18s ease, transform .18s ease; }
|
|
|
|
|
|
.ai-eval-pop-enter-from, .ai-eval-pop-leave-to { opacity:0; transform:translateY(-6px); }
|
|
|
|
|
|
</style>
|