chore: 首次纳入版本控制(审查前基线,v1.2.0)
This commit is contained in:
@@ -0,0 +1,394 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<meta charset="utf-8">
|
||||
<title>错题毕业 · 接口控制台</title>
|
||||
<style>
|
||||
:root{--ink:#24211f;--brand:#b3272d;--ochre:#a9761a;--line:#e6dfd8;--paper:#fbf8f5}
|
||||
*{box-sizing:border-box}
|
||||
body{margin:0;background:var(--paper);color:var(--ink);font:14px/1.65 "Microsoft YaHei","PingFang SC",system-ui,sans-serif}
|
||||
header{padding:18px 28px;border-bottom:2px solid var(--brand);display:flex;align-items:baseline;gap:14px}
|
||||
h1{margin:0;font-size:19px;letter-spacing:1px}
|
||||
header .sub{color:#6b6560;font-size:12px}
|
||||
main{max-width:1120px;margin:0 auto;padding:22px 28px 60px;display:grid;grid-template-columns:1fr 1fr;gap:18px}
|
||||
.card{background:#fff;border:1px solid var(--line);border-radius:8px;padding:14px 16px}
|
||||
.card h2{font-size:14px;margin:0 0 10px;padding-bottom:6px;border-bottom:1px dashed var(--line)}
|
||||
button{font:inherit;cursor:pointer;border-radius:6px;border:1px solid var(--line);background:#fff;padding:6px 11px}
|
||||
button:hover{border-color:var(--brand);color:var(--brand)}
|
||||
button.primary{background:var(--brand);color:#fff;border-color:var(--brand)}
|
||||
button.primary:hover{opacity:.9;color:#fff}
|
||||
button.ghost{border-style:dashed;color:#6b6560}
|
||||
.row{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:8px}
|
||||
input,select{font:inherit;padding:5px 8px;border:1px solid var(--line);border-radius:5px;background:#fff}
|
||||
code{background:#f5f1ed;padding:1px 5px;border-radius:3px;font-size:12px}
|
||||
#log{grid-column:1/-1;background:#221f1d;color:#e9e2da;border-radius:8px;padding:12px;height:320px;overflow:auto;
|
||||
font:12px/1.6 Consolas,monospace;white-space:pre-wrap}
|
||||
#log .ok{color:#8fd3a8}#log .err{color:#ef8a7e}#log .dim{color:#9c938a}
|
||||
.kv{display:grid;grid-template-columns:120px 1fr;gap:4px 10px;font-size:13px}
|
||||
.kv b{color:#6b6560;font-weight:400}
|
||||
.tag{display:inline-block;padding:0 6px;border-radius:3px;background:#f0e4e3;color:var(--brand);font-size:11px}
|
||||
ol{margin:6px 0 0 20px;padding:0}
|
||||
</style>
|
||||
<header>
|
||||
<h1>错题毕业 · 小学版</h1>
|
||||
<span class="sub">后端接口控制台 · 零依赖 · <a href="/docs">接口文档</a></span>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<div class="card">
|
||||
<h2>① 登录与建档</h2>
|
||||
<div class="row">
|
||||
<button class="primary" onclick="runFlow()">一键跑完整流程</button>
|
||||
<button onclick="login()">登录(code=demo)</button>
|
||||
<button class="ghost" onclick="reseed()">重置演示数据</button>
|
||||
</div>
|
||||
<div class="kv">
|
||||
<b>token</b><span id="tok" class="dim">未登录</span>
|
||||
<b>监护人</b><span id="gid">—</span>
|
||||
<b>孩子</b><span id="cid">—</span>
|
||||
</div>
|
||||
<p style="color:#6b6560;font-size:12px;margin:10px 0 0">
|
||||
流程:登录 → 监护人同意 → 建孩子 → 拍作业 → 入库 → 今日 5 道 → 作答 → 讲清 → 周报 → 打印。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>② 单个接口</h2>
|
||||
<div class="row">
|
||||
<button onclick="today()">今日队列</button>
|
||||
<button onclick="attempt()">作答(对)</button>
|
||||
<button onclick="attempt(false)">作答(错)</button>
|
||||
<button onclick="explain()">讲清</button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button onclick="weekly()">本周周报</button>
|
||||
<button onclick="printSheet()">周日那张纸</button>
|
||||
<button onclick="csv()">导出 CSV</button>
|
||||
<button onclick="stats()">统计</button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button onclick="notify()">跑一次提醒</button>
|
||||
<button onclick="advance()">时间快进 1 天</button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button onclick="entitlement()">看体验期</button>
|
||||
<button onclick="issueCodes()">签发 1 个体验码</button>
|
||||
<button onclick="redeem()">兑换激活码</button>
|
||||
</div>
|
||||
<div class="kv" style="margin-top:8px">
|
||||
<b>今天的码</b><span id="code" class="dim">先点「签发 1 个体验码」</span>
|
||||
</div>
|
||||
<div class="kv" style="margin-top:8px">
|
||||
<b>today 里的 mid</b><span id="mid" class="dim">先点「今日队列」</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>③ 多孩子</h2>
|
||||
<div class="row">
|
||||
<button onclick="children()">刷新列表</button>
|
||||
<input id="new-nick" placeholder="昵称" style="width:84px" value="朵朵">
|
||||
<select id="new-grade">
|
||||
<option>1</option><option>2</option><option selected>3</option>
|
||||
<option>4</option><option>5</option><option>6</option>
|
||||
</select>
|
||||
<button onclick="addChild()">新增孩子</button>
|
||||
</div>
|
||||
<div id="kids" style="color:#6b6560;font-size:13px">点「刷新列表」看这个账号下的孩子。</div>
|
||||
<p style="color:#6b6560;font-size:12px;margin:8px 0 0">
|
||||
一个家长账号可带多个孩子,数据按 child_id 完全隔离;切换孩子只换当前上下文,不重新登录。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>④ 订阅消息与开通</h2>
|
||||
<div class="row">
|
||||
<button onclick="quota()">看订阅额度</button>
|
||||
<button onclick="subscribe()">模拟一次授权</button>
|
||||
<button onclick="notify()">用额度发提醒</button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button onclick="order('term')">下单:一学期 69 元</button>
|
||||
<button onclick="payLast()">确认到账(发码)</button>
|
||||
</div>
|
||||
<div class="kv" style="margin-top:8px">
|
||||
<b>订阅额度</b><span id="quota" class="dim">先点「看订阅额度」</span>
|
||||
<b>订单</b><span id="order" class="dim">先点「下单」</span>
|
||||
</div>
|
||||
<p style="color:#6b6560;font-size:12px;margin:8px 0 0">
|
||||
个人主体只能拿「一次性订阅」:授权一次只能发一条,发完就得再授权。
|
||||
个人主体也开不了微信支付,所以「下单」只记单,「到账」后发激活码。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="card" style="grid-column:1/-1">
|
||||
<h2>⑤ 今日 5 道(来自 /api/today)</h2>
|
||||
<div id="queue" style="color:#6b6560;font-size:13px">还没有数据。</div>
|
||||
</div>
|
||||
|
||||
<div id="log">// 请求与响应会打印在这里</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
const S = {token: localStorage.getItem("ql_token") || "", gid: "", cid: "", mid: "", queue: []};
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const log = (msg, cls = "") => {
|
||||
const el = $("log");
|
||||
const line = document.createElement("div");
|
||||
if (cls) line.className = cls;
|
||||
line.textContent = msg;
|
||||
el.appendChild(line);
|
||||
el.scrollTop = el.scrollHeight;
|
||||
};
|
||||
|
||||
async function api(method, path, body, opts = {}) {
|
||||
const headers = {"Content-Type": "application/json"};
|
||||
if (S.token) headers.Authorization = "Bearer " + S.token;
|
||||
const res = await fetch(path, {method, headers, body: body ? JSON.stringify(body) : undefined});
|
||||
const data = await res.json().catch(() => ({ok: false, error: {message: "非 JSON 响应"}}));
|
||||
log(`${method} ${path} → ${res.status} ${data.ok ? "ok" : JSON.stringify(data.error)}`,
|
||||
data.ok ? "ok" : "err");
|
||||
if (!data.ok) throw new Error(data.error?.message || "请求失败");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
function paint() {
|
||||
$("tok").textContent = S.token ? S.token.slice(0, 22) + "…" : "未登录";
|
||||
$("gid").textContent = S.gid || "—";
|
||||
$("cid").textContent = S.cid || "—";
|
||||
$("mid").textContent = S.mid || "先点「今日队列」";
|
||||
}
|
||||
|
||||
async function login() {
|
||||
const d = await api("POST", "/api/auth/wx-login", {code: "demo"});
|
||||
S.token = d.token; S.gid = d.guardian_id;
|
||||
localStorage.setItem("ql_token", S.token);
|
||||
paint();
|
||||
if (!d.needs_consent && d.children.length) S.cid = d.children[0].id;
|
||||
paint();
|
||||
return d;
|
||||
}
|
||||
|
||||
async function ensureChild() {
|
||||
if (!S.token) await login();
|
||||
const consent = await api("GET", "/api/consent");
|
||||
if (!consent.consented) await api("POST", "/api/consent", {version: "v1"});
|
||||
const kids = await api("GET", "/api/children");
|
||||
if (kids.items.length) { S.cid = kids.items[0].id; paint(); return kids.items[0]; }
|
||||
const child = await api("POST", "/api/children", {nickname: "皮皮", grade: 2, subjects: ["math", "chinese"]});
|
||||
S.cid = child.id; paint();
|
||||
return child;
|
||||
}
|
||||
|
||||
async function reseed() {
|
||||
S.token = ""; S.gid = ""; S.cid = ""; S.mid = "";
|
||||
localStorage.removeItem("ql_token");
|
||||
await api("POST", "/api/dev/reseed", {});
|
||||
log("演示数据已重建:再次点「一键跑完整流程」。", "dim");
|
||||
paint();
|
||||
}
|
||||
|
||||
async function runFlow() {
|
||||
log("—— 开始完整流程 ——", "dim");
|
||||
S.token = ""; localStorage.removeItem("ql_token");
|
||||
await api("POST", "/api/dev/reseed", {});
|
||||
const d = await login();
|
||||
if (d.needs_consent) await api("POST", "/api/consent", {version: "v1"});
|
||||
// 流程用一个全新的三年级孩子,避免与演示数据(皮皮 · 二年级)同题重复收录
|
||||
const kid = await api("POST", "/api/children",
|
||||
{nickname: "小满", grade: 3, subjects: ["math", "chinese"]});
|
||||
S.cid = kid.id;
|
||||
log(` 建档:${kid.nickname} · ${kid.grade} 年级`, "dim");
|
||||
const paper = await api("POST", "/api/papers", {child_id: kid.id, subject: "math", image_count: 1});
|
||||
log(` 切出 ${paper.questions.length} 道题`, "dim");
|
||||
const wrong = paper.questions.slice(0, 3).map((q) => q.id);
|
||||
const imp = await api("POST", "/api/mistakes/import", {child_id: kid.id, question_ids: wrong});
|
||||
log(` 入库 ${imp.created.length} 道(第一次错 → 观察中,明天才复习)`, "dim");
|
||||
// 入库的题不会立刻出现:先用演示数据(皮皮)走「做题 → 讲清 → 毕业」这一段
|
||||
const kids = await api("GET", "/api/children");
|
||||
const demo = kids.items.find((k) => k.nickname === "皮皮") || kids.items[0];
|
||||
S.cid = demo.id;
|
||||
const q = await api("GET", "/api/today?child_id=" + demo.id);
|
||||
log(` ${demo.nickname} 今日队列 ${q.items.length} 道、待讲清 ${q.to_explain.length} 道`, "dim");
|
||||
if (q.items.length) {
|
||||
const first = q.items[0];
|
||||
const r = await api("POST", `/api/mistakes/${first.id}/attempt`,
|
||||
{child_id: demo.id, answer: first.answer});
|
||||
log(` 做对「${first.stem}」→ ${r.status_zh}`, "dim");
|
||||
}
|
||||
if (q.to_explain.length) {
|
||||
const need = q.to_explain[0];
|
||||
const r = await api("POST", `/api/mistakes/${need.id}/explain`,
|
||||
{child_id: demo.id, channel: "ai_voice",
|
||||
text: "我把个位算对了,但忘了进位,所以少了十。下次先看有没有进位。"});
|
||||
log(` 讲清「${need.stem}」→ ${r.passed ? "通过,毕业" : "没过,回队列"}`, "dim");
|
||||
}
|
||||
await weekly();
|
||||
paint();
|
||||
log("—— 完成。点「周日那张纸」看打印效果 ——", "dim");
|
||||
}
|
||||
|
||||
async function today() {
|
||||
const mid = await ensureChild();
|
||||
const d = await api("GET", "/api/today?child_id=" + S.cid);
|
||||
S.queue = d.items || []; S.mid = d.items?.[0]?.id || "";
|
||||
paint();
|
||||
$("queue").innerHTML = d.items.length
|
||||
? `<ol>${d.items.map((m) => `<li>${m.stem} <span class="tag">${m.status_zh}</span>
|
||||
<code>${m.judge_type}</code></li>`).join("")}</ol>
|
||||
<p style="color:#6b6560;font-size:12px">${d.rule}</p>`
|
||||
: "<p>今天没有到期的题(或已全部做完)。</p>";
|
||||
return d;
|
||||
}
|
||||
|
||||
async function attempt(ok = true) {
|
||||
await ensureChild();
|
||||
if (!S.mid) await today();
|
||||
if (!S.mid) return log("队列为空,先「时间快进 1 天」再看", "err");
|
||||
const m = S.queue.find((x) => x.id === S.mid) || {};
|
||||
const answer = ok ? (m.answer || "83") : "999";
|
||||
const d = await api("POST", `/api/mistakes/${S.mid}/attempt`, {child_id: S.cid, answer, cost_ms: 3800});
|
||||
log(` → ${d.correct ? "对" : "错"}:${d.detail};状态=${d.status_zh}`, "dim");
|
||||
if (d.need_explain) log(" 该讲一遍了:点「讲清」", "dim");
|
||||
await today();
|
||||
}
|
||||
|
||||
async function explain() {
|
||||
await ensureChild();
|
||||
const d = await api("POST", `/api/mistakes/${S.mid}/explain`,
|
||||
{child_id: S.cid, channel: "ai_voice",
|
||||
text: "我先算了个位,忘了进位,所以少了十。下次遇到先看有没有进位。"});
|
||||
log(` → 讲清${d.passed ? "通过" : "没通过"}:错因${d.rubric.wrong_reason} 步骤${d.rubric.key_steps} 下次${d.rubric.next_time}`,
|
||||
d.passed ? "ok" : "err");
|
||||
log(` → 状态=${d.status_zh};${d.hint}`, "dim");
|
||||
}
|
||||
|
||||
async function weekly() {
|
||||
await ensureChild();
|
||||
const d = await api("GET", "/api/report/weekly?child_id=" + S.cid);
|
||||
const n = d.numbers;
|
||||
log(` 周报 ${d.week.start}~${d.week.end}:新增 ${n.new_this_week} / 消灭 ${n.graduated_this_week}` +
|
||||
` / 作答 ${n.attempts_this_week} / 复盘 ${n.review_days} 天 / 总消灭率 ${n.kill_rate}%`, "dim");
|
||||
log(` 一句话:${d.one_line}`, "dim");
|
||||
return d;
|
||||
}
|
||||
|
||||
async function printSheet() {
|
||||
await ensureChild();
|
||||
window.open(`/api/print/weekly?child_id=${S.cid}&token=${encodeURIComponent(S.token)}`, "_blank");
|
||||
}
|
||||
|
||||
async function csv() {
|
||||
await ensureChild();
|
||||
window.open(`/api/export/csv?child_id=${S.cid}&token=${encodeURIComponent(S.token)}`, "_blank");
|
||||
}
|
||||
|
||||
async function stats() {
|
||||
await ensureChild();
|
||||
const d = await api("GET", "/api/stats?child_id=" + S.cid);
|
||||
log(` 统计:错题 ${d.mistakes_total} 道,已毕业 ${d.graduated},消灭率 ${d.kill_rate}%,近 7 天作答 ${d.attempts_last7d}`, "dim");
|
||||
}
|
||||
|
||||
async function notify() {
|
||||
const d = await api("POST", "/api/dev/notify-tick", {});
|
||||
log(` 提醒:发出 ${d.queued.length} 条,跳过 ${d.skipped.length} 条(微信模式 ${d.wx_mode})`, "dim");
|
||||
d.skipped.forEach((s) => log(` · 跳过:${s.reason}`, "dim"));
|
||||
if (d.need_subscribe?.length) {
|
||||
log(` 需要用户再授权一次订阅消息:${d.need_subscribe.map((x) => x.why).join(";")}`, "err");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 多孩子
|
||||
|
||||
async function children() {
|
||||
const d = await api("GET", "/api/children");
|
||||
const box = $("kids");
|
||||
if (!d.items.length) { box.innerHTML = "<p>还没有孩子,先在上面新增一个。</p>"; return d; }
|
||||
box.innerHTML = d.items.map((k) =>
|
||||
`<div class="row" style="margin:4px 0">
|
||||
<span class="tag">${k.grade} 年级</span>
|
||||
<b style="font-weight:400">${k.nickname}</b>
|
||||
<code>${k.id}</code>
|
||||
${k.id === S.cid ? '<span class="tag">当前</span>' : `<button onclick="switchChild('${k.id}')">切到这个</button>`}
|
||||
</div>`).join("");
|
||||
return d;
|
||||
}
|
||||
|
||||
function switchChild(id) {
|
||||
S.cid = id; S.mid = ""; S.queue = [];
|
||||
paint(); children();
|
||||
log(` 已切到孩子 ${id}(数据独立,不重新登录)`, "ok");
|
||||
$("queue").innerHTML = '<span style="color:#6b6560">这是一个独立的孩子,点「今日队列」看它自己的错题。</span>';
|
||||
}
|
||||
|
||||
async function addChild() {
|
||||
const nickname = ($("new-nick").value || "").trim() || "朵朵";
|
||||
const grade = parseInt($("new-grade").value, 10);
|
||||
const k = await api("POST", "/api/children", {nickname, grade, subjects: ["math", "chinese"]});
|
||||
S.cid = k.id; S.mid = ""; S.queue = [];
|
||||
paint(); children();
|
||||
log(` 新增孩子 ${nickname}(${grade} 年级),共 ${k.id}`, "ok");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 订阅与订单
|
||||
|
||||
async function quota() {
|
||||
const d = await api("GET", "/api/notify/quota");
|
||||
$("quota").textContent = `剩 ${d.quota} 条(日提醒 ${d.daily_quota} 条,模式 ${d.mode})`;
|
||||
log(` 订阅额度:${d.quota} 条;${d.hint}`, "dim");
|
||||
return d;
|
||||
}
|
||||
|
||||
async function subscribe() {
|
||||
const cfg = await api("GET", "/api/wx/config");
|
||||
const d = await api("POST", "/api/notify/subscribe", {});
|
||||
$("quota").textContent = `剩 ${d.quota} 条(日提醒 ${d.daily_quota} 条,模式 ${d.mode})`;
|
||||
log(` 记下 1 次授权 → 现在有 ${d.quota} 条额度(微信模式 ${cfg.mode})`, "ok");
|
||||
return d;
|
||||
}
|
||||
|
||||
let lastOrder = "";
|
||||
|
||||
async function order(sku) {
|
||||
const d = await api("POST", "/api/orders", {sku});
|
||||
lastOrder = d.id;
|
||||
$("order").textContent = `${d.id} · ${d.label} · ¥${d.amount} · ${d.status}`;
|
||||
log(` 下单:${d.label} ¥${d.amount};支付可用=false(${d.pay.reason})`, "dim");
|
||||
return d;
|
||||
}
|
||||
|
||||
async function payLast() {
|
||||
if (!lastOrder) { log(" 先点「下单」", "err"); return; }
|
||||
const d = await api("POST", `/api/orders/${lastOrder}/pay`, {});
|
||||
$("order").textContent = `${lastOrder} · paid · 激活码 ${d.code}`;
|
||||
document.getElementById("code").textContent = d.code;
|
||||
log(` 到账:发了一张 ${d.days} 天激活码 ${d.code};${d.next}`, "ok");
|
||||
}
|
||||
|
||||
async function advance() {
|
||||
const d = await api("POST", "/api/dev/advance", {days: 1});
|
||||
log(` 快进 1 天:现在到期 ${d.due_now} 道`, "dim");
|
||||
await today();
|
||||
}
|
||||
|
||||
async function entitlement() {
|
||||
const d = await api("GET", "/api/entitlement");
|
||||
log(` 体验期:${d.kind_zh},还剩 ${d.days_left} 天(到 ${d.expires_at})`, d.active ? "ok" : "err");
|
||||
}
|
||||
|
||||
async function issueCodes() {
|
||||
const d = await api("POST", "/api/dev/issue-codes", {count: 1, kind: "trial7"});
|
||||
document.getElementById("code").textContent = d.codes[0];
|
||||
log(` 签发激活码:${d.codes[0]}(7 天)`, "ok");
|
||||
}
|
||||
|
||||
async function redeem() {
|
||||
const code = document.getElementById("code").textContent.trim();
|
||||
if (!code || code.indexOf("QL-") !== 0) { log(" 先在「今天的码」里签一个码", "err"); return; }
|
||||
const d = await api("POST", "/api/entitlement/redeem", {code});
|
||||
log(` 兑换成功:+${d.days} 天,现在到 ${d.expires_at}(还剩 ${d.entitlement.days_left} 天)`, "ok");
|
||||
}
|
||||
|
||||
paint();
|
||||
log("// 提示:先点「一键跑完整流程」,再点「今日队列」。", "dim");
|
||||
</script>
|
||||
</html>
|
||||
Reference in New Issue
Block a user