同步完成后自动刷新页面更新数据条数,修复持仓同步未提交事务,加大按钮间距
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@ from app.database import SessionLocal
|
||||
from app.models import DailyBar, Contract
|
||||
from app.engine.lock_strategy import compute_amp_5d
|
||||
|
||||
_progress = {"running": False, "label": "", "done": 0, "total": 0, "finished": False}
|
||||
_progress = {"running": False, "label": "", "done": 0, "total": 0, "result": 0, "finished": False}
|
||||
_lock = threading.Lock()
|
||||
|
||||
|
||||
@@ -78,6 +78,8 @@ def sync_contract_bars_bg(contract_code: str) -> bool:
|
||||
db.flush()
|
||||
_recompute_amp(db, code, from_date=min_date)
|
||||
db.commit()
|
||||
with _lock:
|
||||
_progress["result"] = inserted
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
@@ -132,6 +134,9 @@ def sync_positions_bg(contract_code: str) -> bool:
|
||||
with _lock:
|
||||
_progress["done"] = i + 1
|
||||
_progress["label"] = f"同步持仓 {code} · {i + 1}/{total_missing} 天"
|
||||
db.commit()
|
||||
with _lock:
|
||||
_progress["result"] = inserted
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@@ -69,8 +69,8 @@
|
||||
</td>
|
||||
<td style="text-align:center;padding:6px 14px;">
|
||||
<a href="/contracts/{{ c.code }}" style="color:var(--accent);text-decoration:none;font-size:0.82rem;">查看</a>
|
||||
<button style="background:none;border:none;color:var(--accent);cursor:pointer;font-size:0.82rem;margin-left:4px;" onclick="syncBars('{{ c.code }}')">↻ 行情</button>
|
||||
<button style="background:none;border:none;color:var(--success);cursor:pointer;font-size:0.82rem;" onclick="syncPositions('{{ c.code }}')">↻ 持仓</button>
|
||||
<button style="background:none;border:none;color:var(--accent);cursor:pointer;font-size:0.82rem;margin-left:12px;" onclick="syncBars('{{ c.code }}')">↻ 行情</button>
|
||||
<button style="background:none;border:none;color:var(--success);cursor:pointer;font-size:0.82rem;margin-left:10px;" onclick="syncPositions('{{ c.code }}')">↻ 持仓</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
@@ -225,8 +225,16 @@ function pollProgress() {
|
||||
clearInterval(syncTimer);
|
||||
syncTimer = null;
|
||||
document.getElementById('sync-progress-bar').style.width = '100%';
|
||||
document.getElementById('sync-progress-label').textContent = data.label + ' ✓';
|
||||
var resultText = data.result > 0 ? ' · +' + data.result : '';
|
||||
document.getElementById('sync-progress-label').textContent = data.label + ' ✓' + resultText;
|
||||
document.getElementById('sync-progress-pct').textContent = '';
|
||||
// Remember which product headers are expanded before reload
|
||||
var expanded = [];
|
||||
document.querySelectorAll('.product-body').forEach(function(b, i) {
|
||||
if (b.style.display === 'block') expanded.push(i);
|
||||
});
|
||||
try { sessionStorage.setItem('ft-expanded', JSON.stringify(expanded)); } catch(e) {}
|
||||
setTimeout(function() { location.reload(); }, 1200);
|
||||
}, delay);
|
||||
}
|
||||
});
|
||||
@@ -268,5 +276,21 @@ function toggleProduct(header) {
|
||||
}
|
||||
}
|
||||
|
||||
// Restore expanded accordion state after reload
|
||||
(function() {
|
||||
try {
|
||||
var expanded = JSON.parse(sessionStorage.getItem('ft-expanded') || '[]');
|
||||
var bodies = document.querySelectorAll('.product-body');
|
||||
expanded.forEach(function(i) {
|
||||
if (bodies[i]) {
|
||||
bodies[i].style.display = 'block';
|
||||
var arrow = bodies[i].previousElementSibling.querySelector('.collapse-arrow');
|
||||
if (arrow) arrow.style.transform = 'rotate(0deg)';
|
||||
}
|
||||
});
|
||||
sessionStorage.removeItem('ft-expanded');
|
||||
} catch(e) {}
|
||||
})();
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user