fix(portfolio-backtest): 净值曲线 echarts 空白 - watch漏触发手动兜底
CI/CD / test (push) Successful in 10s
CI/CD / nas-deploy (push) Successful in 22s
CI/CD / nas-verify (push) Successful in 3s

根因(浏览器实证): onSubmit 异步轮询 done 后 result/equityCurve 同帧赋值,
v-if result 块(含 chart-box div)此帧才挂载, watch(equityCurve, flush:post)
在该时序下漏触发 renderEquity → echarts 从未 init(chart-box 无 _echarts_instance_)。
手动 echarts.init+setOption 实证容器/echarts/数据全正常(37点),纯 watch 触发遗漏。

修复: equityCurve 赋值后 await nextTick()(等 chart-box 挂载)+ 手动 renderEquity()兜底。
watch 保留(双保险, ensureChart 幂等)。
This commit is contained in:
2026-08-01 16:56:26 +08:00
parent 4986e5c3c4
commit e64b5906da
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, reactive, onMounted, onUnmounted, watch } from 'vue'
import { ref, reactive, onMounted, onUnmounted, watch, nextTick } from 'vue'
import { ElMessage } from 'element-plus'
import type { EChartsCoreOption } from 'echarts'
import { useChart } from '@/composables/useChart'
@@ -126,6 +126,11 @@ async function onSubmit(): Promise<void> {
trades.value = r.trades || []
metrics.value = r.metrics || null
period.value = r.period || null
// v-if result 块(含 chart-box div)在此帧才挂载, watch(equityCurve, flush:post)
// 在异步轮询 done 后赋值时序下会漏触发 echarts.init → 净值曲线空白。
// nextTick 等 chart-box 挂载后手动渲染兜底。
await nextTick()
renderEquity()
ElMessage.success(
`回测完成: ${r.period?.trading_days ?? 0} 交易日, 选股 ${(r.stocks_selected || []).length}`,
)