Align trade record verify/edit UX with Binance instance single-row prompts.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-30 22:02:48 +08:00
parent b6b7bfb248
commit 32838daae0
5 changed files with 259 additions and 139 deletions
+26
View File
@@ -47,6 +47,9 @@
html += '</div>';
html += '<div class="records-detail-actions">';
if (data.id) {
html += '<button type="button" class="btn-records-action review-edit-btn" disabled>核对修改</button>';
}
if (data.fill_review_url) {
html += '<a href="' + data.fill_review_url + '" class="btn-fill">填入复盘</a>';
}
@@ -56,6 +59,29 @@
html += '</div>';
body.innerHTML = html;
var reviewBtn = body.querySelector('.review-edit-btn');
if (reviewBtn && data.id) {
reviewBtn.setAttribute('data-trade-edit', JSON.stringify({
id: data.id,
symbol_name: data.symbol_name || data.symbol,
monitor_type: data.monitor_type,
direction: data.direction_code || (data.direction === '做多' ? 'long' : 'short'),
entry_price: data.entry_price,
close_price: data.close_price,
stop_loss: data.stop_loss,
take_profit: data.take_profit,
lots: data.lots,
margin: data.margin,
holding_minutes: data.holding_minutes,
open_time: data.open_time,
close_time: data.close_time,
pnl: data.pnl,
result: data.result
}));
}
if (typeof window.toggleTradeReviewMode === 'function') {
window.toggleTradeReviewMode();
}
mask.classList.add('show');
}
+85 -32
View File
@@ -1,46 +1,99 @@
/* Copyright (c) 2025-2026 马建军. All rights reserved.
* 专有软件 — 未经授权禁止复制、传播、转售。
* 详见 LICENSE.zh-CN.txt
* 交易记录核对修改 — 与币安实例一致:开关启用后,逐条弹窗核对
*/
(function () {
var switchEl = document.getElementById('trade-edit-switch');
if (!switchEl) return;
function setEditMode(on) {
document.querySelectorAll('.cell-edit-hide').forEach(function (el) {
el.style.display = on ? 'none' : '';
});
document.querySelectorAll('.cell-edit-show').forEach(function (el) {
if (el.type === 'hidden') return;
el.style.display = on ? '' : 'none';
});
document.querySelectorAll('.trade-save-btn').forEach(function (btn) {
function syncReviewEditButtons() {
var on = !!switchEl.checked;
document.querySelectorAll('.review-edit-btn').forEach(function (btn) {
btn.disabled = !on;
});
}
switchEl.addEventListener('change', function () {
setEditMode(switchEl.checked);
});
function normalizeDatetime(v) {
var raw = String(v || '').trim().replace('T', ' ');
var m = raw.match(/^(\d{4}-\d{2}-\d{2})[ ](\d{2}:\d{2})(:\d{2})?/);
if (!m) return raw.slice(0, 19);
return m[1] + ' ' + m[2] + ':' + (m[3] ? m[3].slice(1) : '00');
}
document.querySelectorAll('.trade-save-btn').forEach(function (btn) {
btn.addEventListener('click', function () {
var row = btn.closest('tr[data-trade-id]');
if (!row) return;
var id = row.getAttribute('data-trade-id');
var form = document.createElement('form');
form.method = 'POST';
form.action = '/update_trade/' + id;
row.querySelectorAll('.cell-edit-show').forEach(function (el) {
if (!el.name) return;
var input = document.createElement('input');
input.type = 'hidden';
input.name = el.name;
input.value = el.value;
form.appendChild(input);
});
document.body.appendChild(form);
form.submit();
function fmtPrice(v) {
if (v === null || v === undefined || v === '') return '';
return String(v);
}
function editTradeRecordReview(t) {
if (!t || !t.id) return;
var opened = prompt('开仓时间(YYYY-MM-DD HH:MM:SS)', normalizeDatetime(t.open_time));
if (opened === null) return;
var closed = prompt('平仓时间(YYYY-MM-DD HH:MM:SS)', normalizeDatetime(t.close_time));
if (closed === null) return;
var entry = prompt('开仓价(核对后用于统计)', fmtPrice(t.entry_price));
if (entry === null) return;
var closePx = prompt('平仓价(跨日持仓请以柜台成交为准)', fmtPrice(t.close_price));
if (closePx === null) return;
var stopLoss = prompt('止损价格(核对后用于统计)', fmtPrice(t.stop_loss));
if (stopLoss === null) return;
var takeProfit = prompt('止盈价格(核对后用于统计)', fmtPrice(t.take_profit));
if (takeProfit === null) return;
var pnl = prompt('盈亏(元,可手工核对后填写)', String(t.pnl != null ? t.pnl : ''));
if (pnl === null) return;
var result = prompt(
'结果(止盈/止损/保本止盈/移动止盈/手动平仓/CTP同步)',
String(t.result || '手动平仓')
);
if (result === null) return;
var form = document.createElement('form');
form.method = 'POST';
form.action = '/update_trade/' + t.id;
var fields = {
symbol_name: t.symbol_name || t.symbol || '',
monitor_type: t.monitor_type || '',
direction: t.direction || 'long',
entry_price: entry,
close_price: closePx,
stop_loss: stopLoss,
take_profit: takeProfit,
lots: t.lots != null ? t.lots : '',
margin: t.margin != null ? t.margin : '',
holding_minutes: t.holding_minutes != null ? t.holding_minutes : 0,
open_time: normalizeDatetime(opened),
close_time: normalizeDatetime(closed),
pnl: pnl,
result: String(result || '').trim() || '手动平仓',
};
Object.keys(fields).forEach(function (name) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = fields[name];
form.appendChild(input);
});
document.body.appendChild(form);
form.submit();
}
window.editTradeRecordReview = editTradeRecordReview;
window.toggleTradeReviewMode = syncReviewEditButtons;
switchEl.addEventListener('change', syncReviewEditButtons);
switchEl.addEventListener('input', syncReviewEditButtons);
syncReviewEditButtons();
window.addEventListener('pageshow', syncReviewEditButtons);
document.addEventListener('click', function (e) {
var btn = e.target.closest('.review-edit-btn');
if (!btn || btn.disabled) return;
e.preventDefault();
e.stopPropagation();
var raw = btn.getAttribute('data-trade-edit');
if (!raw) return;
try {
editTradeRecordReview(JSON.parse(raw));
} catch (err) { /* ignore */ }
});
})();