增加仪表板统计数据的导出功能
This commit is contained in:
parent
dfe29d70dc
commit
076b597fb4
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div className="dashboard">
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '20px' }}>
|
||||
|
|
@ -851,7 +879,18 @@ const StatsDashboard = () => {
|
|||
|
||||
{/* 交易统计(最近 7 天):按交易对净盈亏/胜率、按小时净盈亏、白名单/黑名单建议 */}
|
||||
<div className="dashboard-card stats-card">
|
||||
<h3>交易统计(最近 7 天)</h3>
|
||||
<div className="stats-card-header">
|
||||
<h3>交易统计(最近 7 天)</h3>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleExportTradeStats}
|
||||
disabled={!tradeStats}
|
||||
className="stats-export-btn"
|
||||
title="导出交易统计为 JSON,便于离线分析"
|
||||
>
|
||||
导出 JSON
|
||||
</button>
|
||||
</div>
|
||||
{tradeStats ? (
|
||||
<>
|
||||
<div className="stats-section">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user