diff --git a/frontend/src/components/TradesTable.vue b/frontend/src/components/TradesTable.vue index 7d4c0c7..a432931 100644 --- a/frontend/src/components/TradesTable.vue +++ b/frontend/src/components/TradesTable.vue @@ -2,15 +2,62 @@ import type { Trade } from '@/api/backtest' defineProps<{ trades: Trade[] }>() + +// vnpy 枚举 repr → 中文(兼容已是中文的情况) +function fmtDir(d: string): string { + if (!d) return '' + const s = String(d) + if (s.includes('LONG') || s === '多') return '买' + if (s.includes('SHORT') || s === '空') return '卖' + if (s.includes('NET')) return '净' + return s +} +function fmtOff(o: string): string { + if (!o) return '' + const s = String(o) + if (s.includes('CLOSETODAY')) return '平今' + if (s.includes('CLOSEFIRST')) return '平昨' + if (s.includes('CLOSE')) return '平仓' + if (s.includes('OPEN')) return '开仓' + return s +} +// 2024-06-25T00:00:00+08:00 → 2024-06-25(日内带时分则保留) +function fmtDate(dt: string): string { + if (!dt) return '' + const s = String(dt).slice(0, 19).replace('T', ' ') + return s.endsWith(' 00:00:00') ? s.slice(0, 10) : s +} +function dirClass(d: string): string { + const v = fmtDir(d) + return v === '买' ? 'up' : v === '卖' ? 'down' : '' +} + + diff --git a/frontend/src/views/backtest/Result.vue b/frontend/src/views/backtest/Result.vue index d967163..7e0b573 100644 --- a/frontend/src/views/backtest/Result.vue +++ b/frontend/src/views/backtest/Result.vue @@ -3,7 +3,7 @@ import { ref, computed, onMounted } from 'vue' import { useRoute } from 'vue-router' import { getResult, getEquityCurve, getDailyPnl, getTrades, getKline, - getRelativeMetrics, getBenchmarkCurve, getRiskSeries, + getRelativeMetrics, getBenchmarkCurve, getRiskSeries, getLog, type EquityPoint, type PnlPoint, type Trade, type KlineBar, type RelativeMetrics, type BenchmarkCurveData, type RiskSeriesData, } from '@/api/backtest' @@ -42,6 +42,7 @@ const equity = ref([]) const pnl = ref([]) const trades = ref([]) const kline = ref([]) +const logText = ref('') // statEntries is no longer used in the new layout but kept for potential future use // const statEntries = computed(() => @@ -135,10 +136,32 @@ onMounted(async () => { kline.value = [] } } + try { + logText.value = await getLog(taskId) + } catch { + logText.value = '' + } } finally { loading.value = false } }) + +// 每日收益格式化:浮点精度 → 2 位;日期去 00:00:00 +function fmtPnl(v: number | string): string { + const n = typeof v === 'number' ? v : parseFloat(v) + if (!Number.isFinite(n)) return String(v) + return n.toFixed(2) +} +function fmtPnlClass(v: number | string): string { + const n = typeof v === 'number' ? v : parseFloat(v) + if (!Number.isFinite(n) || n === 0) return '' + return n > 0 ? 'up' : 'down' +} +function fmtDate(d: string): string { + if (!d) return '' + const s = String(d).slice(0, 19).replace('T', ' ') + return s.endsWith(' 00:00:00') ? s.slice(0, 10) : s +}