优化修复

This commit is contained in:
Alex Yang
2026-01-17 01:18:03 +08:00
parent cdac4fcf43
commit ac96c7c10b
57 changed files with 895 additions and 1252132 deletions

View File

@@ -157,7 +157,15 @@ function processRealTimeData(stats) {
// 更新新卡片数据
if (document.getElementById('avg-response-time')) {
const responseTime = stats.avgResponseTime ? stats.avgResponseTime.toFixed(2) + 'ms' : '---';
// 首先尝试从stats.dns.AvgResponseTime获取然后尝试stats.avgResponseTime
let avgResponseTime = null;
if (stats.dns && stats.dns.AvgResponseTime !== undefined) {
avgResponseTime = stats.dns.AvgResponseTime;
} else if (stats.avgResponseTime !== undefined) {
avgResponseTime = stats.avgResponseTime;
}
const responseTime = avgResponseTime ? avgResponseTime.toFixed(2) + 'ms' : '---';
// 计算响应时间趋势
let responsePercent = '---';
@@ -176,10 +184,10 @@ function processRealTimeData(stats) {
}
}
if (stats.avgResponseTime !== undefined && stats.avgResponseTime !== null) {
if (avgResponseTime !== undefined && avgResponseTime !== null) {
// 首次加载时初始化历史数据,不计算趋势
if (window.dashboardHistoryData.prevResponseTime === undefined || window.dashboardHistoryData.prevResponseTime === null) {
window.dashboardHistoryData.prevResponseTime = stats.avgResponseTime;
window.dashboardHistoryData.prevResponseTime = avgResponseTime;
responsePercent = '0.0%';
trendIcon = '•';
trendClass = 'text-gray-500';
@@ -191,7 +199,7 @@ function processRealTimeData(stats) {
const prevResponseTime = window.dashboardHistoryData.prevResponseTime;
// 计算变化百分比
const changePercent = ((stats.avgResponseTime - prevResponseTime) / prevResponseTime) * 100;
const changePercent = ((avgResponseTime - prevResponseTime) / prevResponseTime) * 100;
responsePercent = Math.abs(changePercent).toFixed(1) + '%';
// 处理-0.0%的情况
@@ -227,7 +235,7 @@ function processRealTimeData(stats) {
}
// 更新历史数据
window.dashboardHistoryData.prevResponseTime = stats.avgResponseTime;
window.dashboardHistoryData.prevResponseTime = avgResponseTime;
}
}
@@ -690,8 +698,16 @@ async function loadDashboardData() {
// 更新新卡片数据 - 使用API返回的真实数据
if (document.getElementById('avg-response-time')) {
// 首先尝试从stats.dns.AvgResponseTime获取然后尝试stats.avgResponseTime
let avgResponseTime = null;
if (stats.dns && stats.dns.AvgResponseTime !== undefined) {
avgResponseTime = stats.dns.AvgResponseTime;
} else if (stats.avgResponseTime !== undefined) {
avgResponseTime = stats.avgResponseTime;
}
// 保留两位小数并添加单位
const responseTime = stats.avgResponseTime ? stats.avgResponseTime.toFixed(2) + 'ms' : '---';
const responseTime = avgResponseTime ? avgResponseTime.toFixed(2) + 'ms' : '---';
// 计算响应时间趋势
let responsePercent = '---';
@@ -710,10 +726,10 @@ async function loadDashboardData() {
}
}
if (stats.avgResponseTime !== undefined && stats.avgResponseTime !== null) {
if (avgResponseTime !== undefined && avgResponseTime !== null) {
// 首次加载时初始化历史数据,不计算趋势
if (window.dashboardHistoryData.prevResponseTime === undefined || window.dashboardHistoryData.prevResponseTime === null) {
window.dashboardHistoryData.prevResponseTime = stats.avgResponseTime;
window.dashboardHistoryData.prevResponseTime = avgResponseTime;
responsePercent = '0.0%';
trendIcon = '•';
trendClass = 'text-gray-500';
@@ -726,7 +742,7 @@ async function loadDashboardData() {
// 计算变化百分比
if (prevResponseTime > 0) {
const changePercent = ((stats.avgResponseTime - prevResponseTime) / prevResponseTime) * 100;
const changePercent = ((avgResponseTime - prevResponseTime) / prevResponseTime) * 100;
responsePercent = Math.abs(changePercent).toFixed(1) + '%';
// 处理-0.0%的情况
@@ -765,7 +781,7 @@ async function loadDashboardData() {
}
// 更新历史数据
window.dashboardHistoryData.prevResponseTime = stats.avgResponseTime;
window.dashboardHistoryData.prevResponseTime = avgResponseTime;
}
}
@@ -934,6 +950,10 @@ function updateStatsCards(stats) {
if (stats.queryTypePercentage !== undefined) queryTypePercentage = stats.queryTypePercentage;
if (stats.activeIPs !== undefined) activeIPs = stats.activeIPs;
if (stats.activeIPsPercentage !== undefined) activeIPsPercentage = stats.activeIPsPercentage;
if (stats.avgResponseTime !== undefined) {
// 存储平均响应时间,用于后续更新卡片
window.avgResponseTime = stats.avgResponseTime;
}
// 如果dns对象存在优先使用其中的数据
@@ -953,6 +973,12 @@ function updateStatsCards(stats) {
if (activeIPs > 0 && stats.dns.SourceIPs) {
activeIPsPercentage = activeIPs / Object.keys(stats.dns.SourceIPs).length * 100;
}
// 检查并更新平均响应时间
if (stats.dns.AvgResponseTime !== undefined) {
// 存储平均响应时间,用于后续更新卡片
window.avgResponseTime = stats.dns.AvgResponseTime;
}
}
} else if (Array.isArray(stats) && stats.length > 0) {
// 可能的数据结构3: 数组形式
@@ -1330,12 +1356,18 @@ function updateStatsCards(stats) {
updatePercentage('error-percent', '---');
}
// 更新平均响应时间卡片
if (document.getElementById('avg-response-time')) {
const responseTime = window.avgResponseTime ? window.avgResponseTime.toFixed(2) + 'ms' : '---';
document.getElementById('avg-response-time').textContent = responseTime;
}
// 更新历史数据
window.dashboardHistoryData.totalQueries = totalQueries;
window.dashboardHistoryData.blockedQueries = blockedQueries;
window.dashboardHistoryData.allowedQueries = allowedQueries;
window.dashboardHistoryData.errorQueries = errorQueries;
}
@@ -1370,6 +1402,11 @@ async function updateTopBlockedTable(domains) {
console.log('使用示例数据填充Top屏蔽域名表格');
}
// 计算总拦截次数
const totalCount = tableData.reduce((sum, domain) => {
return sum + (typeof domain.count === 'number' ? domain.count : 0);
}, 0);
let html = '';
for (let i = 0; i < tableData.length; i++) {
const domain = tableData[i];
@@ -1388,23 +1425,36 @@ async function updateTopBlockedTable(domains) {
</div>
` : '';
// 计算百分比
const percentage = totalCount > 0 && typeof domain.count === 'number'
? ((domain.count / totalCount) * 100).toFixed(2)
: '0.00';
html += `
<div class="flex items-center justify-between p-3 rounded-md hover:bg-gray-50 transition-colors border-l-4 border-danger">
<div class="flex-1 min-w-0">
<div class="flex items-center">
<span class="w-6 h-6 flex items-center justify-center rounded-full bg-danger/10 text-danger text-xs font-medium mr-3">${i + 1}</span>
<div class="p-3 rounded-md hover:bg-gray-50 transition-colors border-l-4 border-danger">
<div class="flex items-center justify-between mb-2">
<div class="flex-1 min-w-0">
<div class="flex items-center">
<span class="font-medium truncate">${domain.name}</span>
${isTracker ? `
<div class="tracker-icon-container relative ml-2">
<i class="fa fa-eye text-red-500" title="已知跟踪器"></i>
${trackerTooltip}
</div>
` : ''}
<span class="w-6 h-6 flex items-center justify-center rounded-full bg-danger/10 text-danger text-xs font-medium mr-3">${i + 1}</span>
<div class="flex items-center">
<span class="font-medium truncate">${domain.name}</span>
${isTracker ? `
<div class="tracker-icon-container relative ml-2">
<i class="fa fa-eye text-red-500" title="已知跟踪器"></i>
${trackerTooltip}
</div>
` : ''}
</div>
</div>
</div>
<div class="ml-4 flex items-center space-x-2">
<span class="flex-shrink-0 font-semibold text-danger">${formatNumber(domain.count)}</span>
<span class="text-xs text-gray-500">${percentage}%</span>
</div>
</div>
<div class="w-full bg-gray-200 rounded-full h-2.5">
<div class="bg-danger h-2.5 rounded-full" style="width: ${percentage}%"></div>
</div>
<span class="ml-4 flex-shrink-0 font-semibold text-danger">${formatNumber(domain.count)}</span>
</div>
`;
}
@@ -1774,7 +1824,10 @@ async function updateTopDomainsTable(domains) {
console.log('使用示例数据填充请求域名排行表格');
}
// 计算总请求次数
const totalCount = tableData.reduce((sum, domain) => {
return sum + (typeof domain.count === 'number' ? domain.count : 0);
}, 0);
let html = '';
for (let i = 0; i < tableData.length; i++) {
@@ -1794,23 +1847,36 @@ async function updateTopDomainsTable(domains) {
</div>
` : '';
// 计算百分比
const percentage = totalCount > 0 && typeof domain.count === 'number'
? ((domain.count / totalCount) * 100).toFixed(2)
: '0.00';
html += `
<div class="flex items-center justify-between p-3 rounded-md hover:bg-gray-50 transition-colors border-l-4 border-success">
<div class="flex-1 min-w-0">
<div class="flex items-center">
<span class="w-6 h-6 flex items-center justify-center rounded-full bg-success/10 text-success text-xs font-medium mr-3">${i + 1}</span>
<div class="p-3 rounded-md hover:bg-gray-50 transition-colors border-l-4 border-success">
<div class="flex items-center justify-between mb-2">
<div class="flex-1 min-w-0">
<div class="flex items-center">
<span class="font-medium truncate">${domain.name}${domain.dnssec ? ' <i class="fa fa-lock text-green-500"></i>' : ''}</span>
${isTracker ? `
<div class="tracker-icon-container relative ml-2">
<i class="fa fa-eye text-red-500" title="已知跟踪器"></i>
${trackerTooltip}
</div>
` : ''}
<span class="w-6 h-6 flex items-center justify-center rounded-full bg-success/10 text-success text-xs font-medium mr-3">${i + 1}</span>
<div class="flex items-center">
<span class="font-medium truncate">${domain.name}${domain.dnssec ? ' <i class="fa fa-lock text-green-500"></i>' : ''}</span>
${isTracker ? `
<div class="tracker-icon-container relative ml-2">
<i class="fa fa-eye text-red-500" title="已知跟踪器"></i>
${trackerTooltip}
</div>
` : ''}
</div>
</div>
</div>
<div class="ml-4 flex items-center space-x-2">
<span class="flex-shrink-0 font-semibold text-success">${formatNumber(domain.count)}</span>
<span class="text-xs text-gray-500">${percentage}%</span>
</div>
</div>
<div class="w-full bg-gray-200 rounded-full h-2.5">
<div class="bg-success h-2.5 rounded-full" style="width: ${percentage}%"></div>
</div>
<span class="ml-4 flex-shrink-0 font-semibold text-success">${formatNumber(domain.count)}</span>
</div>
`;
}
@@ -2931,16 +2997,18 @@ function updateStatCardCharts(stats) {
// 更新平均响应时间显示
if (document.getElementById('avg-response-time')) {
let avgResponseTime = 0;
let avgResponseTime = null;
// 尝试从不同的数据结构获取平均响应时间
if (stats.dns && stats.dns.AvgResponseTime) {
if (stats.dns && stats.dns.AvgResponseTime !== undefined) {
avgResponseTime = stats.dns.AvgResponseTime;
} else if (stats.avgResponseTime !== undefined) {
avgResponseTime = stats.avgResponseTime;
} else if (stats.responseTime) {
avgResponseTime = stats.responseTime;
}
document.getElementById('avg-response-time').textContent = formatNumber(avgResponseTime);
// 保留两位小数并添加单位
const responseTime = avgResponseTime ? avgResponseTime.toFixed(2) + 'ms' : '---';
document.getElementById('avg-response-time').textContent = responseTime;
}
// 更新规则数图表