|
|
@@ -143,20 +143,15 @@
|
|
|
function renderHistoryDataTable(data) {
|
|
|
const tableContainer = document.getElementById('history-table');
|
|
|
|
|
|
- // 始终销毁现有的DataTable(如果存在)
|
|
|
- if (historyDataTable) {
|
|
|
- try {
|
|
|
- historyDataTable.destroy();
|
|
|
- } catch (e) {
|
|
|
- console.warn("销毁DataTable时出错:", e);
|
|
|
- }
|
|
|
- historyDataTable = null;
|
|
|
- }
|
|
|
-
|
|
|
- // 清空容器
|
|
|
- tableContainer.innerHTML = '';
|
|
|
-
|
|
|
if (!data || data.length === 0) {
|
|
|
+ if (historyDataTable) {
|
|
|
+ try {
|
|
|
+ historyDataTable.destroy();
|
|
|
+ } catch (e) {
|
|
|
+ console.warn("销毁DataTable时出错:", e);
|
|
|
+ }
|
|
|
+ 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>';
|
|
|
historyCountBadge.textContent = 0;
|
|
|
return;
|
|
|
@@ -178,7 +173,25 @@
|
|
|
|
|
|
historyCountBadge.textContent = data.length;
|
|
|
|
|
|
- // 延迟创建新的DataTable,确保DOM完全清理
|
|
|
+ // 安全地检查和销毁现有的 DataTable
|
|
|
+ if (historyDataTable) {
|
|
|
+ try {
|
|
|
+ // 更安全的数据比较
|
|
|
+ const currentDataLength = historyDataTable.data && historyDataTable.data.data ?
|
|
|
+ historyDataTable.data.data.length : 0;
|
|
|
+
|
|
|
+ // 总是重建,避免复杂的数据比较逻辑
|
|
|
+ historyDataTable.destroy();
|
|
|
+ } catch (e) {
|
|
|
+ console.warn("处理现有DataTable时出错:", e);
|
|
|
+ }
|
|
|
+ historyDataTable = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清空容器
|
|
|
+ tableContainer.innerHTML = '';
|
|
|
+
|
|
|
+ // 创建新的 DataTable
|
|
|
setTimeout(() => {
|
|
|
try {
|
|
|
historyDataTable = new simpleDatatables.DataTable(tableContainer, {
|
|
|
@@ -198,9 +211,34 @@
|
|
|
historyDataTable.columns.sort(3, 'desc');
|
|
|
});
|
|
|
} catch (e) {
|
|
|
- console.error("创建DataTable失败:", e);
|
|
|
+ console.error("创建DataTable时出错:", e);
|
|
|
+ // 如果创建失败,回退到简单的HTML表格
|
|
|
+ tableContainer.innerHTML = `
|
|
|
+ <table class="min-w-full text-sm">
|
|
|
+ <thead class="bg-gray-50">
|
|
|
+ <tr>
|
|
|
+ <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">交易对</th>
|
|
|
+ <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">状态</th>
|
|
|
+ <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">利润</th>
|
|
|
+ <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">创建时间</th>
|
|
|
+ <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">操作</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody class="divide-y divide-gray-200">
|
|
|
+ ${tableData.map(row => `
|
|
|
+ <tr class="hover:bg-gray-50">
|
|
|
+ <td class="px-3 py-2 whitespace-nowrap">${row[0]}</td>
|
|
|
+ <td class="px-3 py-2 whitespace-nowrap">${row[1]}</td>
|
|
|
+ <td class="px-3 py-2 whitespace-nowrap">${row[2] !== null ? row[2] : 'N/A'}</td>
|
|
|
+ <td class="px-3 py-2 whitespace-nowrap">${row[3]}</td>
|
|
|
+ <td class="px-3 py-2 whitespace-nowrap">${row[4]}</td>
|
|
|
+ </tr>
|
|
|
+ `).join('')}
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ `;
|
|
|
}
|
|
|
- }, 100);
|
|
|
+ }, 100); // 增加延迟到100ms,确保DOM完全更新
|
|
|
}
|
|
|
|
|
|
// --- Main Logic Functions ---
|