@@ -432,10 +432,10 @@ export default function StepFlow({ chat, userInput, onStepComplete, getLLMConfig
432432 let completedCells = 0
433433 const totalCells = horizontalCombinations . length * verticalCombinations . length
434434
435- // 维护本地的tableData状态,避免异步状态更新问题
436- const currentTableData = { ... chat . crosstabData . tableData }
435+ // 收集所有生成的数据,最后一次性更新
436+ const newTableData : { [ key : string ] : { [ key : string ] : string } } = { }
437437
438- // 为每个交叉点生成值
438+ // 为每个交叉点生成值(串行执行)
439439 for ( const hCombination of horizontalCombinations ) {
440440 for ( const vCombination of verticalCombinations ) {
441441 const hPath = generateDimensionPath ( hCombination )
@@ -529,11 +529,13 @@ export default function StepFlow({ chat, userInput, onStepComplete, getLLMConfig
529529 validatedCellValues [ dim . id ] = processedCellValues [ dim . id ] || ''
530530 } )
531531
532- // 更新本地tableData状态
533- currentTableData [ cellKey ] = validatedCellValues
532+ // 将生成的数据添加到收集器中
533+ newTableData [ cellKey ] = validatedCellValues
534534
535- // 立即更新当前单元格数据到UI
536- stores . crosstab . updateCrosstabData ( chat . id , { tableData : currentTableData } )
535+ // 每生成1个单元格就更新一次UI,实时显示变化
536+ const currentTableData = stores . crosstab . getCrosstabData ( chat . id ) ?. tableData || { }
537+ const updatedTableData = { ...currentTableData , ...newTableData }
538+ stores . crosstab . updateCrosstabData ( chat . id , { tableData : updatedTableData } )
537539
538540 completedCells ++
539541 } catch ( error ) {
@@ -547,6 +549,11 @@ export default function StepFlow({ chat, userInput, onStepComplete, getLLMConfig
547549 }
548550 }
549551
552+ // 最终更新,确保所有数据都已保存
553+ const finalTableData = stores . crosstab . getCrosstabData ( chat . id ) ?. tableData || { }
554+ const finalUpdatedTableData = { ...finalTableData , ...newTableData }
555+ stores . crosstab . updateCrosstabData ( chat . id , { tableData : finalUpdatedTableData } )
556+
550557 message . success ( `表格数据生成完成 (${ completedCells } /${ totalCells } )` )
551558 } catch ( error ) {
552559 console . error ( '表格数据生成失败:' , error )
0 commit comments