修复地理位置漂移的BUG

This commit is contained in:
CN-JS-HuiBai
2026-04-05 17:05:15 +08:00
parent a9fe0f219a
commit dc865c6d9d
3 changed files with 152 additions and 14 deletions

View File

@@ -94,6 +94,7 @@
let currentSourceFilter = 'all';
let currentPage = 1;
let pageSize = 20;
let currentSort = { column: 'up', direction: 'desc' };
let myMap2D = null;
// ---- Initialize ----
@@ -161,6 +162,7 @@
// Server table row click delegator
dom.serverTableBody.addEventListener('click', (e) => {
// Don't trigger detail if clicking a button or something interactive inside (none currently)
const row = e.target.closest('tr');
if (row && !row.classList.contains('empty-row')) {
const instance = row.getAttribute('data-instance');
@@ -172,6 +174,18 @@
}
});
// Server table header sorting
const tableHeader = document.querySelector('.server-table thead');
if (tableHeader) {
tableHeader.addEventListener('click', (e) => {
const th = e.target.closest('th.sortable');
if (th) {
const column = th.getAttribute('data-sort');
handleHeaderSort(column);
}
});
}
// P95 Toggle
if (dom.legendP95) {
dom.legendP95.addEventListener('click', () => {
@@ -428,6 +442,7 @@
series: [{
type: 'effectScatter',
coordinateSystem: 'geo',
geoIndex: 0,
showEffectOn: 'render',
rippleEffect: { brushType: 'stroke', scale: 4, period: 4 },
symbolSize: 6,
@@ -485,7 +500,11 @@
}));
myMap2D.setOption({
series: [{ data: geoData }]
series: [{
coordinateSystem: 'geo',
geoIndex: 0,
data: geoData
}]
});
// Update footer stats
@@ -549,12 +568,60 @@
filtered = allServersData.filter(s => s.source === currentSourceFilter);
}
// Sort servers: online first, then alphabetically by name (job)
// Sort servers: online first, then by currentSort
filtered.sort((a, b) => {
if (a.up !== b.up) return a.up ? -1 : 1;
const nameA = a.job || '';
const nameB = b.job || '';
return nameA.localeCompare(nameB);
// Primary sort: Always put online servers first unless sorting by 'up' explicitly
if (currentSort.column !== 'up') {
if (a.up !== b.up) return a.up ? -1 : 1;
} else {
// Specifically sorting by status: Online vs Offline
if (a.up !== b.up) {
const val = a.up ? -1 : 1;
return currentSort.direction === 'asc' ? -val : val;
}
}
// Secondary sort based on user choice
let valA, valB;
switch (currentSort.column) {
case 'up':
return 0; // Already handled above
case 'job':
valA = a.job || '';
valB = b.job || '';
return currentSort.direction === 'asc' ? valA.localeCompare(valB) : valB.localeCompare(valA);
case 'source':
valA = a.source || '';
valB = b.source || '';
return currentSort.direction === 'asc' ? valA.localeCompare(valB) : valB.localeCompare(valA);
case 'cpu':
valA = a.cpuPercent || 0;
valB = b.cpuPercent || 0;
break;
case 'mem':
valA = a.memTotal > 0 ? (a.memUsed / a.memTotal) : 0;
valB = b.memTotal > 0 ? (b.memUsed / b.memTotal) : 0;
break;
case 'disk':
valA = a.diskTotal > 0 ? (a.diskUsed / a.diskTotal) : 0;
valB = b.diskTotal > 0 ? (b.diskUsed / b.diskTotal) : 0;
break;
case 'netRx':
valA = a.netRx || 0;
valB = b.netRx || 0;
break;
case 'netTx':
valA = a.netTx || 0;
valB = b.netTx || 0;
break;
default:
valA = a.job || '';
valB = b.job || '';
return valA.localeCompare(valB);
}
if (currentSort.direction === 'asc') return valA - valB;
return valB - valA;
});
const totalFiltered = filtered.length;
@@ -601,6 +668,31 @@
renderFilteredServers();
};
function handleHeaderSort(column) {
if (currentSort.column === column) {
// Toggle direction
currentSort.direction = currentSort.direction === 'asc' ? 'desc' : 'asc';
} else {
currentSort.column = column;
currentSort.direction = 'desc'; // Default to desc for most metrics
}
// Update UI headers
const headers = document.querySelectorAll('.server-table th.sortable');
headers.forEach(th => {
const col = th.getAttribute('data-sort');
if (col === currentSort.column) {
th.classList.add('active');
th.setAttribute('data-dir', currentSort.direction);
} else {
th.classList.remove('active');
th.removeAttribute('data-dir');
}
});
renderFilteredServers();
}
// ---- Server Table ----
function updateServerTable(servers) {
if (!servers || servers.length === 0) {