From ab2ba8b9f85cdd70bfa3020663f1d44b7e145531 Mon Sep 17 00:00:00 2001
From: Sycun <165354365+Sycun@users.noreply.github.com>
Date: Fri, 13 Nov 2026 15:40:37 +0800
Subject: [PATCH] fix(vulnerabilities): preserve domain scope across refresh
---
web/static/js/vulnerability.js | 14 +++++++++++---
web/templates/index.html | 2 +-
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/web/static/js/vulnerability.js b/web/static/js/vulnerability.js
index 60aa3d9d..afc7a5b5 100644
--- a/web/static/js/vulnerability.js
+++ b/web/static/js/vulnerability.js
@@ -1313,6 +1313,9 @@ async function loadVulnerabilities(page = null, options = {}) {
const groupOpenStates = preserveScroll
? new Map(Array.from(listContainer.querySelectorAll('.vulnerability-group'), group => [group.dataset.groupKey, group.open]))
: new Map();
+ const hostOpenStates = preserveScroll
+ ? new Map(Array.from(listContainer.querySelectorAll('.vulnerability-domain-branch'), branch => [branch.dataset.domain, branch.open]))
+ : new Map();
if (!silent) {
listContainer.innerHTML = `
${escapeHtml(vulnT('vulnerabilityPage.loading'))}
`;
updateVulnerabilityGroupControls();
@@ -1369,7 +1372,10 @@ async function loadVulnerabilities(page = null, options = {}) {
console.error('未知的响应格式:', data);
}
- renderVulnerabilities(vulnerabilities, { view, expandedIds: expandedIds || [], groupOpenStates });
+ renderVulnerabilities(vulnerabilities, {
+ view, expandedIds: expandedIds || [], groupOpenStates, hostOpenStates,
+ preserveHostSelection: preserveScroll
+ });
renderVulnerabilityPagination();
if (page !== null && !preserveScroll) {
const container = getVulnerabilityScrollContainer();
@@ -1526,7 +1532,8 @@ function renderVulnerabilityHostBrowser(vulnerabilities, opts) {
return button('host:' + domain, domain || vulnT('vulnerabilityPage.unknownHost'), count,
vulnerabilities.filter(vuln => (vuln.target_host || '') === domain));
}
- return `
+ const open = opts.hostOpenStates?.get(domain) ?? true;
+ return `
${escapeHtml(domain)} ${count}
${button('domain:' + domain, vulnT('vulnerabilityPage.domainAll'), count)}
${Array.from(hosts, ([host, n]) => button('host:' + host, host, n,
@@ -1575,7 +1582,8 @@ function renderVulnerabilityHostBrowser(vulnerabilities, opts) {
vulnerabilityHostSelection = option.dataset.hostKey;
renderVulnerabilityHostTable();
});
- if (!Array.from(list.querySelectorAll('[data-host-key]')).some(el => el.dataset.hostKey === vulnerabilityHostSelection)) {
+ if (!opts.preserveHostSelection &&
+ !Array.from(list.querySelectorAll('[data-host-key]')).some(el => el.dataset.hostKey === vulnerabilityHostSelection)) {
vulnerabilityHostSelection = '';
}
renderVulnerabilityHostTable(opts.expandedIds);
diff --git a/web/templates/index.html b/web/templates/index.html
index f2110a85..b0f91666 100644
--- a/web/templates/index.html
+++ b/web/templates/index.html
@@ -7106,7 +7106,7 @@
-
+