/* 仪表盘 */
async function loadOverview() {
try {
const d = await api('/api/overview');
renderIndexes(d.indexes, d.stat);
renderTop(d.top);
renderHeat(d.heat);
renderNews(d.news);
renderWatch(d.watchlist);
} catch (e) {
$('#indexBox').innerHTML = '
加载失败:' + escapeHtml(e.message) + '
';
}
}
function renderIndexes(indexes, stat) {
const cards = indexes.map(ix => {
const cls = pctClass(ix.chg);
return `
${ix.label}
${Number(ix.value).toFixed(2)}
${fmtPct(ix.chg)}
`;
}).join('');
const s = stat || {};
$('#indexBox').innerHTML = cards + `
市场情绪
成交额
${fmtAmountYi(s.amount_yi)}
股票池 ${s.total || 0} 只 · 综合评分由 趋势/动量/技术/量能/消息/机构 六因子加权得出
`;
}
function renderTop(list) {
if (!list || !list.length) { $('#topRecBox').innerHTML = '暂无数据
'; return; }
$('#topRecBox').innerHTML = `
| 排名 | 股票 | 现价 | 今日 | 评分 | 评级 | 推荐理由 |
${list.map((it, i) => `
| ${i + 1} |
${it.name} ${it.code} · ${it.industry} |
${it.close} |
${fmtPct(it.change_pct)} |
${it.score.total} |
${it.score.rating} |
${escapeHtml((it.reasons || []).join(';'))} |
`).join('')}
`;
}
function renderHeat(heat) {
if (!heat || !heat.length) { $('#heatBox').innerHTML = '暂无数据
'; return; }
const max = Math.max(...heat.map(h => Math.abs(h.chg)), 0.01);
$('#heatBox').innerHTML = heat.map(h => {
const w = Math.min(100, Math.abs(h.chg) / max * 100);
const cls = pctClass(h.chg);
return `
${escapeHtml(h.industry)} (${h.cnt})
${fmtPct(h.chg)}
`;
}).join('');
}
function renderNews(news) {
if (!news || !news.length) { $('#newsBox').innerHTML = '暂无数据
'; return; }
$('#newsBox').innerHTML = news.map(n => `
${escapeHtml(n.title)}
${n.category}
${n.sentiment > 0 ? '利好' : n.sentiment < 0 ? '利空' : '中性'}
${escapeHtml(n.source)}${n.publish_date}
`).join('');
}
function renderWatch(list) {
if (!list || !list.length) {
$('#watchBox').innerHTML = ``;
return;
}
$('#watchBox').innerHTML = `
| 股票 | 现价 | 今日 | 评分 | 评级 |
${list.map(it => `
| ${it.name} ${it.code} |
${it.close} |
${fmtPct(it.change_pct)} |
${it.score} |
${it.rating} |
`).join('')}
`;
}
loadOverview();