83 lines
2.0 KiB
JavaScript
83 lines
2.0 KiB
JavaScript
const api = require("../../utils/api");
|
|
|
|
/** 估算时长:口算 30 秒、选择题 40 秒、应用题/自评 60 秒。 */
|
|
function estimate(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: {
|
|
child: null,
|
|
date: "",
|
|
cap: 5,
|
|
items: [],
|
|
preview: [],
|
|
rest: 0,
|
|
minutes: 0,
|
|
toExplain: [],
|
|
week: { graduated: 0, days: 0, rate: 0, line: "" },
|
|
rule: "",
|
|
loading: true,
|
|
},
|
|
|
|
onShow() {
|
|
if (!api.requireChild()) return;
|
|
this.setData({ child: getApp().globalData.child });
|
|
this.load();
|
|
},
|
|
|
|
load() {
|
|
const child = getApp().globalData.child;
|
|
this.setData({ loading: true });
|
|
Promise.all([
|
|
api.get("/api/today?child_id=" + child.id),
|
|
api.get("/api/report/weekly?child_id=" + child.id).catch(() => null),
|
|
])
|
|
.then(([d, w]) => {
|
|
const items = d.items || [];
|
|
this.setData({
|
|
date: d.date,
|
|
cap: d.cap,
|
|
items,
|
|
preview: items.slice(0, 3),
|
|
rest: Math.max(0, items.length - 3),
|
|
minutes: estimate(items),
|
|
toExplain: d.to_explain || [],
|
|
rule: d.rule,
|
|
week: w
|
|
? {
|
|
graduated: (w.numbers && w.numbers.graduated_this_week) || 0,
|
|
days: (w.numbers && w.numbers.review_days) || 0,
|
|
rate: Math.round(((w.numbers && w.numbers.kill_rate) || 0) * 100),
|
|
line: w.one_line || "",
|
|
}
|
|
: this.data.week,
|
|
loading: false,
|
|
});
|
|
})
|
|
.catch((e) => {
|
|
api.toastError(e);
|
|
this.setData({ loading: false });
|
|
});
|
|
},
|
|
|
|
onWorkbench() {
|
|
wx.navigateTo({ url: "/pages/wb/wb" });
|
|
},
|
|
|
|
/** 排题是 tab,必须用 switchTab */
|
|
onQueue() {
|
|
wx.switchTab({ url: "/pages/queue/queue" });
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.load();
|
|
wx.stopPullDownRefresh();
|
|
},
|
|
});
|