同步完成后自动刷新页面更新数据条数,修复持仓同步未提交事务,加大按钮间距

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-25 14:47:54 +08:00
parent 19203c050c
commit 012b220c60
3 changed files with 33 additions and 4 deletions
+6 -1
View File
@@ -5,7 +5,7 @@ from app.database import SessionLocal
from app.models import DailyBar, Contract from app.models import DailyBar, Contract
from app.engine.lock_strategy import compute_amp_5d 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() _lock = threading.Lock()
@@ -78,6 +78,8 @@ def sync_contract_bars_bg(contract_code: str) -> bool:
db.flush() db.flush()
_recompute_amp(db, code, from_date=min_date) _recompute_amp(db, code, from_date=min_date)
db.commit() db.commit()
with _lock:
_progress["result"] = inserted
finally: finally:
db.close() db.close()
@@ -132,6 +134,9 @@ def sync_positions_bg(contract_code: str) -> bool:
with _lock: with _lock:
_progress["done"] = i + 1 _progress["done"] = i + 1
_progress["label"] = f"同步持仓 {code} · {i + 1}/{total_missing}" _progress["label"] = f"同步持仓 {code} · {i + 1}/{total_missing}"
db.commit()
with _lock:
_progress["result"] = inserted
finally: finally:
db.close() db.close()
+27 -3
View File
@@ -69,8 +69,8 @@
</td> </td>
<td style="text-align:center;padding:6px 14px;"> <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> <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(--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;" onclick="syncPositions('{{ 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> </td>
</tr> </tr>
{% endfor %} {% endfor %}
@@ -225,8 +225,16 @@ function pollProgress() {
clearInterval(syncTimer); clearInterval(syncTimer);
syncTimer = null; syncTimer = null;
document.getElementById('sync-progress-bar').style.width = '100%'; 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 = ''; 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); }, 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> </script>
{% endblock %} {% endblock %}
BIN
View File
Binary file not shown.