From 5948e5e4a745f4fdc784026f4b17eb35c3c2a48c Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 08 Jul 2026 11:50:45 +0800
Subject: [PATCH] refactor(gate-config): 替换jQuery选择器为原生DOM方法并优化错误处理
---
src/main/resources/static/gate-config.html | 34 +++++++++++++++++-----------------
1 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/src/main/resources/static/gate-config.html b/src/main/resources/static/gate-config.html
index 3313236..42c6f5d 100644
--- a/src/main/resources/static/gate-config.html
+++ b/src/main/resources/static/gate-config.html
@@ -136,6 +136,8 @@
let logLines = [];
const logPanel = document.getElementById('logPanel');
+function byId(id) { return document.getElementById(id); }
+
function toast(msg, type) {
const t = document.getElementById('toast');
t.innerHTML = msg; t.className = 'toast ' + type;
@@ -181,7 +183,7 @@
const key = document.getElementById('inputApiKey').value.trim();
if (!key) return toast('请输入 API Key', 'error');
try {
- const d = await fetchApi(API + '/config/load?apiKey=' + encodeURIComponent(key));
+ const d = await fetchApi(API + '/config/load?apiKey=' + encodeURIComponent(key), { method: 'POST' });
fillForm(d);
toast('配置已加载', 'success');
} catch(e) {
@@ -197,29 +199,27 @@
}
function fillForm(d) {
- document.getElementById('gridRate').value = d.gridRate || '';
- document.getElementById('expectedProfit').value = d.expectedProfit || '';
- document.getElementById('maxLoss').value = d.maxLoss || '';
- document.getElementById('baseQuantity').value = d.baseQuantity || '';
- document.getElementById('quantity').value = d.quantity || '';
- document.getElementById('maxPositionSize').value = d.maxPositionSize ?? '';
- document.getElementById('stopLossCount').value = d.stopLossCount ?? '';
+ byId('gridRate').value = d.gridRate || '';
+ byId('expectedProfit').value = d.expectedProfit || '';
+ byId('maxLoss').value = d.maxLoss || '';
+ byId('baseQuantity').value = d.baseQuantity || '';
+ byId('quantity').value = d.quantity || '';
+ byId('maxPositionSize').value = d.maxPositionSize ?? '';
+ byId('stopLossCount').value = d.stopLossCount ?? '';
}
function collectForm() {
return {
apiKey: currentApiKey,
- gridRate: parseFloat($('#gridRate').value) || 0,
- expectedProfit: parseFloat($('#expectedProfit').value) || 0,
- maxLoss: parseFloat($('#maxLoss').value) || 0,
- baseQuantity: $('#baseQuantity').value,
- quantity: $('#quantity').value,
- maxPositionSize: parseInt($('#maxPositionSize').value) || 0,
- stopLossCount: parseInt($('#stopLossCount').value) || 0
+ gridRate: parseFloat(byId('gridRate').value) || 0,
+ expectedProfit: parseFloat(byId('expectedProfit').value) || 0,
+ maxLoss: parseFloat(byId('maxLoss').value) || 0,
+ baseQuantity: byId('baseQuantity').value,
+ quantity: byId('quantity').value,
+ maxPositionSize: parseInt(byId('maxPositionSize').value) || 0,
+ stopLossCount: parseInt(byId('stopLossCount').value) || 0
};
}
-
-function $(id) { return document.getElementById(id); }
async function saveConfig() {
if (!currentApiKey) return toast('请先输入 API Key', 'error');
--
Gitblit v1.9.1