diff --git a/src/views/assessment/categoryOptimizationExcel.js b/src/views/assessment/categoryOptimizationExcel.js
index 7d12b5f..3e00423 100644
--- a/src/views/assessment/categoryOptimizationExcel.js
+++ b/src/views/assessment/categoryOptimizationExcel.js
@@ -6,7 +6,7 @@ export const CATEGORY_EXCEL_COLUMNS = [
{ key: "inventoryCapital", label: "库存资金占用(万元)" },
{ key: "capitalOccupancyRate", label: "资金占用率(%)" },
{ key: "sellThroughRate", label: "近30天动销率(%)" },
- { key: "grossMargin", label: "毛利率" },
+ { key: "grossMargin", label: "毛利率(%)" },
];
const boundedRates = new Set(["capitalOccupancyRate", "sellThroughRate"]);
diff --git a/src/views/assessment/optimization.vue b/src/views/assessment/optimization.vue
index e253d1c..ca5d6c5 100644
--- a/src/views/assessment/optimization.vue
+++ b/src/views/assessment/optimization.vue
@@ -77,7 +77,7 @@
库存资金占用(万元) |
资金占用率(%) |
近30天动销率(%) |
- 毛利率 |
+ 毛利率(%) |
diff --git a/src/views/schoolAdmin/trainingTask/index.vue b/src/views/schoolAdmin/trainingTask/index.vue
index 5fd9d26..6548f7f 100644
--- a/src/views/schoolAdmin/trainingTask/index.vue
+++ b/src/views/schoolAdmin/trainingTask/index.vue
@@ -429,7 +429,7 @@ const materialSlots = [
{ key: "trainingData", label: "案例数据" },
{ key: "guideManual", label: "实训指导手册" },
{ key: "aiManual", label: "AI辅助指导手册" },
- { key: "referenceAnswer", label: "参考答案", accept: ".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
+ { key: "referenceAnswer", label: "参考答案", accept: ".pdf,application/pdf" },
];
const tasks = ref([]);
const dialogVisible = ref(false);
@@ -692,12 +692,13 @@ async function handleImportChange(file) {
async function handleMaterialChange(slotKey, file) {
const rawFile = file?.raw;
if (!rawFile) return;
- if (slotKey === "referenceAnswer" && !isWordFile(rawFile)) {
- proxy?.$modal?.msgError?.("参考答案仅支持 Word 文件(.doc 或 .docx)");
+ if (slotKey === "referenceAnswer" && !isPdfFile(rawFile)) {
+ proxy?.$modal?.msgError?.("参考答案仅支持 PDF 文件(.pdf)");
return;
}
const data = new FormData();
data.append("file", rawFile);
+ data.append("materialType", slotKey);
uploadingField.value = slotKey;
try {
const res = await uploadTrainingTaskMaterial(data);
@@ -711,9 +712,9 @@ async function handleMaterialChange(slotKey, file) {
}
}
-function isWordFile(file) {
+function isPdfFile(file) {
const name = String(file?.name || "").trim().toLowerCase();
- return name.endsWith(".doc") || name.endsWith(".docx");
+ return name.endsWith(".pdf");
}
function clearMaterial(slotKey) {
diff --git a/src/views/teacherEnd/score/TaskReviewPanel.vue b/src/views/teacherEnd/score/TaskReviewPanel.vue
index d817215..030d890 100644
--- a/src/views/teacherEnd/score/TaskReviewPanel.vue
+++ b/src/views/teacherEnd/score/TaskReviewPanel.vue
@@ -339,7 +339,7 @@
-
+
diff --git a/src/views/teacherEnd/trainingTask/index.vue b/src/views/teacherEnd/trainingTask/index.vue
index 524e7e7..c90ad05 100644
--- a/src/views/teacherEnd/trainingTask/index.vue
+++ b/src/views/teacherEnd/trainingTask/index.vue
@@ -394,7 +394,7 @@ const materialSlots = [
{ key: "trainingData", label: "案例数据" },
{ key: "guideManual", label: "实训指导手册" },
{ key: "aiManual", label: "AI辅助指导手册" },
- { key: "referenceAnswer", label: "参考答案", accept: ".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
+ { key: "referenceAnswer", label: "参考答案", accept: ".pdf,application/pdf" },
];
const tasks = ref([]);
const classList = ref([]);
@@ -717,12 +717,13 @@ function removeObjective(index) {
async function handleMaterialChange(slotKey, file) {
const rawFile = file?.raw;
if (!rawFile) return;
- if (slotKey === "referenceAnswer" && !isWordFile(rawFile)) {
- proxy?.$modal?.msgError?.("参考答案仅支持 Word 文件(.doc 或 .docx)");
+ if (slotKey === "referenceAnswer" && !isPdfFile(rawFile)) {
+ proxy?.$modal?.msgError?.("参考答案仅支持 PDF 文件(.pdf)");
return;
}
const data = new FormData();
data.append("file", rawFile);
+ data.append("materialType", slotKey);
uploadingField.value = slotKey;
try {
const res = await uploadTrainingTaskMaterial(data);
@@ -736,9 +737,9 @@ async function handleMaterialChange(slotKey, file) {
}
}
-function isWordFile(file) {
+function isPdfFile(file) {
const name = String(file?.name || "").trim().toLowerCase();
- return name.endsWith(".doc") || name.endsWith(".docx");
+ return name.endsWith(".pdf");
}
function clearMaterial(slotKey) {
diff --git a/tests/reference-answer-upload.test.cjs b/tests/reference-answer-upload.test.cjs
new file mode 100644
index 0000000..5d1dcde
--- /dev/null
+++ b/tests/reference-answer-upload.test.cjs
@@ -0,0 +1,51 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const path = require("node:path");
+const vm = require("node:vm");
+const { parse, compileScript, compileTemplate } = require("@vue/compiler-sfc");
+const editors = ["teacherEnd", "schoolAdmin"].map((role) => path.resolve(__dirname, `../src/views/${role}/trainingTask/index.vue`));
+function page(filename) {
+ const source = fs.readFileSync(filename, "utf8");
+ const calls = [], errors = [];
+ const context = { taskForm: { referenceAnswerName: "existing.pdf", referenceAnswerUrl: "/file/existing.pdf" }, uploadingField: { value: "" },
+ proxy: { $modal: { msgError: (text) => errors.push(text), msgSuccess() {} } },
+ FormData: class { constructor() { this.values = new Map(); } append(key, value) { this.values.set(key, value); } get(key) { return this.values.get(key); } },
+ normalizeMaterialUrl: (value) => value, materialLabel: (key) => key,
+ uploadTrainingTaskMaterial: async (data) => { calls.push(data); return { originalFilename: data.get("file").name, url: "/file/uploaded.pdf" }; },
+ };
+ const handlers = source.slice(source.indexOf("async function handleMaterialChange("), source.indexOf("function clearMaterial("));
+ const slots = source.match(/const materialSlots = \[[\s\S]*?\];/)[0];
+ vm.runInNewContext(slots + "\n" + handlers + "\nglobalThis.page={handleMaterialChange,materialSlots};", context);
+ return { ...context, ...context.page, source, calls, errors };
+}
+test("both task editors block non PDF reference uploads without replacing existing files", async () => {
+ for (const filename of editors) {
+ const editor = page(filename);
+ assert.equal(editor.materialSlots.find((slot) => slot.key === "referenceAnswer").accept, ".pdf,application/pdf");
+ for (const name of ["answer.doc", "answer.docx", "answer.xlsx", "answer.pdf.exe"]) {
+ await editor.handleMaterialChange("referenceAnswer", { raw: { name, type: "application/pdf" } });
+ }
+ assert.equal(editor.calls.length, 0);
+ assert.equal(editor.errors.length, 4);
+ assert.match(editor.errors[0], /仅支持 PDF/);
+ assert.equal(editor.taskForm.referenceAnswerName, "existing.pdf");
+ assert.equal(editor.taskForm.referenceAnswerUrl, "/file/existing.pdf");
+ }
+});
+test("PDF reference uploads and other materials keep separate upload rules", async () => {
+ for (const filename of editors) {
+ const editor = page(filename);
+ await editor.handleMaterialChange("referenceAnswer", { raw: { name: "答案.PDF" } });
+ assert.equal(editor.calls[0].get("materialType"), "referenceAnswer");
+ assert.equal(editor.taskForm.referenceAnswerName, "答案.PDF");
+ assert.equal(editor.taskForm.referenceAnswerUrl, "/file/uploaded.pdf");
+ await editor.handleMaterialChange("material", { raw: { name: "案例.docx" } });
+ assert.equal(editor.calls[1].get("materialType"), "material");
+ assert.equal(editor.taskForm.materialName, "案例.docx");
+ const { descriptor, errors } = parse(editor.source);
+ assert.deepEqual(errors, []);
+ compileScript(descriptor, { id: "reference-answer-upload" });
+ assert.deepEqual(compileTemplate({ source: descriptor.template.content, filename, id: "reference-answer-upload" }).errors, []);
+ }
+});
diff --git a/tests/teacher-training-reference-answer.static.test.cjs b/tests/teacher-training-reference-answer.static.test.cjs
index 28e1b2e..6e0760b 100644
--- a/tests/teacher-training-reference-answer.static.test.cjs
+++ b/tests/teacher-training-reference-answer.static.test.cjs
@@ -9,14 +9,14 @@ const editor = fs.readFileSync(
);
assert(/key: "referenceAnswer",\s*label: "参考答案"/.test(editor));
-assert(/accept: "\.doc,\.docx/.test(editor), "reference answers should expose Word file types");
+assert(/accept: "\.pdf,application\/pdf"/.test(editor), "reference answers should expose PDF 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));
+assert(/slotKey === "referenceAnswer" && !isPdfFile\(rawFile\)/.test(editor));
+assert(/name\.endsWith\("\.pdf"\)/.test(editor));
console.log("teacher reference-answer upload contract passed");