chore: 首次纳入版本控制(审查前基线,v1.2.0)
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
const api = require("../../utils/api");
|
||||
|
||||
Page({
|
||||
data: {
|
||||
guardian: null,
|
||||
child: null,
|
||||
wx: null,
|
||||
quota: 0,
|
||||
ent: null,
|
||||
entState: { text: "—", hint: "", active: false, cls: "" },
|
||||
deletion: null,
|
||||
code: "",
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!api.requireLogin()) return;
|
||||
const app = getApp();
|
||||
this.setData({
|
||||
guardian: wx.getStorageSync("ql_guardian") || null,
|
||||
child: app.globalData.child,
|
||||
});
|
||||
this.load();
|
||||
},
|
||||
|
||||
load() {
|
||||
Promise.all([
|
||||
api.get("/api/wx/config").catch(() => null),
|
||||
api.get("/api/notify/quota").catch(() => null),
|
||||
api.get("/api/entitlement").catch(() => null),
|
||||
api.get("/api/me").catch(() => null),
|
||||
]).then(([wxcfg, q, e, me]) => {
|
||||
this.setData({
|
||||
wx: wxcfg,
|
||||
quota: q ? q.quota : 0,
|
||||
ent: e || null,
|
||||
entState: this.entState(e),
|
||||
deletion: (me && me.deletion) || null,
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/** 开通四态:试用中 / 有效 / 已过期 / 没用过 —— 每种都要说清「还能做什么」 */
|
||||
entState(e) {
|
||||
const left = e && typeof e.days_left === "number" ? e.days_left : null;
|
||||
if (!e || !e.kind) {
|
||||
return { text: "未开通", hint: "先免费用 3 天。到期后已入库的错题仍然能复习,只是不能拍新卷子。", active: false, cls: "" };
|
||||
}
|
||||
if (left !== null && left <= 0) {
|
||||
return {
|
||||
text: "已过期",
|
||||
hint: "已入库的错题还能继续做,拍不了新卷子。兑换激活码即可继续。",
|
||||
active: false,
|
||||
cls: "red",
|
||||
};
|
||||
}
|
||||
const kind = e.kind_zh || e.kind;
|
||||
const day = String(e.expires_at || "").slice(0, 10);
|
||||
return {
|
||||
text: `${kind} · ${day} 到期${left !== null ? " · 剩 " + left + " 天" : ""}`,
|
||||
hint: "有效期内不限题数、不限孩子个数(2 个)。",
|
||||
active: true,
|
||||
cls: "green",
|
||||
};
|
||||
},
|
||||
|
||||
onSubscribe() {
|
||||
const cfg = this.data.wx || {};
|
||||
const tmpl = cfg.daily_template;
|
||||
if (!tmpl) {
|
||||
wx.showModal({
|
||||
title: "还差模板 ID",
|
||||
content: "订阅消息模板要在微信公众平台「功能 → 订阅消息」里建,然后把 ID 配到后端环境变量 WX_TMPL_DAILY,这里才能拉起授权弹窗。",
|
||||
showCancel: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
wx.requestSubscribeMessage({
|
||||
tmplIds: [tmpl],
|
||||
success: (res) => {
|
||||
const ids = Object.keys(res).filter((k) => res[k] === "accept");
|
||||
if (!ids.length) {
|
||||
wx.showToast({ title: "没同意,明天不会提醒", icon: "none" });
|
||||
return;
|
||||
}
|
||||
api
|
||||
.post("/api/notify/subscribe", { template_ids: ids })
|
||||
.then(() => {
|
||||
wx.showToast({ title: "已记下一条额度", icon: "success" });
|
||||
this.load();
|
||||
})
|
||||
.catch(api.toastError);
|
||||
},
|
||||
fail: () => wx.showToast({ title: "授权没成功", icon: "none" }),
|
||||
});
|
||||
},
|
||||
|
||||
onCode(e) {
|
||||
this.setData({ code: e.detail.value });
|
||||
},
|
||||
|
||||
onRedeem() {
|
||||
const code = (this.data.code || "").trim();
|
||||
if (!code) return;
|
||||
api
|
||||
.post("/api/entitlement/redeem", { code })
|
||||
.then((r) => {
|
||||
wx.showToast({ title: "已开通 " + (r.days || 0) + " 天", icon: "success" });
|
||||
this.setData({ code: "" });
|
||||
this.load();
|
||||
})
|
||||
.catch(api.toastError);
|
||||
},
|
||||
|
||||
onSwitch() {
|
||||
wx.navigateTo({ url: "/pages/children/children" });
|
||||
},
|
||||
|
||||
onWorkbench() {
|
||||
wx.navigateTo({ url: "/pages/wb/wb" });
|
||||
},
|
||||
|
||||
/** 删号:进 7 天冷静期,期间随时能撤销 */
|
||||
onDelete() {
|
||||
wx.showModal({
|
||||
title: "删除账号?",
|
||||
content:
|
||||
"会删掉:孩子档案、全部题目与错题、作答记录、周报。\n\n不是你点了就删——先进入 7 天冷静期,这 7 天里重新登录点「撤销删号」就能全部恢复。7 天后才真删,且不可恢复。",
|
||||
confirmText: "申请删号",
|
||||
confirmColor: "#C8362D",
|
||||
success: (r) => {
|
||||
if (!r.confirm) return;
|
||||
api
|
||||
.del("/api/me", { reason: "家长主动删除" }) .then((res) => {
|
||||
wx.showModal({
|
||||
title: "已提交",
|
||||
content: `${res.purge_after} 之后删除,这之前随时可以撤销。`,
|
||||
showCancel: false,
|
||||
success: () => {
|
||||
getApp().clearAuth();
|
||||
wx.reLaunch({ url: "/pages/login/login" });
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch(api.toastError);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
onCancelDelete() {
|
||||
api
|
||||
.post("/api/me/cancel-deletion", {})
|
||||
.then(() => {
|
||||
wx.showToast({ title: "已撤销", icon: "success" });
|
||||
this.load();
|
||||
})
|
||||
.catch(api.toastError);
|
||||
},
|
||||
|
||||
onComputer() {
|
||||
wx.navigateTo({ url: "/pages/scan/scan" });
|
||||
},
|
||||
|
||||
onLogout() {
|
||||
wx.showModal({
|
||||
title: "退出登录",
|
||||
content: "只是退出这台设备,数据还在。",
|
||||
success: (r) => {
|
||||
if (!r.confirm) return;
|
||||
api.post("/api/auth/logout", {}).catch(() => {});
|
||||
getApp().clearAuth();
|
||||
wx.reLaunch({ url: "/pages/login/login" });
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "我的"
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<view class="wrap">
|
||||
<!-- 一、孩子 -->
|
||||
<view class="card">
|
||||
<view class="card-title">孩子</view>
|
||||
<view class="li" wx:if="{{child}}" bindtap="onSwitch">
|
||||
<text class="l">{{child.nickname}} · {{child.grade}} 年级</text>
|
||||
<text class="r">切换 / 新建 ›</text>
|
||||
</view>
|
||||
<view class="li" wx:else bindtap="onSwitch">
|
||||
<text class="l">还没有建档</text>
|
||||
<text class="r">去建一个 ›</text>
|
||||
</view>
|
||||
<view class="muted small" style="margin-top:6px">一个家长可以带多个孩子,错题各记各的。</view>
|
||||
</view>
|
||||
|
||||
<!-- 二、科目 -->
|
||||
<view class="card">
|
||||
<view class="card-title">科目</view>
|
||||
<view class="li">
|
||||
<text class="l">语文 · 数学</text>
|
||||
<text class="r" bindtap="onSwitch">修改 ›</text>
|
||||
</view>
|
||||
<view class="muted small">V1 只开这两科,判得准才做。英语要等发音评测,先不上。</view>
|
||||
</view>
|
||||
|
||||
<!-- 三、提醒 -->
|
||||
<view class="card">
|
||||
<view class="card-title">提醒</view>
|
||||
<view class="li">
|
||||
<text class="l">每天</text>
|
||||
<text class="r">{{child.remind_at || "19:30"}}</text>
|
||||
</view>
|
||||
<view class="li">
|
||||
<text class="l">明天的额度</text>
|
||||
<text class="r">{{quota}} 条</text>
|
||||
</view>
|
||||
<button class="btn ghost" style="margin-top:12px" bindtap="onSubscribe">顺手订明天的提醒</button>
|
||||
<view class="muted small" style="margin-top:8px">微信只给一条:今天订的只能发明天那条,发完要再订一次。</view>
|
||||
</view>
|
||||
|
||||
<!-- 四、开通 -->
|
||||
<view class="card">
|
||||
<view class="card-title">开通</view>
|
||||
<view class="li">
|
||||
<text class="l">状态</text>
|
||||
<text class="r {{entState.cls}}">{{entState.text}}</text>
|
||||
</view>
|
||||
<view class="muted small" style="margin-top:6px">{{entState.hint}}</view>
|
||||
|
||||
<view class="row-in" wx:if="{{!entState.active}}">
|
||||
<input class="ipt" placeholder="QL-XXXXXX" value="{{code}}" bindinput="onCode" />
|
||||
<view class="go" bindtap="onRedeem">兑换</view>
|
||||
</view>
|
||||
<view class="muted small" style="margin-top:10px">69 元 / 学期,一次付清不限题数,含两个孩子的名额。</view>
|
||||
</view>
|
||||
|
||||
<!-- 五、数据 -->
|
||||
<view class="card">
|
||||
<view class="card-title">数据</view>
|
||||
<view class="li"><text class="l">原图</text><text class="r">90 天自动删除</text></view>
|
||||
<view class="li"><text class="l">导出</text><text class="r" bindtap="onWorkbench">在工作台导出 PDF / CSV ›</text></view>
|
||||
<view class="li"><text class="l">不锁数据</text><text class="r">随时能全量导出</text></view>
|
||||
|
||||
<block wx:if="{{deletion}}">
|
||||
<view class="danger-box">
|
||||
<view class="db-h">已提交删号</view>
|
||||
<view class="db-s">{{deletion.purge_after}} 之后会删除全部数据(孩子、题目、作答记录)。这之前你都可以撤销。</view>
|
||||
<button class="btn plain" style="margin-top:10px" bindtap="onCancelDelete">撤销删号</button>
|
||||
</view>
|
||||
</block>
|
||||
<view class="li danger" wx:else bindtap="onDelete">
|
||||
<text class="l">删除账号</text>
|
||||
<text class="r">7 天内可撤销 ›</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 六、关于 -->
|
||||
<view class="card">
|
||||
<view class="card-title">关于</view>
|
||||
<view class="li" bindtap="onComputer"><text class="l">电脑上登录</text><text class="r">显示登录码 ›</text></view>
|
||||
|
||||
<view class="li"><text class="l">错题毕业</text><text class="r">小学版 v1.0</text></view>
|
||||
<view class="li"><text class="l">一句话</text><text class="r">每天 5 分钟,把错题做到毕业</text></view>
|
||||
<view class="muted small" style="margin-top:6px">手机只负责拍照录题和提醒;做题、解析、打印在电脑或平板的 workbench 上。</view>
|
||||
</view>
|
||||
|
||||
<button class="btn plain" bindtap="onLogout">退出登录</button>
|
||||
</view>
|
||||
@@ -0,0 +1,21 @@
|
||||
.row-in { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
|
||||
.ipt {
|
||||
flex: 1; height: 44px; padding: 0 12px; background: #faf6f1;
|
||||
border: 1px solid var(--line); border-radius: 10px; font-size: 15px;
|
||||
}
|
||||
.go {
|
||||
padding: 0 18px; height: 44px; line-height: 44px; border-radius: 10px;
|
||||
background: var(--brand); color: #fff; font-size: 14px; font-weight: 700;
|
||||
}
|
||||
|
||||
.red { color: var(--red, #C8362D); }
|
||||
.green { color: var(--green); }
|
||||
.danger .l,
|
||||
.danger .r { color: #C8362D; }
|
||||
|
||||
.danger-box {
|
||||
margin-top: 12px; padding: 12px 13px; border-radius: 12px;
|
||||
background: #FFF5F3; border: 1px solid #F3CFC7;
|
||||
}
|
||||
.db-h { font-size: 13px; font-weight: 700; color: #B3322A; }
|
||||
.db-s { margin-top: 5px; font-size: 11px; color: #8B5A52; line-height: 1.6; }
|
||||
Reference in New Issue
Block a user