You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
|
2 months ago
|
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 "";
|
||
|
|
}
|