1533 lines
50 KiB
HTML
1533 lines
50 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN" data-theme="auto">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>监控看板</title>
|
||
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>📊</text></svg>">
|
||
<style>
|
||
/* ============================================================
|
||
设计令牌 —— 明暗两套各自选定(非机械反转)
|
||
系列色取自校验通过的调色板:蓝 #2a78d6 / 橙 #eb6834
|
||
============================================================ */
|
||
:root {
|
||
color-scheme: light;
|
||
--page: #f4f4f1;
|
||
--page-accent: radial-gradient(1100px 520px at 12% -8%, #e8effa 0%, transparent 62%),
|
||
radial-gradient(900px 460px at 92% 0%, #f4ece6 0%, transparent 58%);
|
||
--surface-1: #ffffff;
|
||
--surface-2: #fafaf8;
|
||
--text-primary: #0b0b0b;
|
||
--text-secondary: #52514e;
|
||
--text-muted: #898781;
|
||
--gridline: #e7e6e0;
|
||
--baseline: #c3c2b7;
|
||
--border: rgba(11, 11, 11, 0.09);
|
||
--border-strong: rgba(11, 11, 11, 0.16);
|
||
--series-1: #2a78d6;
|
||
--series-2: #eb6834;
|
||
--status-good: #0ca30c;
|
||
--status-warning: #fab219;
|
||
--status-critical: #d03b3b;
|
||
--success-text: #006300;
|
||
--track: #eeede8;
|
||
--ghost: rgba(11, 11, 11, 0.035);
|
||
--shadow-sm: 0 1px 2px rgba(11,11,11,.04), 0 1px 3px rgba(11,11,11,.03);
|
||
--shadow-md: 0 2px 4px rgba(11,11,11,.04), 0 8px 24px rgba(11,11,11,.06);
|
||
--accent-soft: rgba(42, 120, 214, 0.10);
|
||
}
|
||
@media (prefers-color-scheme: dark) {
|
||
:root:where(:not([data-theme="light"])) {
|
||
color-scheme: dark;
|
||
--page: #0b0b0b;
|
||
--page-accent: radial-gradient(1100px 520px at 12% -8%, #12233a 0%, transparent 62%),
|
||
radial-gradient(900px 460px at 92% 0%, #2a1d16 0%, transparent 58%);
|
||
--surface-1: #171716;
|
||
--surface-2: #1e1e1c;
|
||
--text-primary: #f0efec;
|
||
--text-secondary: #c3c2b7;
|
||
--text-muted: #898781;
|
||
--gridline: #2c2c2a;
|
||
--baseline: #383835;
|
||
--border: rgba(255, 255, 255, 0.09);
|
||
--border-strong: rgba(255, 255, 255, 0.18);
|
||
--series-1: #3987e5;
|
||
--series-2: #d95926;
|
||
--success-text: #0ca30c;
|
||
--track: #2c2c2a;
|
||
--ghost: rgba(255, 255, 255, 0.055);
|
||
--shadow-sm: 0 1px 2px rgba(0,0,0,.4);
|
||
--shadow-md: 0 2px 4px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
|
||
--accent-soft: rgba(57, 135, 229, 0.16);
|
||
}
|
||
}
|
||
:root[data-theme="dark"] {
|
||
color-scheme: dark;
|
||
--page: #0b0b0b;
|
||
--page-accent: radial-gradient(1100px 520px at 12% -8%, #12233a 0%, transparent 62%),
|
||
radial-gradient(900px 460px at 92% 0%, #2a1d16 0%, transparent 58%);
|
||
--surface-1: #171716;
|
||
--surface-2: #1e1e1c;
|
||
--text-primary: #f0efec;
|
||
--text-secondary: #c3c2b7;
|
||
--text-muted: #898781;
|
||
--gridline: #2c2c2a;
|
||
--baseline: #383835;
|
||
--border: rgba(255, 255, 255, 0.09);
|
||
--border-strong: rgba(255, 255, 255, 0.18);
|
||
--series-1: #3987e5;
|
||
--series-2: #d95926;
|
||
--success-text: #0ca30c;
|
||
--track: #2c2c2a;
|
||
--ghost: rgba(255, 255, 255, 0.055);
|
||
--shadow-sm: 0 1px 2px rgba(0,0,0,.4);
|
||
--shadow-md: 0 2px 4px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
|
||
--accent-soft: rgba(57, 135, 229, 0.16);
|
||
}
|
||
|
||
* { box-sizing: border-box; }
|
||
|
||
/* ============================================================
|
||
整页固定一屏高,不出现全屏滚动条;内容超高时卡片内部滚动
|
||
============================================================ */
|
||
html, body { height: 100%; overflow: hidden; }
|
||
|
||
body {
|
||
margin: 0;
|
||
background-color: var(--page);
|
||
background-image: var(--page-accent);
|
||
background-attachment: fixed;
|
||
color: var(--text-primary);
|
||
font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
|
||
font-size: 14px;
|
||
line-height: 1.5;
|
||
-webkit-font-smoothing: antialiased;
|
||
}
|
||
|
||
/* 整体居中:水平居中 + 垂直居中 */
|
||
.shell {
|
||
height: 100vh;
|
||
max-width: 1360px;
|
||
margin: 0 auto;
|
||
padding: 20px 24px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 14px;
|
||
justify-content: center;
|
||
}
|
||
/* 内容超出视口时允许 shell 自身参与压缩,避免溢出 */
|
||
.shell > * { flex-shrink: 0; }
|
||
.shell .card.main { flex: 1 1 auto; min-height: 0; }
|
||
|
||
/* ============================================================ 顶部栏 */
|
||
.topbar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 13px;
|
||
flex-wrap: wrap;
|
||
}
|
||
.brand { display: flex; align-items: center; gap: 11px; }
|
||
.brand .mark {
|
||
width: 34px; height: 34px;
|
||
border-radius: 9px;
|
||
background: linear-gradient(135deg, var(--series-1), var(--series-2));
|
||
display: grid;
|
||
place-items: center;
|
||
color: #fff;
|
||
font-size: 17px;
|
||
box-shadow: var(--shadow-sm);
|
||
flex: none;
|
||
}
|
||
.brand h1 {
|
||
margin: 0;
|
||
font-size: 18px;
|
||
font-weight: 660;
|
||
letter-spacing: -0.02em;
|
||
white-space: nowrap;
|
||
}
|
||
.brand .tag {
|
||
font-size: 11.5px;
|
||
color: var(--text-muted);
|
||
margin-top: -3px;
|
||
white-space: nowrap;
|
||
}
|
||
.topbar .spacer { flex: 1; }
|
||
|
||
.meta {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
font-variant-numeric: tabular-nums;
|
||
text-align: right;
|
||
line-height: 1.35;
|
||
white-space: nowrap;
|
||
}
|
||
.meta b { color: var(--text-secondary); font-weight: 600; }
|
||
|
||
button {
|
||
font-family: inherit;
|
||
font-size: 13px;
|
||
padding: 7px 14px;
|
||
border-radius: 9px;
|
||
border: 1px solid var(--border-strong);
|
||
background: var(--surface-1);
|
||
color: var(--text-primary);
|
||
cursor: pointer;
|
||
box-shadow: var(--shadow-sm);
|
||
transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
|
||
white-space: nowrap;
|
||
}
|
||
button:hover:not(:disabled) { background: var(--ghost); border-color: var(--text-muted); }
|
||
button:active:not(:disabled) { transform: translateY(1px); }
|
||
button:disabled { opacity: .55; cursor: default; }
|
||
button.primary {
|
||
background: var(--series-1);
|
||
border-color: var(--series-1);
|
||
color: #fff;
|
||
font-weight: 560;
|
||
box-shadow: 0 1px 2px rgba(11,11,11,.1), 0 3px 10px var(--accent-soft);
|
||
}
|
||
button.primary:hover:not(:disabled) { background: #256abf; border-color: #256abf; }
|
||
button.icon-btn { padding: 7px 11px; }
|
||
|
||
.badge {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
font-size: 11.5px;
|
||
padding: 4px 10px;
|
||
border-radius: 999px;
|
||
border: 1px solid var(--border);
|
||
background: var(--surface-1);
|
||
color: var(--text-secondary);
|
||
white-space: nowrap;
|
||
}
|
||
.badge .dot {
|
||
width: 6px; height: 6px; border-radius: 50%;
|
||
background: var(--status-good);
|
||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-good) 20%, transparent);
|
||
}
|
||
.badge.stale .dot {
|
||
background: var(--status-warning);
|
||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-warning) 22%, transparent);
|
||
}
|
||
.badge.err .dot {
|
||
background: var(--status-critical);
|
||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-critical) 22%, transparent);
|
||
}
|
||
|
||
/* ============================================================ KPI */
|
||
.kpis {
|
||
display: grid;
|
||
grid-template-columns: repeat(4, 1fr);
|
||
gap: 12px;
|
||
}
|
||
.kpi {
|
||
position: relative;
|
||
background: var(--surface-1);
|
||
border: 1px solid var(--border);
|
||
border-radius: 13px;
|
||
padding: 14px 17px 13px;
|
||
box-shadow: var(--shadow-sm);
|
||
overflow: hidden;
|
||
transition: box-shadow .2s, transform .2s;
|
||
}
|
||
/* 顶部提示条:圆角与卡片一致,避免直角溢出 */
|
||
.kpi::before {
|
||
content: "";
|
||
position: absolute;
|
||
top: 0; left: 0; right: 0;
|
||
height: 3px;
|
||
background: var(--kpi-accent, var(--series-1));
|
||
border-radius: 13px 13px 0 0;
|
||
}
|
||
.kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
|
||
.kpi .label { font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }
|
||
.kpi .value {
|
||
font-size: 27px;
|
||
font-weight: 650;
|
||
letter-spacing: -0.03em;
|
||
line-height: 1.05;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
.kpi .foot { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
|
||
|
||
/* 批次进度:横向紧凑布局,与 KPI 同一行节奏 */
|
||
.batches-row {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
||
gap: 12px;
|
||
}
|
||
/* 筛选单个批次时只渲染该卡片,容器收窄为单列并限制最大宽度,避免拉满整行 */
|
||
.batches-row.single {
|
||
grid-template-columns: minmax(320px, 1fr);
|
||
max-width: 520px;
|
||
}
|
||
/* ---------- 折叠区:批次卡片最多显示 N 行,其余收起 ---------- */
|
||
.batches-wrap { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
|
||
/* 收起时按「行高上限」裁切,不做内容位移;露出的行底部做一层淡出,暗示还有更多 */
|
||
.batches-clip {
|
||
overflow: hidden;
|
||
transition: max-height .22s cubic-bezier(.4, 0, .2, 1);
|
||
}
|
||
.batches-clip.collapsed { max-height: var(--clip-h); }
|
||
.batches-wrap.has-more .batches-clip.collapsed {
|
||
-webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent 100%);
|
||
mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent 100%);
|
||
}
|
||
/* 展开/收起按钮:与筛选下拉同一档次的控件,靠左对齐在卡片区下方 */
|
||
.batches-more {
|
||
align-self: flex-start;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
font-family: inherit;
|
||
font-size: 12.5px;
|
||
font-weight: 520;
|
||
color: var(--text-secondary);
|
||
background: var(--surface-1);
|
||
border: 1px solid var(--border-strong);
|
||
border-radius: 9px;
|
||
padding: 5px 12px;
|
||
cursor: pointer;
|
||
box-shadow: var(--shadow-sm);
|
||
transition: color .18s, border-color .18s, background .18s;
|
||
}
|
||
.batches-more:hover {
|
||
color: var(--text-primary);
|
||
background: var(--surface-2);
|
||
border-color: color-mix(in srgb, var(--series-1) 40%, var(--border-strong));
|
||
}
|
||
.batches-more .arrow {
|
||
font-size: 9px;
|
||
line-height: 1;
|
||
color: var(--text-muted);
|
||
transition: transform .22s cubic-bezier(.4, 0, .2, 1);
|
||
}
|
||
.batches-more[aria-expanded="true"] .arrow { transform: rotate(180deg); }
|
||
.batches-more .cnt {
|
||
font-size: 11px;
|
||
font-variant-numeric: tabular-nums;
|
||
color: var(--text-muted);
|
||
}
|
||
.batch-card {
|
||
position: relative;
|
||
background: var(--surface-1);
|
||
border: 1px solid var(--border);
|
||
border-radius: 13px;
|
||
padding: 13px 16px 12px;
|
||
box-shadow: var(--shadow-sm);
|
||
transition: border-color .18s, box-shadow .18s;
|
||
}
|
||
/* 被筛选选中的卡片:描边高亮,明确当前整页数据口径 */
|
||
.batch-card.active {
|
||
border-color: color-mix(in srgb, var(--series-1) 45%, var(--border));
|
||
box-shadow: var(--shadow-md), 0 0 0 1px color-mix(in srgb, var(--series-1) 30%, transparent);
|
||
}
|
||
.batch-head {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
margin-bottom: 9px;
|
||
}
|
||
.batch-name {
|
||
font-size: 14px;
|
||
font-weight: 640;
|
||
font-variant-numeric: tabular-nums;
|
||
letter-spacing: -0.01em;
|
||
}
|
||
/* 筛选作用域标签:明确整页数据口径 */
|
||
.badge.scope {
|
||
border-color: color-mix(in srgb, var(--series-1) 40%, transparent);
|
||
background: color-mix(in srgb, var(--series-1) 8%, transparent);
|
||
color: var(--series-1);
|
||
font-weight: 600;
|
||
}
|
||
.chip {
|
||
font-size: 10.5px;
|
||
padding: 1px 7px;
|
||
border-radius: 999px;
|
||
border: 1px solid var(--border);
|
||
color: var(--text-muted);
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
.chip.done {
|
||
color: var(--success-text);
|
||
border-color: color-mix(in srgb, var(--status-good) 34%, transparent);
|
||
background: color-mix(in srgb, var(--status-good) 9%, transparent);
|
||
font-weight: 560;
|
||
}
|
||
.batch-rate {
|
||
margin-left: auto;
|
||
font-size: 17px;
|
||
font-weight: 660;
|
||
font-variant-numeric: tabular-nums;
|
||
letter-spacing: -0.02em;
|
||
}
|
||
.bar {
|
||
height: 8px;
|
||
border-radius: 4px;
|
||
background: var(--track);
|
||
overflow: hidden;
|
||
display: flex;
|
||
gap: 2px;
|
||
}
|
||
.bar .fill {
|
||
background: linear-gradient(90deg, var(--series-1), color-mix(in srgb, var(--series-1) 74%, var(--series-2)));
|
||
border-radius: 4px;
|
||
transition: width .6s cubic-bezier(.4, 0, .2, 1);
|
||
min-width: 3px;
|
||
}
|
||
.bar .rest { flex: 1; }
|
||
.batch-nums {
|
||
display: flex;
|
||
gap: 15px;
|
||
margin-top: 9px;
|
||
font-size: 12px;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
.batch-nums .n { display: flex; align-items: baseline; gap: 5px; }
|
||
.batch-nums .n .k { color: var(--text-muted); font-size: 11.5px; }
|
||
.batch-nums .n .v { font-weight: 620; font-size: 13.5px; }
|
||
.batch-nums .n .v.ok { color: var(--success-text); }
|
||
.batch-nums .time {
|
||
margin-left: auto;
|
||
color: var(--text-muted);
|
||
font-size: 11px;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
|
||
/* ============================================================ 主卡片 */
|
||
.card {
|
||
background: var(--surface-1);
|
||
border: 1px solid var(--border);
|
||
border-radius: 13px;
|
||
box-shadow: var(--shadow-sm);
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
}
|
||
.card.main { overflow: hidden; }
|
||
|
||
.card-head {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
padding: 13px 18px 11px;
|
||
border-bottom: 1px solid var(--gridline);
|
||
flex-wrap: wrap;
|
||
}
|
||
.card-head .titles { min-width: 0; }
|
||
.card-head h2 {
|
||
margin: 0 0 1px;
|
||
font-size: 14.5px;
|
||
font-weight: 620;
|
||
letter-spacing: -0.01em;
|
||
}
|
||
.card-head .sub {
|
||
margin: 0;
|
||
font-size: 11.5px;
|
||
color: var(--text-muted);
|
||
}
|
||
.card-head .spacer { flex: 1; }
|
||
|
||
/* 分段控件:图形 / 表格切换 */
|
||
.segmented {
|
||
display: inline-flex;
|
||
padding: 3px;
|
||
gap: 2px;
|
||
border-radius: 9px;
|
||
background: var(--track);
|
||
border: 1px solid var(--border);
|
||
}
|
||
.segmented button {
|
||
border: none;
|
||
background: transparent;
|
||
box-shadow: none;
|
||
padding: 5px 13px;
|
||
border-radius: 6px;
|
||
font-size: 12.5px;
|
||
color: var(--text-secondary);
|
||
font-weight: 520;
|
||
}
|
||
.segmented button:hover:not(.active) { background: var(--ghost); border: none; }
|
||
.segmented button.active {
|
||
background: var(--surface-1);
|
||
color: var(--text-primary);
|
||
font-weight: 620;
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
|
||
/* 批次筛选下拉 */
|
||
select {
|
||
font-family: inherit;
|
||
font-size: 12.5px;
|
||
padding: 6px 10px;
|
||
border-radius: 9px;
|
||
border: 1px solid var(--border-strong);
|
||
background: var(--surface-1);
|
||
color: var(--text-primary);
|
||
cursor: pointer;
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
|
||
/* ============================================================ 视图容器 */
|
||
.view {
|
||
flex: 1;
|
||
min-height: 0;
|
||
padding: 14px 18px 16px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
.view.hidden { display: none; }
|
||
|
||
/* ---- 图形视图 */
|
||
.chart-wrap {
|
||
flex: 1;
|
||
min-height: 0;
|
||
position: relative;
|
||
}
|
||
#chart { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
|
||
|
||
.legend {
|
||
display: flex;
|
||
gap: 20px;
|
||
flex-wrap: wrap;
|
||
margin-top: 11px;
|
||
padding-top: 11px;
|
||
border-top: 1px solid var(--gridline);
|
||
font-size: 12px;
|
||
color: var(--text-secondary);
|
||
flex: none;
|
||
}
|
||
.legend .item { display: inline-flex; align-items: center; gap: 7px; }
|
||
.legend .swatch { width: 12px; height: 3px; border-radius: 2px; }
|
||
|
||
.tooltip {
|
||
position: absolute;
|
||
pointer-events: none;
|
||
opacity: 0;
|
||
transition: opacity .1s;
|
||
background: var(--surface-1);
|
||
border: 1px solid var(--border-strong);
|
||
border-radius: 10px;
|
||
padding: 9px 12px;
|
||
font-size: 12.5px;
|
||
box-shadow: var(--shadow-md);
|
||
min-width: 148px;
|
||
z-index: 10;
|
||
}
|
||
.tooltip .tt-title {
|
||
font-weight: 640;
|
||
margin-bottom: 6px;
|
||
font-variant-numeric: tabular-nums;
|
||
letter-spacing: -0.01em;
|
||
}
|
||
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; line-height: 1.72; }
|
||
.tooltip .tt-row .swatch { width: 9px; height: 3px; border-radius: 2px; flex: none; }
|
||
.tooltip .tt-row .nm { color: var(--text-secondary); }
|
||
.tooltip .tt-row .vl {
|
||
margin-left: auto;
|
||
font-weight: 640;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
.tooltip .tt-total {
|
||
border-top: 1px solid var(--gridline);
|
||
margin-top: 5px;
|
||
padding-top: 5px;
|
||
}
|
||
|
||
/* ---- 表格视图 ----
|
||
样式对齐「机票酒店面板」的表格语汇:
|
||
发丝线分隔、弱化的小号表头、悬停整行浅底、数字走等宽字体,
|
||
去掉所有色块底色与描边胶囊,信息靠字重与色彩本身分层。 */
|
||
.table-scroll {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden; /* 24 行 + 三行表头一屏放下,不出现内部滚动条 */
|
||
background: var(--surface-1);
|
||
border: 1px solid var(--border);
|
||
border-radius: 12px;
|
||
}
|
||
table {
|
||
width: 100%;
|
||
height: 100%; /* 行高等分撑满容器,避免底部行被裁切 */
|
||
border-collapse: collapse;
|
||
font-size: 12.5px;
|
||
font-variant-numeric: tabular-nums;
|
||
font-feature-settings: "tnum" 1;
|
||
}
|
||
th, td {
|
||
text-align: right;
|
||
padding: 0 16px; /* 纵向内边距交给行高控制 */
|
||
white-space: nowrap;
|
||
}
|
||
th:first-child, td:first-child {
|
||
text-align: left;
|
||
position: sticky;
|
||
left: 0;
|
||
background: var(--surface-1);
|
||
z-index: 1;
|
||
}
|
||
thead th {
|
||
position: sticky;
|
||
top: 0;
|
||
background: var(--surface-1);
|
||
z-index: 2;
|
||
}
|
||
thead th:first-child { z-index: 3; }
|
||
|
||
/* --- 表头三行:分组名 / 列名 / 快照数值 ---
|
||
两行小号灰字 + 一行收敛的快照数值,靠发丝线分层,不铺底色 */
|
||
thead tr:nth-child(1) { height: 24px; }
|
||
thead tr:nth-child(2) { height: 26px; }
|
||
thead tr.snapshot-row { height: 30px; }
|
||
|
||
thead tr:nth-child(1) th {
|
||
font-size: 11px;
|
||
font-weight: 500;
|
||
color: var(--text-muted);
|
||
letter-spacing: .02em;
|
||
border-bottom: 1px solid var(--border);
|
||
}
|
||
thead tr:nth-child(2) th {
|
||
font-size: 13.5px;
|
||
font-weight: 660;
|
||
color: var(--text-primary);
|
||
letter-spacing: -0.01em;
|
||
border-bottom: 1px solid var(--border);
|
||
}
|
||
thead tr.snapshot-row th {
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
color: var(--text-secondary);
|
||
background: var(--ghost);
|
||
border-top: 1px solid var(--border);
|
||
border-bottom: 1px solid var(--border);
|
||
}
|
||
/* 快照行的行首格补齐底色,与整行连成一条 */
|
||
thead tr.snapshot-row th:first-child {
|
||
background: var(--surface-1);
|
||
border-top-color: transparent;
|
||
border-bottom-color: transparent;
|
||
}
|
||
th.snap-done { color: var(--success-text); font-weight: 620; }
|
||
|
||
/* --- 表体 --- */
|
||
tbody tr { height: calc((100% - 80px) / 24); }
|
||
tbody td { border-bottom: 1px solid var(--border); }
|
||
tbody tr:last-child td { border-bottom: none; }
|
||
tbody tr:hover td { background: var(--ghost); }
|
||
tbody tr:hover td:first-child { background: var(--surface-1); }
|
||
tbody tr.dim { color: var(--text-muted); }
|
||
/* 峰值小时:只在「完成量」格的左内缘挂一条色条,不铺整行底色。
|
||
该格左边缘正好压在分组发丝线上,色条贴齐内缘后与发丝线视觉相接,
|
||
成为一条自表头贯通到表尾的竖线,而不是悬在半空的半截短线。 */
|
||
tbody tr.peak td.peak-mark {
|
||
position: relative;
|
||
box-shadow: inset 2px 0 0 var(--series-1);
|
||
font-weight: 700;
|
||
}
|
||
/* 当前小时:时间列转主色 + 右侧小小圆点 */
|
||
tbody tr.current td:first-child { font-weight: 620; color: var(--text-primary); }
|
||
tbody tr.current td:first-child::after {
|
||
content: "";
|
||
display: inline-block;
|
||
width: 5px;
|
||
height: 5px;
|
||
border-radius: 50%;
|
||
background: var(--series-1);
|
||
margin-left: 7px;
|
||
vertical-align: 1.5px;
|
||
}
|
||
/* 时间列:等宽数字 + 分隔符弱化 */
|
||
td.time-cell { color: var(--text-secondary); }
|
||
td.time-cell .sep { color: var(--text-muted); }
|
||
/* 主指标(完成量)加粗,是第一视线落点 */
|
||
td.main-cell { font-weight: 660; color: var(--text-primary); }
|
||
|
||
/* 列分隔:小时增量 | 各批次 | 全量快照 —— 只用发丝线,不用底色块 */
|
||
th.grp-start, td.grp-start { border-left: 1px solid var(--border); }
|
||
|
||
/* 增减量:正增量走成功色、零与负走弱化灰,去掉胶囊底 */
|
||
td.up, td.down {
|
||
font-weight: 620;
|
||
font-size: 12.5px;
|
||
}
|
||
td.up { color: var(--success-text); }
|
||
td.down { color: var(--text-secondary); }
|
||
td.zero { color: var(--text-muted); }
|
||
/* 各批次配色点 */
|
||
td.batch-cell .dot { margin-right: 6px; font-size: 10px; vertical-align: 1px; }
|
||
|
||
.state {
|
||
padding: 34px 10px;
|
||
text-align: center;
|
||
color: var(--text-muted);
|
||
font-size: 13px;
|
||
}
|
||
.state.error { color: var(--status-critical); }
|
||
|
||
@media (max-width: 1100px) {
|
||
.kpis { grid-template-columns: repeat(2, 1fr); }
|
||
}
|
||
@media (max-width: 720px) {
|
||
.shell { padding: 12px; gap: 10px; justify-content: flex-start; overflow: auto; }
|
||
body { overflow: auto; }
|
||
.brand .tag { display: none; }
|
||
.kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
|
||
.kpi .value { font-size: 21px; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<div class="shell">
|
||
|
||
<!-- ======================================================== 顶部栏 -->
|
||
<div class="topbar">
|
||
<div class="brand">
|
||
<div class="mark">📊</div>
|
||
<div>
|
||
<h1>监控看板</h1>
|
||
<div class="tag">project_drug_detail · drug_detail_list</div>
|
||
</div>
|
||
</div>
|
||
<span class="badge" id="cacheBadge"><span class="dot"></span><span id="cacheText">加载中</span></span>
|
||
<span class="badge scope" id="scopeBadge" hidden></span>
|
||
<span class="spacer"></span>
|
||
<span class="meta" id="genTime"></span>
|
||
<button class="primary" id="refreshBtn">立即刷新</button>
|
||
<button class="icon-btn" id="themeBtn" title="切换明暗模式">◐</button>
|
||
</div>
|
||
|
||
<!-- ======================================================== KPI -->
|
||
<div class="kpis" id="kpis"></div>
|
||
|
||
<!-- ======================================================== 批次进度 -->
|
||
<!-- 批次多时最多显示若干行,其余收起,由下方按钮展开 -->
|
||
<div class="batches-wrap" id="batchesWrap">
|
||
<div class="batches-clip" id="batchesClip">
|
||
<div class="batches-row" id="batches"></div>
|
||
</div>
|
||
<button class="batches-more" id="batchesMore" type="button" aria-expanded="false" data-n="0" hidden>
|
||
<span class="txt">展开全部批次</span>
|
||
<span class="cnt">共 0 个批次</span>
|
||
<span class="arrow">▼</span>
|
||
</button>
|
||
</div>
|
||
|
||
<!-- ======================================================== 主卡片:图形 / 表格 -->
|
||
<div class="card main">
|
||
<div class="card-head">
|
||
<div class="titles">
|
||
<h2 id="viewTitle">今日每小时完成量</h2>
|
||
<p class="sub" id="viewSub">按任务完成时间(update_time)的小时切片统计</p>
|
||
</div>
|
||
<span class="spacer"></span>
|
||
<select id="batchFilter" title="按批次筛选"></select>
|
||
<div class="segmented" role="tablist">
|
||
<button id="tabChart" class="active" role="tab">图形</button>
|
||
<button id="tabTable" role="tab">表格</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 图形视图 -->
|
||
<div class="view" id="viewChart">
|
||
<div class="chart-wrap">
|
||
<canvas id="chart"></canvas>
|
||
<div class="tooltip" id="tooltip"></div>
|
||
</div>
|
||
<div class="legend" id="legend"></div>
|
||
</div>
|
||
|
||
<!-- 表格视图 -->
|
||
<div class="view hidden" id="viewTable">
|
||
<div class="table-scroll">
|
||
<table>
|
||
<thead id="tHead"></thead>
|
||
<tbody id="tBody"></tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<script>
|
||
"use strict";
|
||
|
||
/* ================================================================ 常量 */
|
||
const PALETTE = {
|
||
light: { series: ["#2a78d6", "#eb6834"], grid: "#e7e6e0", baseline: "#c3c2b7", muted: "#898781", surface: "#ffffff" },
|
||
dark: { series: ["#3987e5", "#d95926"], grid: "#2c2c2a", baseline: "#383835", muted: "#898781", surface: "#171716" }
|
||
};
|
||
|
||
const $ = (id) => document.getElementById(id);
|
||
const fmt = (n) => (n === null || n === undefined ? "-" : Number(n).toLocaleString("zh-CN"));
|
||
const pad2 = (n) => String(n).padStart(2, "0");
|
||
|
||
function isDark() {
|
||
const attr = document.documentElement.getAttribute("data-theme");
|
||
if (attr === "dark") return true;
|
||
if (attr === "light") return false;
|
||
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||
}
|
||
function theme() { return isDark() ? PALETTE.dark : PALETTE.light; }
|
||
|
||
/* ================================================================ 状态 */
|
||
let STATE = null;
|
||
let hoverIndex = -1;
|
||
let visible = { start: 0, end: 23 };
|
||
let activeBatch = "__all__"; // "__all__" 表示全部批次
|
||
let currentView = "chart"; // chart | table
|
||
|
||
/* ================================================================ 取数 */
|
||
async function loadData(force) {
|
||
const btn = $("refreshBtn");
|
||
btn.disabled = true;
|
||
const origText = btn.textContent;
|
||
btn.textContent = force ? "刷新中…" : "加载中…";
|
||
|
||
try {
|
||
const resp = await fetch("/api/stats" + (force ? "?force=1" : ""), { cache: "no-store" });
|
||
const json = await resp.json();
|
||
if (!resp.ok) throw new Error(json.detail || json.error || ("HTTP " + resp.status));
|
||
|
||
STATE = json;
|
||
|
||
// 若当前选中的批次已不存在,回退到全部
|
||
const batches = Object.keys(json.hourly.by_batch);
|
||
if (activeBatch !== "__all__" && !batches.includes(activeBatch)) activeBatch = "__all__";
|
||
|
||
renderBatchFilter();
|
||
recompute();
|
||
renderAll();
|
||
|
||
$("cacheBadge").className = "badge" + (json.cached ? " stale" : "");
|
||
$("cacheText").textContent = json.cached
|
||
? `缓存 · ${Math.floor((json.cache_age || 0) / 60)} 分钟前`
|
||
: "实时数据";
|
||
} catch (err) {
|
||
$("cacheBadge").className = "badge err";
|
||
$("cacheText").textContent = "获取失败";
|
||
$("batches").innerHTML = `<div class="state error">加载失败:${err.message}</div>`;
|
||
$("kpis").innerHTML = "";
|
||
$("genTime").textContent = "";
|
||
drawChart();
|
||
} finally {
|
||
btn.disabled = false;
|
||
btn.textContent = origText;
|
||
}
|
||
}
|
||
|
||
/* ================================================================ 派生数据 */
|
||
/** 当前筛选下的系列:{ 名称: [24 个小时值] } 与逐小时合计 */
|
||
let SERIES = {};
|
||
let TOTAL = [];
|
||
let DELTA = []; // 相对上一小时的新增量
|
||
|
||
function recompute() {
|
||
const h = STATE.hourly;
|
||
const batches = Object.keys(h.by_batch);
|
||
|
||
if (activeBatch === "__all__") {
|
||
SERIES = {};
|
||
batches.forEach((b) => { SERIES[b] = h.by_batch[b] || new Array(24).fill(0); });
|
||
TOTAL = h.total_by_hour.slice();
|
||
} else {
|
||
SERIES = { [activeBatch]: (h.by_batch[activeBatch] || new Array(24).fill(0)).slice() };
|
||
TOTAL = SERIES[activeBatch].slice();
|
||
}
|
||
|
||
// 环比上一小时的新增量:第一小时相对 0
|
||
DELTA = TOTAL.map((v, i) => (i === 0 ? v : v - TOTAL[i - 1]));
|
||
|
||
computeVisibleRange();
|
||
}
|
||
|
||
/**
|
||
* 横轴范围:只渲染有数据的部分,两侧各留 1 小时余量,
|
||
* 并延伸到当前时刻,让"今天跑到几点"有直观参照。
|
||
*/
|
||
function computeVisibleRange() {
|
||
const nz = TOTAL.map((v, i) => (v > 0 ? i : -1)).filter((i) => i >= 0);
|
||
if (!nz.length) { visible = { start: 0, end: 23 }; return; }
|
||
|
||
const now = new Date().getHours();
|
||
let start = Math.max(0, Math.min(nz[0], now) - 1);
|
||
let end = Math.min(23, Math.max(nz[nz.length - 1], now) + 1);
|
||
|
||
if (end - start < 5) {
|
||
const need = 5 - (end - start);
|
||
start = Math.max(0, start - Math.ceil(need / 2));
|
||
end = Math.min(23, start + 5);
|
||
}
|
||
visible = { start, end };
|
||
}
|
||
|
||
/** 当前筛选批次的全量累计(来自 batches) */
|
||
function currentBatchStats() {
|
||
if (!STATE) return null;
|
||
if (activeBatch === "__all__") {
|
||
const s = STATE.summary;
|
||
return { total: s.total, done: s.done, undone: s.undone, rate: s.rate, batch: "全部批次" };
|
||
}
|
||
return STATE.batches.find((b) => b.batch === activeBatch) || null;
|
||
}
|
||
|
||
/* ================================================================ 渲染:KPI */
|
||
/**
|
||
* KPI 跟随顶部批次筛选口径:
|
||
* 全部批次 -> 使用全局汇总 summary
|
||
* 单个批次 -> 只显示该批次的累计数与今日该批次的完成量
|
||
*/
|
||
function renderKpi() {
|
||
const h = STATE.hourly;
|
||
const scoped = activeBatch !== "__all__";
|
||
const bs = currentBatchStats() || {};
|
||
const all = STATE.summary;
|
||
|
||
// 今日完成量:按当前筛选范围取
|
||
const todayDone = scoped
|
||
? (h.by_batch[activeBatch] || []).reduce((a, v) => a + v, 0)
|
||
: h.today_done;
|
||
|
||
// 峰值小时:按当前筛选范围重算,避免显示的是别的批次峰值
|
||
let peak = null;
|
||
if (todayDone > 0) {
|
||
const arr = scoped ? (h.by_batch[activeBatch] || new Array(24).fill(0)) : h.total_by_hour;
|
||
const idx = arr.indexOf(Math.max(...arr));
|
||
peak = { hour: h.hours[idx], count: arr[idx] };
|
||
}
|
||
|
||
const total = scoped ? (bs.total || 0) : all.total;
|
||
const done = scoped ? (bs.done || 0) : all.done;
|
||
const undone = scoped ? (bs.undone || 0) : all.undone;
|
||
const rate = scoped ? (bs.rate || 0) : all.rate;
|
||
|
||
const cards = [
|
||
{
|
||
label: scoped ? "批次任务总量" : "任务总量",
|
||
value: fmt(total),
|
||
foot: scoped ? "当前筛选范围" : `${all.batch_count} 个批次`,
|
||
accent: "var(--series-1)"
|
||
},
|
||
{
|
||
label: scoped ? "批次已完成" : "已完成",
|
||
value: fmt(done),
|
||
foot: `完成率 ${rate}%`,
|
||
accent: "var(--status-good)",
|
||
color: "var(--success-text)"
|
||
},
|
||
{
|
||
label: scoped ? "批次未完成" : "未完成",
|
||
value: fmt(undone),
|
||
foot: "含 is_ok 为 0 / NULL",
|
||
accent: "var(--series-2)"
|
||
},
|
||
{
|
||
label: scoped ? "该批次今日完成" : "今日完成",
|
||
value: fmt(todayDone),
|
||
foot: peak && peak.count ? `峰值 ${peak.hour} · ${fmt(peak.count)} 条` : "今日暂无完成",
|
||
accent: "var(--series-1)"
|
||
}
|
||
];
|
||
|
||
$("kpis").innerHTML = cards.map((c) => `
|
||
<div class="kpi" style="--kpi-accent:${c.accent}">
|
||
<div class="label">${c.label}</div>
|
||
<div class="value"${c.color ? ` style="color:${c.color}"` : ""}>${c.value}</div>
|
||
<div class="foot">${c.foot}</div>
|
||
</div>
|
||
`).join("");
|
||
|
||
$("genTime").innerHTML = `统计时间<br><b>${STATE.generated_at}</b>`;
|
||
}
|
||
|
||
/* ================================================================ 渲染:批次卡片 */
|
||
/**
|
||
* 批次卡片跟随顶部筛选口径:
|
||
* 全部批次 -> 展示所有批次,行数超过 MAX_BATCH_ROWS 时默认收起,由按钮展开
|
||
* 单个批次 -> 只保留被选中的那张卡片(其余不渲染,避免视觉干扰)
|
||
*/
|
||
const MAX_BATCH_ROWS = 2; // 收起状态下最多显示的行数
|
||
let batchesExpanded = false; // 批次卡片区是否处于展开状态
|
||
|
||
/** 按各卡片的纵向偏移归组,数出实际占了几行(比解析 grid 模板更稳) */
|
||
function cardsPerRow() {
|
||
const row = $("batches");
|
||
if (!row || !row.children.length) return 1;
|
||
const firstTop = row.children[0].offsetTop;
|
||
const count = [...row.children].filter((c) => c.offsetTop === firstTop).length;
|
||
return Math.max(1, count);
|
||
}
|
||
|
||
/** 按下当前行的实际高度,给折叠容器算出裁切高度 */
|
||
function applyBatchesClip(limit) {
|
||
const clip = $("batchesClip");
|
||
const row = $("batches");
|
||
const more = $("batchesMore");
|
||
if (!clip || !row || !more) return;
|
||
|
||
const cards = [...row.children];
|
||
const total = cards.length;
|
||
const perRow = cardsPerRow();
|
||
const rows = Math.ceil(total / perRow);
|
||
const clipped = rows > limit; // 超过「行数上限」才需要收起
|
||
|
||
$("batchesWrap").classList.toggle("has-more", clipped);
|
||
|
||
if (!clipped) {
|
||
clip.classList.remove("collapsed");
|
||
clip.style.removeProperty("--clip-h");
|
||
more.hidden = true;
|
||
return;
|
||
}
|
||
|
||
// 第 limit 行最后一张卡片的下边缘,就是收起的裁切高度
|
||
const lastIdx = Math.min(limit * perRow, total) - 1;
|
||
const lastCard = cards[lastIdx];
|
||
const rowTop = row.getBoundingClientRect().top;
|
||
const h = lastCard.getBoundingClientRect().bottom - rowTop;
|
||
|
||
clip.style.setProperty("--clip-h", h + "px");
|
||
clip.classList.toggle("collapsed", !batchesExpanded);
|
||
more.hidden = false;
|
||
more.setAttribute("aria-expanded", String(batchesExpanded));
|
||
more.querySelector(".txt").textContent = batchesExpanded ? "收起批次卡片" : "展开全部批次";
|
||
// 行数按「上限」取整展示:收起时就是 limit 行,展开时才是实际行数
|
||
const shownRows = batchesExpanded ? rows : limit;
|
||
more.querySelector(".cnt").textContent = `共 ${total} 个批次 · ${shownRows} 行`;
|
||
}
|
||
|
||
function renderBatches() {
|
||
const scoped = activeBatch !== "__all__";
|
||
const list = scoped
|
||
? STATE.batches.filter((b) => b.batch === activeBatch)
|
||
: STATE.batches;
|
||
const row = $("batches");
|
||
const clip = $("batchesClip");
|
||
const wrap = $("batchesWrap");
|
||
const more = $("batchesMore");
|
||
|
||
// 每次重绘先复位裁切高度,避免上一轮的旧值在下一帧前短暂生效
|
||
clip.style.removeProperty("--clip-h");
|
||
clip.classList.remove("collapsed");
|
||
wrap.classList.remove("has-more");
|
||
more.hidden = true;
|
||
more.setAttribute("aria-expanded", "false");
|
||
more.querySelector(".cnt").textContent = "";
|
||
|
||
if (!list.length) {
|
||
row.className = "batches-row";
|
||
row.innerHTML = '<div class="state">暂无批次数据</div>';
|
||
return;
|
||
}
|
||
|
||
// 单批次时容器收窄为单列,卡片不会拉满整行显得空旷
|
||
row.className = "batches-row" + (scoped ? " single" : "");
|
||
|
||
row.innerHTML = list.map((b) => {
|
||
const pct = b.total ? (b.done / b.total * 100) : 0;
|
||
const allDone = b.undone === 0 && b.total > 0;
|
||
const isActive = activeBatch === b.batch;
|
||
return `
|
||
<div class="batch-card${isActive ? " active" : ""}">
|
||
<div class="batch-head">
|
||
<span class="batch-name">${b.batch}</span>
|
||
${isActive && scoped ? '<span class="chip">筛选中</span>' : ""}
|
||
${allDone ? '<span class="chip done">全部完成</span>' : ""}
|
||
<span class="batch-rate">${b.rate}%</span>
|
||
</div>
|
||
<div class="bar">
|
||
<div class="fill" style="width:${pct.toFixed(2)}%"></div>
|
||
${pct < 100 ? '<div class="rest"></div>' : ""}
|
||
</div>
|
||
<div class="batch-nums">
|
||
<span class="n"><span class="k">总量</span><span class="v">${fmt(b.total)}</span></span>
|
||
<span class="n"><span class="k">已完成</span><span class="v ok">${fmt(b.done)}</span></span>
|
||
<span class="n"><span class="k">未完成</span><span class="v">${fmt(b.undone)}</span></span>
|
||
<span class="time">更新 ${(b.last_update || "-").slice(5)}</span>
|
||
</div>
|
||
</div>`;
|
||
}).join("");
|
||
|
||
// 筛选到单个批次时只有一张卡,无需折叠;直接复位到展开态
|
||
if (scoped) {
|
||
clip.classList.remove("collapsed");
|
||
clip.style.removeProperty("--clip-h");
|
||
wrap.classList.remove("has-more");
|
||
more.hidden = true;
|
||
return;
|
||
}
|
||
|
||
// 布局完成后才能量出真实行高
|
||
requestAnimationFrame(() => applyBatchesClip(MAX_BATCH_ROWS));
|
||
}
|
||
|
||
/* ================================================================ 渲染:筛选作用域提示 */
|
||
function renderScopeBadge() {
|
||
const el = $("scopeBadge");
|
||
if (activeBatch === "__all__") {
|
||
el.hidden = true;
|
||
el.textContent = "";
|
||
} else {
|
||
el.hidden = false;
|
||
el.textContent = `已筛选:批次 ${activeBatch}`;
|
||
}
|
||
}
|
||
|
||
/* ================================================================ 渲染:批次筛选 */
|
||
function renderBatchFilter() {
|
||
const batches = Object.keys(STATE.hourly.by_batch);
|
||
const opts = [`<option value="__all__">全部批次</option>`]
|
||
.concat(batches.map((b) => `<option value="${b}">批次 ${b}</option>`));
|
||
const sel = $("batchFilter");
|
||
sel.innerHTML = opts.join("");
|
||
sel.value = activeBatch;
|
||
}
|
||
|
||
/* ================================================================ 渲染:图例与标题 */
|
||
function renderLegend() {
|
||
const names = Object.keys(SERIES);
|
||
const colors = theme().series;
|
||
const multi = names.length > 1;
|
||
|
||
$("legend").innerHTML = names.map((b, i) => `
|
||
<span class="item">
|
||
<span class="swatch" style="background:${colors[i % colors.length]}"></span>批次 ${b}
|
||
</span>
|
||
`).join("") + (multi ? `<span class="item" style="color:var(--text-muted)">合计 ${fmt(TOTAL.reduce((a, v) => a + v, 0))} 条</span>` : "");
|
||
|
||
const bs = currentBatchStats();
|
||
const scope = activeBatch === "__all__" ? "全部批次" : `批次 ${activeBatch}`;
|
||
$("viewTitle").textContent = `${scope} · 今日每小时完成量`;
|
||
$("viewSub").textContent =
|
||
`${STATE.hourly.date} · 按 update_time 小时切片 · 仅计已完成任务` +
|
||
(bs ? ` · 该范围累计完成 ${fmt(bs.done)} / 未完成 ${fmt(bs.undone)}` : "");
|
||
}
|
||
|
||
/* ================================================================ 渲染:表格 */
|
||
/**
|
||
* 表格列:
|
||
* 时间 | 该小时完成 | 环比上一小时 | [各批次小时完成...] | 批次已完成(累计) | 批次未完成(累计)
|
||
*
|
||
* 注意口径差异:
|
||
* 「该小时完成 / 环比」= 今日 0 点至该小时的当日增量(来自 update_time)
|
||
* 「已完成 / 未完成」= 该批次的全量累计快照(未完成任务没有完成时间,
|
||
* 无法归入具体小时,只能按批次整体展示)
|
||
*/
|
||
function renderTable() {
|
||
const h = STATE.hourly;
|
||
const names = Object.keys(SERIES);
|
||
const colors = theme().series;
|
||
const stats = currentBatchStats();
|
||
const nowHour = new Date().getHours();
|
||
const peakIdx = TOTAL.indexOf(Math.max(...TOTAL));
|
||
|
||
// ---------- 表头(三行:分组名 / 列名 / 快照数值)
|
||
const groupCells = [];
|
||
const colCells = [];
|
||
|
||
groupCells.push(`<th rowspan="3">时间</th>`);
|
||
|
||
const scopeName = activeBatch === "__all__" ? "全部批次" : "批次 " + activeBatch;
|
||
const hasBatchCols = names.length > 1;
|
||
|
||
groupCells.push(`<th colspan="2" class="grp-start grp-a">${scopeName} · 小时增量</th>`);
|
||
colCells.push(`<th>完成量</th>`, `<th>环比上一小时</th>`);
|
||
|
||
if (hasBatchCols) {
|
||
groupCells.push(`<th colspan="${names.length}" class="grp-start grp-a">各批次小时完成量</th>`);
|
||
names.forEach((b, i) => {
|
||
colCells.push(`<th>${b}</th>`);
|
||
});
|
||
}
|
||
|
||
groupCells.push(`<th colspan="3" class="grp-start grp-b">${scopeName} · 全量累计快照</th>`);
|
||
colCells.push(`<th>任务总量</th>`, `<th>已完成</th>`, `<th>未完成</th>`);
|
||
|
||
// 第三行:与小时无关的批次级常量,只在表头汇总一次,不随 24 行重复
|
||
const snapCellsHead = [
|
||
`<th class="snap-th">${stats ? fmt(stats.total) : "—"}</th>`,
|
||
`<th class="snap-th snap-done">${stats ? fmt(stats.done) : "—"}</th>`,
|
||
`<th class="snap-th">${stats ? fmt(stats.undone) : "—"}</th>`,
|
||
];
|
||
|
||
$("tHead").innerHTML =
|
||
`<tr>${groupCells.join("")}</tr>` +
|
||
`<tr>${colCells.join("")}</tr>` +
|
||
`<tr class="snapshot-row">${snapCellsHead.join("")}</tr>`;
|
||
|
||
// ---------- 表体
|
||
$("tBody").innerHTML = h.hours.map((hr, i) => {
|
||
const done = TOTAL[i];
|
||
const d = DELTA[i];
|
||
const isPeak = i === peakIdx && done > 0;
|
||
|
||
const cls = [];
|
||
if (done === 0) cls.push("dim");
|
||
if (isPeak) cls.push("peak");
|
||
if (i === nowHour) cls.push("current");
|
||
|
||
// 环比:正增量走成功色,零/负走弱化灰,空小时留白
|
||
let deltaCell;
|
||
if (done === 0 && d === 0) {
|
||
deltaCell = `<td class="zero">—</td>`;
|
||
} else if (d > 0) {
|
||
deltaCell = `<td class="up">+${fmt(d)}</td>`;
|
||
} else {
|
||
deltaCell = `<td class="down">${d === 0 ? "0" : fmt(d)}</td>`;
|
||
}
|
||
|
||
// 各批次小时值:带配色点,与图例、图形保持一致
|
||
const batchCells = names.map((b, k) => {
|
||
const v = SERIES[b][i] || 0;
|
||
if (v === 0) return `<td class="zero batch-cell">—</td>`;
|
||
return `<td class="batch-cell"><span class="dot" style="color:${colors[k % colors.length]}">●</span>${fmt(v)}</td>`;
|
||
}).join("");
|
||
|
||
// 峰值小时:把左侧色条挂在「完成量」格上
|
||
// 该格紧邻分组分隔线,色条若走 inset 会与发丝线叠在一起显脏,
|
||
// 因此直接用 2px 的内描边柱贴齐格子的左边缘,与外框线重合。
|
||
const mainCell = done === 0
|
||
? `<td class="zero main-cell">—</td>`
|
||
: `<td class="main-cell${isPeak ? " peak-mark" : ""}">${fmt(done)}</td>`;
|
||
|
||
return `<tr class="${cls.join(" ")}">
|
||
<td class="time-cell">${pad2(i)}<span class="sep">:00 – </span>${pad2(i + 1)}<span class="sep">:00</span></td>
|
||
${mainCell}
|
||
${deltaCell}
|
||
${batchCells}
|
||
<td>${stats ? fmt(stats.total) : "—"}</td>
|
||
<td class="snap-done">${stats ? fmt(stats.done) : "—"}</td>
|
||
<td>${stats ? fmt(stats.undone) : "—"}</td>
|
||
</tr>`;
|
||
}).join("");
|
||
}
|
||
|
||
/* ================================================================ 图表 */
|
||
function drawChart() {
|
||
const canvas = $("chart");
|
||
if (!canvas) return;
|
||
const ctx = canvas.getContext("2d");
|
||
const dpr = window.devicePixelRatio || 1;
|
||
const cssW = canvas.clientWidth;
|
||
const cssH = canvas.clientHeight;
|
||
|
||
if (cssW === 0 || cssH === 0) return;
|
||
canvas.width = Math.round(cssW * dpr);
|
||
canvas.height = Math.round(cssH * dpr);
|
||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||
ctx.clearRect(0, 0, cssW, cssH);
|
||
|
||
if (!STATE || !STATE.hourly) return;
|
||
|
||
const th = theme();
|
||
const names = Object.keys(SERIES);
|
||
const { start, end } = visible;
|
||
const span = end - start;
|
||
|
||
if (!names.length || TOTAL.every((v) => v === 0)) {
|
||
ctx.fillStyle = th.muted;
|
||
ctx.font = '13px system-ui, "Microsoft YaHei", sans-serif';
|
||
ctx.textAlign = "center";
|
||
ctx.textBaseline = "middle";
|
||
ctx.fillText("今日暂无完成数据", cssW / 2, cssH / 2);
|
||
return;
|
||
}
|
||
|
||
const padL = 56, padR = 18, padT = 20, padB = 32;
|
||
const plotW = cssW - padL - padR;
|
||
const plotH = cssH - padT - padB;
|
||
|
||
// 纵轴上限只看可见区间,曲线更饱满
|
||
const inView = [];
|
||
for (let i = start; i <= end; i++) {
|
||
names.forEach((b) => inView.push(SERIES[b][i] || 0));
|
||
}
|
||
const maxVal = Math.max(1, ...inView);
|
||
const step = niceStep(maxVal / 4);
|
||
const yMax = Math.ceil(maxVal / step) * step;
|
||
|
||
const X = (i) => padL + (plotW * (i - start)) / span;
|
||
const Y = (v) => padT + plotH - (plotH * v) / yMax;
|
||
|
||
// "当前时刻"参考线
|
||
const nowHour = new Date().getHours();
|
||
if (nowHour >= start && nowHour <= end) {
|
||
const nx = X(nowHour);
|
||
ctx.beginPath();
|
||
ctx.strokeStyle = th.baseline;
|
||
ctx.lineWidth = 1;
|
||
ctx.setLineDash([4, 4]);
|
||
ctx.moveTo(nx, padT - 4);
|
||
ctx.lineTo(nx, padT + plotH);
|
||
ctx.stroke();
|
||
ctx.setLineDash([]);
|
||
ctx.fillStyle = th.muted;
|
||
ctx.font = '10.5px system-ui, "Microsoft YaHei", sans-serif';
|
||
ctx.textAlign = "center";
|
||
ctx.textBaseline = "bottom";
|
||
ctx.fillText("当前", nx, padT - 7);
|
||
}
|
||
|
||
// 水平网格 + Y 轴刻度
|
||
ctx.font = '11.5px system-ui, "Microsoft YaHei", sans-serif';
|
||
ctx.textAlign = "right";
|
||
ctx.textBaseline = "middle";
|
||
for (let v = 0; v <= yMax + 1e-9; v += step) {
|
||
const y = Y(v);
|
||
ctx.beginPath();
|
||
ctx.strokeStyle = v === 0 ? th.baseline : th.grid;
|
||
ctx.lineWidth = 1;
|
||
ctx.moveTo(padL, Math.round(y) + 0.5);
|
||
ctx.lineTo(padL + plotW, Math.round(y) + 0.5);
|
||
ctx.stroke();
|
||
ctx.fillStyle = th.muted;
|
||
ctx.fillText(fmt(v), padL - 10, y);
|
||
}
|
||
|
||
// X 轴刻度(按跨度自适应密度)
|
||
const tickEvery = span <= 8 ? 1 : span <= 14 ? 2 : 3;
|
||
ctx.textAlign = "center";
|
||
ctx.textBaseline = "top";
|
||
ctx.fillStyle = th.muted;
|
||
for (let i = start; i <= end; i++) {
|
||
if ((i - start) % tickEvery !== 0 && i !== end) continue;
|
||
ctx.fillText(pad2(i), X(i), padT + plotH + 10);
|
||
}
|
||
|
||
// 悬浮准线
|
||
if (hoverIndex >= start && hoverIndex <= end) {
|
||
const hx = X(hoverIndex);
|
||
ctx.beginPath();
|
||
ctx.strokeStyle = th.baseline;
|
||
ctx.lineWidth = 1;
|
||
ctx.setLineDash([3, 4]);
|
||
ctx.moveTo(hx, padT);
|
||
ctx.lineTo(hx, padT + plotH);
|
||
ctx.stroke();
|
||
ctx.setLineDash([]);
|
||
}
|
||
|
||
// 数据线
|
||
names.forEach((b, bi) => {
|
||
const data = SERIES[b];
|
||
const color = th.series[bi % th.series.length];
|
||
|
||
// 单系列时加淡渐变填充,增强体量感
|
||
if (names.length === 1) {
|
||
const grad = ctx.createLinearGradient(0, padT, 0, padT + plotH);
|
||
grad.addColorStop(0, hexToRgba(color, isDark() ? 0.22 : 0.16));
|
||
grad.addColorStop(1, hexToRgba(color, 0));
|
||
ctx.beginPath();
|
||
ctx.moveTo(X(start), Y(0));
|
||
for (let i = start; i <= end; i++) ctx.lineTo(X(i), Y(data[i] || 0));
|
||
ctx.lineTo(X(end), Y(0));
|
||
ctx.closePath();
|
||
ctx.fillStyle = grad;
|
||
ctx.fill();
|
||
}
|
||
|
||
ctx.beginPath();
|
||
ctx.strokeStyle = color;
|
||
ctx.lineWidth = 2;
|
||
ctx.lineJoin = "round";
|
||
ctx.lineCap = "round";
|
||
for (let i = start; i <= end; i++) {
|
||
const x = X(i), y = Y(data[i] || 0);
|
||
i === start ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
|
||
}
|
||
ctx.stroke();
|
||
|
||
// 悬浮点:同色外圈 + 表面色内圈,形成环形间隙
|
||
if (hoverIndex >= start && hoverIndex <= end) {
|
||
const v = data[hoverIndex] || 0;
|
||
const x = X(hoverIndex), y = Y(v);
|
||
ctx.beginPath();
|
||
ctx.arc(x, y, 6, 0, Math.PI * 2);
|
||
ctx.fillStyle = color;
|
||
ctx.fill();
|
||
ctx.beginPath();
|
||
ctx.arc(x, y, 4, 0, Math.PI * 2);
|
||
ctx.fillStyle = th.surface;
|
||
ctx.fill();
|
||
}
|
||
});
|
||
|
||
// 峰值直接标注(只标一个)
|
||
if (hoverIndex < 0) {
|
||
const peakIdx = TOTAL.indexOf(Math.max(...TOTAL));
|
||
if (peakIdx >= start && peakIdx <= end && TOTAL[peakIdx] > 0) {
|
||
const v = TOTAL[peakIdx];
|
||
ctx.font = '620 11.5px system-ui, "Microsoft YaHei", sans-serif';
|
||
ctx.textAlign = "center";
|
||
ctx.textBaseline = "bottom";
|
||
ctx.fillStyle = th.baseline;
|
||
ctx.fillText(`峰值 ${fmt(v)}`, X(peakIdx), Y(v) - 9);
|
||
}
|
||
}
|
||
}
|
||
|
||
function niceStep(raw) {
|
||
if (!(raw > 0)) return 1;
|
||
const mag = Math.pow(10, Math.floor(Math.log10(raw)));
|
||
const norm = raw / mag;
|
||
const mult = norm <= 1 ? 1 : norm <= 2 ? 2 : norm <= 5 ? 5 : 10;
|
||
return mult * mag;
|
||
}
|
||
|
||
function hexToRgba(hex, alpha) {
|
||
const n = parseInt(hex.slice(1), 16);
|
||
return `rgba(${(n >> 16) & 255},${(n >> 8) & 255},${n & 255},${alpha})`;
|
||
}
|
||
|
||
/* ================================================================ 悬浮交互 */
|
||
function setupHover() {
|
||
const canvas = $("chart");
|
||
const tip = $("tooltip");
|
||
|
||
function update(evt) {
|
||
if (currentView !== "chart" || !STATE || !STATE.hourly) return;
|
||
const rect = canvas.getBoundingClientRect();
|
||
const x = evt.clientX - rect.left;
|
||
|
||
const padL = 56, padR = 18;
|
||
const plotW = rect.width - padL - padR;
|
||
const { start, end } = visible;
|
||
const span = end - start;
|
||
|
||
const ratio = (x - padL) / plotW;
|
||
const idx = Math.round(start + ratio * span);
|
||
if (idx < start || idx > end) { hide(); return; }
|
||
|
||
if (idx !== hoverIndex) { hoverIndex = idx; drawChart(); }
|
||
|
||
const names = Object.keys(SERIES);
|
||
const th = theme();
|
||
const d = DELTA[idx];
|
||
|
||
tip.innerHTML =
|
||
`<div class="tt-title">${pad2(idx)}:00 – ${pad2(idx + 1)}:00</div>` +
|
||
names.map((b, i) => `
|
||
<div class="tt-row">
|
||
<span class="swatch" style="background:${th.series[i % th.series.length]}"></span>
|
||
<span class="nm">批次 ${b}</span>
|
||
<span class="vl">${fmt(SERIES[b][idx] || 0)}</span>
|
||
</div>`).join("") +
|
||
`<div class="tt-row tt-total"><span class="nm">本小时合计</span><span class="vl">${fmt(TOTAL[idx])}</span></div>` +
|
||
`<div class="tt-row"><span class="nm">环比上一小时</span><span class="vl" style="color:${d > 0 ? "var(--success-text)" : "var(--text-muted)"}">${d > 0 ? "+" : ""}${fmt(d)}</span></div>`;
|
||
|
||
tip.style.opacity = "1";
|
||
const tw = tip.offsetWidth;
|
||
let left = x + 16;
|
||
if (left + tw > rect.width) left = x - tw - 16;
|
||
tip.style.left = Math.max(4, left) + "px";
|
||
tip.style.top = Math.max(4, (evt.clientY - rect.top) - 12) + "px";
|
||
}
|
||
|
||
function hide() {
|
||
tip.style.opacity = "0";
|
||
if (hoverIndex !== -1) { hoverIndex = -1; drawChart(); }
|
||
}
|
||
|
||
canvas.addEventListener("mousemove", update);
|
||
canvas.addEventListener("mouseleave", hide);
|
||
canvas.addEventListener("touchstart", (e) => e.touches[0] && update(e.touches[0]), { passive: true });
|
||
canvas.addEventListener("touchmove", (e) => e.touches[0] && update(e.touches[0]), { passive: true });
|
||
canvas.addEventListener("touchend", hide);
|
||
}
|
||
|
||
/* ================================================================ 视图切换 */
|
||
function switchView(view) {
|
||
currentView = view;
|
||
const isChart = view === "chart";
|
||
$("viewChart").classList.toggle("hidden", !isChart);
|
||
$("viewTable").classList.toggle("hidden", isChart);
|
||
$("tabChart").classList.toggle("active", isChart);
|
||
$("tabTable").classList.toggle("active", !isChart);
|
||
|
||
if (isChart) {
|
||
// 切回图形时容器尺寸才可测量,需要重绘
|
||
requestAnimationFrame(() => {
|
||
drawChart();
|
||
// 再把悬浮层重新挂上(画布尺寸变化不影响监听,这里只需重绘)
|
||
});
|
||
}
|
||
}
|
||
|
||
/* ================================================================ 主题 */
|
||
function initTheme() {
|
||
const saved = localStorage.getItem("dash-theme") || "auto";
|
||
document.documentElement.setAttribute("data-theme", saved);
|
||
|
||
$("themeBtn").addEventListener("click", () => {
|
||
const cur = document.documentElement.getAttribute("data-theme");
|
||
const next = cur === "dark" ? "light" : cur === "light" ? "auto" : "dark";
|
||
document.documentElement.setAttribute("data-theme", next);
|
||
localStorage.setItem("dash-theme", next);
|
||
renderLegend();
|
||
renderTable();
|
||
drawChart();
|
||
});
|
||
|
||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
|
||
renderLegend();
|
||
renderTable();
|
||
drawChart();
|
||
});
|
||
}
|
||
|
||
/* ================================================================ 汇总渲染 */
|
||
/** 顶部批次筛选是全局口径,选中后 KPI、批次卡片、图形、表格全部联动 */
|
||
function renderAll() {
|
||
renderKpi();
|
||
renderBatches();
|
||
renderScopeBadge();
|
||
renderLegend();
|
||
renderTable();
|
||
if (currentView === "chart") requestAnimationFrame(drawChart);
|
||
}
|
||
|
||
function init() {
|
||
initTheme();
|
||
setupHover();
|
||
switchView("chart");
|
||
|
||
$("refreshBtn").addEventListener("click", () => loadData(true));
|
||
|
||
$("batchFilter").addEventListener("change", (e) => {
|
||
activeBatch = e.target.value;
|
||
recompute();
|
||
renderAll();
|
||
});
|
||
|
||
$("tabChart").addEventListener("click", () => switchView("chart"));
|
||
$("tabTable").addEventListener("click", () => switchView("table"));
|
||
|
||
// 批次卡片区:展开 / 收起
|
||
$("batchesMore").addEventListener("click", () => {
|
||
batchesExpanded = !batchesExpanded;
|
||
applyBatchesClip(MAX_BATCH_ROWS);
|
||
});
|
||
|
||
let rt;
|
||
window.addEventListener("resize", () => {
|
||
clearTimeout(rt);
|
||
rt = setTimeout(() => {
|
||
if (currentView === "chart") drawChart();
|
||
// 列数会随宽度变化,裁切高度需要跟着重算
|
||
if (activeBatch === "__all__" && STATE) applyBatchesClip(MAX_BATCH_ROWS);
|
||
}, 120);
|
||
});
|
||
|
||
loadData(false);
|
||
setInterval(() => loadData(false), 30 * 60 * 1000);
|
||
}
|
||
|
||
document.addEventListener("DOMContentLoaded", init);
|
||
</script>
|
||
</body>
|
||
</html>
|