Files

329 lines
16 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>错题毕业 · 初中版 · 接口控制台</title>
<style>
:root{--ink:#24211f;--brand:#b3272d;--muted:#8b8178;--line:#e6dfd8;--paper:#fbf9f6;--green:#2f6b57}
*{box-sizing:border-box}
body{margin:0;font:14px/1.6 -apple-system,"Microsoft YaHei",system-ui;color:var(--ink);background:var(--paper)}
header{display:flex;align-items:center;gap:12px;padding:14px 20px;background:#fff;border-bottom:1px solid var(--line)}
.mark{width:34px;height:34px;border-radius:10px;background:#FFF3DF url(../../brand/mark.svg) center/100% 100% no-repeat}
header h1{font-size:16px;margin:0}
header .sub{color:var(--muted);font-size:12px}
header .grow{flex:1}
main{display:grid;grid-template-columns:1fr 380px;gap:16px;padding:16px 20px 40px}
.card{background:#fff;border:1px solid var(--line);border-radius:12px;padding:14px 16px;margin-bottom:14px}
.card h2{font-size:13px;margin:0 0 10px;color:var(--muted);font-weight:600;letter-spacing:.02em}
button{font:inherit;padding:7px 12px;border-radius:8px;border:1px solid var(--line);background:#fff;cursor:pointer}
button:hover{border-color:#cfc6bd}
button.primary{background:var(--brand);color:#fff;border-color:var(--brand)}
button.primary:hover{background:#9d2227}
button.ghost{border-style:dashed;color:var(--muted)}
button:disabled{opacity:.45;cursor:not-allowed}
input,select,textarea{font:inherit;padding:7px 10px;border:1px solid var(--line);border-radius:8px;background:#fff;min-width:0}
textarea{width:100%;min-height:58px;resize:vertical}
.row{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
.q{border:1px solid var(--line);border-radius:10px;padding:10px 12px;margin-bottom:8px;background:#fdfcfb}
.q .stem{font-weight:600}
.q .meta{color:var(--muted);font-size:12px;margin-top:2px}
.tag{display:inline-block;font-size:11px;padding:1px 7px;border-radius:999px;background:#f2ede8;color:#6d645c;margin-right:6px}
.tag.red{background:#fbeaea;color:#a3282c}
.tag.green{background:#e9f2ee;color:var(--green)}
pre{background:#1f1d1b;color:#e9e2d9;padding:12px;border-radius:10px;font-size:12px;line-height:1.55;
height:calc(100vh - 300px);overflow:auto;margin:0;white-space:pre-wrap;word-break:break-all}
.kv{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.kv div{background:#fdfcfb;border:1px solid var(--line);border-radius:10px;padding:8px 10px}
.kv b{display:block;font-size:18px}
.kv span{color:var(--muted);font-size:12px}
.muted{color:var(--muted);font-size:12px}
.toast{position:fixed;left:50%;bottom:24px;transform:translateX(-50%);background:var(--ink);color:#fff;
padding:9px 16px;border-radius:999px;font-size:13px;opacity:0;transition:.2s}
.toast.on{opacity:1}
</style>
</head>
<body>
<header>
<div class="mark"></div>
<div>
<h1>错题毕业 · 初中版 · 接口控制台</h1>
<div class="sub">学生是主账号 · 家长逐题授权 · 每天 6 道 · 周日一张 A4</div>
</div>
<div class="grow"></div>
<button id="btn-reset" class="ghost">重置演示</button>
<button id="btn-flow" class="primary">一键跑完整流程</button>
</header>
<main>
<section>
<div class="card">
<h2>学生 / 家长</h2>
<div class="row">
<button id="btn-login">学生登录(code=demo)</button>
<button id="btn-invite">生成家长邀请码</button>
<input id="invite-code" placeholder="6 位码" style="width:110px">
<button id="btn-claim">家长绑定</button>
<button id="btn-me" class="ghost">我是谁</button>
</div>
<div class="muted" id="who" style="margin-top:8px">未登录</div>
</div>
<div class="card">
<h2>今日 6 道(21:00 推送)</h2>
<div class="row" style="margin-bottom:10px">
<button id="btn-today">拉取今日队列</button>
<button id="btn-advance" class="ghost">时间快进 1 天</button>
<button id="btn-notify" class="ghost">跑一次提醒</button>
</div>
<div id="today"></div>
</div>
<div class="card">
<h2>采集 → 入库 → 讲清</h2>
<div class="row">
<select id="subject">
<option value="math">数学</option><option value="physics">物理</option>
<option value="chemistry">化学</option><option value="english">英语</option>
</select>
<button id="btn-paper">拍一张卷子</button>
<button id="btn-import">把标错的入库</button>
<button id="btn-mistakes" class="ghost">看错题本</button>
</div>
<div id="paper" style="margin-top:10px"></div>
</div>
<div class="card">
<h2>周报 / 那张纸 / 导出</h2>
<div class="row" style="margin-bottom:10px">
<button id="btn-weekly">周报</button>
<button id="btn-a4">周日那张 A4</button>
<button id="btn-csv" class="ghost">导出 CSV</button>
</div>
<div id="weekly"></div>
</div>
<div class="card">
<h2>家长视角(只能看被授权的东西)</h2>
<div class="row" style="margin-bottom:10px">
<button id="btn-g-report">家长看周报</button>
<button id="btn-g-q" class="ghost">家长点开第一道题</button>
<button id="btn-grant" class="ghost">学生授权这道题</button>
</div>
<div id="gview" class="muted">家长默认只拿到三个数字;原题要学生单独授权。</div>
</div>
</section>
<aside>
<div class="card" style="margin-bottom:14px">
<h2>实时日志</h2>
<pre id="log"></pre>
</div>
</aside>
</main>
<div class="toast" id="toast"></div>
<script>
const S = { student: localStorage.getItem("jl_student") || "", guardian: localStorage.getItem("jl_guardian") || "" };
const $ = (id) => document.getElementById(id);
const logEl = $("log");
let lastPaper = null, lastToday = null, lastWeekly = null;
function log(title, obj) {
const t = new Date().toLocaleTimeString();
logEl.textContent += `\n[${t}] ${title}\n` + (obj === undefined ? "" : JSON.stringify(obj, null, 2));
logEl.scrollTop = logEl.scrollHeight;
}
function toast(msg) {
const el = $("toast"); el.textContent = msg; el.classList.add("on");
setTimeout(() => el.classList.remove("on"), 1400);
}
async function api(path, { method = "GET", body, token } = {}) {
const headers = { "Content-Type": "application/json" };
const tk = token || S.student;
if (tk) headers.Authorization = "Bearer " + tk;
const res = await fetch(path, { method, headers, body: body ? JSON.stringify(body) : undefined });
const json = await res.json().catch(() => ({}));
log(`${method} ${path} → ${res.status}`, json);
if (!json.ok) throw new Error((json.error && json.error.message) || res.status);
return json.data;
}
function setWho(txt) { $("who").textContent = txt; }
$("btn-login").onclick = async () => {
const d = await api("/api/auth/student", { method: "POST", body: { code: "demo" } });
S.student = d.token; localStorage.setItem("jl_student", d.token);
setWho(`学生:${d.student.nickname}(${d.student.grade} 年级)`);
toast("学生登录成功");
};
$("btn-me").onclick = async () => {
const d = await api("/api/me");
setWho(`学生:${d.student.nickname}(${d.student.grade} 年级)· 科目 ${d.subjects.join("/")} · 家长 ${d.guardians.length} 位`);
};
$("btn-invite").onclick = async () => {
const d = await api("/api/invite", { method: "POST", body: {} });
$("invite-code").value = d.code; toast("邀请码 " + d.code + "(10 分钟有效)");
};
$("btn-claim").onclick = async () => {
const code = $("invite-code").value.trim();
if (!code) return toast("先填 6 位码");
const res = await fetch("/api/auth/guardian", { method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ code, nickname: "妈妈" }) });
const json = await res.json(); log("POST /api/auth/guardian", json);
if (!json.ok) return toast(json.error.message);
S.guardian = json.data.token; localStorage.setItem("jl_guardian", S.guardian);
toast("家长已绑定(默认只能看结论)");
};
$("btn-today").onclick = async () => {
lastToday = await api("/api/today");
const box = $("today"); box.innerHTML = "";
const all = [...(lastToday.items || []), ...(lastToday.variants || []), ...(lastToday.explains || [])];
if (!all.length) box.innerHTML = `<div class="muted">今天没有要做的题(${lastToday.note})</div>`;
all.forEach((m) => {
const div = document.createElement("div");
div.className = "q";
div.innerHTML = `<div class="stem">${m.stem || m.variant_stem || ""}</div>
<div class="meta"><span class="tag">${m.status_zh || ""}</span>
<span class="tag green">${m.error_type_zh || "会做但错了"}</span>
第 ${m.repeat_count || 1} 次 · 到期 ${m.next_due || "-"}</div>
<div class="row" style="margin-top:8px">
<input placeholder="你的答案" style="width:150px">
<button data-act="attempt">提交</button>
<button data-act="variant" class="ghost">交变式</button>
<button data-act="explain" class="ghost">讲一遍</button>
</div>`;
const input = div.querySelector("input");
div.querySelectorAll("button").forEach((b) => {
b.onclick = async () => {
try {
const act = b.dataset.act;
if (act === "attempt") {
const r = await api(`/api/mistakes/${m.id}/attempt`, { method: "POST", body: { answer: input.value } });
toast(r.refused ? "拒答:" + r.detail : (r.correct ? "对了 → " + r.status_zh : "错了:" + r.detail));
} else if (act === "variant") {
const r = await api(`/api/mistakes/${m.id}/variant`, { method: "POST", body: { answer: input.value } });
toast(r.correct ? "变式对了 → " + r.status_zh : "变式错了:" + r.detail);
} else {
const r = await api(`/api/mistakes/${m.id}/explain`, { method: "POST",
body: { channel: "ai_voice", text: "错在符号写反了,先移项再合并同类项,下次遇到先检查符号" } });
toast(r.passed ? "讲清了,毕业" : "没过:" + r.reason);
}
} catch (e) { toast(e.message); }
};
});
box.appendChild(div);
});
};
$("btn-advance").onclick = async () => { await api("/api/dev/advance", { method: "POST", body: { days: 1 } }); toast("已快进 1 天"); };
$("btn-notify").onclick = async () => { const d = await api("/api/dev/notify-tick", { method: "POST", body: {} }); toast(`推送 ${d.sent.length} 条,降频 ${d.suppressed.length} 条`); };
$("btn-paper").onclick = async () => {
lastPaper = await api("/api/papers", { method: "POST", body: { subject: $("subject").value } });
const box = $("paper"); box.innerHTML = "";
lastPaper.questions.forEach((q, i) => {
const div = document.createElement("div");
div.className = "q";
div.innerHTML = `<div class="stem">${i + 1}. ${q.stem}</div>
<div class="meta">知识点 ${q.knowledge} · ${q.judge_type} · <span class="tag" data-v="${q.verdict}">${q.verdict}</span></div>
<div class="row" style="margin-top:6px">
<label><input type="radio" name="v${q.id}" value="right"> 对</label>
<label><input type="radio" name="v${q.id}" value="wrong" checked> 错</label>
<label><input type="radio" name="v${q.id}" value="unknown"> 不确定</label>
</div>`;
box.appendChild(div);
});
const btns = document.createElement("div");
btns.innerHTML = `<button id="btn-markall" class="ghost">全部标成错</button>`;
box.appendChild(btns);
$("btn-markall").onclick = async () => {
for (const q of lastPaper.questions) {
await api(`/api/questions/${q.id}`, { method: "PATCH", body: { verdict: "wrong" } });
}
toast("已全部标错");
};
};
$("btn-import").onclick = async () => {
if (!lastPaper) return toast("先拍一张卷子");
const ids = lastPaper.questions.map((q) => q.id);
const d = await api("/api/mistakes/import", { method: "POST", body: { question_ids: ids } });
toast(`进队列 ${d.in_queue.length} · 观察 ${d.observing.length} · 待补 ${d.backlog.length}`);
};
$("btn-mistakes").onclick = async () => {
const d = await api("/api/mistakes");
log("错题本 " + d.items.length + " 条", d.counts);
toast("共 " + d.items.length + " 条,见日志");
};
$("btn-weekly").onclick = async () => {
lastWeekly = await api("/api/report/weekly");
const n = lastWeekly.numbers;
$("weekly").innerHTML = `<div class="kv">
<div><b>${n.new_this_week}</b><span>本周新增</span></div>
<div><b>${n.graduated_this_week}</b><span>本周消灭</span></div>
<div><b>${n.kill_rate}%</b><span>累计消灭率</span></div>
<div><b>${n.attempts_this_week}</b><span>本周作答</span></div>
<div><b>${n.review_days}</b><span>练习天数</span></div>
<div><b>${n.in_queue}</b><span>队列里还有</span></div>
</div><div class="muted" style="margin-top:8px">${lastWeekly.one_line}</div>`;
};
$("btn-a4").onclick = async () => {
if (!S.student) return toast("先登录");
window.open(`/api/print/a4?token=${encodeURIComponent(S.student)}`, "_blank");
};
$("btn-csv").onclick = async () => {
if (!S.student) return toast("先登录");
window.open(`/api/export/csv?token=${encodeURIComponent(S.student)}`, "_blank");
};
$("btn-g-report").onclick = async () => {
const me = await api("/api/me");
const sid = me.student.id;
const res = await fetch(`/api/g/report?student_id=${sid}`, { headers: { Authorization: "Bearer " + S.guardian } });
const json = await res.json(); log("GET /api/g/report", json);
if (!json.ok) return toast(json.error.message);
$("gview").innerHTML = `家长看到:新增 ${json.data.numbers.new_this_week} / 消灭 ${json.data.numbers.graduated_this_week} / 累计 ${json.data.numbers.kill_rate}%`;
};
$("btn-g-q").onclick = async () => {
if (!lastToday || !lastToday.items.length) return toast("先拉今日队列");
const qid = lastToday.items[0].question_id;
const res = await fetch(`/api/g/question/${qid}`, { headers: { Authorization: "Bearer " + S.guardian } });
const json = await res.json(); log("GET /api/g/question/{id}", json);
$("gview").textContent = json.ok ? "家长看到了原题(学生已授权)" : "被拦住了:" + json.error.message;
};
$("btn-grant").onclick = async () => {
if (!lastToday || !lastToday.items.length) return toast("先拉今日队列");
const me = await api("/api/me");
const g = me.guardians[0];
if (!g) return toast("家长还没绑定");
const d = await api("/api/share-grants", { method: "POST",
body: { guardian_id: g.guardian_id, question_id: lastToday.items[0].question_id, days: 7 } });
toast("已授权这道题,到 " + d.expires_at.slice(0, 16));
};
$("btn-reset").onclick = async () => { await api("/api/dev/reseed", { method: "POST", body: {} }); toast("演示数据已重置"); };
$("btn-flow").onclick = async () => {
try {
await api("/api/dev/reseed", { method: "POST", body: {} });
const d = await api("/api/auth/student", { method: "POST", body: { code: "demo" } });
S.student = d.token; localStorage.setItem("jl_student", d.token);
setWho(`学生:${d.student.nickname}(${d.student.grade} 年级)`);
await $("btn-today").onclick();
const m = lastToday.items[0];
if (m) {
await api(`/api/mistakes/${m.id}/attempt`, { method: "POST", body: { answer: "5" } });
await api(`/api/mistakes/${m.id}/attempt`, { method: "POST", body: { answer: "5" } });
await api(`/api/mistakes/${m.id}/variant`, { method: "POST", body: { answer: "6" } });
await api(`/api/mistakes/${m.id}/explain`, { method: "POST",
body: { channel: "ai_voice", text: "错在没有先移项,先把常数挪到右边,再合并同类项" } });
}
await $("btn-weekly").onclick();
toast("跑完了,看日志");
} catch (e) { toast(e.message); }
};
log("控制台就绪:先点「学生登录」,或直接「一键跑完整流程」");
</script>
</body>
</html>