fix: 添加自选功能;修复细节问题

alphaFuthures
Lxy 6 days ago
parent 46edd861b5
commit 36c33eb005

@ -216,6 +216,10 @@ def get_kline_data(symbol: str, period: str = "15", db: Session = Depends(get_db
def _get_futures_name(symbol: str) -> str:
"""根据合约代码获取品种名称"""
# 从合约代码中提取品种代码(去除数字部分)
import re
symbol_base = re.sub(r'\d+', '', symbol).upper()
name_map = {
"AU": "黄金", "AG": "白银", "CU": "", "AL": "",
"ZN": "", "NI": "", "SN": "", "PB": "",
@ -232,7 +236,7 @@ def _get_futures_name(symbol: str) -> str:
"IF": "沪深300", "IC": "中证500", "IH": "上证50", "IM": "中证1000",
"T": "10年期国债", "TF": "5年期国债", "TS": "2年期国债", "TL": "30年期国债",
}
return name_map.get(symbol, symbol)
return name_map.get(symbol_base, symbol)
def _get_suggestion(close: float, open: float, change_pct: float) -> str:

@ -132,7 +132,11 @@
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.code-box { width: 36px; height: 36px; background: #F5F5F7; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: var(--text-tertiary); margin-bottom: 8px; }
.card-left { display: flex; gap: 12px; align-items: flex-start; }
.code-box { width: 36px; height: 36px; background: #F5F5F7; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: var(--text-tertiary); }
.info-group { display: flex; flex-direction: column; }
.name-row { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 15px; }
.contract-code { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.price-area { text-align: right; }
.price { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.price.up { color: var(--color-up); }
@ -170,6 +174,10 @@
.support-resist .green { color: var(--color-down); }
.link { color: var(--color-brand); font-weight: 500; text-decoration: none; }
.link:hover { text-decoration: underline; }
.fav-icon { font-size: 15px; color: #D1D1D6; cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; user-select: none; }
.fav-icon:hover { color: #FF9F0A; }
.fav-icon.active { color: #FF9F0A; transform: scale(1.1); }
/* 详情视图样式 */
.view { display: none; }

@ -279,6 +279,14 @@ async function toggleWatch(symbol, name, event) {
}
}
function toggleFav(symbol, name, event) {
event.stopPropagation();
// 调用原有的toggleWatch函数处理API请求和数据更新
// toggleWatch 会重新渲染网格,星标状态会根据 watchedSymbols 自动更新
toggleWatch(symbol, name, event);
}
function getCurrentFilteredData() {
const activePill = document.querySelector('.pill.active');
const category = activePill ? activePill.dataset.category : 'all';
@ -512,10 +520,12 @@ function renderFuturesGrid(data) {
return `
<div class="card" onclick="showDetailView('${item.symbol}')">
<div class="card-header">
<div>
<div class="card-left">
<div class="code-box">${code}</div>
<div style="font-weight:600;">${item.name}</div>
<div style="font-size:12px; color:var(--text-tertiary);">${item.symbol}</div>
<div class="info-group">
<div class="name-row">${item.name} <span class="fav-icon ${isWatched ? 'active' : ''}" onclick="toggleFav('${item.symbol}', '${item.name}', event)"></span></div>
<div class="contract-code">${item.symbol}</div>
</div>
</div>
<div class="price-area">
<div class="price ${priceClass}">¥${formatNumber(item.price)}</div>

@ -1,24 +1,16 @@
{
"futures": {
"原油": "SC2606",
"燃油": "FU2606",
"低硫燃油": "LU2607",
"沪银": "AG2606",
"沪金": "AU2606",
"沪铜": "CU2606",
"沪镍": "NI2606",
"沪锡": "SN2606",
"沪铝": "AL2606",
"沪锌": "PB2606",
"氧化铝": "AO2609",
"工业硅": "SI2609",
"多晶硅": "PS2606",
"碳酸锂": "LC2609",
"纯碱": "SA2609",
"烧碱": "SH2607",
"玻璃": "FG2609",
"橡胶": "RU2609",
"合成橡胶": "BR2606",
"20号胶": "NR2607",
"螺纹钢": "RB2610",
"铁矿石": "I2609",
@ -31,7 +23,21 @@
"尿素": "UR2609",
"中证1000": "IM2606",
"焦煤": "JM2609",
"焦炭": "J2609"
"焦炭": "J2609",
"沪银": "AG2608",
"沪金": "AU2608",
"合成橡胶": "BR2607",
"沪铜": "CU2607",
"沪铝": "AL2607",
"原油": "SC2607",
"沪锌": "ZN2607",
"沪铅": "PB2607",
"铝合金": "AD2607",
"热卷": "hc2610",
"PVC": "v2609",
"乙二醇": "eg2609",
"集运欧线": "ec2606",
"多晶硅": "PS2609"
},
"stock": {}
}

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save