// 漏洞管理相关功能 let currentVulnerabilityId = null; let vulnerabilityFilters = { id: '', conversation_id: '', severity: '', status: '' }; // 初始化漏洞管理页面 function initVulnerabilityPage() { loadVulnerabilityStats(); loadVulnerabilities(); } // 加载漏洞统计 async function loadVulnerabilityStats() { try { // 检查apiFetch是否可用 if (typeof apiFetch === 'undefined') { console.error('apiFetch未定义,请确保auth.js已加载'); throw new Error('apiFetch未定义'); } const params = new URLSearchParams(); if (vulnerabilityFilters.conversation_id) { params.append('conversation_id', vulnerabilityFilters.conversation_id); } const response = await apiFetch(`/api/vulnerabilities/stats?${params.toString()}`); if (!response.ok) { const errorText = await response.text(); console.error('获取统计失败:', response.status, errorText); throw new Error(`获取统计失败: ${response.status}`); } const stats = await response.json(); updateVulnerabilityStats(stats); } catch (error) { console.error('加载漏洞统计失败:', error); // 统计失败不影响列表显示,只重置统计为0 updateVulnerabilityStats(null); } } // 更新漏洞统计显示 function updateVulnerabilityStats(stats) { // 处理空值情况 if (!stats) { stats = { total: 0, by_severity: {}, by_status: {} }; } document.getElementById('stat-total').textContent = stats.total || 0; const bySeverity = stats.by_severity || {}; document.getElementById('stat-critical').textContent = bySeverity.critical || 0; document.getElementById('stat-high').textContent = bySeverity.high || 0; document.getElementById('stat-medium').textContent = bySeverity.medium || 0; document.getElementById('stat-low').textContent = bySeverity.low || 0; document.getElementById('stat-info').textContent = bySeverity.info || 0; } // 加载漏洞列表 async function loadVulnerabilities() { const listContainer = document.getElementById('vulnerabilities-list'); listContainer.innerHTML = '