Administrator
4 hours ago 5948e5e4a745f4fdc784026f4b17eb35c3c2a48c
refactor(gate-config): 替换jQuery选择器为原生DOM方法并优化错误处理

- 将$函数重命名为byId以避免与jQuery冲突
- 使用document.getElementById替代自定义$函数获取DOM元素
- 修改配置加载逻辑,当apiKey不存在时返回错误信息而不是创建空对象
- 统一表单填充和数据收集方法中的元素获取方式
2 files modified
32 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateConfigController.java 2 ●●● patch | view | raw | blame | history
src/main/resources/static/gate-config.html 30 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateConfigController.java
@@ -38,7 +38,7 @@
        }
        GateConfigDTO dto = persistenceService.load(apiKey);
        if (dto == null) {
            dto = new GateConfigDTO();
            return Result.fail("apiKey 错误,未找到该配置");
        }
        dto.setApiKey(apiKey);
        return Result.ok(dto);
src/main/resources/static/gate-config.html
@@ -136,7 +136,7 @@
let logLines = [];
const logPanel = document.getElementById('logPanel');
function $(id) { return document.getElementById(id); }
function byId(id) { return document.getElementById(id); }
function toast(msg, type) {
    const t = document.getElementById('toast');
@@ -199,25 +199,25 @@
}
function fillForm(d) {
    $('#gridRate').value = d.gridRate || '';
    $('#expectedProfit').value = d.expectedProfit || '';
    $('#maxLoss').value = d.maxLoss || '';
    $('#baseQuantity').value = d.baseQuantity || '';
    $('#quantity').value = d.quantity || '';
    $('#maxPositionSize').value = d.maxPositionSize ?? '';
    $('#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
    };
}