Include auto-refresh script on trade review list page.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -103,3 +103,46 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
(function () {
|
||||
var fpUrl = {{ url_for('records_fingerprint')|tojson }};
|
||||
var machineId = {{ (selected_machine_id or '')|tojson }};
|
||||
var hint = document.getElementById('records-live-hint');
|
||||
var lastFp = null;
|
||||
var q = machineId ? ('?machine_id=' + encodeURIComponent(machineId)) : '';
|
||||
|
||||
function setHint(text, kind) {
|
||||
if (!hint) return;
|
||||
hint.textContent = text;
|
||||
hint.className = 'tag' + (kind ? ' ' + kind : '');
|
||||
}
|
||||
|
||||
function tick() {
|
||||
fetch(fpUrl + q, { credentials: 'same-origin' })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (d) {
|
||||
if (!d || !d.ok) return;
|
||||
if (lastFp === null) {
|
||||
lastFp = d.fp;
|
||||
setHint('自动刷新 · 监听中', 'green');
|
||||
return;
|
||||
}
|
||||
if (d.fp !== lastFp) {
|
||||
setHint('有新成交,刷新中…', 'green');
|
||||
location.reload();
|
||||
return;
|
||||
}
|
||||
setHint('自动刷新 · 监听中', 'green');
|
||||
})
|
||||
.catch(function () {
|
||||
setHint('自动刷新暂时不可用', '');
|
||||
});
|
||||
}
|
||||
|
||||
tick();
|
||||
setInterval(tick, 3000);
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user