diff --git a/frontend/src/components/StatsDashboard.css b/frontend/src/components/StatsDashboard.css index b33ac98..ca32564 100644 --- a/frontend/src/components/StatsDashboard.css +++ b/frontend/src/components/StatsDashboard.css @@ -693,10 +693,43 @@ grid-column: 1 / -1; } -.stats-card h3 { +.stats-card-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; margin-bottom: 0.75rem; } +.stats-card-header h3 { + margin: 0; +} + +.stats-export-btn { + padding: 6px 12px; + background: #607D8B; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; + font-size: 13px; + font-weight: 600; + white-space: nowrap; +} + +.stats-export-btn:hover:not(:disabled) { + background: #546E7A; +} + +.stats-export-btn:disabled { + opacity: 0.6; + cursor: not-allowed; +} + +.stats-card h4 { + margin-top: 0; +} + .stats-card h4 { font-size: 0.95rem; color: #555; diff --git a/frontend/src/components/StatsDashboard.jsx b/frontend/src/components/StatsDashboard.jsx index 4f48c51..8593ba5 100644 --- a/frontend/src/components/StatsDashboard.jsx +++ b/frontend/src/components/StatsDashboard.jsx @@ -327,6 +327,34 @@ const StatsDashboard = () => { URL.revokeObjectURL(url) } + const handleExportTradeStats = () => { + if (!tradeStats) { + alert('暂无交易统计数据可导出') + return + } + const timestamp = new Date().toISOString().slice(0, 19).replace(/:/g, '-') + const filename = `交易统计_最近${tradeStats.days || 7}天_${timestamp}.json` + const exportData = { + exported_at: new Date().toISOString(), + days: tradeStats.days, + by_symbol: tradeStats.by_symbol || [], + hourly_agg: tradeStats.hourly_agg || [], + suggestions: tradeStats.suggestions || { blacklist: [], whitelist: [] }, + daily: tradeStats.daily || [], + by_hour: tradeStats.by_hour || [], + } + const dataStr = JSON.stringify(exportData, null, 2) + const dataBlob = new Blob([dataStr], { type: 'application/json' }) + const url = URL.createObjectURL(dataBlob) + const link = document.createElement('a') + link.href = url + link.download = filename + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + URL.revokeObjectURL(url) + } + return (
@@ -851,7 +879,18 @@ const StatsDashboard = () => { {/* 交易统计(最近 7 天):按交易对净盈亏/胜率、按小时净盈亏、白名单/黑名单建议 */}
-

交易统计(最近 7 天)

+
+

交易统计(最近 7 天)

+ +
{tradeStats ? ( <>