// 测试信息页 function toSpeed(v) { if (v === null || v === undefined || v === '') return '-'; return (parseFloat(v) / 10).toFixed(1); } let currentPage = 1; let totalPages = 1; async function searchData(page = 1) { currentPage = page; const serial = document.getElementById("search-serial").value; const dateFrom = document.getElementById("search-date-from").value; const dateTo = document.getElementById("search-date-to").value; const params = new URLSearchParams({ page, per_page: 20 }); if (serial) params.set("serial", serial); if (dateFrom) params.set("date_from", dateFrom); if (dateTo) params.set("date_to", dateTo); try { const resp = await fetch(`/api/test-data?${params}`); const data = await resp.json(); renderTable(data.records); totalPages = data.pages; renderPagination(); } catch (e) { console.error("查询失败:", e); } } function renderTable(records) { const tbody = document.querySelector("#test-data-table tbody"); if (!records.length) { tbody.innerHTML = '暂无数据'; return; } tbody.innerHTML = records.map(r => ` ${r.id} ${r.serial || '-'} ${r.dpg430_addr} ${r.sub_type === 1 ? 'PD132' : r.sub_type === 2 ? 'DLD110' : '-'} ${r.str_type || '-'} ${r.iffinish === '1' ? '是' : '否'} ${r.fault_info || '无'} ${r.relay_out || '无'} ${r.ppvalue?.toFixed(2) || '-'} ${r.idle_freq || '-'} ${r.enter_freq || '-'} ${r.exit_freq || '-'} ${r.enter_dist || '-'} ${r.exit_dist || '-'} ${toSpeed(r.enter_speed)} ${toSpeed(r.exit_speed)} ${r.create_time || '-'} `).join(""); } function renderPagination() { const div = document.getElementById("pagination"); let html = ""; html += ``; for (let i = 1; i <= totalPages; i++) { if (i === currentPage) { html += ``; } else { html += ``; } } html += ``; div.innerHTML = html; } function exportCSV() { const serial = document.getElementById("search-serial").value; const dateFrom = document.getElementById("search-date-from").value; const dateTo = document.getElementById("search-date-to").value; const params = new URLSearchParams(); if (serial) params.set("serial", serial); if (dateFrom) params.set("date_from", dateFrom); if (dateTo) params.set("date_to", dateTo); window.location.href = `/api/test-data/export?${params}`; } // 初始加载 searchData(1);