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
+104
View File
@@ -0,0 +1,104 @@
const api = require("../../utils/api");
const GRADES = ["一年级", "二年级", "三年级", "四年级", "五年级", "六年级"];
Page({
data: {
list: [],
nickname: "",
gradeIndex: 1,
grades: GRADES,
math: true,
chinese: true,
saving: false,
},
onShow() {
if (!api.requireLogin()) return;
this.load();
},
load() {
api
.get("/api/children")
.then((d) => {
this.setData({ list: d.items || [] });
if (!d.items || !d.items.length) {
// 登录成功但还没有档案、也没做过同意 → 先去同意页
api
.get("/api/consent")
.then((c) => {
if (!c.consented) wx.reLaunch({ url: "/pages/consent/consent" });
})
.catch(() => {});
}
})
.catch(api.toastError);
},
onNick(e) {
this.setData({ nickname: e.detail.value });
},
onGrade(e) {
this.setData({ gradeIndex: Number(e.detail.value) });
},
toggleSubject(e) {
const k = e.currentTarget.dataset.k;
const next = {};
next[k] = !this.data[k];
this.setData(next);
},
onSave() {
const nickname = (this.data.nickname || "").trim();
if (!nickname) {
wx.showToast({ title: "给他起个昵称(不用真名)", icon: "none" });
return;
}
if (!this.data.math && !this.data.chinese) {
wx.showToast({ title: "至少开一科", icon: "none" });
return;
}
if (this.data.saving) return;
this.setData({ saving: true });
const subjects = [];
if (this.data.math) subjects.push("math");
if (this.data.chinese) subjects.push("chinese");
api
.post("/api/children", { nickname, grade: this.data.gradeIndex + 1, subjects })
.then((child) => {
getApp().setChild(child);
wx.reLaunch({ url: "/pages/home/home" });
})
.catch((e) => {
api.toastError(e);
this.setData({ saving: false });
});
},
onPick(e) {
const child = this.data.list[Number(e.currentTarget.dataset.i)];
getApp().setChild(child);
wx.reLaunch({ url: "/pages/home/home" });
},
onDemo() {
wx.showLoading({ title: "装演示数据…" });
api
.post("/api/dev/demo-data", {})
.then((d) => {
getApp().setChild(d.child);
wx.hideLoading();
wx.showToast({ title: "已装好 " + d.mistakes + " 道", icon: "success" });
setTimeout(() => wx.reLaunch({ url: "/pages/home/home" }), 700);
})
.catch((e) => {
wx.hideLoading();
api.toastError(e);
});
},
});
+3
View File
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "孩子档案"
}
+45
View File
@@ -0,0 +1,45 @@
<view class="wrap">
<block wx:if="{{list.length}}">
<view class="card">
<view class="card-title">已建档</view>
<view class="li" wx:for="{{list}}" wx:key="id" data-i="{{index}}" bindtap="onPick">
<text class="l">{{item.nickname}} · {{item.grade}} 年级</text>
<text class="r">{{item.subjects.length === 2 ? "数学 / 语文" : (item.subjects[0] === "math" ? "数学" : "语文")}} ›</text>
</view>
</view>
<view class="muted" style="margin:4px 0 22px">点一行就切过去,两个孩子的错题本互不相通。</view>
</block>
<view class="h">新建一个孩子</view>
<view class="lead">昵称就好,别写真名。一年级起就能用。</view>
<view class="card">
<view class="li">
<text class="l">昵称</text>
<input class="ipt" placeholder="皮皮" value="{{nickname}}" bindinput="onNick" maxlength="12" />
</view>
<view class="li">
<text class="l">年级</text>
<picker mode="selector" range="{{grades}}" value="{{gradeIndex}}" bindchange="onGrade">
<view class="r">{{grades[gradeIndex]}} ›</view>
</picker>
</view>
<view class="li">
<text class="l">数学</text>
<switch checked="{{math}}" data-k="math" bindchange="toggleSubject" color="#b3272d" />
</view>
<view class="li">
<text class="l">语文</text>
<switch checked="{{chinese}}" data-k="chinese" bindchange="toggleSubject" color="#2f6b57" />
</view>
</view>
<button class="btn" bindtap="onSave" disabled="{{saving}}">
{{saving ? "创建中…" : "建好,进去看看"}}
</button>
<button class="btn plain" style="margin-top:10px" bindtap="onDemo">填充演示数据(看效果用)</button>
<view class="muted" style="margin-top:10px;text-align:center">
演示数据会建一个「皮皮 · 二年级」,带 6 道不同状态的错题。
</view>
</view>
+3
View File
@@ -0,0 +1,3 @@
.h { font-size: 20px; font-weight: 700; margin-top: 6px; }
.lead { margin: 8px 0 16px; color: var(--muted); font-size: 13px; }
.ipt { flex: 1; text-align: right; font-size: 15px; color: var(--ink); }