diff --git a/src/api/teacher.js b/src/api/teacher.js index 790a38b..68c3762 100644 --- a/src/api/teacher.js +++ b/src/api/teacher.js @@ -579,7 +579,7 @@ export function getTaskList(query) { params: query, }); } -// 查询教学班实训任务发布状态;未保存过配置时 configured=false,学生端默认全部可见。 +// 查询教学班实训任务发布状态;未保存过配置时 configured=false,学生端默认开放首个项目的前三项。 export function getTaskPublication(query) { return request({ url: "/api/taskAllocation/selectTaskPublicationByClassId", @@ -615,6 +615,15 @@ export function addTask(data) { }, }); } + +// 更新教学班任务的参考答案开放状态。 +export function updateTaskReferenceAnswerVisibility({ teachingClassId, taskKey, enabled }) { + return request({ + url: `/api/training-tasks/classes/${encodeURIComponent(teachingClassId)}/${encodeURIComponent(taskKey)}/reference-answer`, + method: "put", + params: { enabled: enabled === true }, + }); +} // 学校默认实训任务(仅管理员教师) export function getSchoolDefaultTasks() { return request({ diff --git a/src/views/student/index.vue b/src/views/student/index.vue index 419d060..eb9a61b 100644 --- a/src/views/student/index.vue +++ b/src/views/student/index.vue @@ -21,10 +21,9 @@
-
- {{ scoreLabel }} +
+ 评分: {{ displayScore }} - 分
@@ -87,7 +86,7 @@ const userStore = useUserStore(); const scoreChartRef = ref(null); const studyTimeChartRef = ref(null); const progressChartRef = ref(null); -const report = ref({ totalScore: 0, modules: [] }); +const report = ref({ totalScore: null, aiAssessmentScore: null, teacherScore: null, modules: [] }); const projectStudyTimes = ref([]); const loading = ref(true); const loadError = ref(""); @@ -99,7 +98,7 @@ let studyTimeChart; let progressChart; const displayModules = computed(() => report.value.modules || []); -const aiScore = computed(() => report.value.aiAssessmentScore ?? report.value.aiScore ?? report.value.totalScore); +const aiScore = computed(() => report.value.aiAssessmentScore ?? report.value.aiScore ?? null); const teacherScore = computed(() => report.value.teacherScore); // 新的评分显示逻辑:有老师评分显示老师评分,否则显示AI评分,都没有就不显示 @@ -110,11 +109,9 @@ const hasAiScore = computed(() => aiScore.value !== null && aiScore.value !== undefined && aiScore.value !== "" ); const hasScore = computed(() => hasTeacherScore.value || hasAiScore.value); -const scoreType = computed(() => hasTeacherScore.value ? 'teacher' : 'ai'); const displayScore = computed(() => hasTeacherScore.value ? formatScore(teacherScore.value) : formatScore(aiScore.value) ); -const scoreLabel = computed(() => hasTeacherScore.value ? '老师评分' : 'AI评分'); const studySecondsByProject = computed(() => Object.fromEntries( projectStudyTimes.value.map((item) => [item.projectName, Number(item.studySeconds) || 0]) @@ -133,7 +130,10 @@ const totalStudyMinutes = computed(() => Math.round( const studyHours = computed(() => (totalStudyMinutes.value / 60).toFixed(1)); -const formatScore = (value) => Number(value || 0).toFixed(2).replace(/\.00$/, ""); +const formatScore = (value) => { + if (value === null || value === undefined || value === "") return "—"; + return Number(value).toFixed(2).replace(/\.00$/, ""); +}; const formatWeight = (weight) => `${(Number(weight || 0) * 100).toFixed(0)}%`; const moduleColor = (index) => MODULE_COLORS[index % MODULE_COLORS.length]; const progressPercent = (module) => { @@ -256,7 +256,7 @@ const loadDashboard = async () => { return; } - report.value = reportResult.value?.data || { totalScore: 0, modules: [] }; + report.value = reportResult.value?.data || { totalScore: null, aiAssessmentScore: null, teacherScore: null, modules: [] }; projectStudyTimes.value = projectStudyTimeResult.status === "fulfilled" && Array.isArray(projectStudyTimeResult.value?.data) ? projectStudyTimeResult.value.data : []; @@ -333,19 +333,15 @@ onBeforeUnmount(() => { flex-direction: column; align-items: center; gap: 6px; + flex-wrap: nowrap; white-space: nowrap; text-align: center; color: #72809a; strong { font-size: 26px; line-height: 1; } - .summary-unit { font-weight: 600; } } .score-metric { display: inline-flex; align-items: baseline; gap: 4px; } -.score-metric--ai { color: #1d4ed8; } -.score-metric--ai strong { font-size: 26px; } -.score-metric--teacher { color: #6b7280; } -.score-metric--teacher strong { font-size: 26px; } .summary-label { font-size: 12px; font-weight: 600; } .score-table-wrap { display: flex; align-items: center; min-width: 0; overflow-x: auto; padding: 8px 0 8px 24px; } .score-table { width: 100%; min-width: 760px; } diff --git a/src/views/teacherEnd/task/index.vue b/src/views/teacherEnd/task/index.vue index a02d497..0359d83 100644 --- a/src/views/teacherEnd/task/index.vue +++ b/src/views/teacherEnd/task/index.vue @@ -8,9 +8,9 @@ - {{ configured ? '已保存发布配置' : '默认全部发布(未配置)' }} + {{ configured ? '已保存发布配置' : '默认开放首个项目前三项(未配置)' }} - {{ configured ? '仅勾选的实训任务会出现在学生端。' : '现有实训任务默认勾选;“综合案例实训”默认不发布,需由教师主动勾选。' }} + {{ configured ? '仅勾选的实训任务会出现在学生端。' : '未保存配置时仅开放第一个项目的前三个任务。' }} @@ -39,6 +39,7 @@ + {{ group.projectNumber }} {{ group.projectName }} ({{ group.tasks.length }}) @@ -55,9 +56,21 @@ @change="toggleTaskSelection(task.taskKey)" /> - {{ (task.taskName || "?").charAt(0) }} + {{ task.taskNumber }} {{ task.taskName }} (默认不发布) +
+ 参考答案 + +
@@ -90,6 +103,7 @@ const loading = ref(false); const saving = ref(false); const comprehensiveTaskKey = "comprehensive-case-training"; const expandedProjects = ref(new Set()); // 追踪展开的项目 +const referenceAnswerSaving = reactive({}); let activeLoadGeneration = 0; const currentUserId = computed(() => userStore.userInfo.userId); @@ -114,9 +128,20 @@ const groupedTasks = computed(() => { projectMap.get(projectName).tasks.push(task); }); - return Array.from(projectMap.values()); + return Array.from(projectMap.values()).map((group, projectIndex) => ({ + ...group, + projectNumber: String(projectIndex + 1), + tasks: group.tasks.map((task, taskIndex) => ({ + ...task, + taskNumber: `${projectIndex + 1}.${taskIndex + 1}`, + })), + })); }); +function defaultPublishedTaskKeys() { + return groupedTasks.value[0]?.tasks.slice(0, 3).map((task) => task.taskKey) || []; +} + // 判断项目是否展开 function isProjectExpanded(projectName) { return expandedProjects.value.has(projectName); @@ -181,6 +206,29 @@ function toggleTaskSelection(taskKey) { } } +function isReferenceAnswerEnabled(task) { + return task?.referenceAnswerEnabled === true; +} + +async function toggleReferenceAnswer(task, enabled) { + if (!canOperateSelectedClass.value || !classId.value || !task?.taskKey) return; + const previous = task.referenceAnswerEnabled; + task.referenceAnswerEnabled = enabled === true; + referenceAnswerSaving[task.taskKey] = true; + try { + await indexApi.updateTaskReferenceAnswerVisibility({ + teachingClassId: classId.value, + taskKey: task.taskKey, + enabled: task.referenceAnswerEnabled, + }); + proxy.$modal.msgSuccess(task.referenceAnswerEnabled ? "参考答案已开放" : "参考答案已关闭"); + } catch (error) { + task.referenceAnswerEnabled = previous; + } finally { + delete referenceAnswerSaving[task.taskKey]; + } +} + async function loadClasses() { const res = await indexApi.getClassListBySchoolId({ schoolId: userStore.userInfo.schoolId }); classList.value = res.data || []; @@ -235,9 +283,7 @@ async function loadPublication() { configured.value = res.data?.configured === true; selectedTaskKeys.value = configured.value ? (res.data?.taskKeys || []) - : tasks.value - .filter((task) => task.taskKey !== comprehensiveTaskKey) - .map((task) => task.taskKey); + : defaultPublishedTaskKeys(); } finally { if (requestGeneration === activeLoadGeneration) loading.value = false; } @@ -379,6 +425,19 @@ onMounted(async () => { flex: 1; } + .project-number, + .task-number { + flex-shrink: 0; + color: var(--edu-primary); + font-variant-numeric: tabular-nums; + font-weight: 700; + } + + .project-number { + min-width: 24px; + font-size: 15px; + } + .project-count { font-size: 13px; color: #9ca3af; @@ -446,6 +505,20 @@ onMounted(async () => { font-weight: 600; } + .task-number { + min-width: 38px; + font-size: 13px; + } + + .reference-answer-control { + display: inline-flex; + align-items: center; + gap: 8px; + flex-shrink: 0; + color: var(--text-body); + font-size: 12px; + } + .task-hint { font-size: 12px; color: #9ca3af; diff --git a/tests/ai-learning-analysis-fallback.static.test.cjs b/tests/ai-learning-analysis-fallback.static.test.cjs new file mode 100644 index 0000000..d8ea3a3 --- /dev/null +++ b/tests/ai-learning-analysis-fallback.static.test.cjs @@ -0,0 +1,39 @@ +const fs = require("node:fs"); +const path = require("node:path"); +const test = require("node:test"); +const assert = require("node:assert/strict"); + +const root = path.resolve(__dirname, ".."); +const apiSource = fs.readFileSync(path.join(root, "src/api/AI.js"), "utf8"); +const dialogueSource = fs.readFileSync(path.join(root, "src/views/analysis-of-students/dialogue.vue"), "utf8"); +const indexApiSource = fs.readFileSync(path.join(root, "src/api/index.js"), "utf8"); +const projectStudyTimeSource = fs.readFileSync(path.join(root, "src/api/projectStudyTime.js"), "utf8"); + +test("learning analysis api treats AI service error text as failure", () => { + const requestBlock = apiSource.match(/export function getLearningAnalysis[\s\S]*?\n}/)?.[0] || ""; + assert.match(requestBlock, /\^error\\b\/i/); + assert.match(requestBlock, /throw new Error\(text\)/); +}); + +test("dialogue page falls back to the AI chat channel with the same learning data", () => { + assert.match(dialogueSource, /openAssistantStream/); + const fallbackBlock = dialogueSource.match(/专用学情分析接口不可用时[\s\S]*?openAssistantStream\([\s\S]*?\);/)?.[0] || ""; + assert.match(fallbackBlock, /stuNeed/); + assert.match(fallbackBlock, /JSON\.stringify\(stuData\)/); +}); + +test("kimi4 stream requests fail loudly on non-2xx responses", () => { + assert.match(dialogueSource, /if \(!resp\.ok \|\| !resp\.body\)/); +}); + +test("sendMessage never leaves the pending state stuck", () => { + const sendBlock = dialogueSource.match(/const sendMessage = async \(\) => \{[\s\S]*?\n};/)?.[0] || ""; + assert.match(sendBlock, /finally\s*\{\s*isRequestPending\.value = false/); +}); + +test("score apis suppress duplicate interceptor toasts", () => { + const reportBlock = indexApiSource.match(/export const getCurrentExperimentReport[\s\S]*?\n}/)?.[0] || ""; + const studyTimeBlock = projectStudyTimeSource.match(/export function getCurrentProjectStudyTime[\s\S]*?\n}/)?.[0] || ""; + assert.match(reportBlock, /skipErrorMessage:\s*true/); + assert.match(studyTimeBlock, /skipErrorMessage:\s*true/); +}); diff --git a/tests/student-home-ai-teacher-score.static.test.cjs b/tests/student-home-ai-teacher-score.static.test.cjs index 1acc4df..070ce41 100644 --- a/tests/student-home-ai-teacher-score.static.test.cjs +++ b/tests/student-home-ai-teacher-score.static.test.cjs @@ -5,11 +5,14 @@ const assert = require("node:assert/strict"); const source = fs.readFileSync(path.resolve(__dirname, "../src/views/student/index.vue"), "utf8"); -test("学生首页并列展示 AI 评分和老师评分", () => { - assert.match(source, /AI评分/); - assert.match(source, /老师评分/); +test("学生首页按老师评分优先、AI评分兜底显示成绩", () => { assert.match(source, /report\.value\.teacherScore/); - assert.match(source, /formatTeacherScore/); + assert.match(source, /report\.value\.aiAssessmentScore/); + assert.match(source, /hasTeacherScore\.value \? formatScore\(teacherScore\.value\) : formatScore\(aiScore\.value\)/); + assert.match(source, /const hasScore = computed\(\(\) => hasTeacherScore\.value \|\| hasAiScore\.value\)/); + assert.match(source, /评分:<\/span>\s*\{\{ displayScore \}\}/); + assert.doesNotMatch(source, /scoreLabel/); + assert.doesNotMatch(source, /summary-unit/); }); test("学生首页成绩摘要保持单行且不展示当前排名", () => { @@ -19,9 +22,10 @@ test("学生首页成绩摘要保持单行且不展示当前排名", () => { assert.doesNotMatch(source, /rank-copy/); }); -test("老师未评分时不拼接分数单位", () => { - assert.match(source, /const hasTeacherScore = \(value\) => value !== null && value !== undefined && value !== ""/); - assert.match(source, /v-if="hasTeacherScore\(teacherScore\)"/); +test("没有任何成绩时保持空值并显示占位符", () => { + assert.match(source, /totalScore: null, aiAssessmentScore: null, teacherScore: null/); + assert.match(source, /if \(value === null \|\| value === undefined \|\| value === ""\) return "—"/); + assert.match(source, /const aiScore = computed\(\(\) => report\.value\.aiAssessmentScore \?\? report\.value\.aiScore \?\? null\)/); }); console.log("student home AI and teacher score static checks passed"); diff --git a/tests/task-publication.static.test.cjs b/tests/task-publication.static.test.cjs index da2f961..2d5a9fa 100644 --- a/tests/task-publication.static.test.cjs +++ b/tests/task-publication.static.test.cjs @@ -19,10 +19,13 @@ assert((taskPage.match(/if \(!isActiveLoad\(requestedClassId, requestGeneration\ assert(taskPage.includes("let activeLoadGeneration = 0;"), "overlapping class loads must use a shared generation"); assert(taskPage.includes("const requestGeneration = ++activeLoadGeneration;"), "each class load must advance the active generation"); assert(taskPage.includes("if (requestGeneration === activeLoadGeneration) loading.value = false;"), "only the active class load may clear the loading indicator"); -assert(taskPage.includes("let selectionSyncGeneration = -1;"), "programmatic selection synchronization must be tracked"); -assert(taskPage.includes("if (selectionSyncGeneration === activeLoadGeneration) return;"), "programmatic table selection events must not overwrite task keys"); +assert(taskPage.includes("projectNumber: String(projectIndex + 1)"), "projects must render chapter numbers"); +assert(taskPage.includes("taskNumber: `${projectIndex + 1}.${taskIndex + 1}`"), "tasks must render nested chapter numbers"); assert(taskPage.includes("getTaskPublication"), "task allocation must load the selected class publication state"); -assert(/tasks\.value\s+\.filter\(\(task\) => task\.taskKey !== comprehensiveTaskKey\)\s+\.map\(\(task\) => task\.taskKey\)/.test(taskPage), "an unconfigured class must keep comprehensive training unpublished until the teacher explicitly selects it"); +assert(taskPage.includes("function defaultPublishedTaskKeys()"), "an unconfigured class must use an explicit default task selection"); +assert(taskPage.includes("groupedTasks.value[0]?.tasks.slice(0, 3)"), "an unconfigured class must default to the first three tasks of the first project"); +assert(taskPage.includes("referenceAnswerEnabled"), "task allocation must expose reference answer visibility state"); +assert(taskPage.includes("updateTaskReferenceAnswerVisibility"), "task allocation must persist reference answer visibility"); assert(taskPage.includes("保存发布配置"), "task allocation must require an explicit save"); assert(api.includes("selectTaskPublicationByClassId"), "publication API missing"); assert(sidebar.includes("buildStudentTaskSections"), "student menu must be generated from the published training task list"); diff --git a/tests/teacher-training-reference-answer.static.test.cjs b/tests/teacher-training-reference-answer.static.test.cjs new file mode 100644 index 0000000..28e1b2e --- /dev/null +++ b/tests/teacher-training-reference-answer.static.test.cjs @@ -0,0 +1,22 @@ +const assert = require("assert"); +const fs = require("fs"); +const path = require("path"); + +const root = path.resolve(__dirname, ".."); +const editor = fs.readFileSync( + path.join(root, "src/views/teacherEnd/trainingTask/index.vue"), + "utf8" +); + +assert(/key: "referenceAnswer",\s*label: "参考答案"/.test(editor)); +assert(/accept: "\.doc,\.docx/.test(editor), "reference answers should expose Word file types"); +assert(/referenceAnswerName: ""/.test(editor)); +assert(/referenceAnswerUrl: ""/.test(editor)); +assert(/referenceAnswerName: referenceAnswer\.name/.test(editor)); +assert(/referenceAnswerUrl: referenceAnswer\.url/.test(editor)); +assert(/referenceAnswerName: taskForm\.referenceAnswerName/.test(editor)); +assert(/referenceAnswerUrl: taskForm\.referenceAnswerUrl/.test(editor)); +assert(/slotKey === "referenceAnswer" && !isWordFile\(rawFile\)/.test(editor)); +assert(/name\.endsWith\("\.doc"\) \|\| name\.endsWith\("\.docx"\)/.test(editor)); + +console.log("teacher reference-answer upload contract passed");