Fix strategy roll page JS broken by Jinja in static file.
Pass trading_session via inline page config, restore roll preview/execute handlers, and validate new stop-loss before preview. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -122,11 +122,13 @@
|
||||
btnExec.textContent = mode === 'market' ? '执行滚仓' : '提交监控';
|
||||
}
|
||||
if (btnPreview) {
|
||||
btnPreview.disabled = !inTradingSession && !isBreak;
|
||||
btnPreview.disabled = false;
|
||||
btnPreview.title = (!inTradingSession && !isBreak)
|
||||
? '休盘期间请切换为突破加仓'
|
||||
? '休盘可预览;市价加仓须交易时段内执行'
|
||||
: '';
|
||||
}
|
||||
var offHint = document.getElementById('roll-off-session-hint');
|
||||
if (offHint) offHint.hidden = inTradingSession || isBreak;
|
||||
}
|
||||
|
||||
function syncRollRiskHint() {
|
||||
@@ -203,7 +205,7 @@
|
||||
var rollPayload = null;
|
||||
var rollMonitorSel = document.getElementById('roll-monitor-select');
|
||||
var rollModeSel = document.getElementById('roll-add-mode');
|
||||
var inTradingSession = {{ 'true' if trading_session else 'false' }};
|
||||
var inTradingSession = !!(window.STRATEGY_PAGE && window.STRATEGY_PAGE.inTradingSession);
|
||||
|
||||
if (rollModeSel) rollModeSel.addEventListener('change', syncRollModeUi);
|
||||
if (rollMonitorSel) rollMonitorSel.addEventListener('change', syncRollRiskHint);
|
||||
@@ -212,19 +214,29 @@
|
||||
|
||||
if (btnRollP && rollForm) {
|
||||
btnRollP.addEventListener('click', function () {
|
||||
btnRollP.disabled = true;
|
||||
rollPayload = formData(rollForm);
|
||||
var sl = parseFloat(rollPayload.new_stop_loss);
|
||||
if (!sl || sl <= 0) {
|
||||
showPreview(rollPrev, '请填写新统一止损', false, false);
|
||||
if (btnRollE) btnRollE.hidden = true;
|
||||
return;
|
||||
}
|
||||
btnRollP.disabled = true;
|
||||
jsonPost('/api/strategy/roll/preview', rollPayload).then(function (d) {
|
||||
if (!d.ok) {
|
||||
showPreview(rollPrev, d.error, false, false);
|
||||
showPreview(rollPrev, d.error || '预览失败', false, false);
|
||||
btnRollE.hidden = true;
|
||||
return;
|
||||
}
|
||||
showPreview(rollPrev, formatRoll(d.preview), true, false);
|
||||
btnRollE.hidden = false;
|
||||
syncRollModeUi();
|
||||
}).catch(function () {
|
||||
showPreview(rollPrev, '预览请求失败,请稍后重试', false, false);
|
||||
if (btnRollE) btnRollE.hidden = true;
|
||||
}).finally(function () {
|
||||
btnRollP.disabled = false;
|
||||
syncRollModeUi();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user