A lesson-oriented page plus a loopback job service: click a lesson and the page really runs tools/web-freecad-functional-suite.mjs, tools/layout-probe.mjs or tools/static-host.mjs, streaming logs and rendering verdicts from the suite's own manifest/checkpoint/results files. - web/tools/teaching-console: catalog derived from scenarios + registry, 73 workbench lessons, template, builder (--check), Playwright gate, no-browser self-test for every spawn validation path - web/teaching/suite-runner.mjs: argv whitelist, env whitelist, single concurrent job, process-group cancel, ring-buffered logs, preflight - web/teaching/server.mjs: /api/console/* routes with startup token, Origin check, SSE events, artifact serving; existing routes untouched - preflight blocks runs (E_PREFLIGHT) instead of starting without dist, Chrome, DISPLAY, kernel or Playwright - gates: self-test OK, build --check idempotent, offline + live Playwright (MOD-Part-01 pass, cancel path) OK Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
438 lines
23 KiB
HTML
438 lines
23 KiB
HTML
<!doctype html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Web FreeCAD 教学控制台</title>
|
||
<style>
|
||
:root{--bg:#0f1419;--panel:#17212b;--panel2:#1b2733;--line:#2a3a45;--text:#dbe6ee;--muted:#93a6b3;--accent:#73c6d4;--ok:#7fc98b;--warn:#e0b15c;--bad:#e58a8a;color-scheme:dark}
|
||
*{box-sizing:border-box}
|
||
body{margin:0;background:var(--bg);color:var(--text);font:15px/1.6 system-ui,-apple-system,"Segoe UI","Noto Sans CJK SC","Microsoft YaHei",sans-serif;overflow-wrap:break-word}
|
||
a{color:var(--accent);text-decoration:none}
|
||
a:hover{text-decoration:underline}
|
||
code,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
||
code{background:#0b1117;border:1px solid var(--line);border-radius:4px;padding:.1em .35em;font-size:.9em}
|
||
header.top{position:sticky;top:0;z-index:20;display:flex;gap:12px;align-items:center;padding:10px 16px;background:rgba(15,20,25,.92);border-bottom:1px solid var(--line);backdrop-filter:blur(6px)}
|
||
header.top .brand{font-weight:650;font-size:16px}
|
||
header.top .spacer{flex:1}
|
||
.chip{display:inline-flex;gap:6px;align-items:center;border:1px solid var(--line);border-radius:999px;padding:2px 10px;font-size:12.5px;color:var(--muted);background:var(--panel)}
|
||
.chip.ok{color:var(--ok);border-color:#2f5138}
|
||
.chip.bad{color:var(--bad);border-color:#5a3030}
|
||
.chip.warn{color:var(--warn);border-color:#5a4a2a}
|
||
.layout{display:grid;grid-template-columns:300px minmax(0,1fr);gap:18px;padding:16px;max-width:1500px;margin:0 auto}
|
||
nav.side{position:sticky;top:60px;align-self:start;max-height:calc(100vh - 76px);overflow:auto;background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:10px}
|
||
nav.side input{width:100%;margin-bottom:8px;background:#0b1117;color:var(--text);border:1px solid var(--line);border-radius:8px;padding:7px 10px;font-size:13.5px}
|
||
nav.side .group{margin:10px 0 4px;font-size:12px;color:var(--muted);text-transform:none;letter-spacing:.02em}
|
||
nav.side button{display:block;width:100%;text-align:left;background:none;border:0;color:var(--text);border-radius:6px;padding:5px 8px;font-size:13.5px;line-height:1.35;cursor:pointer}
|
||
nav.side button:hover{background:var(--panel2)}
|
||
nav.side button.active{background:#223243;color:#eaf6fb}
|
||
nav.side button.done::after{content:" ✓";color:var(--ok)}
|
||
main{min-width:0}
|
||
section.card{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:14px 16px;margin-bottom:14px}
|
||
h1{font-size:21px;margin:0 0 6px}
|
||
h2{font-size:16px;margin:0 0 8px}
|
||
h3{font-size:14px;margin:14px 0 6px;color:var(--muted)}
|
||
p{margin:6px 0}
|
||
ul{margin:6px 0 6px 20px;padding:0}
|
||
li{margin:2px 0}
|
||
.lead{color:#c6d6e2}
|
||
.muted{color:var(--muted)}
|
||
.small{font-size:12.5px}
|
||
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
|
||
button.act{background:var(--accent);color:#04161a;border:0;border-radius:8px;padding:8px 16px;font-size:14px;font-weight:600;cursor:pointer}
|
||
button.act:disabled{opacity:.45;cursor:not-allowed}
|
||
button.ghost{background:transparent;color:var(--text);border:1px solid var(--line);border-radius:8px;padding:8px 14px;cursor:pointer}
|
||
button.ghost:disabled{opacity:.45;cursor:not-allowed}
|
||
label.opt{display:inline-flex;gap:6px;align-items:center;color:var(--muted);font-size:13px}
|
||
pre.term{background:#070b0f;border:1px solid var(--line);border-radius:8px;padding:10px 12px;height:320px;overflow:auto;font-size:12.5px;line-height:1.5;white-space:pre-wrap;word-break:break-word}
|
||
pre.term .err{color:var(--bad)}
|
||
pre.term .ok{color:var(--ok)}
|
||
pre.term .sys{color:var(--muted)}
|
||
pre.cmd{background:#0b1117;border:1px solid var(--line);border-radius:8px;padding:9px 11px;overflow:auto;font-size:12.5px;white-space:pre-wrap;word-break:break-all}
|
||
.progress{height:8px;background:#0b1117;border:1px solid var(--line);border-radius:999px;overflow:hidden}
|
||
.progress > i{display:block;height:100%;width:0;background:var(--accent);transition:width .3s}
|
||
.verdict{font-size:15px;font-weight:650}
|
||
.verdict.pass{color:var(--ok)}
|
||
.verdict.product_fail,.verdict.run_fail,.verdict.timeout,.verdict.preflight_failed{color:var(--bad)}
|
||
.verdict.precondition_fail{color:var(--warn)}
|
||
.verdict.cancelled{color:var(--muted)}
|
||
table{border-collapse:collapse;width:100%;font-size:13px}
|
||
th,td{border-bottom:1px solid var(--line);padding:5px 8px;text-align:left;vertical-align:top}
|
||
th{color:var(--muted);font-weight:500}
|
||
td.st-passed{color:var(--ok)}td.st-failed{color:var(--bad)}td.st-blocked{color:var(--warn)}td.st-running{color:var(--accent)}
|
||
.chips{display:flex;gap:8px;flex-wrap:wrap;margin:8px 0}
|
||
.chip .fix{display:block;color:var(--muted);font-size:11.5px}
|
||
details{border:1px solid var(--line);border-radius:8px;padding:6px 10px;margin:6px 0;background:#0d1319}
|
||
summary{cursor:pointer;font-size:13.5px}
|
||
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
|
||
.banner{padding:9px 12px;border-radius:8px;margin-bottom:12px;font-size:13.5px}
|
||
.banner.offline{background:#2a2317;border:1px solid #5a4a2a;color:var(--warn)}
|
||
.practice-list{max-height:240px;overflow:auto;border:1px solid var(--line);border-radius:8px;padding:8px}
|
||
.practice-list label{display:block;font-size:13px;color:var(--text);padding:2px 0}
|
||
.practice-list .g{color:var(--muted);font-size:12px;margin-top:6px}
|
||
.skip{position:absolute;left:-999px}
|
||
@media (max-width:900px){.layout{grid-template-columns:1fr;padding:10px}nav.side{position:static;max-height:none}.grid2{grid-template-columns:1fr}header.top{flex-wrap:wrap}}
|
||
@media print{header.top,nav.side,button{display:none!important}.layout{display:block}}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<a class="skip" href="#main">跳到主内容</a>
|
||
<header class="top">
|
||
<span class="brand">Web FreeCAD 教学控制台</span>
|
||
<span id="status" class="chip">检测服务…</span>
|
||
<span class="spacer"></span>
|
||
<a href="index.html">教学中心</a>
|
||
<a href="runner.html">可视化执行</a>
|
||
<a href="manual.html">图文教案</a>
|
||
</header>
|
||
<div class="layout">
|
||
<nav class="side" aria-label="课程目录">
|
||
<input id="search" type="search" placeholder="搜索课程…(按 / 聚焦)" aria-label="搜索课程">
|
||
<div id="course-list"></div>
|
||
</nav>
|
||
<main id="main">
|
||
<div id="offline-banner" class="banner offline" hidden>
|
||
未连接教学服务(或服务是旧版本)。页面仍可阅读与复制命令;要在线运行,请在仓库根执行
|
||
<code>DISPLAY=:1 node web/teaching/server.mjs</code>,再打开它打印的 console 地址。
|
||
</div>
|
||
<section class="card" id="preflight-card">
|
||
<h2>前置条件</h2>
|
||
<p class="small muted">铁律:前置未满足时不执行产品断言。任一硬性检查失败,运行按钮会被禁用。</p>
|
||
<div class="chips" id="preflight-chips"><span class="chip">检查中…</span></div>
|
||
<div class="row"><button class="ghost" id="recheck" type="button">重新检查</button></div>
|
||
</section>
|
||
<section class="card" id="lesson-card">
|
||
<div class="row"><h1 id="lesson-title">选择一门课程</h1><span id="lesson-meta" class="muted small"></span></div>
|
||
<p class="lead" id="lesson-summary">左侧按工作台分组,从「第 0 课 · 环境自检」开始。</p>
|
||
<h3>你会看到</h3><ul id="lesson-sees"></ul>
|
||
<h3>预期判定</h3><p id="lesson-expect" class="small"></p>
|
||
<div id="lesson-notes"></div>
|
||
<div id="practice-box" hidden>
|
||
<h3>选择用例(最多 8 个)</h3>
|
||
<div class="practice-list" id="practice-list"></div>
|
||
</div>
|
||
<h3>运行</h3>
|
||
<div class="row">
|
||
<button class="act" id="run" type="button">开始</button>
|
||
<button class="ghost" id="cancel" type="button" disabled>取消</button>
|
||
<label class="opt" id="opt-observe"><input id="observe" type="checkbox" checked> 观察模式(慢速 + 高亮)</label>
|
||
<label class="opt" id="opt-shots"><input id="shots" type="checkbox"> 全部截图</label>
|
||
</div>
|
||
<h3>等价命令</h3>
|
||
<pre class="cmd" id="lesson-command">(选择课程后显示)</pre>
|
||
</section>
|
||
<section class="card">
|
||
<div class="row"><h2 style="margin:0">运行状态</h2><span id="job-id" class="muted small"></span><span class="spacer" style="flex:1"></span><span id="verdict" class="verdict muted">等待运行</span></div>
|
||
<div class="row small muted" style="margin:8px 0"><span id="progress-text">0 / 0</span><span id="current-case"></span></div>
|
||
<div class="progress"><i id="progress-bar"></i></div>
|
||
<h3>实时日志</h3>
|
||
<pre class="term" id="terminal"><span class="sys">等待运行…</span></pre>
|
||
<h3>用例结果</h3>
|
||
<div id="results"><p class="muted small">运行结束后按用例列出。</p></div>
|
||
<h3>证据</h3>
|
||
<div id="evidence"><p class="muted small">套件运行结束后可打开完整报告与截图。</p></div>
|
||
</section>
|
||
</main>
|
||
</div>
|
||
<script>window.__LESSONS__ = {{LESSONS_JSON}};</script>
|
||
<script>window.__CATALOG__ = {{CATALOG_JSON}};</script>
|
||
<script>window.__COMMANDS__ = {{COMMANDS_JSON}};</script>
|
||
<script>
|
||
(function(){
|
||
"use strict";
|
||
var LESSONS = window.__LESSONS__;
|
||
var CATALOG = window.__CATALOG__;
|
||
var COMMANDS = window.__COMMANDS__;
|
||
var byId = {};
|
||
LESSONS.lessons.forEach(function(l){ byId[l.id] = l; });
|
||
var groups = LESSONS.groups;
|
||
|
||
var token = "";
|
||
(function(){
|
||
var url = new URL(location.href);
|
||
var param = url.searchParams.get("token");
|
||
if (param) { token = param; try { sessionStorage.setItem("teaching-token", param); } catch(e){} url.searchParams.delete("token"); history.replaceState(null, "", url.toString()); }
|
||
else { try { token = sessionStorage.getItem("teaching-token") || ""; } catch(e){} }
|
||
})();
|
||
|
||
var state = {
|
||
online: false, checked: false, preflight: null, lesson: null,
|
||
job: null, jobId: null, source: null, running: false, logs: 0,
|
||
practice: {}, autoScroll: true, completed: {}
|
||
};
|
||
try { state.completed = JSON.parse(localStorage.getItem("teaching-console-done-v1") || "{}"); } catch(e) { state.completed = {}; }
|
||
|
||
function $(id){ return document.getElementById(id); }
|
||
function esc(text){ return String(text == null ? "" : text).replace(/[&<>"]/g, function(c){ return {"&":"&","<":"<",">":">","\"":"""}[c]; }); }
|
||
|
||
/* --------------------------------------------------------------- sidebar */
|
||
function renderSidebar(){
|
||
var q = ($("search").value || "").trim().toLowerCase();
|
||
var html = "";
|
||
groups.forEach(function(group){
|
||
var items = LESSONS.lessons.filter(function(l){ return l.groupId === group.id; });
|
||
if (q) items = items.filter(function(l){ return (l.title + " " + l.summary + " " + group.title).toLowerCase().indexOf(q) >= 0; });
|
||
if (!items.length) return;
|
||
html += '<div class="group">' + esc(group.title) + ' · ' + items.length + '</div>';
|
||
items.forEach(function(l){
|
||
var cls = "lesson-btn" + (state.lesson && state.lesson.id === l.id ? " active" : "") + (state.completed[l.id] ? " done" : "");
|
||
html += '<button type="button" class="' + cls + '" data-id="' + esc(l.id) + '">' + esc(l.title) + '</button>';
|
||
});
|
||
});
|
||
$("course-list").innerHTML = html || '<p class="muted small">没有匹配的课程。</p>';
|
||
}
|
||
|
||
/* ---------------------------------------------------------------- lesson */
|
||
function renderLesson(){
|
||
var l = state.lesson;
|
||
if (!l) return;
|
||
$("lesson-title").textContent = l.title;
|
||
$("lesson-meta").textContent = (l.level || "") + " · 约 " + (l.durationMin || 1) + " 分钟 · " + l.job.kind;
|
||
$("lesson-summary").textContent = l.summary || "";
|
||
$("lesson-sees").innerHTML = (l.sees || []).map(function(x){ return "<li>" + esc(x) + "</li>"; }).join("");
|
||
$("lesson-expect").textContent = l.expect || "";
|
||
$("lesson-notes").innerHTML = (l.notes || []).map(function(x){ return '<p class="small muted">注意:' + esc(x) + "</p>"; }).join("");
|
||
$("practice-box").hidden = !l.job.selectable;
|
||
if (l.job.selectable) renderPractice();
|
||
$("opt-observe").hidden = l.job.kind !== "suite" || l.job.selectable;
|
||
$("opt-shots").hidden = l.job.kind !== "suite" || l.job.selectable;
|
||
$("lesson-command").textContent = commandFor(l);
|
||
updateButtons();
|
||
renderSidebar();
|
||
}
|
||
|
||
function commandFor(l){
|
||
if (l.job.kind === "preflight") return "(无需命令:只读取前置检查结果)";
|
||
var cmd = COMMANDS[l.id];
|
||
return (cmd || "(命令将在运行时由服务端生成)") + "\n# 工作目录:仓库根(WebFreeCAD 工作区),有头浏览器需要 DISPLAY=:1";
|
||
}
|
||
|
||
function renderPractice(){
|
||
var html = "";
|
||
var groupsByKind = [
|
||
["壳层", CATALOG.shell],
|
||
["交叉", CATALOG.crosscut],
|
||
["手册章节", CATALOG.chapters.map(function(c){ return c.id; })],
|
||
["模块", CATALOG.modules.map(function(m){ return "MOD-" + m + "-01"; })]
|
||
];
|
||
groupsByKind.forEach(function(pair){
|
||
html += '<div class="g">' + esc(pair[0]) + '</div>';
|
||
pair[1].forEach(function(id){
|
||
var checked = state.practice[id] ? " checked" : "";
|
||
html += '<label><input type="checkbox" class="practice-case" value="' + esc(id) + '"' + checked + '> ' + esc(id) + '</label>';
|
||
});
|
||
});
|
||
$("practice-list").innerHTML = html;
|
||
}
|
||
|
||
/* ------------------------------------------------------------- preflight */
|
||
function renderPreflight(report){
|
||
state.preflight = report;
|
||
if (!report) { $("preflight-chips").innerHTML = '<span class="chip bad">无法读取前置检查</span>'; return; }
|
||
$("preflight-chips").innerHTML = report.checks.map(function(c){
|
||
return '<span class="chip ' + (c.ok ? "ok" : "bad") + '">' + (c.ok ? "✓ " : "✗ ") + esc(c.id) +
|
||
'<span class="fix">' + esc(c.detail) + (c.ok ? "" : " · 修复:" + esc(c.fix)) + '</span></span>';
|
||
}).join("");
|
||
updateButtons();
|
||
}
|
||
|
||
function updateButtons(){
|
||
var l = state.lesson;
|
||
var ready = state.online && !state.running && l && (!state.preflight || state.preflight.ok || l.job.kind === "preflight");
|
||
$("run").disabled = !ready;
|
||
$("cancel").disabled = !state.running || !state.online;
|
||
}
|
||
|
||
/* ------------------------------------------------------------------- api */
|
||
function api(path, options){
|
||
options = options || {};
|
||
options.headers = Object.assign({ "x-teaching-token": token }, options.headers || {});
|
||
return fetch(path, options).then(function(res){
|
||
return res.json().catch(function(){ return {}; }).then(function(body){
|
||
if (!res.ok) { var err = new Error(body.error || ("HTTP " + res.status)); err.code = body.code; err.detail = body.detail; throw err; }
|
||
return body;
|
||
});
|
||
});
|
||
}
|
||
|
||
function checkHealth(){
|
||
fetch("/api/console/health", { cache: "no-store" }).then(function(res){ return res.json(); }).then(function(){
|
||
state.online = true; state.checked = true; setStatus(); refreshPreflight(); updateButtons();
|
||
}).catch(function(){
|
||
state.online = false; state.checked = true; setStatus(); updateButtons();
|
||
$("preflight-chips").innerHTML = '<span class="chip warn">离线:无法读取前置检查</span>';
|
||
});
|
||
}
|
||
|
||
function setStatus(){
|
||
var chip = $("status");
|
||
chip.className = "chip " + (state.online ? "ok" : "bad");
|
||
chip.textContent = state.online ? "服务在线" : "服务离线";
|
||
$("offline-banner").hidden = state.online;
|
||
}
|
||
|
||
function refreshPreflight(){
|
||
if (!state.online) return;
|
||
fetch("/api/console/preflight", { cache: "no-store" }).then(function(r){ return r.json(); }).then(renderPreflight).catch(function(){
|
||
$("preflight-chips").innerHTML = '<span class="chip bad">前置检查失败</span>';
|
||
});
|
||
}
|
||
|
||
/* ---------------------------------------------------------------- running */
|
||
function params(){
|
||
if (!state.lesson || !state.lesson.job.selectable) return {};
|
||
var ids = Object.keys(state.practice).filter(function(id){ return state.practice[id]; });
|
||
return { only: ids, slow: $("observe").checked ? 300 : 0, highlight: $("observe").checked, screenshots: $("shots").checked ? "all" : "fails" };
|
||
}
|
||
|
||
function startRun(){
|
||
var l = state.lesson;
|
||
if (!l) return;
|
||
clearTerminal();
|
||
state.logs = 0; state.running = true; state.job = null; state.jobId = null;
|
||
$("verdict").className = "verdict muted"; $("verdict").textContent = "启动中…";
|
||
$("results").innerHTML = '<p class="muted small">运行中…</p>';
|
||
$("evidence").innerHTML = '<p class="muted small">运行结束后生成。</p>';
|
||
updateButtons();
|
||
var payload = { lessonId: l.id, params: params() };
|
||
api("/api/console/run", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(payload) }).then(function(job){
|
||
state.jobId = job.jobId;
|
||
$("job-id").textContent = job.jobId;
|
||
subscribe(job.jobId);
|
||
}).catch(function(err){
|
||
state.running = false; updateButtons();
|
||
appendLine("stderr", "无法启动:" + (err.message || err));
|
||
if (err.code === "E_PREFLIGHT" && err.detail && err.detail.blockers) {
|
||
appendLine("sys", "未满足的前置:" + err.detail.blockers.map(function(b){ return b.id; }).join(", "));
|
||
}
|
||
$("verdict").className = "verdict bad"; $("verdict").textContent = "未启动(" + (err.code || "错误") + ")";
|
||
});
|
||
}
|
||
|
||
function subscribe(jobId){
|
||
if (state.source) { state.source.close(); state.source = null; }
|
||
var source = new EventSource("/api/console/events?jobId=" + encodeURIComponent(jobId) + "&token=" + encodeURIComponent(token));
|
||
state.source = source;
|
||
source.addEventListener("snapshot", function(event){ onSnapshot(JSON.parse(event.data)); });
|
||
source.addEventListener("log", function(event){ var data = JSON.parse(event.data); appendLine(data.stream, data.text); });
|
||
source.addEventListener("done", function(event){ onSnapshot(JSON.parse(event.data)); finishRun(); });
|
||
source.onerror = function(){ /* server restarts close the stream; the page stays readable */ };
|
||
}
|
||
|
||
function finishRun(){
|
||
state.running = false;
|
||
if (state.source) { state.source.close(); state.source = null; }
|
||
updateButtons();
|
||
var job = state.job;
|
||
if (job && job.verdict === "pass") {
|
||
state.completed[state.lesson.id] = true;
|
||
try { localStorage.setItem("teaching-console-done-v1", JSON.stringify(state.completed)); } catch(e){}
|
||
renderSidebar();
|
||
}
|
||
}
|
||
|
||
function onSnapshot(job){
|
||
state.job = job;
|
||
$("job-id").textContent = job.jobId || "";
|
||
var planned = job.planned || 0, completed = job.completed || 0;
|
||
$("progress-text").textContent = completed + " / " + planned;
|
||
$("progress-bar").style.width = planned ? Math.round(100 * completed / planned) + "%" : "0%";
|
||
$("current-case").textContent = job.current ? ("当前:" + job.current) : "";
|
||
if (job.verdict) {
|
||
$("verdict").className = "verdict " + job.verdict;
|
||
$("verdict").textContent = verdictLabel(job.verdict) + (job.exitCode != null ? "(exit " + job.exitCode + ")" : "");
|
||
} else if (job.state) {
|
||
$("verdict").className = "verdict muted";
|
||
$("verdict").textContent = job.state === "running" ? "运行中…" : job.state;
|
||
}
|
||
renderResults(job);
|
||
renderEvidence(job);
|
||
}
|
||
|
||
function verdictLabel(v){
|
||
return { pass: "通过", product_fail: "产品失败", precondition_fail: "前置失败", run_fail: "运行失败",
|
||
timeout: "超时", cancelled: "已取消", preflight_failed: "前置失败" }[v] || v;
|
||
}
|
||
|
||
function renderResults(job){
|
||
var results = job.results || [];
|
||
if (!results.length) return;
|
||
var rows = results.map(function(item){
|
||
return '<tr><td class="path">' + esc(item.id) + '</td><td>' + esc(item.title || "") + '</td><td class="st-' + esc(item.status) + '">' + esc(item.status) + '</td><td>' + (item.seconds != null ? Number(item.seconds).toFixed(1) + "s" : "") + '</td><td class="small">' + esc(item.error || "") + '</td></tr>';
|
||
}).join("");
|
||
$("results").innerHTML = '<div class="table-scroll" style="overflow:auto"><table><thead><tr><th>用例</th><th>标题</th><th>状态</th><th>耗时</th><th>错误</th></tr></thead><tbody>' + rows + "</tbody></table></div>";
|
||
}
|
||
|
||
function renderEvidence(job){
|
||
var links = [];
|
||
if (job.runDir) {
|
||
var base = "/evidence/" + job.runDir.replace(/^docs\//, "");
|
||
links.push('<a href="' + esc(base) + '/index.html" target="_blank" rel="noopener">完整报告(index.html)</a>');
|
||
links.push('<a href="' + esc(base) + '/report.md" target="_blank" rel="noopener">report.md</a>');
|
||
links.push('<a href="' + esc(base) + '/GAPS.md" target="_blank" rel="noopener">GAPS.md</a>');
|
||
}
|
||
if (job.kind === "probe") links.push('<a href="/api/console/artifacts/' + esc(job.jobId) + '/layout.json" target="_blank" rel="noopener">布局报告 JSON</a>');
|
||
if (job.origin) links.push('<span class="small muted">本次运行 origin:<code>' + esc(job.origin) + '</code></span>');
|
||
$("evidence").innerHTML = links.length ? links.map(function(x){ return '<div>' + x + '</div>'; }).join("") : '<p class="muted small">运行结束后可打开完整报告与截图。</p>';
|
||
}
|
||
|
||
/* --------------------------------------------------------------- terminal */
|
||
function appendLine(stream, text){
|
||
var term = $("terminal");
|
||
if (state.logs === 0) term.textContent = "";
|
||
state.logs += 1;
|
||
var span = document.createElement("span");
|
||
span.className = stream === "stderr" ? "err" : (/passed|ORIGIN=/.test(text) ? "ok" : (stream === "sys" ? "sys" : ""));
|
||
span.textContent = text + "\n";
|
||
term.appendChild(span);
|
||
while (term.childNodes.length > 2000) term.removeChild(term.firstChild);
|
||
if (state.autoScroll) term.scrollTop = term.scrollHeight;
|
||
}
|
||
|
||
function clearTerminal(){
|
||
$("terminal").textContent = "";
|
||
state.logs = 0;
|
||
}
|
||
|
||
/* ----------------------------------------------------------------- wiring */
|
||
$("search").addEventListener("input", renderSidebar);
|
||
document.addEventListener("keydown", function(event){
|
||
if (event.key === "/" && document.activeElement !== $("search")) { event.preventDefault(); $("search").focus(); }
|
||
});
|
||
$("course-list").addEventListener("click", function(event){
|
||
var button = event.target.closest("button[data-id]");
|
||
if (!button) return;
|
||
state.lesson = byId[button.getAttribute("data-id")];
|
||
state.practice = {};
|
||
renderLesson();
|
||
});
|
||
$("practice-list").addEventListener("change", function(event){
|
||
var input = event.target.closest("input.practice-case");
|
||
if (!input) return;
|
||
var id = input.value;
|
||
if (input.checked) {
|
||
var selected = Object.keys(state.practice).filter(function(k){ return state.practice[k]; });
|
||
if (selected.length >= 8) { input.checked = false; appendLine("sys", "自由练习最多选择 8 个用例。"); return; }
|
||
state.practice[id] = true;
|
||
} else {
|
||
delete state.practice[id];
|
||
}
|
||
});
|
||
$("run").addEventListener("click", startRun);
|
||
$("cancel").addEventListener("click", function(){
|
||
if (!state.jobId) return;
|
||
api("/api/console/cancel", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ jobId: state.jobId }) })
|
||
.catch(function(err){ appendLine("stderr", "取消失败:" + err.message); });
|
||
});
|
||
$("recheck").addEventListener("click", function(){ checkHealth(); });
|
||
$("terminal").addEventListener("scroll", function(){ var t = $("terminal"); state.autoScroll = t.scrollTop + t.clientHeight >= t.scrollHeight - 30; });
|
||
|
||
renderSidebar();
|
||
state.lesson = byId["lesson-00-preflight"] || LESSONS.lessons[0];
|
||
renderLesson();
|
||
checkHealth();
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|