@ -11,15 +11,22 @@
: goals = "taskGoals"
: requirements = "taskRequirement"
: show - material = "false"
: show - toolbar = "false"
/ >
< section class = "task-card hardware-workbench" >
< div class = "workbench-head hardware-workbench-head" >
< div >
< p class = "section-eyebrow" > BOM cost workspace < / p >
< h2 > 智能硬件成本估算 < / h2 >
< h2 > { { currentStepTitle } } < / h2 >
< / div >
< TrainingMaterialButton :material-name ="taskConfig?.materialName" :material-url ="taskConfig?.materialUrl" / >
< TrainingTaskToolbar
class = "hardware-cost-toolbar"
: task - key = "TASK_KEY"
: on - submit = "submitTask"
: on - reset = "resetTraining"
: on - export = "exportTrainingOutcome"
/ >
< / div >
< nav class = "step-indicator" aria -label = " 智 能 硬 件 成 本 估 算 步 骤 " >
@ -45,13 +52,6 @@
< / nav >
< section v-if ="currentStep === 1" class="step-card hardware-step-card" >
< div class = "workbench-head" >
< div >
< p class = "section-eyebrow" > Step 01 · BOM selection < / p >
< h2 > 核心元器件选型组合 < / h2 >
< / div >
< / div >
< section class = "cost-brief" >
< span class = "cost-brief__index" > 01 < / span >
< p > 在目标成本约束下 , 权衡性能与成本 , 为每个元器件选择合适档位 。 请基于案例资料中的 “ 元器件选型库 ” , 完成核心元器件的选型组合 。 < / p >
@ -94,20 +94,11 @@
< p class = "row-hint" : class = "{ ready: rows.length >= MIN_ROWS }" >
{ { rows . length >= MIN _ROWS ? '已达到最低填写要求,还可增加 ' + ( MAX _ROWS - rows . length ) + ' 行。' : '还需补充 ' + ( MIN _ROWS - rows . length ) + ' 行后才能保存。' } }
< / p >
< div class = "task-actions" >
< button type = "button" class = "btn-nav" :disabled ="saving" @click ="restoreExample" > 恢 复 示 例 < / button >
< button type = "button" class = "btn-nav btn-primary" :disabled ="saving" @click ="saveStepOne(false)" > {{ saving ? " 保 存 中 … " : " 校 验 并 保 存 本 步 骤 " }} < / button >
< button type = "button" class = "btn-nav btn-primary" :disabled ="saving" @click ="saveStepOne(true)" > 保 存 并 进 入 第 2 步 < / button >
< / div >
< / section >
< / section >
< section v -else -if = " currentStep = = = 2 " class = "step-card hardware-step-card" >
< div class = "workbench-head" >
< div >
< p class = "section-eyebrow" > Step 02 · Volume costing < / p >
< h2 > 批量成本核算与约束验证 < / h2 >
< / div >
< div class = "step-utility-actions" >
< button type = "button" class = "btn-nav" : disabled = "exporting || !costRows.length" @click ="exportStepTwo" > {{ exporting ? " 导 出 中 … " : " 导 出 成 本 核 算 表 " }} < / button >
< / div >
< section class = "cost-brief" >
@ -157,20 +148,11 @@
< / article >
< / div >
< p v-if ="stepTwoValidation?.message" class="validation-message" :class="{ failed: stepTwoValidation.valid === false }" > {{ stepTwoValidation.message }} < / p >
< div class = "task-actions" >
< button type = "button" class = "btn-nav" :disabled ="savingStepTwo" @ click = "currentStep = 1" > 返回第 1 步 < / button >
< button type = "button" class = "btn-nav btn-primary" : disabled = "savingStepTwo || !costRows.length" @click ="saveStepTwo" > {{ savingStepTwo ? " 校 验 并 保 存 中 … " : " 校 验 并 保 存 本 步 骤 " }} < / button >
< button type = "button" class = "btn-nav btn-primary" : disabled = "savingStepTwo || !costRows.length" @click ="saveStepTwoAndNext" > 保 存 并 进 入 第 3 步 < / button >
< / div >
< / section >
< / section >
< section v -else -if = " currentStep = = = 3 " class = "step-card hardware-step-card" >
< div class = "workbench-head" >
< div >
< p class = "section-eyebrow" > Step 03 · Manufacturing costing < / p >
< h2 > 制造费用与单件总成本核算 < / h2 >
< / div >
< div class = "step-utility-actions" >
< button type = "button" class = "btn-nav" :disabled ="exportingStepThree" @click ="exportStepThree" >
{ { exportingStepThree ? "导出中…" : "导出单件总成本表" } }
< / button >
@ -216,20 +198,11 @@
{ { stepThree . items . length >= MIN _MANUFACTURING _ROWS ? "已达到最低费用项要求。" : "还需补充 " + ( MIN _MANUFACTURING _ROWS - stepThree . items . length ) + " 项制造费用后才能保存。" } }
< / p >
< p v-if ="stepThreeValidation?.message" class="validation-message" :class="{ failed: stepThreeValidation.valid === false }" > {{ stepThreeValidation.message }} < / p >
< div class = "task-actions" >
< button type = "button" class = "btn-nav" :disabled ="savingStepThree" @ click = "currentStep = 2" > 返回第 2 步 < / button >
< button type = "button" class = "btn-nav btn-primary" :disabled ="savingStepThree" @click ="saveStepThree(false)" > {{ savingStepThree ? " 校 验 并 保 存 中 … " : " 校 验 并 保 存 本 步 骤 " }} < / button >
< button type = "button" class = "btn-nav btn-primary" :disabled ="savingStepThree" @click ="saveStepThree(true)" > 保 存 并 进 入 第 4 步 < / button >
< / div >
< / section >
< / section >
< section v -else class = "step-card hardware-step-card" >
< div class = "workbench-head" >
< div >
< p class = "section-eyebrow" > Step 04 · Cost optimisation < / p >
< h2 > 成本结构可视化与优化决策 < / h2 >
< / div >
< div class = "step-utility-actions" >
< span class = "step-chip" > 以第 2 、 3 步核算结果为依据 < / span >
< / div >
@ -287,12 +260,13 @@
< button type = "button" class = "btn-nav" @click ="downloadCostStructureTemplate" > 下 载 Excel 模 板 < / button >
< / div >
< p v-if ="stepFourValidation?.message" class="validation-message" :class="{ failed: stepFourValidation.valid === false }" > {{ stepFourValidation.message }} < / p >
< div class = "task-actions" >
< button type = "button" class = "btn-nav" :disabled ="savingStepFour" @ click = "currentStep = 3" > 返回第 3 步 < / button >
< button type = "button" class = "btn-nav btn-primary" : disabled = "savingStepFour || !!uploadingChart" @click ="saveStepFour" > {{ savingStepFour ? ' 保 存 中 … ' : ' 保 存 成 本 优 化 决 策 ' }} < / button >
< / div >
< / section >
< / section >
< div class = "step-actions" >
< button v-if ="currentStep > 1" type="button" class="btn-nav" @click="previousStep" > 上 一 步 < / button >
< button type = "button" class = "btn-nav btn-primary" :disabled ="isStepSaving" @click ="saveCurrentProgress" > 保 存 当 前 进 度 < / button >
< button v-if ="currentStep < 4" type="button" class="btn-nav btn-primary" :disabled="isStepSaving" @click="nextStep" > 下 一 步 < / button >
< / div >
< / section >
< / main >
@ -311,11 +285,11 @@
< script setup >
import { computed , getCurrentInstance , onMounted , reactive , ref } from "vue" ;
import TrainingAiSidebar from "@/views/components/TrainingAiSidebar.vue" ;
import Training MaterialButton from "@/views/components/TrainingMaterialButton .vue";
import Training TaskToolbar from "@/views/components/TrainingTaskToolbar .vue";
import TrainingTaskBrief from "@/views/components/TrainingTaskBrief.vue" ;
import { getTrainingTaskByKey } from "@/api/trainingTask" ;
import { parseTrainingArray } from "@/views/training/taskKeyMap" ;
import { getStudentTrainingAnswer, saveStudentTrainingAnswer , uploadStudentTrainingFile , validateHardwareCostStepOne , validateHardwareCostStepTwo , validateHardwareCostStepThree , validateHardwareCostStepFour } from "@/api/studentTrainingAnswer" ;
import { deleteStudentTrainingAnswer, getStudentTrainingAnswer, saveStudentTrainingAnswer , uploadStudentTrainingFile , validateHardwareCostStepOne , validateHardwareCostStepTwo , validateHardwareCostStepThree , validateHardwareCostStepFour } from "@/api/studentTrainingAnswer" ;
import { isStudentDemo } from "@/utils/studentDemo" ;
const TASK _KEY = "hardware-cost" ;
@ -326,6 +300,13 @@ const MAX_ROWS = 40;
const { proxy } = getCurrentInstance ( ) ;
const taskConfig = ref ( { } ) ;
const currentStep = ref ( 1 ) ;
const isStepSaving = computed ( ( ) => saving . value || savingStepTwo . value || savingStepThree . value || savingStepFour . value || submittingTraining . value || Boolean ( uploadingChart . value ) ) ;
const currentStepTitle = computed ( ( ) => ( {
1 : "核心元器件选型组合" ,
2 : "批量成本核算与约束验证" ,
3 : "制造费用与单件总成本核算" ,
4 : "成本结构可视化与优化决策" ,
} ) [ currentStep . value ] || "智能硬件成本估算" ) ;
let rowSeed = 1 ;
const rows = ref ( [ createExampleRow ( ) ] ) ;
const savedStepOneItems = ref ( [ ] ) ;
@ -337,6 +318,7 @@ const savingStepThree = ref(false);
const exportingStepThree = ref ( false ) ;
const stepThreeSaved = ref ( false ) ;
const savingStepFour = ref ( false ) ;
const submittingTraining = ref ( false ) ;
const uploadingChart = ref ( "" ) ;
const stepTwoValidation = ref ( null ) ;
const stepTwo = reactive ( { smallBatchConstraint : "" , largeBatchConstraint : "" , items : [ ] } ) ;
@ -620,7 +602,7 @@ async function handleCostChartUpload(event, type) {
uploadingChart . value = "" ;
}
}
async function saveStepFour ( ) {
async function saveStepFour ( saveAction = "SAVE" ) {
savingStepFour . value = true ;
try {
const payload = stepFourPayload ( ) ;
@ -630,21 +612,170 @@ async function saveStepFour() {
if ( ! validated . valid ) { notifyError ( validated . message || "请完善成本结构图和优化方案" ) ; return ; }
await saveStudentTrainingAnswer ( TASK _KEY , {
currentStep : 4 ,
saveAction : "SUBMIT" ,
submitted : true ,
saveAction ,
submitted : saveAction === "SUBMIT" ,
step4Answer : JSON . stringify ( {
smallBatchChart : { ... stepFour . smallBatchChart } ,
largeBatchChart : { ... stepFour . largeBatchChart } ,
optimizationPlan : payload . optimizationPlan ,
} ) ,
} ) ;
notifySuccess ( "成本优化决策已保存" ) ;
notifySuccess ( saveAction === "SUBMIT" ? "实训任务已提交" : "成本优化决策已保存" ) ;
return true ;
} catch ( error ) {
notifyError ( error ? . message || "成本优化决策保存失败,请检查填写内容" ) ;
return false ;
} finally {
savingStepFour . value = false ;
}
}
async function saveCurrentProgress ( ) {
if ( currentStep . value === 1 ) { await saveStepOne ( false ) ; return Boolean ( savedStepOneItems . value . length ) ; }
if ( currentStep . value === 2 ) { await saveStepTwo ( ) ; return stepTwoSaved . value ; }
if ( currentStep . value === 3 ) { await saveStepThree ( false ) ; return stepThreeSaved . value ; }
return saveStepFour ( ) ;
}
function buildStepOneAnswer ( items , total ) {
return JSON . stringify ( { items , totalAmount : Number ( total ) . toFixed ( 2 ) } ) ;
}
function buildStepTwoAnswer ( validated ) {
return JSON . stringify ( {
items : stepTwo . items ,
smallBatchConstraint : validated . smallBatchConstraint ,
largeBatchConstraint : validated . largeBatchConstraint ,
smallBatchTotal : validated . smallBatchTotal ,
largeBatchTotal : validated . largeBatchTotal ,
} ) ;
}
function buildStepThreeAnswer ( validated ) {
return JSON . stringify ( {
items : stepThree . items ,
smallBatchManufacturingCost : validated . smallBatchManufacturingCost ,
largeBatchManufacturingCost : validated . largeBatchManufacturingCost ,
smallBatchBomCost : validated . smallBatchBomCost ,
largeBatchBomCost : validated . largeBatchBomCost ,
smallBatchUnitTotalCost : validated . smallBatchUnitTotalCost ,
largeBatchUnitTotalCost : validated . largeBatchUnitTotalCost ,
} ) ;
}
function buildStepFourAnswer ( ) {
return JSON . stringify ( {
smallBatchChart : { ... stepFour . smallBatchChart } ,
largeBatchChart : { ... stepFour . largeBatchChart } ,
optimizationPlan : stepFourPayload ( ) . optimizationPlan ,
} ) ;
}
async function submitTask ( ) {
if ( isStepSaving . value ) return false ;
submittingTraining . value = true ;
try {
/ / 顶 部 “ 提 交 任 务 ” 必 须 使 用 本 页 四 步 真 实 数 据 , 不 能 走 通 用 D O M 快 照 提 交 。
const stepOneResult = ( await validateHardwareCostStepOne ( stepOnePayload ( ) ) ) ? . data || { } ;
if ( stepOneResult . valid === false ) throw new Error ( stepOneResult . message || "请完善第 1 步 BOM 物料选型" ) ;
const normalizedRows = Array . isArray ( stepOneResult . items ) && stepOneResult . items . length
? normalizeRows ( stepOneResult . items )
: normalizeRows ( stepOnePayload ( ) . items ) ;
rows . value = normalizedRows ;
const stepOneItems = stepOnePayload ( normalizedRows ) . items ;
savedStepOneItems . value = stepOneItems ;
syncStepTwoRows ( stepOneItems ) ;
await saveStudentTrainingAnswer ( TASK _KEY , {
currentStep : 1 ,
saveAction : "SAVE" ,
step1Answer : buildStepOneAnswer ( stepOneItems , stepOneResult . totalAmount ? ? totalAmount . value ) ,
} ) ;
const stepTwoResult = ( await validateHardwareCostStepTwo ( stepTwoPayload ( ) ) ) ? . data || { } ;
applyValidationResult ( stepTwoResult ) ;
if ( ! stepTwoResult . valid ) throw new Error ( stepTwoResult . message || "请完善第 2 步批量成本核算" ) ;
await saveStudentTrainingAnswer ( TASK _KEY , {
currentStep : 2 ,
saveAction : "SAVE" ,
step2Answer : buildStepTwoAnswer ( stepTwoResult ) ,
} ) ;
stepTwoSaved . value = true ;
const stepThreeResult = ( await validateHardwareCostStepThree ( stepThreePayload ( ) ) ) ? . data || { } ;
applyStepThreeValidation ( stepThreeResult ) ;
if ( ! stepThreeResult . valid ) throw new Error ( stepThreeResult . message || "请完善第 3 步制造成本核算" ) ;
await saveStudentTrainingAnswer ( TASK _KEY , {
currentStep : 3 ,
saveAction : "SAVE" ,
step3Answer : buildStepThreeAnswer ( stepThreeResult ) ,
} ) ;
stepThreeSaved . value = true ;
const stepFourResult = ( await validateHardwareCostStepFour ( stepFourPayload ( ) ) ) ? . data || { } ;
stepFourValidation . value = stepFourResult ;
if ( ! stepFourResult . valid ) throw new Error ( stepFourResult . message || "请完善第 4 步成本优化决策" ) ;
await saveStudentTrainingAnswer ( TASK _KEY , {
currentStep : 4 ,
saveAction : "SUBMIT" ,
submitted : true ,
step4Answer : buildStepFourAnswer ( ) ,
} ) ;
currentStep . value = 4 ;
notifySuccess ( "实训任务已提交" ) ;
return true ;
} catch ( error ) {
notifyError ( error ? . message || "提交失败,请检查四个步骤的填写内容" ) ;
return false ;
} finally {
submittingTraining . value = false ;
}
}
async function resetTraining ( ) {
if ( isStepSaving . value ) return false ;
try {
await deleteStudentTrainingAnswer ( TASK _KEY ) ;
rows . value = [ createExampleRow ( ) ] ;
savedStepOneItems . value = [ ] ;
stepTwo . smallBatchConstraint = "" ;
stepTwo . largeBatchConstraint = "" ;
stepTwo . items = [ ] ;
stepTwoSaved . value = false ;
stepTwoValidation . value = null ;
stepThree . items = createDefaultManufacturingRows ( ) ;
stepThreeSaved . value = false ;
stepThreeValidation . value = null ;
resetStepFour ( ) ;
currentStep . value = 1 ;
notifySuccess ( "已清空全部实训步骤,可以重新开始" ) ;
return true ;
} catch ( error ) {
notifyError ( error ? . message || "重新实训失败,请稍后重试" ) ;
return false ;
}
}
function exportTrainingOutcome ( ) {
const outcome = {
taskName : taskTitle . value ,
exportedAt : new Date ( ) . toISOString ( ) ,
step1 : { items : stepOnePayload ( ) . items , totalAmount : totalAmount . value } ,
step2 : { ... stepTwoPayload ( ) , smallBatchTotal : smallBatchTotal . value , largeBatchTotal : largeBatchTotal . value } ,
step3 : { ... stepThreePayload ( ) , smallBatchUnitTotalCost : smallBatchUnitTotalCost . value , largeBatchUnitTotalCost : largeBatchUnitTotalCost . value } ,
step4 : JSON . parse ( buildStepFourAnswer ( ) ) ,
} ;
const url = URL . createObjectURL ( new Blob ( [ JSON . stringify ( outcome , null , 2 ) ] , { type : "application/json;charset=utf-8" } ) ) ;
const link = document . createElement ( "a" ) ;
link . href = url ;
link . download = "智能硬件成本估算-实训成果.json" ;
document . body . appendChild ( link ) ;
link . click ( ) ;
document . body . removeChild ( link ) ;
URL . revokeObjectURL ( url ) ;
notifySuccess ( "实训成果已导出" ) ;
}
function previousStep ( ) { if ( currentStep . value > 1 ) currentStep . value -= 1 ; }
async function nextStep ( ) { if ( currentStep . value < 4 && await saveCurrentProgress ( ) ) currentStep . value += 1 ; }
function resultClass ( field ) { return stepTwoValidation . value ? . [ field ] === true ? "passed" : stepTwoValidation . value ? . [ field ] === false ? "failed" : "" ; }
function validationLabel ( field ) { return stepTwoValidation . value ? . [ field ] === true ? "满足成本约束" : stepTwoValidation . value ? . [ field ] === false ? "超出成本约束" : "待校验" ; }
async function exportStepTwo ( ) {
@ -845,6 +976,18 @@ onMounted(async () => {
line - height : 1.3 ;
}
. hardware - cost - page . hardware - cost - toolbar {
align - self : center ;
justify - content : flex - end ;
max - width : 100 % ;
}
. hardware - cost - page . step - utility - actions {
display : flex ;
justify - content : flex - end ;
margin : 0 0 16 px ;
}
. hardware - cost - page . hardware - workbench > . step - indicator {
margin : 0 0 30 px ! important ;
}
@ -934,6 +1077,11 @@ onMounted(async () => {
. step - tab . complete + . step - connector : : after { border - color : # 63 e6f1 ; }
@ media ( max - width : 900 px ) {
. hardware - cost - page . hardware - cost - toolbar {
width : 100 % ;
justify - content : flex - start ;
}
. step - indicator {
flex - direction : column ;
align - items : stretch ;