- 16 个业务模块,856 个测试用例,40 个 E2E 测试 - 单一 React 19 前端 + PlatformSwitcher 二合一切换 - Flask 后端支持 scenario/dcloud_module/dcloud_e2e/dcloud_all 四种任务类型 - E2E 测试面板:API 全链路(8条) + UI 点击(3条) + 分步测试(3个) - SSE 实时日志流 + 飞书告警 + 定时调度 - 完整还原原 ToB 平台 TestPanel E2E 模块
2157 lines
72 KiB
HTML
2157 lines
72 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
|
||
<head>
|
||
<meta charset="UTF-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<title>AutoFlow | 自动化平台</title>
|
||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||
<link
|
||
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
|
||
rel="stylesheet" />
|
||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||
<style>
|
||
/* ── Design Tokens ──────────────────────────────────────── */
|
||
:root {
|
||
--bg: #0d0f14;
|
||
--surface: #141720;
|
||
--surface2: #1c2030;
|
||
--surface3: #252a3a;
|
||
--border: #2a3048;
|
||
--accent: #6c72ff;
|
||
--accent2: #38e0b0;
|
||
--danger: #ff5c6c;
|
||
--warn: #ffb547;
|
||
--success: #38e0b0;
|
||
--text: #e6e9f4;
|
||
--text-muted: #7a82a0;
|
||
--sidebar-w: 240px;
|
||
--radius: 12px;
|
||
}
|
||
|
||
* {
|
||
box-sizing: border-box;
|
||
margin: 0;
|
||
padding: 0;
|
||
}
|
||
|
||
body {
|
||
font-family: 'Inter', sans-serif;
|
||
background: var(--bg);
|
||
color: var(--text);
|
||
min-height: 100vh;
|
||
display: flex;
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* ── Sidebar ────────────────────────────────────────────── */
|
||
#sidebar {
|
||
width: var(--sidebar-w);
|
||
min-height: 100vh;
|
||
background: var(--surface);
|
||
border-right: 1px solid var(--border);
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 20px 0;
|
||
position: fixed;
|
||
left: 0;
|
||
top: 0;
|
||
bottom: 0;
|
||
z-index: 100;
|
||
}
|
||
|
||
.logo {
|
||
padding: 0 20px 24px;
|
||
border-bottom: 1px solid var(--border);
|
||
}
|
||
|
||
.logo h1 {
|
||
font-size: 18px;
|
||
font-weight: 700;
|
||
background: linear-gradient(135deg, var(--accent), var(--accent2));
|
||
-webkit-background-clip: text;
|
||
background-clip: text;
|
||
-webkit-text-fill-color: transparent;
|
||
}
|
||
|
||
.logo span {
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
letter-spacing: 1px;
|
||
text-transform: uppercase;
|
||
}
|
||
|
||
.nav-section {
|
||
padding: 20px 12px 8px;
|
||
}
|
||
|
||
.nav-section-title {
|
||
font-size: 10px;
|
||
color: var(--text-muted);
|
||
text-transform: uppercase;
|
||
letter-spacing: 1.5px;
|
||
padding: 0 8px 8px;
|
||
}
|
||
|
||
.nav-item {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
padding: 10px 12px;
|
||
border-radius: 8px;
|
||
cursor: pointer;
|
||
font-size: 13.5px;
|
||
font-weight: 500;
|
||
color: var(--text-muted);
|
||
transition: all 0.2s;
|
||
margin-bottom: 2px;
|
||
user-select: none;
|
||
}
|
||
|
||
.nav-item:hover {
|
||
background: var(--surface3);
|
||
color: var(--text);
|
||
}
|
||
|
||
.nav-item.active {
|
||
background: rgba(108, 114, 255, 0.12);
|
||
color: var(--accent);
|
||
}
|
||
|
||
.nav-item .icon {
|
||
font-size: 16px;
|
||
width: 20px;
|
||
text-align: center;
|
||
}
|
||
|
||
.nav-badge {
|
||
margin-left: auto;
|
||
background: var(--accent);
|
||
color: #fff;
|
||
border-radius: 10px;
|
||
font-size: 10px;
|
||
padding: 1px 7px;
|
||
min-width: 18px;
|
||
text-align: center;
|
||
}
|
||
|
||
.sidebar-footer {
|
||
margin-top: auto;
|
||
padding: 20px 12px;
|
||
border-top: 1px solid var(--border);
|
||
}
|
||
|
||
.status-dot {
|
||
width: 8px;
|
||
height: 8px;
|
||
border-radius: 50%;
|
||
background: var(--accent2);
|
||
box-shadow: 0 0 6px var(--accent2);
|
||
display: inline-block;
|
||
margin-right: 8px;
|
||
animation: pulse 2s infinite;
|
||
}
|
||
|
||
@keyframes pulse {
|
||
|
||
0%,
|
||
100% {
|
||
opacity: 1
|
||
}
|
||
|
||
50% {
|
||
opacity: .4
|
||
}
|
||
}
|
||
|
||
/* ── Main Layout ────────────────────────────────────────── */
|
||
#main {
|
||
margin-left: var(--sidebar-w);
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100vh;
|
||
overflow: hidden;
|
||
}
|
||
|
||
#topbar {
|
||
padding: 20px 28px;
|
||
border-bottom: 1px solid var(--border);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
background: var(--surface);
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
#topbar h2 {
|
||
font-size: 18px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
#topbar .sub {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
margin-top: 2px;
|
||
}
|
||
|
||
.btn {
|
||
padding: 9px 18px;
|
||
border-radius: 8px;
|
||
border: none;
|
||
cursor: pointer;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
transition: all 0.2s;
|
||
font-family: 'Inter', sans-serif;
|
||
}
|
||
|
||
.btn-primary {
|
||
background: linear-gradient(135deg, var(--accent), #4f56e8);
|
||
color: #fff;
|
||
box-shadow: 0 4px 15px rgba(108, 114, 255, 0.3);
|
||
}
|
||
|
||
.btn-primary:hover {
|
||
transform: translateY(-1px);
|
||
box-shadow: 0 6px 20px rgba(108, 114, 255, 0.45);
|
||
}
|
||
|
||
.btn-ghost {
|
||
background: var(--surface3);
|
||
color: var(--text-muted);
|
||
border: 1px solid var(--border);
|
||
}
|
||
|
||
.btn-ghost:hover {
|
||
color: var(--text);
|
||
border-color: var(--accent);
|
||
}
|
||
|
||
.btn-danger {
|
||
background: rgba(255, 92, 108, 0.12);
|
||
color: var(--danger);
|
||
border: 1px solid rgba(255, 92, 108, 0.3);
|
||
}
|
||
|
||
#content {
|
||
flex: 1;
|
||
overflow-y: auto;
|
||
padding: 24px 28px;
|
||
}
|
||
|
||
/* ── Cards / Grid ───────────────────────────────────────── */
|
||
.stats-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(4, 1fr);
|
||
gap: 16px;
|
||
margin-bottom: 24px;
|
||
}
|
||
|
||
.stat-card {
|
||
background: var(--surface);
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius);
|
||
padding: 20px;
|
||
position: relative;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.stat-card::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
right: 0;
|
||
height: 2px;
|
||
background: var(--accent-grad, linear-gradient(90deg, var(--accent), var(--accent2)));
|
||
}
|
||
|
||
.stat-label {
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
text-transform: uppercase;
|
||
letter-spacing: 1px;
|
||
}
|
||
|
||
.stat-value {
|
||
font-size: 32px;
|
||
font-weight: 700;
|
||
margin: 8px 0 4px;
|
||
}
|
||
|
||
.stat-meta {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
/* ── Task Table ─────────────────────────────────────────── */
|
||
.panel {
|
||
background: var(--surface);
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius);
|
||
overflow: hidden;
|
||
}
|
||
|
||
.panel-header {
|
||
padding: 16px 20px;
|
||
border-bottom: 1px solid var(--border);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.panel-title {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
}
|
||
|
||
th {
|
||
text-align: left;
|
||
padding: 12px 20px;
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
text-transform: uppercase;
|
||
letter-spacing: 1px;
|
||
border-bottom: 1px solid var(--border);
|
||
font-weight: 500;
|
||
}
|
||
|
||
td {
|
||
padding: 14px 20px;
|
||
font-size: 13px;
|
||
border-bottom: 1px solid rgba(42, 48, 72, 0.5);
|
||
vertical-align: middle;
|
||
}
|
||
|
||
tr:last-child td {
|
||
border-bottom: none;
|
||
}
|
||
|
||
tr:hover td {
|
||
background: rgba(255, 255, 255, 0.02);
|
||
}
|
||
|
||
.status-badge {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 5px;
|
||
padding: 3px 10px;
|
||
border-radius: 20px;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.status-badge.running {
|
||
background: rgba(108, 114, 255, 0.15);
|
||
color: var(--accent);
|
||
}
|
||
|
||
.status-badge.pass {
|
||
background: rgba(56, 224, 176, 0.12);
|
||
color: var(--accent2);
|
||
}
|
||
|
||
.status-badge.fail {
|
||
background: rgba(255, 92, 108, 0.12);
|
||
color: var(--danger);
|
||
}
|
||
|
||
.status-badge.pending {
|
||
background: rgba(122, 130, 160, 0.12);
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.spin {
|
||
display: inline-block;
|
||
width: 8px;
|
||
height: 8px;
|
||
border: 2px solid transparent;
|
||
border-top-color: currentColor;
|
||
border-radius: 50%;
|
||
animation: spin 0.8s linear infinite;
|
||
}
|
||
|
||
@keyframes spin {
|
||
to {
|
||
transform: rotate(360deg);
|
||
}
|
||
}
|
||
|
||
.action-btn {
|
||
padding: 5px 12px;
|
||
border-radius: 6px;
|
||
border: 1px solid var(--border);
|
||
background: transparent;
|
||
color: var(--text-muted);
|
||
font-size: 12px;
|
||
cursor: pointer;
|
||
transition: all .2s;
|
||
}
|
||
|
||
.action-btn:hover {
|
||
border-color: var(--accent);
|
||
color: var(--accent);
|
||
}
|
||
|
||
/* ── Modal ──────────────────────────────────────────────── */
|
||
.modal-overlay {
|
||
position: fixed;
|
||
inset: 0;
|
||
background: rgba(0, 0, 0, 0.65);
|
||
backdrop-filter: blur(4px);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
z-index: 999;
|
||
opacity: 0;
|
||
pointer-events: none;
|
||
transition: opacity .25s;
|
||
}
|
||
|
||
.modal-overlay.open {
|
||
opacity: 1;
|
||
pointer-events: all;
|
||
}
|
||
|
||
.modal {
|
||
background: var(--surface2);
|
||
border: 1px solid var(--border);
|
||
border-radius: 16px;
|
||
width: 520px;
|
||
max-height: 90vh;
|
||
overflow-y: auto;
|
||
box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
|
||
transform: translateY(20px);
|
||
transition: transform .25s;
|
||
}
|
||
|
||
.modal-overlay.open .modal {
|
||
transform: translateY(0);
|
||
}
|
||
|
||
.modal-header {
|
||
padding: 24px 24px 0;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: flex-start;
|
||
}
|
||
|
||
.modal-header h3 {
|
||
font-size: 18px;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.modal-header p {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
margin-top: 4px;
|
||
}
|
||
|
||
.modal-close {
|
||
background: var(--surface3);
|
||
border: none;
|
||
color: var(--text-muted);
|
||
width: 30px;
|
||
height: 30px;
|
||
border-radius: 8px;
|
||
cursor: pointer;
|
||
font-size: 16px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
transition: all .2s;
|
||
}
|
||
|
||
.modal-close:hover {
|
||
color: var(--text);
|
||
background: var(--border);
|
||
}
|
||
|
||
.modal-body {
|
||
padding: 24px;
|
||
}
|
||
|
||
.form-group {
|
||
margin-bottom: 18px;
|
||
}
|
||
|
||
.form-label {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
font-weight: 500;
|
||
margin-bottom: 8px;
|
||
display: block;
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.5px;
|
||
}
|
||
|
||
.form-input {
|
||
width: 100%;
|
||
background: var(--surface3);
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
color: var(--text);
|
||
padding: 10px 14px;
|
||
font-size: 13.5px;
|
||
font-family: 'Inter', sans-serif;
|
||
outline: none;
|
||
transition: border .2s;
|
||
}
|
||
|
||
.form-input:focus {
|
||
border-color: var(--accent);
|
||
}
|
||
|
||
.form-input[type=password] {
|
||
font-family: 'JetBrains Mono', monospace;
|
||
letter-spacing: 2px;
|
||
}
|
||
|
||
.product-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 10px;
|
||
}
|
||
|
||
.product-card {
|
||
border: 2px solid var(--border);
|
||
border-radius: 10px;
|
||
padding: 14px;
|
||
cursor: pointer;
|
||
transition: all .2s;
|
||
background: var(--surface3);
|
||
}
|
||
|
||
.product-card:hover {
|
||
border-color: var(--accent);
|
||
}
|
||
|
||
.product-card.selected {
|
||
border-color: var(--accent);
|
||
background: rgba(108, 114, 255, 0.1);
|
||
}
|
||
|
||
.product-card .p-icon {
|
||
font-size: 24px;
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.product-card .p-name {
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.product-card .p-desc {
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
margin-top: 4px;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
.form-row {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 14px;
|
||
}
|
||
|
||
.toggle {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
background: var(--surface3);
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 12px 14px;
|
||
}
|
||
|
||
.toggle-label {
|
||
font-size: 13px;
|
||
}
|
||
|
||
.toggle-sub {
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.switch {
|
||
position: relative;
|
||
width: 40px;
|
||
height: 22px;
|
||
}
|
||
|
||
.switch input {
|
||
opacity: 0;
|
||
width: 0;
|
||
height: 0;
|
||
}
|
||
|
||
.slider {
|
||
position: absolute;
|
||
inset: 0;
|
||
background: var(--surface2);
|
||
border-radius: 22px;
|
||
cursor: pointer;
|
||
transition: .3s;
|
||
border: 1px solid var(--border);
|
||
}
|
||
|
||
.slider:before {
|
||
content: '';
|
||
position: absolute;
|
||
width: 16px;
|
||
height: 16px;
|
||
border-radius: 50%;
|
||
background: var(--text-muted);
|
||
left: 2px;
|
||
top: 2px;
|
||
transition: .3s;
|
||
}
|
||
|
||
input:checked+.slider {
|
||
background: rgba(108, 114, 255, 0.3);
|
||
border-color: var(--accent);
|
||
}
|
||
|
||
input:checked+.slider:before {
|
||
transform: translateX(18px);
|
||
background: var(--accent);
|
||
}
|
||
|
||
.modal-footer {
|
||
padding: 0 24px 24px;
|
||
display: flex;
|
||
gap: 10px;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.pwd-toggle {
|
||
position: absolute;
|
||
right: 12px;
|
||
top: 34px;
|
||
cursor: pointer;
|
||
font-size: 16px;
|
||
opacity: 0.5;
|
||
transition: opacity .2s;
|
||
user-select: none;
|
||
}
|
||
|
||
.pwd-toggle:hover {
|
||
opacity: 1;
|
||
}
|
||
|
||
/* ── Log Viewer ─────────────────────────────────────────── */
|
||
.log-viewer-modal .modal {
|
||
width: 800px;
|
||
}
|
||
|
||
.log-box {
|
||
background: #0a0c10;
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 16px;
|
||
height: 360px;
|
||
overflow-y: auto;
|
||
font-family: 'JetBrains Mono', monospace;
|
||
font-size: 12px;
|
||
line-height: 1.7;
|
||
}
|
||
|
||
.log-line {
|
||
padding: 1px 0;
|
||
}
|
||
|
||
.log-line .ts {
|
||
color: #4a5270;
|
||
margin-right: 8px;
|
||
}
|
||
|
||
.log-line.INFO .level {
|
||
color: #6c72ff;
|
||
}
|
||
|
||
.log-line.SUCCESS .level {
|
||
color: #38e0b0;
|
||
}
|
||
|
||
.log-line.WARN .level {
|
||
color: #ffb547;
|
||
}
|
||
|
||
.log-line.ERROR .level {
|
||
color: #ff5c6c;
|
||
}
|
||
|
||
.log-line.INFO .msg {
|
||
color: #b4bcd8;
|
||
}
|
||
|
||
.log-line.SUCCESS .msg {
|
||
color: #38e0b0;
|
||
}
|
||
|
||
.log-line.WARN .msg {
|
||
color: #ffb547;
|
||
}
|
||
|
||
.log-line.ERROR .msg {
|
||
color: #ff5c6c;
|
||
}
|
||
|
||
.log-status {
|
||
padding: 12px 20px;
|
||
border-top: 1px solid var(--border);
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
background: var(--surface2);
|
||
}
|
||
|
||
/* ── Report ─────────────────────────────────────────────── */
|
||
.report-card {
|
||
background: var(--surface);
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius);
|
||
padding: 20px;
|
||
margin-bottom: 12px;
|
||
display: grid;
|
||
grid-template-columns: 1fr auto;
|
||
gap: 16px;
|
||
align-items: center;
|
||
}
|
||
|
||
.report-result {
|
||
font-size: 28px;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.report-result.PASS {
|
||
color: var(--accent2);
|
||
}
|
||
|
||
.report-result.FAIL {
|
||
color: var(--danger);
|
||
}
|
||
|
||
.report-meta {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
display: flex;
|
||
gap: 16px;
|
||
flex-wrap: wrap;
|
||
margin-top: 8px;
|
||
}
|
||
|
||
.report-meta span {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
}
|
||
|
||
.progress-bar {
|
||
height: 4px;
|
||
background: var(--surface3);
|
||
border-radius: 4px;
|
||
overflow: hidden;
|
||
margin-top: 12px;
|
||
}
|
||
|
||
.progress-fill {
|
||
height: 100%;
|
||
border-radius: 4px;
|
||
transition: width .5s;
|
||
}
|
||
|
||
/* ── Products Page ──────────────────────────────────────── */
|
||
.product-list {
|
||
display: grid;
|
||
grid-template-columns: repeat(2, 1fr);
|
||
gap: 16px;
|
||
}
|
||
|
||
.product-item {
|
||
background: var(--surface);
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius);
|
||
padding: 24px;
|
||
cursor: pointer;
|
||
transition: all .2s;
|
||
}
|
||
|
||
.product-item:hover {
|
||
border-color: var(--accent);
|
||
transform: translateY(-2px);
|
||
box-shadow: 0 8px 24px rgba(108, 114, 255, .15);
|
||
}
|
||
|
||
.product-item .big-icon {
|
||
font-size: 40px;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.product-item h3 {
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.product-item p {
|
||
font-size: 13px;
|
||
color: var(--text-muted);
|
||
margin-top: 6px;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
/* ── Empty State ────────────────────────────────────────── */
|
||
.empty {
|
||
text-align: center;
|
||
padding: 60px 20px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.empty .e-icon {
|
||
font-size: 48px;
|
||
margin-bottom: 16px;
|
||
opacity: .4;
|
||
}
|
||
|
||
.empty h3 {
|
||
font-size: 16px;
|
||
color: var(--text);
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.empty p {
|
||
font-size: 13px;
|
||
}
|
||
|
||
/* ── Report Detail (Full-Screen Page Design) ─────────────── */
|
||
#report-detail-modal-overlay {
|
||
background: transparent !important;
|
||
backdrop-filter: none !important;
|
||
align-items: stretch !important;
|
||
justify-content: stretch !important;
|
||
}
|
||
|
||
#report-detail-modal-overlay.open {
|
||
display: flex;
|
||
}
|
||
|
||
#report-detail-modal {
|
||
width: 100%;
|
||
max-width: 100%;
|
||
height: 100%;
|
||
max-height: 100%;
|
||
border-radius: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
background: #f0f2f5;
|
||
color: #333;
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* 深蓝标题栏 */
|
||
.rd-header {
|
||
background: linear-gradient(135deg, #1a2a6c 0%, #1e3a8a 60%, #2563eb 100%);
|
||
padding: 28px 40px 24px;
|
||
color: white;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.rd-header h1 {
|
||
margin: 0 0 6px 0;
|
||
font-size: 22px;
|
||
font-weight: 700;
|
||
letter-spacing: 0.5px;
|
||
}
|
||
|
||
.rd-header .rd-meta {
|
||
font-size: 12px;
|
||
opacity: 0.75;
|
||
}
|
||
|
||
.rd-header .rd-back {
|
||
position: absolute;
|
||
top: 28px;
|
||
right: 40px;
|
||
background: rgba(255,255,255,0.15);
|
||
border: 1px solid rgba(255,255,255,0.3);
|
||
color: white;
|
||
border-radius: 8px;
|
||
padding: 8px 18px;
|
||
cursor: pointer;
|
||
font-size: 13px;
|
||
transition: background 0.2s;
|
||
}
|
||
.rd-header .rd-back:hover { background: rgba(255,255,255,0.25); }
|
||
|
||
/* 统计数字栏 */
|
||
.rd-stats-bar {
|
||
background: white;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0;
|
||
padding: 0;
|
||
border-bottom: 1px solid #e5e7eb;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.rd-stat-item {
|
||
flex: 1;
|
||
text-align: center;
|
||
padding: 18px 10px;
|
||
border-right: 1px solid #e5e7eb;
|
||
}
|
||
.rd-stat-item:last-child { border-right: none; }
|
||
|
||
.rd-stat-item .sv {
|
||
font-size: 32px;
|
||
font-weight: 800;
|
||
line-height: 1;
|
||
font-family: 'Inter', system-ui, sans-serif;
|
||
color: #1a202c;
|
||
}
|
||
.rd-stat-item .sl {
|
||
font-size: 12px;
|
||
color: #9ca3af;
|
||
margin-top: 6px;
|
||
font-weight: 500;
|
||
}
|
||
.rd-stat-item.s-pass .sv { color: #10b981; }
|
||
.rd-stat-item.s-fail .sv { color: #ef4444; }
|
||
.rd-stat-item.s-skip .sv { color: #f59e0b; }
|
||
.rd-stat-item.s-rate .sv { color: #3b82f6; }
|
||
.rd-stat-item.s-dur .sv { color: #0ea5e9; }
|
||
|
||
/* 主体区域 */
|
||
.rd-body {
|
||
flex: 1;
|
||
overflow-y: auto;
|
||
padding: 24px 32px;
|
||
}
|
||
|
||
/* 模块分组 */
|
||
.rd-module-group {
|
||
background: white;
|
||
border-radius: 10px;
|
||
margin-bottom: 20px;
|
||
overflow: hidden;
|
||
box-shadow: 0 1px 4px rgba(0,0,0,0.06);
|
||
}
|
||
|
||
.rd-module-header {
|
||
background: #1e293b;
|
||
color: white;
|
||
padding: 12px 20px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
cursor: pointer;
|
||
user-select: none;
|
||
}
|
||
|
||
.rd-module-header .mh-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.rd-module-header .mh-arrow {
|
||
font-size: 12px;
|
||
transition: transform 0.2s;
|
||
}
|
||
.rd-module-header.collapsed .mh-arrow { transform: rotate(-90deg); }
|
||
|
||
.rd-module-name {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.rd-module-counts {
|
||
font-size: 12px;
|
||
opacity: 0.7;
|
||
display: flex;
|
||
gap: 12px;
|
||
}
|
||
|
||
.rd-module-counts .mc-pass { color: #34d399; }
|
||
.rd-module-counts .mc-fail { color: #f87171; }
|
||
|
||
/* 用例表格 */
|
||
.rd-case-table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
}
|
||
|
||
.rd-case-table th {
|
||
background: #f8fafc;
|
||
padding: 10px 16px;
|
||
text-align: left;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
color: #64748b;
|
||
border-bottom: 1px solid #e2e8f0;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.rd-case-table td {
|
||
padding: 12px 16px;
|
||
font-size: 13px;
|
||
color: #374151;
|
||
border-bottom: 1px solid #f1f5f9;
|
||
vertical-align: middle;
|
||
}
|
||
|
||
.rd-case-table tr:last-child td { border-bottom: none; }
|
||
.rd-case-table tbody tr:hover { background: #fafbfc; }
|
||
|
||
.rd-case-name {
|
||
font-weight: 600;
|
||
color: #1e293b;
|
||
font-size: 12.5px;
|
||
word-break: break-all;
|
||
}
|
||
|
||
/* 结果徽章 */
|
||
.badge-pass {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
background: #ecfdf5;
|
||
color: #065f46;
|
||
border: 1px solid #6ee7b7;
|
||
border-radius: 5px;
|
||
padding: 3px 10px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.badge-fail {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
background: #fef2f2;
|
||
color: #991b1b;
|
||
border: 1px solid #fca5a5;
|
||
border-radius: 5px;
|
||
padding: 3px 10px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.badge-skip {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
background: #fffbeb;
|
||
color: #92400e;
|
||
border: 1px solid #fcd34d;
|
||
border-radius: 5px;
|
||
padding: 3px 10px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
/* 截图展示区 */
|
||
.rd-gallery {
|
||
margin-top: 32px;
|
||
padding-top: 24px;
|
||
border-top: 1px dashed #e2e8f0;
|
||
}
|
||
.rd-gallery-title {
|
||
font-size: 15px;
|
||
font-weight: 700;
|
||
color: #1e293b;
|
||
margin-bottom: 16px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
.rd-gallery-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||
gap: 16px;
|
||
}
|
||
.rd-screenshot-item {
|
||
background: white;
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
border: 1px solid #e2e8f0;
|
||
cursor: pointer;
|
||
transition: transform 0.2s, box-shadow 0.2s;
|
||
}
|
||
.rd-screenshot-item:hover {
|
||
transform: translateY(-2px);
|
||
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
||
}
|
||
.rd-screenshot-item img {
|
||
width: 100%;
|
||
height: 150px;
|
||
object-fit: cover;
|
||
display: block;
|
||
}
|
||
.rd-screenshot-info {
|
||
padding: 10px;
|
||
font-size: 11px;
|
||
color: #64748b;
|
||
text-align: center;
|
||
background: #f8fafc;
|
||
border-top: 1px solid #e2e8f0;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
::-webkit-scrollbar { width: 6px; height: 6px; }
|
||
::-webkit-scrollbar-track { background: transparent; }
|
||
::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 6px; }
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
|
||
<!-- ── Sidebar ─────────────────────────────────────────────────────────────── -->
|
||
<nav id="sidebar">
|
||
<div class="logo">
|
||
<h1>AutoFlow</h1>
|
||
<span>自动化平台</span>
|
||
</div>
|
||
|
||
<div class="nav-section">
|
||
<div class="nav-section-title">核心功能</div>
|
||
<div class="nav-item active" data-page="tasks" onclick="nav(this,'tasks')">
|
||
<span class="icon">⚡</span> 自动化任务
|
||
<span class="nav-badge" id="badge-tasks">0</span>
|
||
</div>
|
||
<div class="nav-item" data-page="reports" onclick="nav(this,'reports')">
|
||
<span class="icon">📊</span> 测试报告
|
||
<span class="nav-badge" id="badge-reports" style="background:var(--accent2)">0</span>
|
||
</div>
|
||
<div class="nav-item" data-page="stats" onclick="nav(this,'stats')">
|
||
<span class="icon">📈</span> 数据看板
|
||
</div>
|
||
</div>
|
||
|
||
<div class="nav-section">
|
||
<div class="nav-section-title">产品</div>
|
||
<div class="nav-item" data-page="products" onclick="nav(this,'products')">
|
||
<span class="icon">🤖</span> Robogo
|
||
</div>
|
||
<div class="nav-item" data-page="dataloop" onclick="nav(this,'dataloop')">
|
||
<span class="icon">🔄</span> 数据闭环
|
||
</div>
|
||
</div>
|
||
|
||
<div class="sidebar-footer">
|
||
<div style="font-size:12px;color:var(--text-muted);display:flex;align-items:center">
|
||
<span class="status-dot"></span> 平台运行中
|
||
</div>
|
||
<a href="/" style="display:block;margin-top:12px;padding:8px 12px;background:var(--surface3);border-radius:8px;font-size:12px;color:var(--accent);text-decoration:none;text-align:center;transition:all 0.2s"
|
||
onmouseover="this.style.background='rgba(108,114,255,0.2)'" onmouseout="this.style.background='var(--surface3)'">
|
||
← 返回统一平台
|
||
</a>
|
||
</div>
|
||
</nav>
|
||
|
||
<!-- ── Main ────────────────────────────────────────────────────────────────── -->
|
||
<div id="main">
|
||
<div id="topbar">
|
||
<div>
|
||
<h2 id="page-title">自动化任务</h2>
|
||
<div class="sub" id="page-sub">管理并执行所有自动化测试任务</div>
|
||
</div>
|
||
<button class="btn btn-primary" id="create-btn" onclick="openCreateModal()">+ 创建任务</button>
|
||
</div>
|
||
<div id="content"></div>
|
||
</div>
|
||
|
||
<!-- ── Create Task Modal ──────────────────────────────────────────────────── -->
|
||
<div class="modal-overlay" id="create-modal">
|
||
<div class="modal">
|
||
<div class="modal-header">
|
||
<div>
|
||
<h3>创建自动化任务</h3>
|
||
<p>配置并启动一次自动化测试</p>
|
||
</div>
|
||
<button class="modal-close" onclick="closeModal('create-modal')">✕</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<!-- 1. 基础配置 -->
|
||
<div style="display:flex; align-items:center; gap:8px; margin-bottom:12px">
|
||
<span style="font-size:16px">📌</span> <span style="font-size:13px; font-weight:700">基础配置</span>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label">任务名称</label>
|
||
<input type="text" id="f-name" class="form-input" placeholder="例: Robogo 巡检任务" />
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label">选择产品</label>
|
||
<select id="f-product" class="form-input"></select>
|
||
</div>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label">账号</label>
|
||
<input type="text" id="f-account" class="form-input" placeholder="登录账号" />
|
||
</div>
|
||
<div class="form-group" style="position:relative">
|
||
<label class="form-label">密码</label>
|
||
<input type="password" id="f-password" class="form-input" placeholder="登录密码" style="padding-right:40px" />
|
||
<span class="pwd-toggle" onclick="togglePwd()">👁️</span>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 2. 运行环境与范围 -->
|
||
<div style="display:flex; align-items:center; gap:8px; margin:20px 0 12px">
|
||
<span style="font-size:16px">🌍</span> <span style="font-size:13px; font-weight:700">运行策略</span>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label">运行环境</label>
|
||
<select id="f-env" class="form-input" onchange="checkProdWarn()">
|
||
<option value="FAT">FAT环境</option>
|
||
<option value="PROD" selected>PROD环境</option>
|
||
</select>
|
||
<div id="env-warn" style="font-size:10px; color:var(--danger); margin-top:4px">⚠️ 生产环境操作将产生真实数据变更</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label">巡检范围</label>
|
||
<select id="f-scope" class="form-input">
|
||
<option value="all">全量覆盖 (All)</option>
|
||
<option value="smoke">冒烟测试 (Smoke)</option>
|
||
<option value="core">核心业务 (Core)</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label">定时模式</label>
|
||
<select id="f-schedule-type" class="form-input" onchange="updateScheduleUI()">
|
||
<option value="once">单次执行</option>
|
||
<option value="continuous">7x24h 连续运行 (结束后立即重启)</option>
|
||
<option value="hourly">每小时 (Hourly)</option>
|
||
<option value="daily">每天 (Daily)</option>
|
||
<option value="weekly">每周 (Weekly)</option>
|
||
</select>
|
||
</div>
|
||
<div class="form-group" id="f-schedule-date-wrap">
|
||
<label class="form-label">定时时间</label>
|
||
<input type="datetime-local" id="f-schedule" class="form-input" onchange="updateSubmitBtn()" />
|
||
</div>
|
||
<div class="form-group" id="f-schedule-window-wrap" style="display:none">
|
||
<label class="form-label">分时段运行 (e.g. 09:00-18:00)</label>
|
||
<input type="text" id="f-schedule-window" class="form-input" placeholder="00:00-23:59" value="00:00-23:59" />
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 3. 告警配置 -->
|
||
<div style="display:flex; align-items:center; gap:8px; margin:20px 0 12px">
|
||
<span style="font-size:16px">🔔</span> <span style="font-size:13px; font-weight:700">告警通知</span>
|
||
</div>
|
||
<div class="form-row" style="grid-template-columns: 1.5fr 1fr">
|
||
<div class="form-group">
|
||
<div class="toggle" style="height:44px; padding:0 12px">
|
||
<span class="toggle-label">飞书(Lark) 推送</span>
|
||
<label class="switch"><input type="checkbox" id="f-lark" checked /><span class="slider"></span></label>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<select id="f-alert-rule" class="form-input">
|
||
<option value="always">始终提醒</option>
|
||
<option value="only_on_fail">仅失败时</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 4. 重试策略 -->
|
||
<div style="display:flex; align-items:center; gap:8px; margin:20px 0 12px">
|
||
<span style="font-size:16px">🔁</span> <span style="font-size:13px; font-weight:700">失败重跑</span>
|
||
</div>
|
||
<div class="form-row">
|
||
<div class="form-group">
|
||
<label class="form-label">重试次数</label>
|
||
<input type="number" id="f-retry-count" class="form-input" value="1" min="0" max="5" />
|
||
</div>
|
||
<div class="form-group">
|
||
<label class="form-label">重试间隔(s)</label>
|
||
<input type="number" id="f-retry-delay" class="form-input" value="5" min="2" />
|
||
</div>
|
||
</div>
|
||
<div class="form-group" style="margin-top:-8px">
|
||
<label class="switch" style="display:none"><input type="checkbox" id="f-retry" checked /></label>
|
||
<div style="font-size:11px; color:var(--text-muted)">* 若任务执行失败,系统将按配置频率自动发起二次巡检尝试。</div>
|
||
</div>
|
||
</div>
|
||
<button class="btn btn-ghost" onclick="closeModal('create-modal')">取消</button>
|
||
<button class="btn btn-primary" id="submit-btn" onclick="submitTask()">🚀 立即运行</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ── Report Detail (Full-Screen, matches reference screenshot) ── -->
|
||
<div class="modal-overlay" id="report-detail-modal-overlay" style="position:fixed;inset:0;z-index:1000;background:transparent">
|
||
<div id="report-detail-modal" class="modal" style="position:relative">
|
||
|
||
<!-- 深蓝渐变标题栏 -->
|
||
<div class="rd-header" style="position:relative">
|
||
<h1 id="rd-title">自动化测试报告</h1>
|
||
<div class="rd-meta">生成时间: <span id="rd-time"></span></div>
|
||
<button class="rd-back" onclick="closeModal('report-detail-modal-overlay')">← 返回列表</button>
|
||
</div>
|
||
|
||
<!-- 统计数字栏 -->
|
||
<div class="rd-stats-bar">
|
||
<div class="rd-stat-item">
|
||
<div class="sv" id="rd-stat-total">0</div>
|
||
<div class="sl">总计</div>
|
||
</div>
|
||
<div class="rd-stat-item s-pass">
|
||
<div class="sv" id="rd-stat-pass">0</div>
|
||
<div class="sl">通过</div>
|
||
</div>
|
||
<div class="rd-stat-item s-fail">
|
||
<div class="sv" id="rd-stat-fail">0</div>
|
||
<div class="sl">失败</div>
|
||
</div>
|
||
<div class="rd-stat-item s-skip">
|
||
<div class="sv" id="rd-stat-skip">0</div>
|
||
<div class="sl">跳过</div>
|
||
</div>
|
||
<div class="rd-stat-item s-rate">
|
||
<div class="sv" id="rd-stat-rate">0%</div>
|
||
<div class="sl">通过率</div>
|
||
</div>
|
||
<div class="rd-stat-item s-dur">
|
||
<div class="sv" id="rd-stat-duration">0s</div>
|
||
<div class="sl">总耗时</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 主体: 按模块分组的用例列表 -->
|
||
<div class="rd-body" id="rd-body">
|
||
<!-- Dynamic content -->
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ── Log Viewer Modal ───────────────────────────────────────────────────── -->
|
||
<div class="modal-overlay log-viewer-modal" id="log-modal">
|
||
<div class="modal">
|
||
<div class="modal-header">
|
||
<div>
|
||
<h3 id="log-modal-title">任务日志</h3>
|
||
<p id="log-modal-sub">实时执行输出</p>
|
||
</div>
|
||
<button class="modal-close" onclick="closeModal('log-modal')">✕</button>
|
||
</div>
|
||
<div class="modal-body" style="padding-bottom:0">
|
||
<div class="log-box" id="log-box"></div>
|
||
</div>
|
||
<div class="log-status">
|
||
<div id="log-status-dot" class="spin"
|
||
style="width:10px;height:10px;border:2px solid var(--accent);border-top-color:transparent;border-radius:50%;">
|
||
</div>
|
||
<span id="log-status-text" style="font-size:12px;color:var(--text-muted)">运行中...</span>
|
||
<button class="btn btn-ghost" style="margin-left:auto;padding:5px 12px;font-size:12px"
|
||
onclick="closeModal('log-modal')">关闭</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
// ── State ──────────────────────────────────────────────────────────────────
|
||
const API = window.location.origin; // 自动锁定 API 基础地址
|
||
let products = {}, tasks = [], reports = [];
|
||
let currentPage = 'stats';
|
||
let selectedProduct = 'robogo';
|
||
|
||
// ── Init ───────────────────────────────────────────────────────────────────
|
||
async function init() {
|
||
products = await fetch(`${API}/api/products`).then(r => r.json());
|
||
renderProductGrid();
|
||
renderPage('tasks');
|
||
setInterval(refreshBadges, 3000);
|
||
}
|
||
|
||
// ── Navigation ─────────────────────────────────────────────────────────────
|
||
const pages = {
|
||
tasks: { title: '自动化任务', sub: '管理并执行所有自动化测试任务' },
|
||
reports: { title: '测试报告', sub: '查看历史运行报告与结果分析' },
|
||
stats: { title: '数据看板', sub: '全量巡检任务健康度与趋势分析' },
|
||
products: { title: 'Robogo', sub: 'Robogo PROD 环境全链路巡检' },
|
||
dataloop: { title: '数据闭环', sub: '数据闭环平台端到端验证' },
|
||
};
|
||
|
||
async function nav(el, page) {
|
||
document.querySelectorAll('.nav-item').forEach(i => i.classList.remove('active'));
|
||
if (el) el.classList.add('active');
|
||
currentPage = page;
|
||
const p = pages[page] || pages.tasks;
|
||
document.getElementById('page-title').textContent = p.title;
|
||
document.getElementById('page-sub').textContent = p.sub;
|
||
const btn = document.getElementById('create-btn');
|
||
btn.style.display = page === 'tasks' ? '' : 'none';
|
||
await renderPage(page);
|
||
}
|
||
|
||
// ── Render Pages ───────────────────────────────────────────────────────────
|
||
async function renderPage(page) {
|
||
const c = document.getElementById('content');
|
||
if (page === 'tasks') await renderTasks(c);
|
||
else if (page === 'reports') await renderReports(c);
|
||
else if (page === 'stats') await renderDashboard(c);
|
||
else if (page === 'products') renderProducts(c, 'robogo');
|
||
else if (page === 'dataloop') renderProducts(c, 'data_loop');
|
||
}
|
||
|
||
async function renderTasks(c) {
|
||
const tasks = await fetch(`${API}/api/tasks`).then(r => r.json());
|
||
const running = tasks.filter(t => t.status === 'running').length;
|
||
const passed = tasks.filter(t => t.status === 'pass').length;
|
||
const failed = tasks.filter(t => t.status === 'fail').length;
|
||
|
||
c.innerHTML = `
|
||
<div class="stats-grid">
|
||
${stat('总任务数', tasks.length, '累计创建', 'linear-gradient(90deg,#6c72ff,#a78bfa)')}
|
||
${stat('运行中', running, '当前活跃', 'linear-gradient(90deg,#6c72ff,#38e0b0)', running > 0 ? 'var(--accent)' : '')}
|
||
${stat('通过', passed, '历史成功次数', 'linear-gradient(90deg,#38e0b0,#22c55e)', 'var(--accent2)')}
|
||
${stat('失败', failed, '需要关注', 'linear-gradient(90deg,#ff5c6c,#f97316)', failed > 0 ? 'var(--danger)' : '')}
|
||
</div>
|
||
<div class="panel">
|
||
<div class="panel-header">
|
||
<span class="panel-title">任务列表</span>
|
||
<span style="font-size:12px;color:var(--text-muted)">${tasks.length} 个任务</span>
|
||
</div>
|
||
${tasks.length === 0 ? emptyState('📋', '暂无任务', '点击右上角 + 创建第一个自动化任务') : `
|
||
<table>
|
||
<thead><tr>
|
||
<th>任务名称</th><th>产品</th><th>状态</th><th>运行次数</th><th>创建时间</th><th>操作</th>
|
||
</tr></thead>
|
||
<tbody>
|
||
${tasks.sort((a, b) => new Date(b.created_at) - new Date(a.created_at)).map(t => `
|
||
<tr>
|
||
<td><strong>${t.name}</strong></td>
|
||
<td>${productTag(t.product)}</td>
|
||
<td>${statusBadge(t.status)}</td>
|
||
<td><span style="color:var(--text-muted)">${t.run_count} 次</span></td>
|
||
<td><span style="color:var(--text-muted);font-size:12px">${fmtDate(t.created_at)}</span></td>
|
||
<td>
|
||
<button class="action-btn" onclick="openLog('${t.id}','${t.name}','${t.status}')">日志</button>
|
||
${t.report_id ? `<button class="action-btn" style="margin-left:6px" onclick="viewReport('${t.id}')">报告</button>` : ''}
|
||
${t.status === 'running' ? `<button class="action-btn btn-danger" style="margin-left:6px" onclick="stopTask('${t.id}')">停止</button>` : ''}
|
||
<button class="action-btn" style="margin-left:6px;color:var(--danger)" onclick="deleteTask('${t.id}')">删除</button>
|
||
</td>
|
||
</tr>
|
||
`).join('')}
|
||
</tbody>
|
||
</table>`}
|
||
</div>`;
|
||
}
|
||
|
||
async function renderReports(c) {
|
||
const reports = await fetch(`${API}/api/reports`).then(r => r.json());
|
||
if (reports.length === 0) {
|
||
c.innerHTML = emptyState('📊', '暂无报告', '完成一次任务后报告将在此出现');
|
||
return;
|
||
}
|
||
c.innerHTML = (await Promise.all(reports.sort((a, b) => new Date(b.finished_at) - new Date(a.finished_at)).map(async r => {
|
||
const pct = r.total_runs > 0 ? Math.round(r.pass / r.total_runs * 100) : 0;
|
||
const dur = r.started_at && r.finished_at ? Math.round((new Date(r.finished_at) - new Date(r.started_at)) / 1000) : '?';
|
||
|
||
return `
|
||
<div class="report-card" style="display:block; cursor:pointer" onclick="openReportDetail('${r.task_id}')">
|
||
<div style="display:flex; justify-content:space-between; align-items:center">
|
||
<div style="display:flex;align-items:center;gap:15px">
|
||
${r.thumbnail ? `<img src="${API}/artifacts/screenshots/${r.thumbnail}" style="width:64px;height:42px;object-fit:cover;border-radius:4px;border:1px solid rgba(0,0,0,0.1);background:#f0f2f5" />` : ''}
|
||
<div class="report-result ${r.result}">${r.result === 'PASS' ? '✅ PASS' : '❌ FAIL'}</div>
|
||
<div>
|
||
<div style="font-size:16px;font-weight:700;color:var(--text);margin-bottom:4px">${r.task_name}</div>
|
||
<div class="report-meta">
|
||
<span style="background:rgba(108,114,255,0.1); color:var(--accent); padding:2px 8px; border-radius:4px; font-weight:600">🤖 ${r.product}</span>
|
||
<span>✅ ${r.pass} 通过</span>
|
||
<span>❌ ${r.fail} 失败</span>
|
||
<span>⏱ ${dur}s</span>
|
||
<span>🕐 ${fmtDate(r.finished_at)}</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div style="display:flex; gap:10px">
|
||
<button class="btn btn-primary" style="font-size:11px;padding:6px 12px" onclick="event.stopPropagation(); openReportDetail('${r.task_id}')">报告详情</button>
|
||
<button class="btn btn-ghost" style="font-size:11px;padding:6px 12px" onclick="event.stopPropagation(); openLog('${r.task_id}','${r.task_name}','pass')">原始日志</button>
|
||
</div>
|
||
</div>
|
||
<div class="progress-bar" style="margin-top:15px; height:6px">
|
||
<div class="progress-fill" style="width:${pct}%;background:${r.result === 'PASS' ? 'var(--accent2)' : 'var(--danger)'}"></div>
|
||
</div>
|
||
</div>`;
|
||
}))).join('');
|
||
}
|
||
|
||
function renderProducts(c, key) {
|
||
const p = products[key];
|
||
if (!p) { c.innerHTML = emptyState('🔧', '该产品暂未接入', '敬请期待'); return; }
|
||
c.innerHTML = `
|
||
<div class="panel" style="padding:28px">
|
||
<div style="font-size:36px;margin-bottom:16px">${p.icon}</div>
|
||
<h2 style="font-size:22px;font-weight:700;margin-bottom:8px">${p.name}</h2>
|
||
<p style="color:var(--text-muted);font-size:14px;margin-bottom:24px">${p.desc}</p>
|
||
${p.entry ? `<button class="btn btn-primary" onclick="quickRun('${key}')">⚡ 快速创建任务并运行</button>` : `<span style="color:var(--text-muted);font-size:13px">🚧 即将接入...</span>`}
|
||
</div>`;
|
||
}
|
||
|
||
// ── UI Helpers ─────────────────────────────────────────────────────────────
|
||
function stat(label, val, meta, grad, color = 'var(--text)') {
|
||
return `<div class="stat-card" style="--accent-grad:${grad}">
|
||
<div class="stat-label">${label}</div>
|
||
<div class="stat-value" style="color:${color}">${val}</div>
|
||
<div class="stat-meta">${meta}</div>
|
||
</div>`;
|
||
}
|
||
|
||
function statusBadge(s) {
|
||
const map = { running: '<span class="spin"></span> 运行中', pass: '✓ 通过', fail: '✗ 失败', pending: '⏰ 等待中' };
|
||
return `<span class="status-badge ${s}">${map[s] || s}</span>`;
|
||
}
|
||
|
||
function productTag(key) {
|
||
const p = products[key];
|
||
return `<span style="font-size:12px;color:var(--text-muted)">${p ? p.icon + ' ' + p.name : key}</span>`;
|
||
}
|
||
|
||
function emptyState(icon, h, p) {
|
||
return `<div class="empty"><div class="e-icon">${icon}</div><h3>${h}</h3><p>${p}</p></div>`;
|
||
}
|
||
|
||
function fmtDate(iso) {
|
||
if (!iso) return '—';
|
||
const d = new Date(iso);
|
||
return `${d.getMonth() + 1}/${d.getDate()} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
|
||
}
|
||
|
||
// ── Product Grid ───────────────────────────────────────────────────────────
|
||
function renderProductGrid() {
|
||
const grid = document.getElementById('product-grid');
|
||
if (!grid) return; // 如果当前页面不需要渲染产品列表,直接返回
|
||
grid.innerHTML = Object.entries(products).map(([k, p]) => `
|
||
<div class="product-card ${k === selectedProduct ? 'selected' : ''}" onclick="selectProduct('${k}')">
|
||
<div class="p-icon">${p.icon}</div>
|
||
<div class="p-name">${p.name}</div>
|
||
<div class="p-desc">${p.desc}</div>
|
||
</div>`).join('');
|
||
}
|
||
|
||
function selectProduct(k) {
|
||
selectedProduct = k;
|
||
renderProductGrid();
|
||
}
|
||
|
||
// ── Modal ──────────────────────────────────────────────────────────────────
|
||
function openCreateModal() {
|
||
document.getElementById('f-name').value = `巡检任务_${new Date().toLocaleTimeString('zh')}`;
|
||
|
||
const prodSelect = document.getElementById('f-product');
|
||
prodSelect.innerHTML = Object.entries(products).map(([k, p]) =>
|
||
`<option value="${k}">${p.icon} ${p.name}</option>`
|
||
).join('');
|
||
prodSelect.value = selectedProduct || 'robogo';
|
||
|
||
document.getElementById('create-modal').classList.add('open');
|
||
}
|
||
|
||
function closeModal(id) {
|
||
document.getElementById(id).classList.remove('open');
|
||
}
|
||
|
||
function openModal(id) {
|
||
document.getElementById(id).classList.add('open');
|
||
}
|
||
|
||
function updateSubmitBtn() {
|
||
const st = document.getElementById('f-schedule-type').value;
|
||
const btn = document.getElementById('submit-btn');
|
||
const dateWrap = document.getElementById('f-schedule-date-wrap');
|
||
const windowWrap = document.getElementById('f-schedule-window-wrap');
|
||
|
||
dateWrap.style.display = (st === 'once') ? '' : 'none';
|
||
windowWrap.style.display = (st === 'continuous') ? '' : 'none';
|
||
|
||
if (st === 'once') {
|
||
btn.textContent = '🚀 立即运行';
|
||
btn.className = 'btn btn-primary';
|
||
} else if (st === 'continuous') {
|
||
btn.textContent = '🔄 开启分时段巡检';
|
||
btn.className = 'btn btn-accent';
|
||
} else {
|
||
btn.textContent = '📅 提交定时任务';
|
||
btn.className = 'btn btn-accent';
|
||
}
|
||
}
|
||
|
||
function togglePwd() {
|
||
const inp = document.getElementById('f-password');
|
||
const tog = document.querySelector('.pwd-toggle');
|
||
if (inp.type === 'password') {
|
||
inp.type = 'text';
|
||
tog.textContent = '🙈';
|
||
} else {
|
||
inp.type = 'password';
|
||
tog.textContent = '👁️';
|
||
}
|
||
}
|
||
|
||
function checkProdWarn() {
|
||
const isProd = document.getElementById('f-env').value === 'PROD';
|
||
document.getElementById('env-warn').style.display = isProd ? '' : 'none';
|
||
}
|
||
|
||
function updateScheduleUI() {
|
||
const type = document.getElementById('f-schedule-type').value;
|
||
const wrap = document.getElementById('f-schedule-date-wrap');
|
||
wrap.style.opacity = type === 'once' ? '1' : '0.4';
|
||
wrap.style.pointerEvents = type === 'once' ? 'all' : 'none';
|
||
updateSubmitBtn();
|
||
}
|
||
|
||
async function submitTask() {
|
||
const name = document.getElementById('f-name').value.trim() || '巡检任务';
|
||
const account = document.getElementById('f-account').value.trim();
|
||
const password = document.getElementById('f-password').value;
|
||
|
||
const env = document.getElementById('f-env').value;
|
||
const scope = document.getElementById('f-scope').value;
|
||
const schedule_type = document.getElementById('f-schedule-type').value;
|
||
const scheduled_at = document.getElementById('f-schedule').value;
|
||
|
||
const alert_channels = [];
|
||
if (document.getElementById('f-lark').checked) alert_channels.push('lark');
|
||
const alert_rule = document.getElementById('f-alert-rule').value;
|
||
|
||
const retry_count = parseInt(document.getElementById('f-retry-count').value) || 0;
|
||
const retry_delay = parseInt(document.getElementById('f-retry-delay').value) || 5;
|
||
|
||
if (!account || !password) { alert('请填写账号和密码'); return; }
|
||
|
||
const product = document.getElementById('f-product').value || 'robogo';
|
||
|
||
const payload = {
|
||
name, product, account, password,
|
||
env, scope, schedule_type, scheduled_at,
|
||
alert_channels, alert_rule,
|
||
retry_on_fail: retry_count > 0, retry_count, retry_delay,
|
||
run_count: 1,
|
||
schedule_window: document.getElementById('f-schedule-window').value
|
||
};
|
||
|
||
const resp = await fetch(`${API}/api/tasks`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(payload)
|
||
});
|
||
|
||
if (!resp.ok) { alert('创建失败'); return; }
|
||
|
||
const task = await resp.json();
|
||
closeModal('create-modal');
|
||
await renderPage('tasks');
|
||
if (task.schedule_type === 'once' && !task.scheduled_at) {
|
||
openLog(task.id, task.name, 'running');
|
||
}
|
||
}
|
||
|
||
async function quickRun(productKey) {
|
||
try {
|
||
const account = prompt('请输入账号:');
|
||
if (account === null) return;
|
||
const password = prompt('请输入密码:');
|
||
if (password === null) return;
|
||
|
||
if (!account || !password) {
|
||
alert('账号和密码不能为空');
|
||
return;
|
||
}
|
||
|
||
const resp = await fetch(`${API}/api/tasks`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({
|
||
name: `快速运行_${productKey}_${new Date().toLocaleTimeString('zh')}`,
|
||
product: productKey,
|
||
account,
|
||
password,
|
||
run_count: 1
|
||
})
|
||
});
|
||
|
||
if (!resp.ok) {
|
||
const err = await resp.json();
|
||
throw new Error(err.error || '创建任务失败');
|
||
}
|
||
|
||
const task = await resp.json();
|
||
// 确保导航完成后再打开日志
|
||
await nav(document.querySelector('[data-page="tasks"]'), 'tasks');
|
||
openLog(task.id, task.name, 'running');
|
||
} catch (e) {
|
||
console.error('QuickRun Error:', e);
|
||
alert('快速运行出错: ' + e.message);
|
||
}
|
||
}
|
||
|
||
// ── Log Viewer ─────────────────────────────────────────────────────────────
|
||
let activeSSE = null;
|
||
|
||
async function openLog(taskId, taskName, status) {
|
||
document.getElementById('log-modal-title').textContent = taskName;
|
||
document.getElementById('log-modal').classList.add('open');
|
||
const box = document.getElementById('log-box');
|
||
box.innerHTML = '';
|
||
|
||
if (activeSSE) { activeSSE.close(); activeSSE = null; }
|
||
|
||
// If already finished, fetch stored logs
|
||
if (status !== 'running') {
|
||
const rept = await fetch(`${API}/api/reports/${taskId}`).catch(() => null);
|
||
if (rept && rept.ok) {
|
||
const data = await rept.json();
|
||
data.logs.forEach(l => appendLog(box, l));
|
||
setLogDone(data.result === 'PASS');
|
||
return;
|
||
}
|
||
}
|
||
|
||
// Stream via SSE
|
||
setLogRunning();
|
||
const src = new EventSource(`${API}/api/tasks/${taskId}/logs`);
|
||
activeSSE = src;
|
||
src.onmessage = e => {
|
||
const data = JSON.parse(e.data);
|
||
if (data.level === 'PING') return;
|
||
if (data.level === 'DONE') {
|
||
src.close(); activeSSE = null;
|
||
renderPage(currentPage);
|
||
refreshBadges();
|
||
fetch(`${API}/api/tasks`)
|
||
.then(r => r.json())
|
||
.then(tasks => {
|
||
const t = tasks.find(x => x.id === taskId);
|
||
setLogDone(t && t.status === 'pass');
|
||
});
|
||
return;
|
||
}
|
||
appendLog(box, data);
|
||
};
|
||
src.onerror = () => { src.close(); setLogDone(false); };
|
||
}
|
||
|
||
function appendLog(box, data) {
|
||
const div = document.createElement('div');
|
||
div.className = `log-line ${data.level}`;
|
||
div.innerHTML = `<span class="ts">${data.ts}</span><span class="level">[${data.level}]</span> <span class="msg">${escHtml(data.msg)}</span>`;
|
||
box.appendChild(div);
|
||
box.scrollTop = box.scrollHeight;
|
||
}
|
||
|
||
function setLogRunning() {
|
||
document.getElementById('log-status-dot').style.display = '';
|
||
document.getElementById('log-status-text').textContent = '运行中...';
|
||
}
|
||
|
||
function setLogDone(pass) {
|
||
document.getElementById('log-status-dot').style.display = 'none';
|
||
const t = document.getElementById('log-status-text');
|
||
t.textContent = pass ? '✅ 测试通过' : '❌ 测试失败';
|
||
t.style.color = pass ? 'var(--accent2)' : 'var(--danger)';
|
||
}
|
||
|
||
async function openReportDetail(tid) {
|
||
try {
|
||
const resp = await fetch(`${API}/api/reports/${tid}`);
|
||
if (!resp.ok) throw new Error('Report not found');
|
||
const data = await resp.json();
|
||
|
||
// ── 1. 标题 & 时间 ──────────────────────────────────────────
|
||
document.getElementById('rd-title').textContent = data.task_name || '自动化测试报告';
|
||
const ts = data.finished_at ? data.finished_at.replace('T', ' ').substring(0, 19) : '-';
|
||
document.getElementById('rd-time').textContent = ts;
|
||
|
||
// ── 2. 统计数字 ─────────────────────────────────────────────
|
||
const results = data.results || [];
|
||
const total = results.length;
|
||
const passCount = results.filter(r => r.status === 'PASS').length;
|
||
const failCount = results.filter(r => r.status === 'FAIL').length;
|
||
const skipCount = results.filter(r => r.status === 'SKIP').length;
|
||
const rate = total > 0 ? ((passCount / total) * 100).toFixed(1) + '%' : '0%';
|
||
|
||
// 计算总耗时 (started_at → finished_at)
|
||
let durationStr = data.duration || '—';
|
||
if (!data.duration && data.started_at && data.finished_at) {
|
||
const secs = (new Date(data.finished_at) - new Date(data.started_at)) / 1000;
|
||
durationStr = secs.toFixed(1) + 's';
|
||
}
|
||
|
||
document.getElementById('rd-stat-total').textContent = total;
|
||
document.getElementById('rd-stat-pass').textContent = passCount;
|
||
document.getElementById('rd-stat-fail').textContent = failCount;
|
||
document.getElementById('rd-stat-skip').textContent = skipCount;
|
||
document.getElementById('rd-stat-rate').textContent = rate;
|
||
document.getElementById('rd-stat-duration').textContent = durationStr;
|
||
|
||
// ── 3. 按 module 字段分组 ────────────────────────────────────
|
||
const body = document.getElementById('rd-body');
|
||
body.innerHTML = '';
|
||
|
||
if (results.length === 0) {
|
||
body.innerHTML = `
|
||
<div style="background:white;border-radius:10px;padding:60px;text-align:center;color:#9ca3af">
|
||
<div style="font-size:48px;margin-bottom:16px">📋</div>
|
||
<div style="font-size:16px;font-weight:600;margin-bottom:8px">暂无详细用例数据</div>
|
||
<div style="font-size:13px">运行新任务后将自动记录用例级别的执行结果</div>
|
||
</div>`;
|
||
} else {
|
||
// 按模块归组
|
||
const moduleMap = {};
|
||
results.forEach(it => {
|
||
const mod = it.module || it.name || '通用';
|
||
if (!moduleMap[mod]) moduleMap[mod] = [];
|
||
moduleMap[mod].push(it);
|
||
});
|
||
|
||
Object.entries(moduleMap).forEach(([modName, items], idx) => {
|
||
const modPass = items.filter(i => i.status === 'PASS').length;
|
||
const modFail = items.filter(i => i.status === 'FAIL').length;
|
||
const groupId = `rd-group-${idx}`;
|
||
|
||
const rows = items.map(it => {
|
||
let badge = '';
|
||
if (it.status === 'PASS') {
|
||
badge = `<span class="badge-pass"><span>✓</span> 通过</span>`;
|
||
} else if (it.status === 'FAIL') {
|
||
badge = `<span class="badge-fail"><span>✕</span> 失败</span>`;
|
||
} else {
|
||
badge = `<span class="badge-skip">— 跳过</span>`;
|
||
}
|
||
return `
|
||
<tr>
|
||
<td><div class="rd-case-name">${escHtml(it.name)}</div></td>
|
||
<td style="color:#6b7280">${escHtml(it.desc || '—')}</td>
|
||
<td style="color:#6b7280">${escHtml(it.expected || '—')}</td>
|
||
<td>${badge}</td>
|
||
<td style="color:#374151;font-variant-numeric:tabular-nums">${it.duration || '—'}</td>
|
||
</tr>`;
|
||
}).join('');
|
||
|
||
const group = document.createElement('div');
|
||
group.className = 'rd-module-group';
|
||
group.innerHTML = `
|
||
<div class="rd-module-header" onclick="toggleGroup('${groupId}')">
|
||
<div class="mh-left">
|
||
<span class="mh-arrow">▼</span>
|
||
<span class="rd-module-name">${escHtml(modName)}</span>
|
||
</div>
|
||
<div class="rd-module-counts">
|
||
<span>共 ${items.length} 项</span>
|
||
<span class="mc-pass">| ${modPass} 通过</span>
|
||
${modFail > 0 ? `<span class="mc-fail">| ${modFail} 失败</span>` : ''}
|
||
</div>
|
||
</div>
|
||
<div id="${groupId}">
|
||
<table class="rd-case-table">
|
||
<thead>
|
||
<tr>
|
||
<th width="18%">测试用例</th>
|
||
<th width="22%">描述</th>
|
||
<th width="30%">预期结果</th>
|
||
<th width="12%">实际结果</th>
|
||
<th width="8%">耗时</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>${rows}</tbody>
|
||
</table>
|
||
</div>`;
|
||
body.appendChild(group);
|
||
});
|
||
}
|
||
|
||
// ── 4. 截图存档 ──
|
||
if (data.screenshots && data.screenshots.length > 0) {
|
||
const gallery = document.createElement('div');
|
||
gallery.className = 'rd-gallery';
|
||
|
||
let itemsHtml = data.screenshots.map(s => {
|
||
// 移除 taskId 前缀以保持简洁
|
||
const displayName = s.includes('_') ? s.split('_').slice(1).join('_') : s;
|
||
return `
|
||
<div class="rd-screenshot-item" onclick="window.open('${API}/artifacts/screenshots/${s}')">
|
||
<img src="${API}/artifacts/screenshots/${s}" loading="lazy" />
|
||
<div class="rd-screenshot-info" title="${s}">${displayName}</div>
|
||
</div>`;
|
||
}).join('');
|
||
|
||
gallery.innerHTML = `
|
||
<div class="rd-gallery-title">🖼️ 截图记录 <span style="font-weight:400; opacity:0.6; font-size:12px">(${data.screenshots.length} 张)</span></div>
|
||
<div class="rd-gallery-grid">${itemsHtml}</div>
|
||
`;
|
||
body.appendChild(gallery);
|
||
}
|
||
|
||
// ── 5. 打开全屏 ──
|
||
openModal('report-detail-modal-overlay');
|
||
} catch (err) {
|
||
console.error('ReportDetail Error:', err);
|
||
alert('查看详情失败: ' + err.message);
|
||
}
|
||
}
|
||
|
||
function toggleGroup(id) {
|
||
const el = document.getElementById(id);
|
||
const hdr = el.previousElementSibling;
|
||
if (el.style.display === 'none') {
|
||
el.style.display = '';
|
||
hdr.classList.remove('collapsed');
|
||
} else {
|
||
el.style.display = 'none';
|
||
hdr.classList.add('collapsed');
|
||
}
|
||
}
|
||
|
||
async function viewReport(tid) {
|
||
openReportDetail(tid);
|
||
}
|
||
|
||
// ── Badges ─────────────────────────────────────────────────────────────────
|
||
async function refreshBadges() {
|
||
try {
|
||
const [respT, respR] = await Promise.all([
|
||
fetch(`${API}/api/tasks`),
|
||
fetch(`${API}/api/reports`)
|
||
]);
|
||
|
||
const tks = respT.ok ? await respT.json() : [];
|
||
const rps = respR.ok ? await respR.json() : [];
|
||
|
||
// 同步全局变量
|
||
if (Array.isArray(tks)) tasks = tks;
|
||
if (Array.isArray(rps)) reports = rps;
|
||
|
||
const bt = document.getElementById('badge-tasks');
|
||
const br = document.getElementById('badge-reports');
|
||
if (bt) bt.textContent = tasks.length;
|
||
if (br) br.textContent = reports.length;
|
||
} catch (e) {
|
||
console.warn('Badge refresh failed', e);
|
||
}
|
||
}
|
||
|
||
// ── Utils ───────────────────────────────────────────────────────────────────
|
||
function escHtml(t) {
|
||
return String(t).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||
}
|
||
|
||
// ── 治理功能 ──
|
||
async function deleteTask(id) {
|
||
if (!confirm('确定删除该任务及其所有日志、截图吗?')) return;
|
||
await fetch(`${API}/api/tasks/${id}`, { method: 'DELETE' });
|
||
renderPage(currentPage);
|
||
}
|
||
|
||
async function stopTask(id) {
|
||
if (!confirm('确定强行停止当前运行的任务吗?')) return;
|
||
await fetch(`${API}/api/tasks/${id}/stop`, { method: 'POST' });
|
||
renderPage(currentPage);
|
||
}
|
||
|
||
// ── 看板渲染 ──
|
||
async function renderDashboard(c) {
|
||
try {
|
||
const resp = (await fetch(`${API}/api/dashboard/stats`).then(r => r.json()).catch(() => ({}))) || {};
|
||
if (resp.error) throw new Error(resp.error);
|
||
if (!resp.summary && !resp.health) throw new Error("数据格式异常");
|
||
|
||
const s = resp.summary || {};
|
||
const healthHtml = Object.entries(resp.health || {}).map(([name, data]) => `
|
||
<div class="panel" style="padding:16px">
|
||
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:12px">
|
||
<span style="font-weight:700; font-size:13px">${name} 健康度: <span style="color:var(--accent2)">${data.rate || 0}%</span></span>
|
||
<span style="font-size:11px; color:var(--text-muted)">(累计 ${data.total || 0} 次)</span>
|
||
</div>
|
||
<div style="display:flex; gap:8px; font-size:10px; overflow-x:auto;">
|
||
${Object.entries(data.envs || {}).filter(([k, v]) => v > 0 || k === 'PROD' || k === 'FAT').map(([env, rate]) => `
|
||
<div style="flex:1; min-width:50px; background:var(--surface3); padding:8px; border-radius:6px">
|
||
<div style="color:var(--text-muted); margin-bottom:4px">${env}</div>
|
||
<div style="font-weight:700; color:${rate > 80 ? 'var(--accent2)' : rate > 50 ? 'var(--warning)' : 'var(--danger)'}">${rate}%</div>
|
||
</div>
|
||
`).join('')}
|
||
</div>
|
||
</div>
|
||
`).join('');
|
||
|
||
c.innerHTML = `
|
||
<div style="margin-bottom:20px; font-size:14px; font-weight:700; letter-spacing:0.5px">
|
||
AutoFlow 数据看板 <span style="font-weight:400; color:var(--text-muted); margin-left:8px">- 全量巡检任务健康度与趋势分析</span>
|
||
</div>
|
||
|
||
<!-- 1. 核心指标 -->
|
||
<div class="stats-grid" style="grid-template-columns: repeat(4, 1fr)">
|
||
${stat('全域平均通过率', s.pass_rate + '%', `基于 ${s.total_reports} 份报告`, 'linear-gradient(90deg, #6c72ff, #38e0b0)', s.pass_rate >= 90 ? 'var(--accent2)' : '')}
|
||
${stat('累计失败任务', s.fail_count, '亟待维护项', 'linear-gradient(90deg, var(--danger), #f97316)', s.fail_count > 0 ? 'var(--danger)' : '')}
|
||
${stat('核心链路通过率', s.core_pass_rate + '%', '聚焦 P0/P1 用例', 'linear-gradient(90deg, #a78bfa, #6c72ff)', 'var(--accent)')}
|
||
${stat('问题闭环率', s.closure_rate + '%', '已修复 / 总失败', 'linear-gradient(90deg,#38e0b0,#22c55e)', 'var(--accent2)')}
|
||
</div>
|
||
|
||
<!-- 2. 分产品健康度 -->
|
||
<div style="display:grid; grid-template-columns: 1fr 1fr; gap:16px; margin:16px 0">
|
||
${healthHtml}
|
||
</div>
|
||
|
||
<!-- 3. 趋势可视化 -->
|
||
<div style="margin:24px 0 12px; font-size:12px; font-weight:700; color:var(--text-muted)">【趋势可视化】</div>
|
||
<div style="display:grid; grid-template-columns: 1.5fr 1fr; gap:16px">
|
||
<div class="panel" style="padding:16px">
|
||
<div style="font-size:12px; margin-bottom:12px">近7天通过率趋势图 <span style="color:var(--text-muted)">(全量 vs 核心)</span></div>
|
||
<canvas id="chart-trend" width="100%" height="40"></canvas>
|
||
</div>
|
||
<div class="panel" style="padding:16px">
|
||
<div style="font-size:12px; margin-bottom:12px">近7天失败数趋势图 <span style="color:var(--text-muted)">(按模块拆分)</span></div>
|
||
<canvas id="chart-fails" width="100%" height="62"></canvas>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 4. 失败分析 -->
|
||
<div style="margin:24px 0 12px; font-size:12px; font-weight:700; color:var(--text-muted)">【失败分析】</div>
|
||
<div style="display:grid; grid-template-columns: 1fr 1.5fr; gap:16px">
|
||
<div class="panel" style="padding:16px; display:flex; flex-direction:column; align-items:center">
|
||
<div style="font-size:12px; width:100%; margin-bottom:12px">失败原因分类饼图</div>
|
||
<canvas id="chart-pie" style="max-height:180px"></canvas>
|
||
</div>
|
||
<div class="panel" style="padding:16px">
|
||
<div style="font-size:12px; margin-bottom:12px">高频失败模块 TOP5</div>
|
||
<canvas id="chart-bar" width="100%" height="50"></canvas>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 5. 失败任务明细 -->
|
||
<div style="margin:24px 0 12px; font-size:12px; font-weight:700; color:var(--text-muted)">【失败任务明细】</div>
|
||
<div class="panel">
|
||
<table>
|
||
<thead><tr>
|
||
<th>任务名称</th><th>产品</th><th>失败时间</th><th>失败原因</th><th>操作</th>
|
||
</tr></thead>
|
||
<tbody>
|
||
${(resp.failed_tasks || []).map(t => `
|
||
<tr>
|
||
<td><strong>${t.name || '未知任务'}</strong></td>
|
||
<td>${t.product || '-'}</td>
|
||
<td style="color:var(--danger)">${t.finished_at || '--:--'}</td>
|
||
<td style="color:var(--text-muted); font-size:12px">${t.reason || '原因未知'}</td>
|
||
<td>
|
||
<button class="action-btn" onclick="openLog('${t.id}','${t.name}','fail')">日志</button>
|
||
<button class="action-btn" style="margin-left:6px" onclick="viewReport('${t.id}')">报告</button>
|
||
</td>
|
||
</tr>
|
||
`).join('')}
|
||
${(!resp.failed_tasks || resp.failed_tasks.length === 0) ? '<tr><td colspan="5" style="text-align:center; padding:20px; color:var(--accent2)">🌈 今日无失败任务,系统运行极其稳定</td></tr>' : ''}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<div style="margin-top:24px; padding:12px; text-align:center; color:var(--text-muted); font-size: 11px; border-top: 1px dashed var(--border)">
|
||
数据已在 ${resp.ts} 完成聚合,系统运行稳定。当前无告警。
|
||
</div>
|
||
`;
|
||
|
||
// 初始化图表
|
||
setTimeout(() => initDashboardCharts(resp), 50);
|
||
} catch (e) {
|
||
console.error('Stats Error:', e);
|
||
c.innerHTML = `
|
||
<div class="panel" style="padding:40px; text-align:center; color:var(--danger)">
|
||
<div style="font-size:40px; margin-bottom:16px">⚠️</div>
|
||
<h3>数据看板加载失败</h3>
|
||
<p style="margin:12px 0; color:var(--text-muted)">故障原因: ${e.message}</p>
|
||
<button class="btn btn-primary" onclick="renderPage('stats')">🚀 尝试重试</button>
|
||
</div>
|
||
`;
|
||
}
|
||
}
|
||
|
||
function initDashboardCharts(data) {
|
||
if (!data) return;
|
||
try {
|
||
const elTrend = document.getElementById('chart-trend');
|
||
if (elTrend) {
|
||
const trends = data.trends || {};
|
||
const dates = Object.keys(trends);
|
||
if (dates.length) {
|
||
new Chart(elTrend.getContext('2d'), {
|
||
type: 'line',
|
||
data: {
|
||
labels: dates,
|
||
datasets: [
|
||
{ label: '通过任务', data: dates.map(d => trends[d].pass), borderColor: '#38e0b0', tension: 0.4, fill: true, backgroundColor: 'rgba(56,224,176,0.1)' },
|
||
{ label: '失败任务', data: dates.map(d => trends[d].fail), borderColor: '#ff5c6c', tension: 0.4 }
|
||
]
|
||
},
|
||
options: { plugins: { legend: { display: false } }, scales: { y: { display: false }, x: { grid: { display: false }, ticks: { color: '#7a82a0', font: { size: 10 } } } } }
|
||
});
|
||
}
|
||
}
|
||
|
||
const elPie = document.getElementById('chart-pie');
|
||
if (elPie && data.failure_analysis) {
|
||
new Chart(elPie.getContext('2d'), {
|
||
type: 'doughnut',
|
||
data: {
|
||
labels: Object.keys(data.failure_analysis),
|
||
datasets: [{ data: Object.values(data.failure_analysis), backgroundColor: ['#6c72ff', '#ff5c6c', '#ffb547', '#2a3048'], borderWidth: 0 }]
|
||
},
|
||
options: { cutout: '70%', plugins: { legend: { position: 'bottom', labels: { color: '#e6e9f4', boxWidth: 10, font: { size: 10 } } } } }
|
||
});
|
||
}
|
||
|
||
const elBar = document.getElementById('chart-bar');
|
||
if (elBar && data.module_analysis) {
|
||
const modItems = Object.entries(data.module_analysis).sort((a, b) => b[1] - a[1]).slice(0, 5);
|
||
new Chart(elBar.getContext('2d'), {
|
||
type: 'bar',
|
||
data: {
|
||
labels: modItems.map(i => i[0]),
|
||
datasets: [{ data: modItems.map(i => i[1]), backgroundColor: '#6c72ff', borderRadius: 4 }]
|
||
},
|
||
options: { indexAxis: 'y', plugins: { legend: { display: false } }, scales: { x: { grid: { display: false }, ticks: { precision: 0, color: '#7a82a0' } }, y: { grid: { display: false }, ticks: { color: '#7a82a0', font: { size: 10 } } } } }
|
||
});
|
||
}
|
||
|
||
const elFails = document.getElementById('chart-fails');
|
||
if (elFails && data.trends) {
|
||
new Chart(elFails.getContext('2d'), {
|
||
type: 'bar',
|
||
data: {
|
||
labels: Object.keys(data.trends),
|
||
datasets: [{ label: '失败数', data: Object.values(data.trends).map(v => v.fail), backgroundColor: '#ff5c6c', borderRadius: 4 }]
|
||
},
|
||
options: { plugins: { legend: { display: false } }, scales: { y: { display: false }, x: { grid: { display: false }, ticks: { color: '#7a82a0', font: { size: 10 } } } } }
|
||
});
|
||
}
|
||
} catch (err) { console.error('Chart Init Error:', err); }
|
||
}
|
||
|
||
// Close modal on overlay click
|
||
document.querySelectorAll('.modal-overlay').forEach(el => {
|
||
el.addEventListener('click', e => { if (e.target === el) closeModal(el.id); });
|
||
});
|
||
|
||
init();
|
||
</script>
|
||
</body>
|
||
|
||
</html> |