关键位与今日计划列表实时现价及距区间距离(1s轮询)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-15 14:30:01 +08:00
parent 58020b6e9c
commit 38ff40111a
6 changed files with 177 additions and 7 deletions
+39
View File
@@ -0,0 +1,39 @@
(function () {
var timer = null;
function fmtDist(v) {
if (v === null || v === undefined) return '--';
return v.toFixed(2);
}
function pollPrices() {
var list = document.getElementById('key-monitor-list');
if (!list || !list.querySelector('.key-item')) return;
fetch('/api/key_prices')
.then(function (r) { return r.json(); })
.then(function (rows) {
rows.forEach(function (row) {
var el = list.querySelector('.key-item[data-key-id="' + row.id + '"]');
if (!el) return;
var priceEl = el.querySelector('.live-price');
var upEl = el.querySelector('.dist-up');
var downEl = el.querySelector('.dist-down');
if (priceEl) {
priceEl.textContent = row.price != null ? row.price : '--';
}
if (upEl) upEl.textContent = fmtDist(row.dist_upper);
if (downEl) downEl.textContent = fmtDist(row.dist_lower);
});
})
.catch(function () { /* ignore */ });
}
function startPolling() {
if (timer) clearInterval(timer);
pollPrices();
timer = setInterval(pollPrices, 1000);
}
document.addEventListener('DOMContentLoaded', startPolling);
})();
+45
View File
@@ -0,0 +1,45 @@
(function () {
var timer = null;
function fmtDist(v) {
if (v === null || v === undefined) return '--';
return v.toFixed(2);
}
function pollPrices() {
var list = document.getElementById('plan-monitor-list');
if (!list || !list.querySelector('.plan-item')) return;
fetch('/api/plan_prices')
.then(function (r) { return r.json(); })
.then(function (rows) {
rows.forEach(function (row) {
var el = list.querySelector('.plan-item[data-plan-id="' + row.id + '"]');
if (!el) return;
var priceEl = el.querySelector('.live-price');
var distEl = el.querySelector('.live-dist');
var upEl = el.querySelector('.dist-up');
var downEl = el.querySelector('.dist-down');
if (priceEl) {
priceEl.textContent = row.price != null ? row.price : '--';
}
if (row.in_zone && distEl) {
distEl.innerHTML = '<span class="text-profit" style="font-weight:600">在区间内</span>';
} else if (distEl && upEl && downEl) {
distEl.innerHTML =
'距上 <span class="dist-up">' + fmtDist(row.dist_upper) + '</span>' +
' · 距下 <span class="dist-down">' + fmtDist(row.dist_lower) + '</span>';
}
});
})
.catch(function () { /* ignore */ });
}
function startPolling() {
if (timer) clearInterval(timer);
pollPrices();
timer = setInterval(pollPrices, 1000);
}
document.addEventListener('DOMContentLoaded', startPolling);
})();