feat(ui): unify cards, drawers and responsive theme styling

This commit is contained in:
Sycun 2026-11-15 09:21:20 +08:00
parent c5f797c521
commit 7e96ce91db
9 changed files with 769 additions and 4 deletions

41
docs/ui-design-system.md Normal file
View File

@ -0,0 +1,41 @@
# 界面样式约定
主应用的公共样式位于 `web/static/css/design-system.css`,在模块与移动端 CSS 后加载。
颜色沿用现有主题变量;卡片圆角 16px,控件圆角 10px,桌面正文内边距 24px,移动端 16px。
状态色、选中态、图表、终端和工作流画布保留各自的业务语义。
## 容器选择
- 详情、日志、长表单:右侧抽屉,默认 720px;代码、长文本等宽编辑面板 960px;标题栏可展开至 1440px。
- 手机(小于 768px):抽屉全屏,适配安全区,正文单独滚动,底部操作保持可见。
- 确认、重命名、简短绑定:居中短弹窗,手机上同样保持紧凑。
- 数据比较和批量操作继续使用表格;终端、工作流、会话工作区不强制改成卡片列表。
`web/static/js/modal.js` 的 `DRAWER_IDS` 和 `WIDE_IDS` 管理既有模块迁移清单。
新模块应通过 `openAppModal` / `closeAppModal` 开关容器,关闭时保留原有清理和未保存提示逻辑。
共用生命周期负责嵌套层级、背景滚动锁定、焦点返回、Tab 焦点约束和 Escape 触发原关闭按钮。
异步更新的标题栏会自动补齐展开按钮。短 C2 休眠设置仍为弹窗。
不要再为单个抽屉添加独立的定位、遮罩、圆角或主题色覆盖。
现阶段公共布局中少量 `!important` 用于覆盖历史内联宽高和移动端旧规则;后续修改这些模块时可逐步去除对应历史声明。
## 验证
前端回归:
```sh
node --test web/static/js/*.test.cjs
```
浏览器验证需要外部安装的 Playwright 和 Chromium,例如:
```sh
npm install --prefix /tmp/csai-ui-tools playwright
/tmp/csai-ui-tools/node_modules/.bin/playwright install chromium
NODE_PATH=/tmp/csai-ui-tools/node_modules node scripts/check-ui-design-system.cjs
```
脚本使用真实模板、样式和选定模块的真实渲染函数,配以合成数据;不启动后端或访问测试目标。
检查 1440、1024、390、360px 四档屏宽和深浅主题,验证抽屉边界、内部横向溢出、底栏、嵌套层级、展开、键盘关闭、焦点返回,以及主页面横向溢出。
截图与结果默认写入系统临时目录,也可通过 `CSAI_UI_ARTIFACTS` 指定目录。
这覆盖界面布局和公共交互,不等同于真实后端数据、保存操作、所有下拉菜单状态或物理手机软键盘的完整验收。

View File

@ -0,0 +1,360 @@
/** Offline Chromium layout/keyboard regression checks using production HTML/CSS/renderers.
* Install Playwright outside the source tree; run with NODE_PATH pointing to that node_modules.
* Uses synthetic records; never starts the backend or sends requests to assessment targets.
*/
const { chromium } = require("playwright");
const fs = require("fs"),
http = require("http"),
path = require("path");
const root = path.resolve(__dirname, "..");
const out =
process.env.CSAI_UI_ARTIFACTS ||
fs.mkdtempSync(path.join(require("os").tmpdir(), "csai-ui-"));
fs.mkdirSync(out, { recursive: true });
const html = fs
.readFileSync(root + "/web/templates/index.html", "utf8")
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/g, "")
.replace(/\{\{\.Version\}\}/g, "UI preview")
.replace(
"</body>",
'<script>window.t=(k)=>({"common.expandPanel":"展开面板","common.close":"关闭"}[k]||k);window.switchPage=function(){};</script><script src="/static/js/modal.js"></script><script src="/static/js/mobile-ui.js"></script></body>',
);
const server = http.createServer((req, res) => {
const p = req.url.split("?")[0];
if (p.startsWith("/api/")) {
res.setHeader("Content-Type", "application/json");
return res.end("{}");
}
if (p === "/") {
res.setHeader("Content-Type", "text/html");
return res.end(html);
}
const f = path.join(root, "web", p);
if (!f.startsWith(root + "/web/") || !fs.existsSync(f)) {
res.statusCode = 404;
return res.end();
}
res.setHeader(
"Content-Type",
p.endsWith(".css")
? "text/css"
: p.endsWith(".js")
? "application/javascript"
: "application/octet-stream",
);
res.end(fs.readFileSync(f));
});
(async () => {
await new Promise((r) => server.listen(0, "127.0.0.1", r));
const browser = await chromium.launch({ headless: true });
const findings = [];
let count = 0;
for (const width of [1440, 1024, 390, 360])
for (const theme of ["light", "dark"]) {
const height =
width === 360 ? 640 : width === 390 ? 844 : width === 1024 ? 768 : 900;
const page = await browser.newPage({
viewport: { width, height },
colorScheme: theme,
});
page.on("pageerror", (e) =>
findings.push({ width, theme, issue: e.message }),
);
await page.goto("http://127.0.0.1:" + server.address().port);
await page.evaluate(
(catalog) => {
window.t = (key, opts = {}) => {
let value = key.split(".").reduce((o, k) => o && o[k], catalog);
return typeof value === "string"
? value.replace(/\{\{(\w+)\}\}/g, (_, k) => opts[k] ?? "")
: key;
};
},
JSON.parse(
fs.readFileSync(root + "/web/static/i18n/zh-CN.json", "utf8"),
),
);
await page.evaluate((t) => {
document.documentElement.dataset.theme = t;
document
.querySelectorAll(".page")
.forEach((e) => e.classList.remove("active"));
document
.getElementById("page-roles-management")
.classList.add("active");
}, theme);
const ids = await page
.locator('[data-ui-surface="drawer"]')
.evaluateAll((els) => els.map((e) => e.id));
for (const id of ids) {
// A drawer nested in a page is visible only while that page is active.
await page.evaluate((id) => {
const e = document.getElementById(id);
e.closest(".settings-section-content")?.classList.add("active");
const parent = e.closest(".page");
if (parent) {
document
.querySelectorAll(".page")
.forEach((p) => p.classList.remove("active"));
parent.classList.add("active");
}
openAppModal(id);
}, id);
await page.waitForTimeout(220);
const info = await page.evaluate((id) => {
const e = document.getElementById(id),
p = e.firstElementChild,
r = p.getBoundingClientRect(),
s = getComputedStyle(p),
b = p.querySelector(
".modal-body,.projects-modal-body,.c2-modal-body,#vulnerability-inspector-body",
);
return {
id,
x: r.x,
y: r.y,
w: r.width,
h: r.height,
bg: s.backgroundColor,
overflow: b ? b.scrollWidth > b.clientWidth + 2 : false,
footer: p
.querySelector(
".modal-footer,.projects-modal-footer,.c2-modal-footer",
)
?.getBoundingClientRect().bottom,
};
}, id);
count++;
const channel = Number(info.bg.match(/\d+/)?.[0]);
if (
(theme === "dark" && channel > 100) ||
(theme === "light" && channel < 200)
)
findings.push({
width,
theme,
id,
issue: "surface theme mismatch",
bg: info.bg,
});
if (
info.x < -0.5 ||
info.y < -0.5 ||
Math.abs(info.x + info.w - width) > 2 ||
Math.abs(info.h - height) > 2 ||
info.footer > height + 1 ||
info.overflow
)
findings.push({ width, theme, ...info });
if (
[
"role-modal",
"asset-editor-modal",
"vulnerability-modal",
"skill-modal",
].includes(id)
)
await page.screenshot({
animations: "disabled",
path: out + "/" + id + "-" + width + "-" + theme + ".png",
});
await page.evaluate((id) => closeAppModal(id), id);
}
// Compact actions should remain short on mobile; test nested layer and restoration.
await page.evaluate(() => {
openAppModal("fact-detail-modal");
openAppModal("fact-modal");
});
const nested = await page.evaluate(
() =>
Number(
getComputedStyle(document.getElementById("fact-modal")).zIndex,
) >
Number(
getComputedStyle(document.getElementById("fact-detail-modal"))
.zIndex,
),
);
if (!nested) throw new Error("nested stacking");
await page.evaluate(() => {
closeAppModal("fact-modal");
closeAppModal("fact-detail-modal");
openAppModal("project-modal");
});
const small = await page.locator("#project-modal > div").boundingBox();
if (small.height >= height - 10)
throw new Error("short dialog is full screen");
await page.evaluate(() => closeAppModal("project-modal"));
if (width === 1440) {
await page.evaluate(() => openAppModal("role-modal"));
await page.locator("#role-modal .app-drawer-expand").click();
const expanded = await page.locator("#role-modal > div").boundingBox();
if (expanded.width < 1200) throw new Error("expand failed");
await page.evaluate(() => closeAppModal("role-modal"));
}
// Load production renderers with synthetic data; no backend or target execution.
await page.evaluate(() => {
window.apiFetch = async () => ({
ok: true,
json: async () => ({
log: {
createdAt: "2026-11-15T08:00:00Z",
category: "config",
action: "apply",
result: "success",
message: "配置已保存",
detail: { source: "UI fixture" },
},
}),
});
window.showToast = (m) => console.log("TOAST", m);
});
for (const script of ["knowledge", "audit", "roles", "c2"])
await page.addScriptTag({ url: "/static/js/" + script + ".js" });
await page.evaluate(() => showAuditLogDetail("fixture"));
await page.waitForTimeout(100);
if (
(await page
.locator("#audit-detail-modal .app-drawer-expand")
.count()) !== 1
) {
console.log(
await page
.locator("#audit-detail-modal")
.evaluateAll((es) => es.map((e) => e.outerHTML)),
);
throw new Error("deferred audit header missing");
}
await page.screenshot({
animations: "disabled",
path: out + "/audit-" + width + "-" + theme + ".png",
});
await page.keyboard.press("Escape");
if (await page.locator("#audit-detail-modal").count())
throw new Error("Escape did not run audit cleanup");
await page.evaluate(() =>
showRetrievalLogDetailsModal(
{
createdAt: "2026-11-15T08:00:00Z",
query: "查找接口鉴权检查方法",
riskType: "鉴权",
},
[
{
title: "接口鉴权检查",
category: "Web",
content: "验证不同角色之间的数据访问边界。",
},
],
),
);
await page.waitForTimeout(100);
await page.screenshot({
animations: "disabled",
path: out + "/retrieval-" + width + "-" + theme + ".png",
});
await page.evaluate(() => closeRetrievalLogDetailsModal());
await page.route("**/api/**", (route) =>
route.fulfill({ json: { profiles: [], projects: [], listeners: [] } }),
);
await page.evaluate(() => C2.showCreateListenerModal());
await page.waitForTimeout(200);
if ((await page.locator("#c2-modal .app-drawer-expand").count()) !== 1)
throw new Error("C2 header missing");
await page.screenshot({
animations: "disabled",
path: out + "/c2-" + width + "-" + theme + ".png",
});
await page.evaluate(() => C2.closeModal());
// Test focus wrap, native close cleanup and restoration through real role handlers.
await page.evaluate(() => {
const b = document.createElement("button");
b.textContent = "Open editor";
document.body.appendChild(b);
b.focus();
window.fixtureFocus = b;
openAppModal("role-modal");
});
await page.waitForTimeout(30);
await page.locator("#role-modal .modal-footer .btn-primary").focus();
await page.keyboard.press("Tab");
if (
!(await page.evaluate(() =>
document
.getElementById("role-modal")
.contains(document.activeElement),
))
)
throw new Error("focus escaped");
await page.keyboard.press("Escape");
if (
!(await page.evaluate(
() =>
!isAppModalOpen("role-modal") &&
document.activeElement === window.fixtureFocus,
))
)
throw new Error("close/focus restore failed");
await page.evaluate(() => {
window.fixtureFocus.remove();
roles = [
{
name: "安全审计",
description: "检查授权范围内的代码与配置,整理可复核的证据。",
tools: ["read_file", "search_code"],
enabled: true,
},
{
name: "报告整理",
description: "汇总已验证发现,生成清晰的报告。",
tools: [],
enabled: true,
},
];
renderRolesList();
});
const pageIds = await page
.locator(".page[id]")
.evaluateAll((es) => es.map((e) => e.id));
for (const id of pageIds) {
await page.evaluate((id) => {
document
.querySelectorAll(".page")
.forEach((e) => e.classList.toggle("active", e.id === id));
if (window.CSAMobile)
CSAMobile.wrapTables(document.getElementById(id));
}, id);
const overflow = await page.evaluate(
() => document.documentElement.scrollWidth > innerWidth + 2,
);
if (overflow)
findings.push({ width, theme, id, issue: "page overflow" });
if (
[
"page-dashboard",
"page-roles-management",
"page-asset-library",
"page-workflows",
"page-settings",
].includes(id)
)
await page.screenshot({
animations: "disabled",
path: out + "/" + id + "-" + width + "-" + theme + ".png",
});
}
await page.close();
}
fs.writeFileSync(
out + "/results.json",
JSON.stringify({ count, findings }, null, 2),
);
console.log(JSON.stringify({ count, findings, artifacts: out }, null, 2));
if (findings.length) process.exitCode = 1;
await browser.close();
server.close();
})().catch((e) => {
console.error(e);
server.close();
process.exit(1);
});

View File

@ -0,0 +1,244 @@
/* Shared application surfaces. Loaded last to bridge legacy module styles.
* Use data-ui-surface="drawer" for details/long forms; short actions use dialog.
* Keep table density, semantic status colors and specialist workspaces intact.
*/
:root {
--ui-radius-card: 16px;
--ui-radius-control: 10px;
--ui-surface: var(--bg-primary);
--ui-surface-muted: var(--bg-secondary);
--ui-border: var(--border-color);
--ui-shadow: 0 2px 8px rgba(15, 23, 42, .04);
--ui-overlay: rgba(15, 23, 42, .42);
--ui-panel-shadow: -12px 0 40px rgba(15, 23, 42, .16);
--ui-space: 24px;
}
html[data-theme="dark"] {
--ui-shadow: 0 2px 8px rgba(0, 0, 0, .12);
--ui-overlay: rgba(0, 0, 0, .58);
--ui-panel-shadow: -12px 0 40px rgba(0, 0, 0, .32);
}
/* Explicit surface inventory: no wildcard class matching, no changes to charts,
* terminals, graph nodes, selected-state fills or severity indicators. */
html body .page :is(
.dashboard-section, .dashboard-card, .dashboard-kpi-card, .asset-total-card, .asset-recent-card, .asset-panel, .asset-list-card,
.knowledge-item-card, .retrieval-log-card, .skill-card, .role-card, .batch-queue-item,
.tool-guard-card, .mcp-management-panel, .projects-sidebar-card, .projects-panel,
.projects-settings-card, .rbac-panel, .rbac-catalog-card, .robot-card,
.workflow-panel, .c2-listener-card, .c2-profile-card, .settings-subsection,
.storage-overview-card, .skills-overview-card
) {
border-radius: var(--ui-radius-card);
border-color: var(--ui-border);
box-shadow: var(--ui-shadow);
}
html body .page :is(.knowledge-item-card, .skill-card, .role-card, .workflow-panel, .settings-subsection) {
background: var(--ui-surface);
color: var(--text-primary);
}
html body .page-header {
gap: 16px;
align-items: center;
flex-wrap: wrap;
}
html body .page-header > h2 { font-size: 22px; line-height: 1.4; letter-spacing: -.02em; }
html body .page-header-actions { display: flex; flex-wrap: wrap; gap: 8px; }
html body :is(.page, [data-ui-surface]) :is(.btn-primary, .btn-secondary) {
border-radius: var(--ui-radius-control) !important;
min-height: 36px;
box-shadow: none;
}
html body :is(.page, [data-ui-surface]) :is(button, input, textarea, select, [role="button"]):focus-visible {
outline: 2px solid var(--accent-color);
outline-offset: 3px;
}
html body :is(.form-group, .settings-form, .modal-body, .projects-modal-body, .c2-modal-body)
:is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="hidden"]), textarea, select) {
border-radius: var(--ui-radius-control);
border-color: var(--ui-border);
color: var(--text-primary);
background-color: var(--input-bg);
max-width: 100%;
}
/* Layering is assigned by the modal lifecycle, including nested short dialogs. */
html body [data-ui-surface] {
z-index: var(--app-overlay-order, 10060) !important;
background: var(--ui-overlay) !important;
backdrop-filter: none;
}
html body [data-ui-surface="drawer"] {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
padding: 0 !important;
overflow: hidden;
--app-drawer-width: 720px;
}
html body [data-ui-surface="drawer"].app-drawer-wide { --app-drawer-width: 960px; }
html body [data-ui-surface="drawer"].app-drawer-expanded { --app-drawer-width: 1440px; }
/* !important only on the layout contract: old modules set inline dimensions. */
html body [data-ui-surface="drawer"] > :is(.modal-content, .projects-modal-dialog, .c2-modal) {
position: absolute !important;
inset-block: 0 !important;
inset-inline: auto 0 !important;
width: min(var(--app-drawer-width), calc(100% - 48px)) !important;
min-width: 0 !important;
max-width: none !important;
height: 100% !important;
height: 100dvh !important;
min-height: 0 !important;
max-height: none !important;
margin: 0 !important;
padding: 0 !important;
border: 0;
border-inline-start: 1px solid var(--ui-border);
border-radius: var(--ui-radius-card) 0 0 var(--ui-radius-card) !important;
display: flex;
flex-direction: column;
overflow: hidden !important;
background: var(--ui-surface) !important;
color: var(--text-primary);
box-shadow: var(--ui-panel-shadow);
animation: app-panel-in .18s ease-out !important;
}
html[dir="rtl"] body [data-ui-surface="drawer"] > :is(.modal-content, .projects-modal-dialog, .c2-modal) {
border-radius: 0 var(--ui-radius-card) var(--ui-radius-card) 0 !important;
}
html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header) {
display: flex;
align-items: center;
flex: 0 0 auto;
flex-wrap: wrap;
gap: 12px;
padding: 20px var(--ui-space) !important;
border-radius: 0;
border-bottom: 1px solid var(--ui-border);
background: var(--ui-surface) !important;
color: var(--text-primary);
box-shadow: none;
}
html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header)::after { display: none; }
html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header) :is(h2, h3) {
font-size: 19px;
line-height: 1.5;
color: var(--text-primary);
margin: 0;
overflow-wrap: anywhere;
}
html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header) > :first-child { flex: 1; min-width: 0; }
html body [data-ui-surface="drawer"] :is(.modal-close, .projects-modal-close, .c2-modal-close) {
position: static;
flex: 0 0 36px;
width: 36px;
height: 36px;
margin: 0;
}
html body [data-ui-surface="drawer"] :is(.modal-body, .projects-modal-body, .c2-modal-body, #vulnerability-inspector-body) {
flex: 1 1 auto;
min-height: 0;
max-height: none !important;
overflow-y: auto !important;
overscroll-behavior: contain;
padding: var(--ui-space) !important;
background: var(--ui-surface) !important;
color: var(--text-primary);
scrollbar-gutter: stable;
}
html body [data-ui-surface="drawer"] :is(.modal-footer, .projects-modal-footer, .c2-modal-footer) {
flex: 0 0 auto;
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 16px var(--ui-space) !important;
border-top: 1px solid var(--ui-border);
background: var(--ui-surface) !important;
box-shadow: none;
}
html body [data-ui-surface="drawer"] #c2-modal-content {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
max-height: none;
overflow: hidden;
}
html body .app-drawer-expand {
display: inline-flex;
justify-content: center;
align-items: center;
flex: 0 0 36px;
width: 36px;
height: 36px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius-control);
background: var(--ui-surface-muted);
color: var(--text-secondary);
font-size: 22px;
cursor: pointer;
}
html body .app-drawer-expand[aria-pressed="true"] { color: var(--accent-color); border-color: var(--accent-color); }
html body [data-ui-surface="dialog"] > :is(.modal-content, .projects-modal-dialog, .c2-modal) {
border-radius: var(--ui-radius-card);
background: var(--ui-surface);
color: var(--text-primary);
border-color: var(--ui-border);
}
@keyframes app-panel-in { from { opacity: .6; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }
@media (max-width: 767.98px) {
:root { --ui-space: 16px; }
html body .page-header > h2 { font-size: 20px; }
html body :is(.page, [data-ui-surface]) :is(.btn-primary, .btn-secondary) { min-height: 44px; }
html body [data-ui-surface="drawer"] > :is(.modal-content, .projects-modal-dialog, .c2-modal) {
width: 100% !important;
border: 0;
border-radius: 0 !important;
padding-top: env(safe-area-inset-top, 0px) !important;
padding-bottom: env(safe-area-inset-bottom, 0px) !important;
}
html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header) { padding-block: 12px !important; }
html body [data-ui-surface="drawer"] :is(.modal-close, .projects-modal-close, .c2-modal-close) { width: 44px; height: 44px; flex-basis: 44px; }
html body .app-drawer-expand { display: none; }
html body [data-ui-surface="drawer"] :is(input, textarea, select) { font-size: 16px; }
html body [data-ui-surface="drawer"] .modal-header-actions { flex-wrap: wrap; }
html body [data-ui-surface="drawer"] #skill-package-editor > div { flex-direction: column; }
html body [data-ui-surface="drawer"] #skill-package-tree { width: 100%; max-height: 180px; }
/* Short actions remain compact, including on phones. */
html body [data-ui-surface="dialog"] > :is(.modal-content, .projects-modal-dialog, .c2-modal) {
width: calc(100% - 32px) !important;
height: auto !important;
min-height: 0 !important;
max-height: calc(100dvh - 48px) !important;
margin: 24px auto !important;
border-radius: var(--ui-radius-card) !important;
}
}
@media (prefers-reduced-motion: reduce) {
html body [data-ui-surface] { animation: none !important; }
html body [data-ui-surface] > :is(.modal-content, .projects-modal-dialog, .c2-modal) { animation: none !important; transition: none !important; }
}
/* The common header is quiet; module status badges retain their own colors. */
html body [data-ui-surface="drawer"] :is(.modal-header, .projects-modal-header, .c2-modal-header) h2::before { display: none; }
html body [data-ui-surface="drawer"] .form-group { margin-bottom: 18px; }
html body [data-ui-surface="drawer"] .form-group:last-child { margin-bottom: 0; }
html body .page :is(.asset-table, .info-collect-table, .data-table, .chat-files-table, .audit-log-table) th {
background: var(--ui-surface-muted);
color: var(--text-secondary);
border-color: var(--ui-border);
font-weight: 600;
}
html body [data-ui-surface="dialog"] :is(.modal-header, .projects-modal-header, .c2-modal-header, .modal-footer, .projects-modal-footer, .c2-modal-footer) {
background: var(--ui-surface);
border-color: var(--ui-border);
color: var(--text-primary);
box-shadow: none;
}
html[dir="rtl"] body [data-ui-surface="drawer"] > :is(.modal-content, .projects-modal-dialog, .c2-modal) {
animation-name: app-panel-in-rtl !important;
}
@keyframes app-panel-in-rtl { from { opacity: .6; transform: translateX(-24px); } to { opacity: 1; transform: translateX(0); } }
@media (prefers-reduced-motion: reduce) {
html[dir="rtl"] body [data-ui-surface="drawer"] > :is(.modal-content, .projects-modal-dialog, .c2-modal) { animation: none !important; }
}

View File

@ -26,6 +26,7 @@
"chatModuleMissing": "لم يتمّ تحميل وحدة المحادثة بعد"
},
"common": {
"expandPanel": "توسيع اللوحة",
"ok": "موافق",
"cancel": "إلغاء",
"refresh": "تحديث",

View File

@ -26,6 +26,7 @@
"chatModuleMissing": "Chat module not loaded yet"
},
"common": {
"expandPanel": "Expand panel",
"ok": "OK",
"cancel": "Cancel",
"refresh": "Refresh",

View File

@ -26,6 +26,7 @@
"chatModuleMissing": "Модуль чата ещё не загружен"
},
"common": {
"expandPanel": "Развернуть панель",
"ok": "ОК",
"cancel": "Отмена",
"refresh": "Обновить",

View File

@ -26,6 +26,7 @@
"chatModuleMissing": "对话模块尚未加载"
},
"common": {
"expandPanel": "展开面板",
"ok": "确定",
"cancel": "取消",
"refresh": "刷新",

View File

@ -1,5 +1,5 @@
/**
* 统一弹窗:先显示遮罩、下一帧再填大段内容,避免与 backdrop 绘制抢主线程。
* Shared dialog/drawer lifecycle: presentation, stacking, keyboard focus and deferred rendering.
*/
(function () {
const BODY_LOCK = 'app-modal-open';
@ -17,6 +17,73 @@
'login-overlay',
]);
// Explicitly opt long forms and inspectable records into the shared surface.
// Short confirmations/selectors retain their existing centered-dialog behavior.
const DRAWER_IDS = new Set([
'asset-detail-modal', 'asset-editor-modal', 'asset-import-modal', 'asset-bulk-edit-modal',
'vulnerability-inspector', 'vulnerability-modal', 'vulnerability-retest-modal',
'batch-queue-detail-modal', 'batch-manage-modal', 'batch-import-modal',
'mcp-detail-modal', 'external-mcp-modal', 'attack-chain-modal',
'fact-modal', 'fact-detail-modal', 'knowledge-item-modal', 'retrieval-log-details-modal',
'audit-detail-modal', 'hitl-log-modal', 'skill-modal', 'agent-md-modal', 'role-modal',
'rbac-user-modal', 'rbac-role-modal', 'chat-files-edit-modal', 'webshell-modal',
'workflow-package-import-modal', 'workflow-ai-modal', 'robot-commands-modal',
'robot-account-binding-modal', 'c2-modal',
]);
const WIDE_IDS = new Set([
'skill-modal', 'agent-md-modal', 'role-modal', 'fact-modal', 'vulnerability-modal',
'chat-files-edit-modal', 'batch-queue-detail-modal', 'mcp-detail-modal', 'attack-chain-modal',
]);
const returnFocus = new WeakMap();
const surfaceObservers = new WeakMap();
const openOrder = [];
function prepareSurface(el) {
if (!el || el.id === 'login-overlay') return;
const drawer = DRAWER_IDS.has(el.id) && !el.querySelector('.c2-modal--sleep');
el.dataset.uiSurface = drawer ? 'drawer' : 'dialog';
el.classList.toggle('app-drawer-wide', drawer && (WIDE_IDS.has(el.id) || !!el.querySelector('.c2-modal--wide')));
if (!drawer) return;
el.setAttribute('role', 'dialog');
el.setAttribute('aria-modal', 'true');
const header = el.querySelector('.modal-header, .projects-modal-header, .c2-modal-header, .vulnerability-inspector-header');
if (!header) return; // Asynchronously rendered details are prepared again after rendering.
const title = header.querySelector('h2, h3');
if (title) {
if (!title.id) title.id = el.id + '-heading';
el.setAttribute('aria-labelledby', title.id);
}
const close = header.querySelector('.modal-close, .projects-modal-close, .c2-modal-close');
if (close && close.tagName !== 'BUTTON') {
close.setAttribute('role', 'button');
close.tabIndex = 0;
close.onkeydown = function (event) {
if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); close.click(); }
};
}
if (close && !close.getAttribute('aria-label')) {
close.setAttribute('aria-label', typeof window.t === 'function' ? window.t('common.close') : 'Close');
}
if (!header.querySelector('.app-drawer-expand')) {
const button = document.createElement('button');
button.type = 'button';
button.className = 'app-drawer-expand';
button.textContent = '⤢';
button.setAttribute('aria-pressed', 'false');
button.setAttribute('data-i18n', 'common.expandPanel');
button.setAttribute('data-i18n-attr', 'aria-label,title');
button.setAttribute('data-i18n-skip-text', 'true');
const label = typeof window.t === 'function' ? window.t('common.expandPanel') : 'Expand panel';
button.setAttribute('aria-label', label);
button.title = label;
button.onclick = function () {
const expanded = el.classList.toggle('app-drawer-expanded');
button.setAttribute('aria-pressed', String(expanded));
};
header.insertBefore(button, close && close.parentNode === header ? close : null);
}
}
function resolveEl(idOrEl) {
if (!idOrEl) return null;
return typeof idOrEl === 'string' ? document.getElementById(idOrEl) : idOrEl;
@ -55,13 +122,27 @@
opts = opts || {};
const el = resolveEl(idOrEl);
if (!el) return null;
prepareSurface(el);
if (!surfaceObservers.has(el)) {
const observer = new MutationObserver(function () { prepareSurface(el); });
observer.observe(el, { childList: true, subtree: true });
surfaceObservers.set(el, observer);
}
if (!isElVisible(el)) returnFocus.set(el, document.activeElement);
const previous = openOrder.indexOf(el);
if (previous !== -1) openOrder.splice(previous, 1);
openOrder.push(el);
// Nested editors must stack above the detail panel they were opened from.
el.style.setProperty('--app-overlay-order', String(10060 + openOrder.length * 2));
el.style.display = opts.display || defaultDisplay(el);
syncBodyLock();
requestAnimationFrame(function () { if (isElVisible(el)) prepareSurface(el); });
if (opts.focus === false) return el;
const sel =
opts.focusSelector ||
'input.form-input, textarea.form-input, select.form-input, input:not([type="hidden"]):not([disabled]), textarea:not([disabled]), select:not([disabled])';
const focusTarget = opts.focusEl || el.querySelector(sel);
const focusTarget = opts.focusEl || Array.from(el.querySelectorAll(sel)).find(item => item.getClientRects().length)
|| el.querySelector('.modal-close, .projects-modal-close, .c2-modal-close');
if (focusTarget) {
requestAnimationFrame(function () {
focusTarget.focus();
@ -72,7 +153,19 @@
function closeAppModal(idOrEl) {
const el = resolveEl(idOrEl);
if (el) el.style.display = 'none';
if (el) {
el.style.display = 'none';
surfaceObservers.get(el)?.disconnect();
surfaceObservers.delete(el);
el.classList.remove('app-drawer-expanded');
const button = el.querySelector('.app-drawer-expand');
if (button) button.setAttribute('aria-pressed', 'false');
const index = openOrder.indexOf(el);
if (index !== -1) openOrder.splice(index, 1);
const target = returnFocus.get(el);
if (target && target.isConnected) target.focus({ preventScroll: true });
returnFocus.delete(el);
}
syncBodyLock();
return el;
}
@ -88,6 +181,28 @@
});
}
// Keep keyboard focus within the topmost drawer. Existing close handlers own
// cleanup and dirty-form semantics, so Escape activates their close control.
document.addEventListener('keydown', function (event) {
const el = openOrder.filter(isElVisible).at(-1);
if (!el || el.dataset.uiSurface !== 'drawer' || event.defaultPrevented) return;
if (event.key === 'Escape') {
const close = el.querySelector('.modal-close, .projects-modal-close, .c2-modal-close');
if (close) { event.preventDefault(); event.stopImmediatePropagation(); close.click(); }
} else if (event.key === 'Tab') {
const items = Array.from(el.querySelectorAll('button, [href], input, select, textarea, [tabindex]'))
.filter(item => !item.disabled && item.tabIndex >= 0 && item.getClientRects().length);
if (!items.length) return;
const first = items[0], last = items[items.length - 1];
if (event.shiftKey && (document.activeElement === first || !el.contains(document.activeElement))) {
event.preventDefault(); last.focus();
} else if (!event.shiftKey && (document.activeElement === last || !el.contains(document.activeElement))) {
event.preventDefault(); first.focus();
}
}
});
document.querySelectorAll(OVERLAY_SELECTOR).forEach(prepareSurface);
window.openAppModal = openAppModal;
window.closeAppModal = closeAppModal;
window.isAppModalOpen = isAppModalOpen;

View File

@ -51,6 +51,7 @@
<link rel="stylesheet" href="/static/css/vulnerability-list.css?v=20261113-compact-rows">
<script src="/static/js/router.js?v=20261114-assessment-links"></script>
<link rel="stylesheet" href="/static/css/deep-assessments.css?v=20261115-intents">
<link rel="stylesheet" href="/static/css/design-system.css?v=20261115-1">
</head>
<body>
<div id="login-overlay" class="login-overlay" style="display: none;">
@ -7095,7 +7096,7 @@
<script src="/static/js/theme.js"></script>
<script src="/static/js/builtin-tools.js"></script>
<script src="/static/js/auth.js?v=20261008-password-eye-1"></script>
<script src="/static/js/modal.js"></script>
<script src="/static/js/modal.js?v=20261115-1"></script>
<dialog id="vulnerability-download-dialog" aria-labelledby="vulnerability-download-heading" aria-describedby="vulnerability-download-hint">
<div class="vulnerability-download-content">
<h3 id="vulnerability-download-heading" data-i18n="vulnerabilityDownload.title">下载漏洞报告</h3>