mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-08-14 15:10:20 +02:00
Add files via upload
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// 仪表盘页面:拉取运行中任务、漏洞统计并渲染
|
||||
|
||||
async function refreshDashboard() {
|
||||
const runningEl = document.getElementById('dashboard-running-tasks');
|
||||
const vulnTotalEl = document.getElementById('dashboard-vuln-total');
|
||||
const severityIds = ['critical', 'high', 'medium', 'low', 'info'];
|
||||
|
||||
if (runningEl) runningEl.textContent = '…';
|
||||
if (vulnTotalEl) vulnTotalEl.textContent = '…';
|
||||
severityIds.forEach(s => {
|
||||
const el = document.getElementById('dashboard-severity-' + s);
|
||||
if (el) el.textContent = '0';
|
||||
const barEl = document.getElementById('dashboard-bar-' + s);
|
||||
if (barEl) barEl.style.width = '0%';
|
||||
});
|
||||
|
||||
if (typeof apiFetch === 'undefined') {
|
||||
if (runningEl) runningEl.textContent = '-';
|
||||
if (vulnTotalEl) vulnTotalEl.textContent = '-';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const [tasksRes, vulnRes] = await Promise.all([
|
||||
apiFetch('/api/agent-loop/tasks').then(r => r.ok ? r.json() : null).catch(() => null),
|
||||
apiFetch('/api/vulnerabilities/stats').then(r => r.ok ? r.json() : null).catch(() => null)
|
||||
]);
|
||||
|
||||
if (tasksRes && Array.isArray(tasksRes.tasks)) {
|
||||
if (runningEl) runningEl.textContent = String(tasksRes.tasks.length);
|
||||
} else {
|
||||
if (runningEl) runningEl.textContent = '-';
|
||||
}
|
||||
|
||||
if (vulnRes && typeof vulnRes.total === 'number') {
|
||||
if (vulnTotalEl) vulnTotalEl.textContent = String(vulnRes.total);
|
||||
const bySeverity = vulnRes.by_severity || {};
|
||||
const total = vulnRes.total || 0;
|
||||
severityIds.forEach(sev => {
|
||||
const count = bySeverity[sev] || 0;
|
||||
const el = document.getElementById('dashboard-severity-' + sev);
|
||||
if (el) el.textContent = String(count);
|
||||
const barEl = document.getElementById('dashboard-bar-' + sev);
|
||||
if (barEl) barEl.style.width = total > 0 ? (count / total * 100) + '%' : '0%';
|
||||
});
|
||||
} else {
|
||||
if (vulnTotalEl) vulnTotalEl.textContent = '-';
|
||||
severityIds.forEach(sev => {
|
||||
const barEl = document.getElementById('dashboard-bar-' + sev);
|
||||
if (barEl) barEl.style.width = '0%';
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('仪表盘拉取统计失败', e);
|
||||
if (runningEl) runningEl.textContent = '-';
|
||||
if (vulnTotalEl) vulnTotalEl.textContent = '-';
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ function initRouter() {
|
||||
if (hash) {
|
||||
const hashParts = hash.split('?');
|
||||
const pageId = hashParts[0];
|
||||
if (pageId && ['chat', 'vulnerabilities', 'mcp-monitor', 'mcp-management', 'knowledge-management', 'knowledge-retrieval-logs', 'roles-management', 'skills-monitor', 'skills-management', 'settings', 'tasks'].includes(pageId)) {
|
||||
if (pageId && ['dashboard', 'chat', 'vulnerabilities', 'mcp-monitor', 'mcp-management', 'knowledge-management', 'knowledge-retrieval-logs', 'roles-management', 'skills-monitor', 'skills-management', 'settings', 'tasks'].includes(pageId)) {
|
||||
switchPage(pageId);
|
||||
|
||||
// 如果是chat页面且带有conversation参数,加载对应对话
|
||||
@@ -237,6 +237,11 @@ function showSubmenuPopup(navItem, menuId) {
|
||||
// 初始化页面
|
||||
function initPage(pageId) {
|
||||
switch(pageId) {
|
||||
case 'dashboard':
|
||||
if (typeof refreshDashboard === 'function') {
|
||||
refreshDashboard();
|
||||
}
|
||||
break;
|
||||
case 'chat':
|
||||
// 对话页面已由chat.js初始化
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user