B-4 逐条勾选:入库前把一块里的题摊开,只收勾上的(prepare 接口 + 弹窗,239 测试)

This commit is contained in:
2026-11-22 15:30:47 +08:00
parent 11a7f18b31
commit ef201ffacc
13 changed files with 305 additions and 15 deletions
+17
View File
@@ -231,3 +231,20 @@ node tools/verify_plan.mjs # → data/plan_verify.md
数字对、话是废话。改成按小数位数缩放后取最低位。
4. **没有闸门**:新增 `planClaims()` / `planConsistent()`,生成完回头重算,
算不通或答案没出现就 `return null`,由上层退回通用三步。
## 十三、这块里有几道:入库前逐条勾选
口算卡一块十几道。切题偶尔会把孩子没做错的题切进来,或者把 `27+69` 读成
`77+69`。上一版的做法是「宁多不漏」——整块入库,让家长事后一条条删。这一版把
最后这个决定权还给家长:
1. 在图上点错题(原有流程,不变);
2. 点「入库选中的 N 道」后,只要勾中的块里有**一块多道**,就先弹一张单子,
把这块里认出来的每一道摊开,默认全勾,家长取消掉没做错的;
3. 确认后只入库勾上的那几道:单题的块传块序号,多题的块传 `{i, subs:[…]}`。
单子里的序号(第 1 道、第 2 道…)与 `subs` 数组下标一一对应,取消的会划掉,
计数按钮同步变。预览这一步只读不写,`recognize_block` 的裁剪图按 sha1 命中
OCR 缓存,所以预览过一遍之后,正式入库不会再花一次调用。
只有一块一道题的时候不会弹这张单子——多一次点击换不来任何信息。
+114 -3
View File
@@ -438,6 +438,15 @@ td .t{font-family:"Consolas",monospace;font-size:13.5px}
.scan-box i { position: absolute; top: -9px; left: -9px; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 1.5px solid rgba(228,99,74,.55); color: #B4482F; font-style: normal; font-size: 11px; line-height: 17px; text-align: center; font-weight: 700; }
.scan-box.on i { background: var(--brand); border-color: var(--brand-d); color: #fff; }
.scan-legend { margin-top: 12px; font-size: 12px; color: var(--muted); }
/* 口算卡逐条勾选 */
.pklist { max-height: 46vh; overflow: auto; margin: 6px 0 14px; border: 1px solid var(--line); border-radius: 12px; }
.pkrow { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #F6EFE4; cursor: pointer; }
.pkrow:last-child { border-bottom: 0; }
.pkrow:hover { background: #FDF8EF; }
.pkrow input { width: 17px; height: 17px; accent-color: var(--brand); flex: none; }
.pkrow .pks { font-size: 14px; }
.pkrow .pkn { font-size: 11.5px; color: var(--muted); margin-left: auto; flex: none; }
.pkrow.off .pks { color: var(--muted); text-decoration: line-through; }
/* ---- 讲一遍 ---- */
.exdlg { position: relative; width: 560px; max-width: 92vw; max-height: 88vh; overflow: auto;
@@ -967,6 +976,18 @@ td .t{font-family:"Consolas",monospace;font-size:13.5px}
<div class="retreat" id="exRetreat" hidden></div>
</div>
</div>
<div class="mask" id="pickMask">
<div class="exdlg">
<button class="ex-x" id="pkClose" aria-label="关闭">×</button>
<h3>这块里有几道?</h3>
<p class="ex-sub">口算卡一块十几道,切题有时会把没做错的、读歪的一起切进来。取消掉没做错的那几道再入库。</p>
<div class="pklist" id="pkList"></div>
<div class="ex-row">
<button class="btn" id="pkGo">入库勾上的 0 道</button>
<span class="ex-hint" id="pkHint">全都不对就直接确认</span>
</div>
</div>
</div>
<script>
/* ================= 数据层 ================= */
const API = (location.protocol === "file:") ? "http://127.0.0.1:8000" : "";
@@ -2607,6 +2628,94 @@ function updateScanCount() {
async function onScanImport() {
if (!SCAN.picks.length || !SCAN.draft || SCAN.busy) return;
// 勾中的块里有「一块多道」(口算卡/竖式区)就先摊开让家长逐条勾,否则直接入库
const multi = SCAN.picks.some((i) => ((SCAN.blocks[i] || {}).subs || []).length > 1);
if (multi) { await openPickSheet(); return; }
await doScanImport(SCAN.picks);
}
/* 拍题入库用哪个科目:跟着当前孩子开的科目走,默认数学 */
function subjectNow() {
return (S.kid && S.kid.subjects && S.kid.subjects[0]) || "math";
}
/* ---- 逐条勾选:这块里到底哪几道是错的 ---- */
let PICK = { items: [], on: [] };
async function openPickSheet() {
SCAN.busy = true;
const btn = scanEl("scanImport"), old = btn.textContent;
btn.textContent = "认一下这块里的题…";
try {
const r = await api("/api/papers/scan/prepare", {
method: "POST",
body: { child_id: S.cid, subject: subjectNow(), draft_id: SCAN.draft, picks: SCAN.picks }
});
PICK.items = r.items || [];
PICK.on = PICK.items.map(() => true);
renderPickSheet();
document.getElementById("pickMask").classList.add("show");
} catch (e) {
toast((e && e.message) || "这块里的题没认出来,试试整页在电脑上重新拍");
} finally {
btn.textContent = old;
SCAN.busy = false;
}
}
function renderPickSheet() {
const box = document.getElementById("pkList");
box.innerHTML = PICK.items.map((it, k) => `
<label class="pkrow${PICK.on[k] ? "" : " off"}">
<input type="checkbox" data-k="${k}"${PICK.on[k] ? " checked" : ""}>
<span class="pks">${esc(it.stem || "(没认出题干)")}</span>
<span class="pkn">${it.sub === null ? "单题" : "第 " + (it.sub + 1) + " 道"}</span>
</label>`).join("");
box.querySelectorAll("input").forEach((el) => {
el.onchange = () => {
const k = Number(el.dataset.k);
PICK.on[k] = el.checked;
el.closest(".pkrow").classList.toggle("off", !el.checked);
updatePickCount();
};
});
updatePickCount();
}
function updatePickCount() {
const n = PICK.on.filter(Boolean).length;
const b = document.getElementById("pkGo");
b.disabled = n === 0;
b.textContent = "入库勾上的 " + n + " 道";
document.getElementById("pkHint").textContent = n === 0
? "一道都不勾就别入库了,点右上角关掉"
: "勾上的这几道会进「错题本」,明天开始复习";
}
function closePickSheet() {
document.getElementById("pickMask").classList.remove("show");
PICK = { items: [], on: [] };
}
async function confirmPickSheet() {
// 按块归组:单题给块序号,多题的块给 {i, subs:[勾中的小题序号]}
const byBlock = new Map();
PICK.items.forEach((it, k) => {
if (!PICK.on[k]) return;
if (!byBlock.has(it.block)) byBlock.set(it.block, { single: false, subs: [] });
const g = byBlock.get(it.block);
if (it.sub === null) g.single = true; else g.subs.push(it.sub);
});
const picks = [];
byBlock.forEach((g, i) => {
if (g.single) picks.push(i); else picks.push({ i, subs: g.subs });
});
if (!picks.length) return;
closePickSheet();
await doScanImport(picks);
}
async function doScanImport(picks) {
SCAN.busy = true;
const btn = scanEl("scanImport");
const old = btn.textContent;
@@ -2614,10 +2723,10 @@ async function onScanImport() {
try {
const r = await api("/api/papers/scan/import", {
method: "POST",
body: { child_id: S.cid, subject: (S.kid && S.kid.subjects && S.kid.subjects[0]) || "math", draft_id: SCAN.draft, picks: SCAN.picks }
body: { child_id: S.cid, subject: subjectNow(), draft_id: SCAN.draft, picks }
});
const picked = (r && r.ocr && r.ocr.picked) || SCAN.picks.length;
toast("已入库 " + picked + " 道,明天开始复习");
const created = (r && r.ocr && r.ocr.created) || 0;
toast("已入库 " + created + " 道,明天开始复习");
scanReset();
await refresh();
show("wrong");
@@ -2635,6 +2744,8 @@ document.addEventListener("DOMContentLoaded", () => {
if (f) f.onchange = () => { onScanFile(f.files && f.files[0]); f.value = ""; };
const imp = scanEl("scanImport"); if (imp) imp.onclick = onScanImport;
const rs = scanEl("scanReset"); if (rs) rs.onclick = scanReset;
const pk = document.getElementById("pkGo"); if (pk) pk.onclick = confirmPickSheet;
const pkc = document.getElementById("pkClose"); if (pkc) pkc.onclick = closePickSheet;
const dr = scanEl("scanDrop");
if (dr) {
dr.addEventListener("dragover", (e) => { e.preventDefault(); dr.style.background = "#FBEFE4"; });