fix: 优化产品架构设计校验提示

bugfix/ai-assessment-evidence-rescore
陈沅 3 months ago
parent e8c1f08640
commit 5005bacad7

@ -922,6 +922,7 @@ export function checkProductArchitectureDesignStepOne(layerIds) {
method: "post",
data: { layerIds: items },
headers: { repeatSubmit: false },
skipErrorMessage: true,
});
}
@ -1023,6 +1024,7 @@ export function checkProductArchitectureDesignStepTwo(actionIds) {
method: "post",
data: { actionIds: items },
headers: { repeatSubmit: false },
skipErrorMessage: true,
});
}
@ -1041,6 +1043,7 @@ export function checkProductArchitectureDesignStepThree(rows) {
method: "post",
data: { rows: items },
headers: { repeatSubmit: false },
skipErrorMessage: true,
});
}
@ -1058,6 +1061,7 @@ export function checkProductArchitectureDesignStepFour(images) {
method: "post",
data: { images: files },
headers: { repeatSubmit: false },
skipErrorMessage: true,
});
}

@ -0,0 +1,52 @@
export const SCENARIO_FIELDS = [
"userScenario",
"hardwareSense",
"driverTransmit",
"algorithmProcess",
"applicationTrigger",
"driverOutput",
"hardwareEffect",
];
const FIELD_LABELS = {
userScenario: "用户场景",
hardwareSense: "硬件物理层(感知)",
driverTransmit: "驱动感知层(传递)",
algorithmProcess: "算法处理层",
applicationTrigger: "应用功能层",
driverOutput: "驱动感知层(输出)",
hardwareEffect: "硬件物理层(效果)",
};
function hasText(value) {
return Boolean(String(value || "").trim());
}
function isEmptyRow(row) {
return SCENARIO_FIELDS.every((field) => !hasText(row?.[field]));
}
function getMissingFieldLabels(row) {
return SCENARIO_FIELDS.filter((field) => !hasText(row?.[field])).map((field) => FIELD_LABELS[field]);
}
export function getRowsForScenarioValidation(rows) {
return (Array.isArray(rows) ? rows : []).filter((row) => !isEmptyRow(row));
}
export function getCompletedScenarioCount(rows) {
return getRowsForScenarioValidation(rows).filter((row) => getMissingFieldLabels(row).length === 0).length;
}
export function getScenarioValidationMessage(rows) {
const sourceRows = Array.isArray(rows) ? rows : [];
const incompleteIndex = sourceRows.findIndex((row) => !isEmptyRow(row) && getMissingFieldLabels(row).length > 0);
if (incompleteIndex >= 0) {
return `第 ${incompleteIndex + 1} 行尚未填写完整,缺少:${getMissingFieldLabels(sourceRows[incompleteIndex]).join("、")}。`;
}
const enteredRows = getRowsForScenarioValidation(sourceRows);
if (enteredRows.length < 3) {
return `请至少完整填写 3 个典型工作场景;当前已完成 ${enteredRows.length} 个。`;
}
return "";
}

@ -89,7 +89,7 @@
<p class="step-desc">根据本实训案例资料,至少选择 3 个典型的工作场景,分析产品架构各层级在场景中的具体工作。每一行需完整填写,系统会将这些内容作为后续架构方案设计的依据。</p>
<div class="scene-toolbar">
<span>已填写 {{ scenarioRows.length }} 个场景 <em>(至少 3 个)</em></span>
<span>已完成 {{ completedScenarioCount }} 个场景 <em>(至少 3 个,空白行不参与校验)</em></span>
<div class="scene-toolbar__actions">
<button type="button" class="btn-nav" :disabled="scenarioRows.length >= 10 || checking" @click="addScenarioRow">增加一行</button>
<button type="button" class="btn-nav" :disabled="scenarioRows.length <= 3 || checking" @click="removeScenarioRow">删除一行</button>
@ -160,6 +160,7 @@ import { parseTrainingArray } from "@/views/training/taskKeyMap";
import TrainingAiSidebar from "@/views/components/TrainingAiSidebar.vue";
import TrainingMaterialButton from "@/views/components/TrainingMaterialButton.vue";
import TrainingTaskBrief from "@/views/components/TrainingTaskBrief.vue";
import { SCENARIO_FIELDS, getCompletedScenarioCount, getRowsForScenarioValidation, getScenarioValidationMessage } from "./productArchitectureScenarioValidation.mjs";
const { proxy } = getCurrentInstance();
const TASK_KEY = "product-structure";
@ -180,7 +181,6 @@ const FLOW_ACTIONS = [
{ id: "driver-outputs", name: "驱动层输出指令", description: "驱动层将功能指令转化为可执行的控制输出。" },
{ id: "hardware-effects", name: "硬件产生效果", description: "硬件执行指令并形成用户可感知的最终效果。" },
];
const SCENARIO_FIELDS = ["userScenario", "hardwareSense", "driverTransmit", "algorithmProcess", "applicationTrigger", "driverOutput", "hardwareEffect"];
const fallbackTask = {
title: "产品架构设计", background: "智能硬件产品采用模块化分层架构。通过本实训理解各层职责和层间关系,为后续功能与技术方案设计建立基础。",
goals: ["理解智能硬件的四层模块化架构", "区分各层的核心职责", "建立从物理硬件到用户功能的系统化思维"],
@ -198,7 +198,7 @@ const flowOrder = ref(shuffle(duplicateFlowActions()));
const dragFlowId = ref("");
const stepTwoPassed = ref(false);
const stepTwoCheckResult = ref(null);
const scenarioRows = ref(createScenarioRows(4));
const scenarioRows = ref(createScenarioRows(3));
const stepThreePassed = ref(false);
const stepThreeCheckResult = ref(null);
const architectureImages = ref(createArchitectureImages());
@ -211,6 +211,7 @@ const taskGoals = computed(() => parseTrainingArray(taskConfig.value?.objectives
const taskRequirement = computed(() => taskConfig.value?.requirements || fallbackTask.requirement);
const trainingSteps = computed(() => parseTrainingArray(taskConfig.value?.steps, DEFAULT_STEPS));
const progressItems = computed(() => trainingSteps.value.map((text, index) => ({ text, status: index + 1 < currentStep.value ? "done" : index + 1 === currentStep.value ? "doing" : "" })));
const completedScenarioCount = computed(() => getCompletedScenarioCount(scenarioRows.value));
onMounted(async () => { await loadTaskConfig(); await loadSavedProgress(); });
@ -317,9 +318,16 @@ async function checkAndSaveStepTwo() {
}
async function checkAndSaveStepThree() {
if (checking.value) return;
const validationMessage = getScenarioValidationMessage(scenarioRows.value);
if (validationMessage) {
stepThreePassed.value = false;
stepThreeCheckResult.value = { valid: false, message: validationMessage };
proxy?.$modal?.msgWarning(validationMessage);
return;
}
checking.value = true;
try {
const response = await checkProductArchitectureDesignStepThree(scenarioRows.value.map((row) => ({ ...row })));
const response = await checkProductArchitectureDesignStepThree(getRowsForScenarioValidation(scenarioRows.value).map((row) => ({ ...row })));
stepThreeCheckResult.value = response?.data || null; stepThreePassed.value = Boolean(stepThreeCheckResult.value?.valid);
await persist("SAVE");
if (stepThreePassed.value) proxy?.$modal?.msgSuccess("场景架构分析已保存并解锁下一步"); else proxy?.$modal?.msgWarning("请至少完整填写 3 个典型工作场景");

@ -0,0 +1,80 @@
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
import {
getRowsForScenarioValidation,
getScenarioValidationMessage,
} from "../src/views/product/productArchitectureScenarioValidation.mjs";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const completeRow = {
userScenario: "用户说小美,打开客厅灯",
hardwareSense: "麦克风采集语音",
driverTransmit: "音频驱动传递数字信号",
algorithmProcess: "识别唤醒词和开灯指令",
applicationTrigger: "触发开灯功能",
driverOutput: "调光驱动输出 PWM 信号",
hardwareEffect: "客厅灯点亮",
};
test("产品架构第 3 步忽略额外空行,只提交三条完整场景", () => {
const rows = [completeRow, { ...completeRow }, { ...completeRow }, {
userScenario: "",
hardwareSense: "",
driverTransmit: "",
algorithmProcess: "",
applicationTrigger: "",
driverOutput: "",
hardwareEffect: "",
}];
assert.equal(getScenarioValidationMessage(rows), "");
assert.equal(getRowsForScenarioValidation(rows).length, 3);
});
test("产品架构第 3 步提示首个未完成场景及缺失字段", () => {
const incomplete = { ...completeRow, algorithmProcess: "", driverOutput: "" };
assert.equal(
getScenarioValidationMessage([completeRow, incomplete, { ...completeRow }]),
"第 2 行尚未填写完整,缺少:算法处理层、驱动感知层(输出)。"
);
});
test("产品架构第 3 步保留半填场景在原表格中的行号", () => {
const emptyRow = {
userScenario: "",
hardwareSense: "",
driverTransmit: "",
algorithmProcess: "",
applicationTrigger: "",
driverOutput: "",
hardwareEffect: "",
};
const incomplete = { ...completeRow, algorithmProcess: "" };
assert.equal(
getScenarioValidationMessage([completeRow, emptyRow, incomplete, { ...completeRow }]),
"第 3 行尚未填写完整,缺少:算法处理层。"
);
});
test("产品架构第 3 步要求至少三条完整场景", () => {
assert.equal(
getScenarioValidationMessage([completeRow, { ...completeRow }]),
"请至少完整填写 3 个典型工作场景;当前已完成 2 个。"
);
});
test("产品架构校验接口保留业务提示且不重复弹出 400 错误", () => {
const apiSource = fs.readFileSync(path.join(root, "src/api/studentTrainingAnswer.js"), "utf8");
const architectureChecks = apiSource.slice(
apiSource.indexOf("export function checkProductArchitectureDesignStepOne"),
apiSource.indexOf("export function checkProductDevelopmentProcessStepTwo")
);
assert.equal((architectureChecks.match(/skipErrorMessage: true/g) || []).length, 4);
});
Loading…
Cancel
Save