a
This commit is contained in:
@@ -0,0 +1,574 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>TradingAgents</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #0b0f19;
|
||||
--card: #131a2b;
|
||||
--border: #1e2a42;
|
||||
--text: #e2e8f0;
|
||||
--dim: #64748b;
|
||||
--accent: #3b82f6;
|
||||
--accent2: #8b5cf6;
|
||||
--green: #22c55e;
|
||||
--red: #ef4444;
|
||||
--yellow: #eab308;
|
||||
--orange: #f97316;
|
||||
}
|
||||
* { margin:0; padding:0; box-sizing:border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
}
|
||||
a { color: var(--accent); text-decoration: none; }
|
||||
|
||||
/* ── Header ── */
|
||||
.header {
|
||||
background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding: 20px 32px;
|
||||
display: flex; align-items: center; gap: 16px;
|
||||
}
|
||||
.header-icon {
|
||||
width: 44px; height: 44px;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent2));
|
||||
border-radius: 12px;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-size: 22px;
|
||||
}
|
||||
.header h1 { font-size: 20px; font-weight: 700; }
|
||||
.header p { font-size: 13px; color: var(--dim); margin-top: 2px; }
|
||||
|
||||
/* ── Login Area ── */
|
||||
.login-area { display: flex; align-items: center; gap: 10px; margin-left: auto; }
|
||||
.login-btn { padding: 8px 18px; border: 1px solid var(--accent); border-radius: 8px; background: transparent; color: var(--accent); font-size: 14px; cursor: pointer; text-decoration: none; transition: all .2s; white-space: nowrap; }
|
||||
.login-btn:hover { background: var(--accent); color: #fff; }
|
||||
.user-info { display: flex; align-items: center; gap: 10px; font-size: 14px; }
|
||||
.user-info .uname { color: var(--text); font-weight: 500; }
|
||||
.user-info .logout { color: var(--dim); cursor: pointer; text-decoration: none; font-size: 12px; }
|
||||
.user-info .logout:hover { color: #ef4444; }
|
||||
.login-guard { text-align: center; padding: 30px; color: var(--dim); font-size: 15px; background: var(--card); border-radius: 12px; margin-top: 20px; }
|
||||
.login-guard a { color: var(--accent); text-decoration: none; font-weight: 500; }
|
||||
|
||||
/* ── Main ── */
|
||||
.main { max-width: 1100px; margin: 0 auto; padding: 24px; }
|
||||
|
||||
/* ── Form Card ── */
|
||||
.form-card {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.form-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
|
||||
.form-group { flex: 1; min-width: 160px; }
|
||||
.form-group label {
|
||||
display: block; font-size: 13px; font-weight: 500;
|
||||
color: var(--dim); margin-bottom: 6px;
|
||||
}
|
||||
.form-group input, .form-group select {
|
||||
width: 100%; padding: 10px 14px;
|
||||
background: var(--bg); border: 1px solid var(--border);
|
||||
border-radius: 8px; color: var(--text); font-size: 14px;
|
||||
outline: none; transition: border .2s;
|
||||
}
|
||||
.form-group input:focus, .form-group select:focus { border-color: var(--accent); }
|
||||
|
||||
.btn {
|
||||
padding: 10px 28px; border: none; border-radius: 8px;
|
||||
font-size: 14px; font-weight: 600; cursor: pointer;
|
||||
transition: all .2s; white-space: nowrap;
|
||||
}
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent2));
|
||||
color: #fff;
|
||||
}
|
||||
.btn-primary:hover { opacity: .9; transform: translateY(-1px); }
|
||||
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }
|
||||
.btn-secondary {
|
||||
background: transparent; color: var(--accent);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.btn-secondary:hover { background: rgba(59,130,246,.1); }
|
||||
|
||||
/* ── Checkbox group ── */
|
||||
.analyst-group { display: flex; gap: 12px; flex-wrap: wrap; padding-top: 4px; }
|
||||
.analyst-group label {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
font-size: 13px; color: var(--text); cursor: pointer;
|
||||
}
|
||||
.analyst-group input[type=checkbox] { accent-color: var(--accent); }
|
||||
|
||||
/* ── Status ── */
|
||||
.status-bar {
|
||||
background: var(--card); border: 1px solid var(--border);
|
||||
border-radius: 12px; padding: 20px 24px; margin-bottom: 24px;
|
||||
display: none;
|
||||
}
|
||||
.status-bar.visible { display: block; }
|
||||
.status-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
|
||||
.status-header .ticker { font-size: 18px; font-weight: 700; }
|
||||
.status-header .date { font-size: 14px; color: var(--dim); }
|
||||
|
||||
.spinner {
|
||||
width: 20px; height: 20px;
|
||||
border: 3px solid var(--border);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 50%;
|
||||
animation: spin .8s linear infinite;
|
||||
}
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
|
||||
.badge {
|
||||
padding: 3px 10px; border-radius: 20px;
|
||||
font-size: 12px; font-weight: 600;
|
||||
}
|
||||
.badge-pending { background: rgba(234,179,8,.15); color: var(--yellow); }
|
||||
.badge-running { background: rgba(59,130,246,.15); color: var(--accent); }
|
||||
.badge-completed { background: rgba(34,197,94,.15); color: var(--green); }
|
||||
.badge-failed { background: rgba(239,68,68,.15); color: var(--red); }
|
||||
|
||||
.progress-track {
|
||||
width: 100%; height: 4px; background: var(--border);
|
||||
border-radius: 2px; overflow: hidden;
|
||||
}
|
||||
.progress-fill {
|
||||
height: 100%; width: 0; border-radius: 2px;
|
||||
background: linear-gradient(90deg, var(--accent), var(--accent2));
|
||||
transition: width .6s ease;
|
||||
}
|
||||
|
||||
/* ── Result ── */
|
||||
.result-section { display: none; }
|
||||
.result-section.visible { display: block; }
|
||||
|
||||
.report-card {
|
||||
background: var(--card); border: 1px solid var(--border);
|
||||
border-radius: 12px; margin-bottom: 16px; overflow: hidden;
|
||||
}
|
||||
.report-header {
|
||||
padding: 14px 20px; display: flex; align-items: center; gap: 10px;
|
||||
cursor: pointer; user-select: none;
|
||||
border-bottom: 1px solid transparent;
|
||||
transition: background .2s;
|
||||
}
|
||||
.report-header:hover { background: rgba(255,255,255,.03); }
|
||||
.report-card.open .report-header { border-bottom-color: var(--border); }
|
||||
.report-header .icon { font-size: 16px; }
|
||||
.report-header .title { font-weight: 600; font-size: 14px; flex:1; }
|
||||
.report-header .arrow {
|
||||
color: var(--dim); transition: transform .2s; font-size: 12px;
|
||||
}
|
||||
.report-card.open .report-header .arrow { transform: rotate(180deg); }
|
||||
.report-body {
|
||||
max-height: 0; overflow: hidden;
|
||||
transition: max-height .3s ease;
|
||||
}
|
||||
.report-card.open .report-body { max-height: 2000px; }
|
||||
.report-content {
|
||||
padding: 20px; font-size: 14px; line-height: 1.7;
|
||||
white-space: pre-wrap; word-wrap: break-word;
|
||||
color: #cbd5e1;
|
||||
}
|
||||
|
||||
/* ── Decision banner ── */
|
||||
.decision-banner {
|
||||
background: var(--card); border: 1px solid var(--border);
|
||||
border-radius: 12px; padding: 24px; margin-bottom: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.decision-banner .label { font-size: 13px; color: var(--dim); margin-bottom: 8px; }
|
||||
.decision-banner .value { font-size: 28px; font-weight: 800; }
|
||||
.value-buy { color: var(--green); }
|
||||
.value-sell { color: var(--red); }
|
||||
.value-hold { color: var(--yellow); }
|
||||
.value-neutral { color: var(--dim); }
|
||||
|
||||
/* ── History ── */
|
||||
.history-card {
|
||||
background: var(--card); border: 1px solid var(--border);
|
||||
border-radius: 12px; margin-bottom: 24px;
|
||||
}
|
||||
.history-header {
|
||||
padding: 14px 20px; font-weight: 600; font-size: 14px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.history-list { max-height: 260px; overflow-y: auto; }
|
||||
.history-item {
|
||||
padding: 12px 20px; display: flex; align-items: center; gap: 12px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
cursor: pointer; transition: background .2s;
|
||||
}
|
||||
.history-item:last-child { border-bottom: none; }
|
||||
.history-item:hover { background: rgba(255,255,255,.03); }
|
||||
.history-item .hi-ticker { font-weight: 600; min-width: 60px; }
|
||||
.history-item .hi-date { color: var(--dim); font-size: 13px; min-width: 90px; }
|
||||
.history-item .hi-time { color: var(--dim); font-size: 12px; flex:1; }
|
||||
|
||||
/* ── Responsive ── */
|
||||
@media (max-width: 600px) {
|
||||
.header { padding: 16px; }
|
||||
.main { padding: 16px; }
|
||||
.form-row { flex-direction: column; }
|
||||
.form-group { min-width: 100%; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="header">
|
||||
<div class="header-icon">📈</div>
|
||||
<div>
|
||||
<h1>TradingAgents</h1>
|
||||
<p>Multi-Agent LLM Financial Trading Framework</p>
|
||||
</div>
|
||||
<div class="login-area" id="loginArea">
|
||||
<span style="color:var(--dim);font-size:13px;">加载中…</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="main">
|
||||
|
||||
<!-- Form -->
|
||||
<div class="form-card">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label>股票代码</label>
|
||||
<input id="ticker" type="text" placeholder="e.g. AAPL, TSLA, NVDA" value="AAPL">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分析日期</label>
|
||||
<input id="date" type="date">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>辩论轮次</label>
|
||||
<select id="debate">
|
||||
<option value="1" selected>1 轮</option>
|
||||
<option value="2">2 轮</option>
|
||||
<option value="3">3 轮</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>输出语言</label>
|
||||
<select id="language">
|
||||
<option value="Chinese" selected>🇨🇳 中文</option>
|
||||
<option value="English">🇬🇧 English</option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-primary" id="submitBtn" onclick="startAnalysis()">
|
||||
🚀 开始分析
|
||||
</button>
|
||||
</div>
|
||||
<div style="margin-top:14px">
|
||||
<label style="font-size:13px;font-weight:500;color:var(--dim);display:block;margin-bottom:8px">分析师</label>
|
||||
<div class="analyst-group">
|
||||
<label><input type="checkbox" value="market" checked> 📊 Market</label>
|
||||
<label><input type="checkbox" value="news" checked> 📰 News</label>
|
||||
<label><input type="checkbox" value="social"> 💬 Social</label>
|
||||
<label><input type="checkbox" value="fundamentals"> 📋 Fundamentals</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Login Guard -->
|
||||
<div class="login-guard" id="loginGuard" style="display:none">
|
||||
🔐 请先<a href="#" onclick="doLogin();return false">登录</a>后再提交分析
|
||||
</div>
|
||||
|
||||
<!-- Status -->
|
||||
<div class="status-bar" id="statusBar">
|
||||
<div class="status-header">
|
||||
<div class="spinner" id="spinner"></div>
|
||||
<span class="ticker" id="statusTicker"></span>
|
||||
<span class="date" id="statusDate"></span>
|
||||
<span class="badge" id="statusBadge"></span>
|
||||
</div>
|
||||
<div class="progress-track"><div class="progress-fill" id="progressFill"></div></div>
|
||||
</div>
|
||||
|
||||
<!-- Decision -->
|
||||
<div class="decision-banner" id="decisionBanner" style="display:none">
|
||||
<div class="label">最终决策</div>
|
||||
<div class="value" id="decisionValue"></div>
|
||||
</div>
|
||||
|
||||
<!-- Reports -->
|
||||
<div class="result-section" id="resultSection"></div>
|
||||
|
||||
<!-- History -->
|
||||
<div class="history-card" id="historyCard" style="display:none">
|
||||
<div class="history-header">📋 历史记录</div>
|
||||
<div class="history-list" id="historyList"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API = location.origin;
|
||||
const SSO_CENTER = 'http://129.211.173.87:9000';
|
||||
let currentUser = null;
|
||||
let pollTimer = null;
|
||||
let history = JSON.parse(localStorage.getItem('ta_history') || '[]');
|
||||
|
||||
// ── SSO Login ──
|
||||
async function checkLogin() {
|
||||
try {
|
||||
const res = await fetch(`${API}/api/user`);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
currentUser = data.username;
|
||||
document.getElementById('loginArea').innerHTML = `
|
||||
<div class="user-info">
|
||||
<span class="uname">👤 ${escHtml(data.username)}</span>
|
||||
<a class="logout" href="#" onclick="doLogout();return false">退出</a>
|
||||
</div>`;
|
||||
document.getElementById('submitBtn').disabled = false;
|
||||
document.getElementById('loginGuard').style.display = 'none';
|
||||
} else {
|
||||
throw new Error('not logged in');
|
||||
}
|
||||
} catch(e) {
|
||||
currentUser = null;
|
||||
document.getElementById('loginArea').innerHTML = `
|
||||
<a class="login-btn" href="${SSO_CENTER}/?redirect=${encodeURIComponent(location.href)}">🔐 登录</a>`;
|
||||
document.getElementById('submitBtn').disabled = true;
|
||||
document.getElementById('loginGuard').style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
async function doLogout() {
|
||||
await fetch(`${API}/api/logout`, { method: 'POST' });
|
||||
currentUser = null;
|
||||
location.reload();
|
||||
}
|
||||
|
||||
function doLogin() {
|
||||
location.href = `${SSO_CENTER}/?redirect=${encodeURIComponent(location.href)}`;
|
||||
}
|
||||
|
||||
checkLogin();
|
||||
|
||||
// Set default date to today
|
||||
document.getElementById('date').value = new Date().toISOString().slice(0, 10);
|
||||
|
||||
// Render history on load
|
||||
renderHistory();
|
||||
|
||||
function getAnalysts() {
|
||||
return [...document.querySelectorAll('.analyst-group input:checked')].map(c => c.value);
|
||||
}
|
||||
|
||||
async function startAnalysis() {
|
||||
const ticker = document.getElementById('ticker').value.trim().toUpperCase();
|
||||
if (!ticker) { alert('请输入股票代码'); return; }
|
||||
|
||||
const date = document.getElementById('date').value;
|
||||
const debate = parseInt(document.getElementById('debate').value);
|
||||
const language = document.getElementById('language').value;
|
||||
const analysts = getAnalysts();
|
||||
if (analysts.length === 0) { alert('请至少选择一个分析师'); return; }
|
||||
|
||||
const btn = document.getElementById('submitBtn');
|
||||
btn.disabled = true;
|
||||
btn.textContent = '⏳ 提交中...';
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API}/api/analyze`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ticker, date, analysts, max_debate_rounds: debate, output_language: language })
|
||||
});
|
||||
|
||||
if (res.status === 401) {
|
||||
alert('登录已过期,请重新登录');
|
||||
doLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (data.task_id) {
|
||||
showStatus(ticker, date, 'pending');
|
||||
startPolling(data.task_id);
|
||||
// add to history
|
||||
history.unshift({ task_id: data.task_id, ticker, date, time: new Date().toLocaleString() });
|
||||
if (history.length > 20) history.pop();
|
||||
localStorage.setItem('ta_history', JSON.stringify(history));
|
||||
renderHistory();
|
||||
}
|
||||
} catch (e) {
|
||||
alert('请求失败: ' + e.message);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = '🚀 开始分析';
|
||||
}
|
||||
}
|
||||
|
||||
function showStatus(ticker, date, status) {
|
||||
const bar = document.getElementById('statusBar');
|
||||
bar.classList.add('visible');
|
||||
document.getElementById('statusTicker').textContent = ticker;
|
||||
document.getElementById('statusDate').textContent = date;
|
||||
|
||||
const badge = document.getElementById('statusBadge');
|
||||
const spinner = document.getElementById('spinner');
|
||||
const fill = document.getElementById('progressFill');
|
||||
|
||||
badge.className = 'badge badge-' + status;
|
||||
const labels = { pending: '排队中', running: '分析中', completed: '完成', failed: '失败' };
|
||||
badge.textContent = labels[status] || status;
|
||||
|
||||
if (status === 'pending') { spinner.style.display = 'block'; fill.style.width = '15%'; }
|
||||
else if (status === 'running') { spinner.style.display = 'block'; fill.style.width = '50%'; fill.style.transition = 'width 30s ease'; setTimeout(()=>fill.style.width='85%',100); }
|
||||
else if (status === 'completed') { spinner.style.display = 'none'; fill.style.width = '100%'; }
|
||||
else if (status === 'failed') { spinner.style.display = 'none'; fill.style.width = '0'; }
|
||||
}
|
||||
|
||||
function startPolling(taskId) {
|
||||
if (pollTimer) clearInterval(pollTimer);
|
||||
pollTimer = setInterval(async () => {
|
||||
try {
|
||||
const res = await fetch(`${API}/api/task/${taskId}`);
|
||||
const task = await res.json();
|
||||
showStatus(task.ticker, task.date, task.status);
|
||||
|
||||
if (task.status === 'completed') {
|
||||
clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
renderResult(task);
|
||||
} else if (task.status === 'failed') {
|
||||
clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
alert('分析失败: ' + (task.error || '未知错误'));
|
||||
}
|
||||
} catch (e) { /* retry */ }
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
function renderResult(task) {
|
||||
const result = task.result;
|
||||
if (!result) return;
|
||||
|
||||
// Decision banner
|
||||
const banner = document.getElementById('decisionBanner');
|
||||
const val = document.getElementById('decisionValue');
|
||||
banner.style.display = 'block';
|
||||
|
||||
const decision = (result.decision || '').toLowerCase();
|
||||
let cls = 'value-neutral', text = result.decision || 'N/A';
|
||||
if (decision.includes('buy') || decision.includes('看涨') || decision.includes('做多')) cls = 'value-buy';
|
||||
else if (decision.includes('sell') || decision.includes('看跌') || decision.includes('做空')) cls = 'value-sell';
|
||||
else if (decision.includes('hold') || decision.includes('持有') || decision.includes('观望')) cls = 'value-hold';
|
||||
val.className = 'value ' + cls;
|
||||
val.textContent = text;
|
||||
|
||||
// Report sections
|
||||
const section = document.getElementById('resultSection');
|
||||
const reports = result.reports || {};
|
||||
const nameMap = {
|
||||
market_report: '📊 Market Analysis',
|
||||
sentiment_report: '💬 Sentiment Analysis',
|
||||
news_report: '📰 News Analysis',
|
||||
fundamentals_report: '📋 Fundamentals Analysis',
|
||||
investment_plan: '📝 Investment Plan',
|
||||
trader_investment_plan: '💰 Trader Plan',
|
||||
final_trade_decision: '⚖️ Final Decision',
|
||||
};
|
||||
|
||||
let html = '';
|
||||
for (const [key, title] of Object.entries(nameMap)) {
|
||||
if (!reports[key]) continue;
|
||||
html += `
|
||||
<div class="report-card">
|
||||
<div class="report-header" onclick="this.parentElement.classList.toggle('open')">
|
||||
<span class="icon">${title.split(' ')[0]}</span>
|
||||
<span class="title">${title.split(' ').slice(1).join(' ')}</span>
|
||||
<span class="arrow">▼</span>
|
||||
</div>
|
||||
<div class="report-body">
|
||||
<div class="report-content">${escHtml(reports[key])}</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// Open first card by default
|
||||
section.innerHTML = html;
|
||||
section.classList.add('visible');
|
||||
const first = section.querySelector('.report-card');
|
||||
if (first) first.classList.add('open');
|
||||
}
|
||||
|
||||
function escHtml(s) {
|
||||
if (!s) return '';
|
||||
return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
}
|
||||
|
||||
function renderHistory() {
|
||||
if (history.length === 0) { document.getElementById('historyCard').style.display = 'none'; return; }
|
||||
document.getElementById('historyCard').style.display = 'block';
|
||||
const list = document.getElementById('historyList');
|
||||
list.innerHTML = history.map(h => `
|
||||
<div class="history-item" onclick="loadTask('${h.task_id}')">
|
||||
<span class="hi-ticker">${h.ticker}</span>
|
||||
<span class="hi-date">${h.date}</span>
|
||||
<span class="badge badge-pending" id="hbadge_${h.task_id}" style="font-size:11px">—</span>
|
||||
<span class="hi-time">${h.time}</span>
|
||||
</div>`).join('');
|
||||
|
||||
// Refresh badge statuses
|
||||
history.forEach(h => refreshHistoryBadge(h.task_id));
|
||||
}
|
||||
|
||||
async function refreshHistoryBadge(taskId) {
|
||||
try {
|
||||
const res = await fetch(`${API}/api/task/${taskId}`);
|
||||
if (!res.ok) {
|
||||
const el = document.getElementById('hbadge_' + taskId);
|
||||
if (el) { el.className = 'badge'; el.textContent = '已过期'; el.style.background = '#334155'; el.style.color = '#94a3b8'; }
|
||||
// 过期任务自动从历史中移除
|
||||
setTimeout(() => {
|
||||
removeFromHistory(taskId);
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
const task = await res.json();
|
||||
const el = document.getElementById('hbadge_' + taskId);
|
||||
if (el) {
|
||||
el.className = 'badge badge-' + task.status;
|
||||
el.textContent = { pending:'排队', running:'分析中', completed:'完成', failed:'失败' }[task.status] || task.status;
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
async function loadTask(taskId) {
|
||||
try {
|
||||
const res = await fetch(`${API}/api/task/${taskId}`);
|
||||
if (!res.ok) {
|
||||
alert('任务已过期,请重新提交分析');
|
||||
removeFromHistory(taskId);
|
||||
return;
|
||||
}
|
||||
const task = await res.json();
|
||||
showStatus(task.ticker, task.date, task.status);
|
||||
if (task.status === 'completed') {
|
||||
renderResult(task);
|
||||
} else if (task.status === 'pending' || task.status === 'running') {
|
||||
startPolling(taskId);
|
||||
}
|
||||
} catch(e) { alert('网络错误,请检查服务'); }
|
||||
}
|
||||
|
||||
function removeFromHistory(taskId) {
|
||||
history = history.filter(h => h.task_id !== taskId);
|
||||
localStorage.setItem('ta_history', JSON.stringify(history));
|
||||
renderHistory();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user