chore: 首次纳入版本控制(审查前基线,v1.2.0)

This commit is contained in:
errortopic
2026-11-18 20:13:37 +08:00
commit f7b28e1740
441 changed files with 31220 additions and 0 deletions
+299
View File
@@ -0,0 +1,299 @@
const api = require("../../utils/api");
/** 估算一道题要多久:口算 30 秒、字词 40 秒、应用题/自评 60 秒,够用了。 */
function estimate(queue) {
const items = (queue && queue.items) || [];
const sec = items.reduce((s, q) => {
if (q.judge_type === "calc") return s + 30;
if (q.judge_type === "choice") return s + 40;
return s + 60;
}, 0);
return Math.max(1, Math.round(sec / 60));
}
Page({
data: {
mode: "photo",
images: [],
subject: "math",
subjects: [
{ k: "math", name: "数学" },
{ k: "chinese", name: "语文" },
],
questions: [],
cutInfo: "",
cutting: false,
importing: false,
// 手输
stem: "",
answer: "",
isChoice: false,
optionsText: "",
saving: false,
// 题单预览
queue: { n: 0, minutes: 0 },
},
onLoad() {
if (!api.requireChild()) return;
},
onShow() {
if (getApp().globalData.child) this.loadQueue();
},
onSubject(e) {
this.setData({ subject: e.currentTarget.dataset.k, questions: [] });
},
onToggleMode() {
this.setData({ mode: this.data.mode === "photo" ? "manual" : "photo", cutInfo: "" });
},
/** 排完看一眼今天几道、大概几分钟 */
loadQueue() {
const child = getApp().globalData.child;
if (!child) return Promise.resolve();
return api
.get("/api/today?child_id=" + child.id)
.then((d) => this.setData({ queue: { n: (d.items || []).length, minutes: estimate(d) } }))
.catch(() => {});
},
// ---------------- 拍一张
onPick() {
wx.chooseMedia({
count: 3,
mediaType: ["image"],
sourceType: ["camera", "album"],
camera: "back",
success: (res) => {
const images = (res.tempFiles || []).map((f) => f.tempFilePath);
if (!images.length) return;
this.checkSize(images).then((ok) => {
if (ok) this.setData({ images });
});
},
});
},
/**
* 太小的图先拦一下再上传。
* 微信转发的图长边常被压到 400px,一行字只剩十几像素——OCR 认出来全是错字,
* 与其等它在后面莫名其妙地失败,不如在这里就说清楚。
*/
checkSize(images) {
const info = (p) =>
new Promise((resolve) => {
wx.getImageInfo({
src: p,
success: (r) => resolve({ w: r.width || 0, h: r.height || 0 }),
fail: () => resolve({ w: 0, h: 0 }),
});
});
return Promise.all(images.map(info)).then((sizes) => {
const bad = sizes.filter((s) => s.w && Math.min(s.w, s.h) < 1200);
if (!bad.length) return true;
const s = bad[0];
return new Promise((resolve) => {
wx.showModal({
title: "这张图太小了",
content:
"只有 " + s.w + "×" + s.h + " 像素,一行字只剩十几像素,识别出来大概率是错字。" +
"\n\n建议:在微信里选「原图」重发,或重新拍一张(一次拍半页)。",
confirmText: "还是上传",
cancelText: "重拍",
success: (r) => resolve(!!r.confirm),
fail: () => resolve(false),
});
});
});
},
onCut() {
if (!this.data.images.length) {
wx.showToast({ title: "先拍一张", icon: "none" });
return;
}
if (this.data.cutting) return;
this.setData({ cutting: true });
const child = getApp().globalData.child;
const fs = wx.getFileSystemManager();
wx.showLoading({ title: "识别中", mask: true });
// 手机拍出来 3–8MB,直接 base64 会撞 wx.request 的包体上限,先压到长边 1600、质量 72。
const send = (filePath) => {
fs.readFile({
filePath,
encoding: "base64",
success: (f) => {
api
.post("/api/papers/ocr", {
child_id: child.id,
subject: this.data.subject,
image_b64: f.data,
filename: "page.jpg",
fallback_demo: false,
})
.then((p) => this.afterCut(p))
.catch((e) => this.onCutFail(e))
.then(() => wx.hideLoading());
},
fail: () => {
wx.hideLoading();
wx.showToast({ title: "读不到这张图", icon: "none" });
this.setData({ cutting: false });
},
});
};
wx.compressImage({
src: this.data.images[0],
quality: 72,
compressedWidth: 1600,
success: (r) => send(r.tempFilePath || this.data.images[0]),
fail: () => send(this.data.images[0]),
});
},
afterCut(p) {
const questions = (p.questions || []).map((q) => ({
...q,
checked: true,
tag: (q.judge_type === "manual" ? "你自己判" : "机器判") + " · " + (q.subject === "chinese" ? "语文" : "数学"),
}));
const ocr = p.ocr || {};
let info = "";
if (ocr.ok) {
info = "识别到 " + ocr.lines + " 行,切出 " + questions.length + " 道题";
if (ocr.warn) info += "\n" + ocr.warn;
} else {
info = "没认出题,可以手动拍清楚一点,或者改成手输";
// 小图 / 太糊时,后端会带一句「这张图只有 400×520」——比「没认出题」有用得多
if (ocr.warn) info = ocr.warn + "\n" + info;
}
this.setData({ questions, cutting: false, cutInfo: info });
},
/** 识别失败:给「用演示题库」这条后路,而不是卡死在这儿。 */
onCutFail(e) {
this.setData({ cutting: false });
wx.hideLoading();
const msg = (e && e.message) || "没认出来";
wx.showModal({
title: "这次没认出来",
content: msg + "\n\n可以:① 把卷子放平、光线亮一点重拍;② 这道题改成手输;③ 先用演示题库走一遍流程。",
confirmText: "用演示题库",
cancelText: "重新拍",
success: (r) => {
if (!r.confirm) return;
this.setData({ cutting: true });
api
.post("/api/papers/ocr", {
child_id: getApp().globalData.child.id,
subject: this.data.subject,
image_b64: "ZGVtbw==",
filename: "demo.jpg",
fallback_demo: true,
})
.then((p) => this.afterCut(p))
.catch((err) => api.toastError(err))
.then(() => this.setData({ cutting: false }));
},
});
},
toggleQ(e) {
const i = Number(e.currentTarget.dataset.i);
const questions = this.data.questions.slice();
questions[i].checked = !questions[i].checked;
this.setData({ questions });
},
onImport() {
const ids = this.data.questions.filter((q) => q.checked).map((q) => q.id);
if (!ids.length) {
wx.showToast({ title: "一道都没选", icon: "none" });
return;
}
if (this.data.importing) return;
this.setData({ importing: true });
api
.post("/api/mistakes/import", {
child_id: getApp().globalData.child.id,
question_ids: ids,
})
.then((r) => {
const n = (r.created || []).length;
this.setData({ importing: false, questions: [] });
wx.showToast({ title: "入库 " + n + " 道", icon: "success" });
this.loadQueue();
})
.catch((e) => {
api.toastError(e);
this.setData({ importing: false });
});
},
// ---------------- 手输一道
onStem(e) {
this.setData({ stem: e.detail.value });
},
onAnswer(e) {
this.setData({ answer: e.detail.value });
},
onChoice(e) {
this.setData({ isChoice: e.detail.value });
},
onOptions(e) {
this.setData({ optionsText: e.detail.value });
},
onManualAdd() {
const stem = (this.data.stem || "").trim();
if (!stem) {
wx.showToast({ title: "题干还没填", icon: "none" });
return;
}
if (this.data.saving) return;
const body = {
child_id: getApp().globalData.child.id,
subject: this.data.subject,
stem,
answer: (this.data.answer || "").trim() || null,
};
if (this.data.isChoice) {
const opts = (this.data.optionsText || "")
.split(/[、,,;;\s]+/)
.map((s) => s.trim())
.filter(Boolean);
if (opts.length < 2) {
wx.showToast({ title: "选择题至少两个选项", icon: "none" });
return;
}
body.options = opts;
}
this.setData({ saving: true });
api
.post("/api/mistakes/manual", body)
.then(() => {
this.setData({ saving: false, stem: "", answer: "", optionsText: "", isChoice: false });
wx.showToast({ title: "已加入", icon: "success" });
this.loadQueue();
})
.catch((e) => {
api.toastError(e);
this.setData({ saving: false });
});
},
onWorkbench() {
wx.navigateTo({ url: "/pages/wb/wb" });
},
});
+4
View File
@@ -0,0 +1,4 @@
{
"navigationBarTitleText": "排题",
"enablePullDownRefresh": false
}
+91
View File
@@ -0,0 +1,91 @@
<view class="wrap">
<view class="pick">
<view class="chip {{subject === item.k ? 'on' : ''}}" wx:for="{{subjects}}" wx:key="k" data-k="{{item.k}}" bindtap="onSubject">{{item.name}}</view>
<view class="chip mode" bindtap="onToggleMode">{{mode === "photo" ? "改成手输" : "改成拍一张"}}</view>
</view>
<!-- ① 拍一张 -->
<block wx:if="{{mode === 'photo'}}">
<view class="shot {{subject === 'chinese' ? 'chn' : 'math'}}" bindtap="onPick">
<block wx:if="{{images.length}}">
<image class="thumb" src="{{images[0]}}" mode="aspectFill" />
<view class="shot-n">已选 {{images.length}} 张,点一下重拍</view>
</block>
<block wx:else>
<view class="plus">+</view>
<view class="shot-t">整页拍一张</view>
<view class="shot-s">卷子放平、光打亮,一次拍半页(5–8 道)最准</view>
</block>
</view>
<button class="btn" bindtap="onCut" disabled="{{cutting}}">
{{cutting ? "识别中…" : "识别这一页"}}
</button>
<view class="cutinfo" wx:if="{{cutInfo}}">{{cutInfo}}</view>
</block>
<!-- ② 手输一道 -->
<block wx:else>
<view class="card">
<view class="card-title">手输一道错题</view>
<textarea class="ta" placeholder="把题干抄进来,比如:36 + 47 =( )" value="{{stem}}" bindinput="onStem" maxlength="400" auto-height />
<view class="muted small" style="margin-top:6px">{{stem.length}} / 400</view>
<view class="line">
<text class="lk">正确答案</text>
<input class="ipt" placeholder="不填就让孩子自己判" value="{{answer}}" bindinput="onAnswer" />
</view>
<view class="line">
<text class="lk">是选择题</text>
<switch checked="{{isChoice}}" bindchange="onChoice" color="#E4634A" />
</view>
<block wx:if="{{isChoice}}">
<view class="line">
<text class="lk">选项</text>
<input class="ipt" placeholder="用顿号或逗号分开,如:48、54、56、64" value="{{optionsText}}" bindinput="onOptions" />
</view>
<view class="muted small">答案填字母(A/B/C/D);不填字母就让孩子自己做对错判断。</view>
</block>
<button class="btn" style="margin-top:14px" bindtap="onManualAdd" disabled="{{saving}}">
{{saving ? "加入中…" : "加入错题本"}}
</button>
<view class="muted small" style="margin-top:8px">手输的题和拍照的题走同一条路:第一次错先进「观察中」,明天开始复习。</view>
</view>
</block>
<!-- ③ 切出来的题:勾选 -->
<view class="card" style="margin-top:18px" wx:if="{{questions.length}}">
<view class="card-title">切出 {{questions.length}} 道,把做错的勾上</view>
<view class="muted" style="margin-bottom:6px">默认全选,你只需要取消勾选「做对了」的。</view>
<view class="q" wx:for="{{questions}}" wx:key="id" data-i="{{index}}" bindtap="toggleQ">
<view class="box {{item.checked ? 'on' : ''}}">{{item.checked ? "✓" : ""}}</view>
<view class="qmain">
<view class="qstem">{{item.stem}}</view>
<view class="muted small">{{item.tag}}</view>
</view>
</view>
<button class="btn" style="margin-top:14px" bindtap="onImport" disabled="{{importing}}">
{{importing ? "入库中…" : "加入错题本"}}
</button>
</view>
<!-- ④ 题单预览:排完就地显示今天的量 -->
<view class="card queue" wx:if="{{queue.n > 0}}">
<view class="card-title">排好了</view>
<view class="qbig">
<text class="qnum">{{queue.n}}</text>
<text class="qunit">道 · 约 {{queue.minutes}} 分钟</text>
</view>
<view class="muted">按遗忘曲线排的,错的多的先做。做完这两件事就结束:连对两次、讲一遍。</view>
<button class="btn" style="margin-top:12px" bindtap="onWorkbench">去工作台做题</button>
<view class="muted small" style="margin-top:8px">手机上只排题,做题在电脑或平板上——题目和解析要横着看。</view>
</view>
<view class="note">
{{mode === "photo" ? "识别用的是本机的 Windows 中文 OCR(不联网、不上传第三方)。算式的答案会自己算出来;应用题、看拼音写词这类没有标准答案的,标成「你自己判」。" : "手输适合几种情况:卷子已经扔了、老师口头报的题、错题想马上记一道。题干抄关键词就行,不用一字不差。"}}
</view>
</view>
+54
View File
@@ -0,0 +1,54 @@
.pick { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { padding: 7px 15px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: 13px; color: #5f5852; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.mode { margin-left: auto; color: var(--brand); border-color: #f0cfc4; background: #fff7f4; }
.shot {
position: relative; height: 210px; border-radius: 16px; border: 2px dashed #e0d5c9;
display: flex; flex-direction: column; align-items: center; justify-content: center;
background: #fff; margin-bottom: 16px; overflow: hidden;
}
.shot.math { background: var(--paper-math) repeating-linear-gradient(0deg, rgba(169,118,26,.07) 0 1px, transparent 1px 13px); }
.shot.chn { background: var(--paper-chn) repeating-linear-gradient(0deg, rgba(47,107,87,.07) 0 1px, transparent 1px 14px); }
.plus { font-size: 40px; color: #c9bda9; line-height: 1; }
.shot-t { margin-top: 8px; font-size: 15px; font-weight: 700; }
.shot-s { margin-top: 4px; font-size: 12px; color: var(--muted); }
.thumb { width: 100%; height: 100%; }
.shot-n { position: absolute; bottom: 10px; font-size: 11px; color: #6b6560; background: rgba(255,255,255,.9); padding: 3px 10px; border-radius: 999px; }
/* 手输 */
.ta {
width: 100%; box-sizing: border-box; min-height: 74px; margin-top: 10px; padding: 10px 12px;
border: 1px solid var(--line); border-radius: 12px; background: #fff; font-size: 15px; line-height: 1.6;
}
.line { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.lk { flex: 0 0 72px; font-size: 13px; color: #5f5852; }
.ipt {
flex: 1; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px;
background: #fff; font-size: 15px;
}
.q { display: flex; gap: 10px; align-items: flex-start; padding: 11px 0; border-bottom: 1px solid #f5efe8; }
.q:last-of-type { border-bottom: none; }
.box {
flex: 0 0 20px; width: 20px; height: 20px; margin-top: 2px;
border: 2px solid #ddd3c9; border-radius: 6px; background: #fff; color: #fff;
font-size: 12px; text-align: center; line-height: 17px;
}
.box.on { background: var(--brand); border-color: var(--brand); }
.qmain { flex: 1; }
.qstem { font-size: 14px; line-height: 1.5; }
/* 题单预览 */
.queue { border: 1px solid #f0cfc4; background: #fffaf7; }
.qbig { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 8px; }
.qnum { font-size: 34px; font-weight: 800; color: var(--brand); line-height: 1; }
.qunit { font-size: 13px; color: #6b6560; }
.note { margin-top: 18px; padding: 11px 13px; background: #fff; border: 1px solid var(--line); border-radius: 12px; font-size: 11px; color: #9a938c; line-height: 1.7; }
.cutinfo {
margin-top: 10px; padding: 8px 12px; border-radius: 10px;
background: #fbf2e1; border: 1px solid #ecd9b6; color: #7a6440; font-size: 12px;
white-space: pre-line; line-height: 1.6;
}