skyfffire 2 mēneši atpakaļ
vecāks
revīzija
b7d1832e3c
1 mainītis faili ar 37 papildinājumiem un 21 dzēšanām
  1. 37 21
      monitor.html

+ 37 - 21
monitor.html

@@ -143,13 +143,11 @@
             function renderHistoryDataTable(data) {
             function renderHistoryDataTable(data) {
                 const tableContainer = document.getElementById('history-table');
                 const tableContainer = document.getElementById('history-table');
     
     
-                // 更简单的检测逻辑 - 销毁旧表格
-                if (historyDataTable) {
-                    historyDataTable.destroy();
-                    historyDataTable = null;
-                }
-
                 if (!data || data.length === 0) {
                 if (!data || data.length === 0) {
+                    if (historyDataTable) {
+                        historyDataTable.destroy();
+                        historyDataTable = null;
+                    }
                     tableContainer.innerHTML = '<thead><tr><th>交易对</th><th>状态</th><th>利润</th><th>创建时间</th><th>操作</th></tr></thead><tbody><tr><td colspan="5" class="text-center p-4 text-gray-500">没有历史记录。</td></tr></tbody>';
                     tableContainer.innerHTML = '<thead><tr><th>交易对</th><th>状态</th><th>利润</th><th>创建时间</th><th>操作</th></tr></thead><tbody><tr><td colspan="5" class="text-center p-4 text-gray-500">没有历史记录。</td></tr></tbody>';
                     historyCountBadge.textContent = 0;
                     historyCountBadge.textContent = 0;
                     return;
                     return;
@@ -171,22 +169,40 @@
 
 
                 historyCountBadge.textContent = data.length;
                 historyCountBadge.textContent = data.length;
                 
                 
-                historyDataTable = new simpleDatatables.DataTable(tableContainer, {
-                    data: { headings, data: tableData },
-                    paging: false,
-                    perPageSelect: false,
-                    searchable: true,
-                    labels: { placeholder: "搜索...", noRows: "未找到记录" },
-                    columns: [ 
-                        { select: 2, type: 'number' },
-                        { select: 3, type: 'date', format: "YYYY-MM-DD HH:mm:ss.SSS" },
-                        { select: 4, sortable: false }
-                    ]
-                });
+                // 如果 DataTable 已存在,先检查数据是否有变化
+                if (historyDataTable) {
+                    // 简单的数据比较(可以根据需要优化)
+                    const currentDataLength = historyDataTable.data.data.length;
+                    if (currentDataLength !== tableData.length) {
+                        // 数据量发生变化,需要重建
+                        historyDataTable.destroy();
+                        historyDataTable = null;
+                        tableContainer.innerHTML = '';
+                    } else {
+                        // 数据量相同,可能不需要重建(这里可以做更细致的比较)
+                        return;
+                    }
+                }
                 
                 
-                historyDataTable.on('datatable.init', () => {
-                    historyDataTable.columns.sort(3, 'desc');
-                });
+                // 创建新的 DataTable
+                setTimeout(() => {
+                    historyDataTable = new simpleDatatables.DataTable(tableContainer, {
+                        data: { headings, data: tableData },
+                        paging: false,
+                        perPageSelect: false,
+                        searchable: true,
+                        labels: { placeholder: "搜索...", noRows: "未找到记录" },
+                        columns: [ 
+                            { select: 2, type: 'number' },
+                            { select: 3, type: 'date', format: "YYYY-MM-DD HH:mm:ss.SSS" },
+                            { select: 4, sortable: false }
+                        ]
+                    });
+                    
+                    historyDataTable.on('datatable.init', () => {
+                        historyDataTable.columns.sort(3, 'desc');
+                    });
+                }, 50);
             }
             }
 
 
             // --- Main Logic Functions ---
             // --- Main Logic Functions ---