feat(review): improve reference answer dialog controls and PDF sidebar

dev-QQq
chenyuan 1 month ago
parent e621f212f3
commit 3f0661a77d

@ -337,7 +337,38 @@
</div>
</el-dialog>
<el-dialog v-model="referenceAnswerDialogVisible" title="参考答案" width="900px" append-to-body class="reference-answer-dialog">
<el-dialog
v-model="referenceAnswerDialogVisible"
title="参考答案"
width="min(1000px, calc(100vw - 32px))"
top="5vh"
append-to-body
draggable
destroy-on-close
:fullscreen="referenceAnswerMaximized"
:show-close="false"
class="reference-answer-dialog"
@closed="referenceAnswerMaximized = false"
>
<template #header="{ close, titleId, titleClass }">
<div class="reference-answer-heading">
<div class="reference-answer-heading__title">
<h2 :id="titleId" :class="titleClass">参考答案</h2>
<span class="reference-answer-heading__hint">{{ referenceAnswerMaximized ? '还原窗口后可移动和调整大小' : '拖动标题栏移动,拖动右下角调整大小' }}</span>
</div>
<div class="reference-answer-heading__actions" @mousedown.stop>
<button type="button" class="reference-answer-window-button"
:aria-label="referenceAnswerMaximized ? '还原窗口' : '最大化窗口'"
:title="referenceAnswerMaximized ? '还原窗口' : '最大化窗口'"
:aria-pressed="referenceAnswerMaximized" @click="referenceAnswerMaximized = !referenceAnswerMaximized">
<el-icon><CopyDocument v-if="referenceAnswerMaximized" /><FullScreen v-else /></el-icon>
</button>
<button type="button" class="reference-answer-window-button" aria-label="关闭参考答案" title="关闭" @click="close">
<el-icon><Close /></el-icon>
</button>
</div>
</div>
</template>
<iframe v-if="referenceAnswerSrc" :src="referenceAnswerSrc" class="reference-answer-frame" title="参考答案在线预览" />
<el-empty v-else description="暂无可预览的参考答案" />
</el-dialog>
@ -346,7 +377,7 @@
<script setup>
import { ElMessage } from "element-plus";
import { EditPen, DocumentChecked, Close, CircleCheck, Loading, DocumentCopy, CirclePlus, TrendCharts } from "@element-plus/icons-vue";
import { EditPen, DocumentChecked, Close, CircleCheck, Loading, DocumentCopy, CopyDocument, FullScreen, CirclePlus, TrendCharts } from "@element-plus/icons-vue";
import * as teacherApi from "@/api/teacher";
import { listClassTrainingTasks } from "@/api/trainingTask";
import useUserStore from "@/store/modules/user";
@ -413,6 +444,7 @@ const batchAiScoreProgress = ref({
const aiAssistEvalDialogVisible = ref(false);
const aiAssistEvaluating = ref(false);
const referenceAnswerDialogVisible = ref(false);
const referenceAnswerMaximized = ref(false);
const referenceAnswerSrc = ref("");
let referenceAnswerObjectUrl = "";
const pagination = ref({
@ -672,8 +704,8 @@ function onViewReferenceAnswer() {
teacherApi.previewTaskReferenceAnswer({ classId: filters.value.classId, taskId: filters.value.taskId }).then((response) => {
const blob = response instanceof Blob ? response : new Blob([response], { type: "application/pdf" });
referenceAnswerObjectUrl = URL.createObjectURL(blob);
// 关闭浏览器 PDF 查看器左侧缩略图导航栏,只保留正文预览。
referenceAnswerSrc.value = `${referenceAnswerObjectUrl}#pagemode=none`;
// Chromium 使用 navpanes 控制侧栏;保留工具栏,pagemode 兼容其他查看器。
referenceAnswerSrc.value = `${referenceAnswerObjectUrl}#navpanes=0&toolbar=1&pagemode=none`;
referenceAnswerDialogVisible.value = true;
}).catch((error) => {
// 404 = 任务未上传参考答案;其余才是预览流程异常
@ -1763,28 +1795,100 @@ function applyAiDetail(data) {
}
}
/* 参考答案弹窗与 PDF 预览 */
:deep(.reference-answer-dialog) {
</style>
<!-- Dialog is teleported to body; scope these styles with its unique class. -->
<style lang="scss">
.el-dialog.reference-answer-dialog {
display: flex;
flex-direction: column;
height: 80vh;
min-width: min(560px, calc(100vw - 32px));
min-height: min(320px, calc(100vh - 32px));
max-width: calc(100vw - 32px);
max-height: calc(100vh - 32px);
margin-bottom: 0;
overflow: hidden;
resize: both;
border-radius: var(--r-card, 12px);
.el-dialog__header {
flex-shrink: 0;
margin: 0;
padding: var(--sp-4);
border-bottom: 1px solid var(--border-color);
padding: 12px 16px;
user-select: none;
border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.el-dialog__body {
padding: var(--sp-4);
display: flex;
flex: 1;
min-height: 0;
padding: 12px;
overflow: hidden;
background: var(--surface-muted, #fafbfc);
}
}
.reference-answer-frame {
display: block;
width: 100%;
height: 64vh;
border: 1px solid var(--border-color);
border-radius: var(--r-sm, 6px);
background: var(--surface-card, #ffffff);
&.is-fullscreen {
width: 100vw !important;
height: 100vh !important;
max-width: none;
max-height: none;
margin: 0;
resize: none;
border-radius: 0;
}
.reference-answer-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.reference-answer-heading__title {
min-width: 0;
h2 { margin: 0; font-size: 18px; line-height: 1.5; }
}
.reference-answer-heading__hint {
color: var(--text-color-secondary, #6b7280);
font-size: 12px;
line-height: 1.5;
user-select: none;
}
.reference-answer-heading__actions { display: flex; gap: 6px; flex-shrink: 0; }
.reference-answer-window-button {
display: inline-flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
padding: 0;
border: 0;
border-radius: 6px;
background: transparent;
color: var(--text-color-secondary, #606266);
font-size: 18px;
cursor: pointer;
&:hover { color: var(--el-color-primary); background: var(--el-color-primary-light-9); }
&:focus-visible { outline: 2px solid var(--el-color-primary); outline-offset: 2px; }
}
.reference-answer-frame {
display: block;
width: 100%;
height: 100%;
min-height: 0;
border: 1px solid var(--border-color, #e5e7eb);
border-radius: var(--r-sm, 6px);
background: var(--surface-card, #ffffff);
}
@media (max-width: 600px) {
.reference-answer-heading__hint { display: none; }
}
}
</style>

@ -70,7 +70,12 @@ assert.match(reviewPanel, /prop="name" label="姓名" width="74"/);
assert.match(reviewPanel, /prop="username" label="学号" width="88"/);
assert.match(reviewPanel, /label="AI评分" width="66"/);
assert.match(reviewPanel, /label="老师评分" width="94"/);
assert.match(reviewPanel, /referenceAnswerSrc\.value = `\$\{referenceAnswerObjectUrl\}#pagemode=none`/);
const referencePreviewFragment = reviewPanel.match(/referenceAnswerSrc\.value = `\$\{referenceAnswerObjectUrl\}(#[^`]+)`/)?.[1];
assert.ok(referencePreviewFragment, "参考答案应配置 PDF 预览参数");
const referencePreviewParams = new URLSearchParams(referencePreviewFragment.slice(1));
assert.equal(referencePreviewParams.get("navpanes"), "0", "参考答案应默认隐藏缩略图侧栏");
assert.equal(referencePreviewParams.get("toolbar"), "1", "参考答案应保留缩放、翻页等工具");
assert.equal(referencePreviewParams.get("pagemode"), "none", "保留其他 PDF 查看器的无侧栏参数");
assert.doesNotMatch(reviewPanel, /task-review__student-preview\s*\{[^}]*background:/, "嵌入框不得覆盖学生页面底色");
assert.doesNotMatch(reviewPanel, /<el-collapse[\s\S]*?formatAnswer/);

Loading…
Cancel
Save