学习闭环增强:错题本+每周能力检测+学习概览日历+模板日历+课程管理
- 错题本:所有检测错题自动入库,带详细讲解,可标记掌握,孩子端可查 - 每周能力检测:从已学知识点确定性组卷10题,计分记录,达标关联当日 英语打卡,错题进错题本,家长可见成绩 - 家长"今日概览"改"学习概览",月日历展示每日打卡/语法点亮/周检测 - 任务模板改日历展示,灵活添加:某一天/每周X/本周/日期区间批量,可删 - 家长中心新增"课程管理"栏目(语法课程编辑+周测成绩),设备管理弱化为 栏目内二级区块 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
f98a21672d
commit
d84d827202
+82
-44
@@ -1,19 +1,30 @@
|
||||
import crypto from "node:crypto";
|
||||
import { and, asc, desc, eq, inArray } from "drizzle-orm";
|
||||
import { and, asc, desc, eq, gte, lte, inArray } from "drizzle-orm";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import { db } from "@/db";
|
||||
import { sessions, taskInstances, taskTemplates, users } from "@/db/schema";
|
||||
import {
|
||||
sessions,
|
||||
taskInstances,
|
||||
taskTemplates,
|
||||
users,
|
||||
grammarProgress,
|
||||
weeklyTest,
|
||||
wrongBook,
|
||||
} from "@/db/schema";
|
||||
import { SESSION_COOKIE, getSessionUser } from "@/lib/auth";
|
||||
import { daysAgo, todayStr } from "@/lib/dates";
|
||||
import { ensureDay } from "@/lib/tasks";
|
||||
import { streakOf } from "@/lib/streak";
|
||||
import { addDays, dowOf, todayStr } from "@/lib/dates";
|
||||
import { passedCount, totalPoints } from "@/lib/grammar";
|
||||
import { ParentDashboard, type DevicesData, type OverviewData, type TemplatesData } from "./dashboard";
|
||||
import {
|
||||
ParentDashboard,
|
||||
type DevicesData,
|
||||
type OverviewData,
|
||||
type TemplatesData,
|
||||
type WeeklyRow,
|
||||
} from "./dashboard";
|
||||
|
||||
const SHANGHAI = { timeZone: "Asia/Shanghai" } as const;
|
||||
const fmtDateTime = (d: Date) =>
|
||||
d.toLocaleString("zh-CN", { ...SHANGHAI, hour12: false }).replace(/\//g, "-");
|
||||
const SH = { timeZone: "Asia/Shanghai" } as const;
|
||||
const dstr = (d: Date) => d.toLocaleDateString("en-CA", SH);
|
||||
|
||||
export default async function ParentPage() {
|
||||
const parent = await getSessionUser();
|
||||
@@ -27,58 +38,62 @@ export default async function ParentPage() {
|
||||
.orderBy(asc(users.sortOrder));
|
||||
|
||||
const today = todayStr();
|
||||
const weekDates = Array.from({ length: 7 }, (_, i) => daysAgo(i)); // 今天在前
|
||||
const ym = today.slice(0, 7);
|
||||
const daysInMonth = new Date(Number(ym.slice(0, 4)), Number(ym.slice(5, 7)), 0).getDate();
|
||||
const mStart = `${ym}-01`;
|
||||
const mEnd = `${ym}-${String(daysInMonth).padStart(2, "0")}`;
|
||||
const gTotal = await totalPoints();
|
||||
|
||||
// ===== 今日概览 =====
|
||||
// ===== 学习概览(日历) =====
|
||||
const overview: OverviewData = { kids: [] };
|
||||
for (const kid of kids) {
|
||||
await ensureDay(kid.id, today); // 家长先看时也要生成今天的快照
|
||||
const [streak, gDone, rows] = await Promise.all([
|
||||
streakOf(kid.id),
|
||||
passedCount(kid.id),
|
||||
const [instRows, gRows, wRows, wrongRow, gDone] = await Promise.all([
|
||||
db
|
||||
.select({
|
||||
id: taskInstances.id,
|
||||
date: taskInstances.date,
|
||||
title: taskInstances.title,
|
||||
subject: taskInstances.subject,
|
||||
status: taskInstances.status,
|
||||
isMakeup: taskInstances.isMakeup,
|
||||
sortOrder: taskInstances.sortOrder,
|
||||
})
|
||||
.select({ date: taskInstances.date, status: taskInstances.status })
|
||||
.from(taskInstances)
|
||||
.where(and(eq(taskInstances.childUserId, kid.id), inArray(taskInstances.date, weekDates)))
|
||||
.orderBy(desc(taskInstances.date), asc(taskInstances.sortOrder)),
|
||||
.where(and(eq(taskInstances.childUserId, kid.id), gte(taskInstances.date, mStart), lte(taskInstances.date, mEnd))),
|
||||
db
|
||||
.select({ completedAt: grammarProgress.completedAt, passed: grammarProgress.passed })
|
||||
.from(grammarProgress)
|
||||
.where(and(eq(grammarProgress.childUserId, kid.id), eq(grammarProgress.passed, true))),
|
||||
db.select().from(weeklyTest).where(eq(weeklyTest.childUserId, kid.id)).orderBy(desc(weeklyTest.takenAt)),
|
||||
db
|
||||
.select({ id: wrongBook.id })
|
||||
.from(wrongBook)
|
||||
.where(and(eq(wrongBook.childUserId, kid.id), eq(wrongBook.mastered, false))),
|
||||
passedCount(kid.id),
|
||||
]);
|
||||
|
||||
const week = weekDates.map((date) => ({
|
||||
date,
|
||||
isToday: date === today,
|
||||
tasks: rows.filter((r) => r.date === date),
|
||||
}));
|
||||
const todayTasks = week.find((w) => w.isToday)?.tasks ?? [];
|
||||
|
||||
const days: OverviewData["kids"][number]["days"] = {};
|
||||
for (let i = 1; i <= daysInMonth; i++) {
|
||||
const d = `${ym}-${String(i).padStart(2, "0")}`;
|
||||
const inst = instRows.filter((r) => r.date === d);
|
||||
const grammar = gRows.filter((r) => dstr(r.completedAt) === d).length;
|
||||
const w = wRows.find((r) => dstr(r.takenAt) === d);
|
||||
days[d] = {
|
||||
done: inst.filter((r) => r.status === "done").length,
|
||||
total: inst.length,
|
||||
grammar,
|
||||
weekly: w ? w.score : null,
|
||||
};
|
||||
}
|
||||
overview.kids.push({
|
||||
id: kid.id,
|
||||
name: kid.name,
|
||||
streak,
|
||||
today: {
|
||||
total: todayTasks.length,
|
||||
done: todayTasks.filter((t) => t.status === "done").length,
|
||||
},
|
||||
grammar: { done: gDone, total: gTotal },
|
||||
week,
|
||||
wrongOpen: wrongRow.length,
|
||||
weeklyLatest: wRows[0] ? { weekKey: wRows[0].weekKey, score: wRows[0].score ?? 0, passed: wRows[0].passed } : null,
|
||||
days,
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 周模板 =====
|
||||
// ===== 任务模板 =====
|
||||
const templateRows = kids.length
|
||||
? await db
|
||||
.select()
|
||||
.from(taskTemplates)
|
||||
.where(inArray(taskTemplates.childUserId, kids.map((k) => k.id)))
|
||||
.orderBy(asc(taskTemplates.childUserId), asc(taskTemplates.dow), asc(taskTemplates.sortOrder))
|
||||
.orderBy(asc(taskTemplates.childUserId), asc(taskTemplates.sortOrder))
|
||||
: [];
|
||||
const templates: TemplatesData = {
|
||||
kids: kids.map((kid) => ({
|
||||
@@ -92,6 +107,9 @@ export default async function ParentPage() {
|
||||
title: t.title,
|
||||
subject: t.subject,
|
||||
requiresPhoto: t.requiresPhoto,
|
||||
mode: t.mode,
|
||||
dateStart: t.dateStart,
|
||||
dateEnd: t.dateEnd,
|
||||
})),
|
||||
})),
|
||||
};
|
||||
@@ -118,11 +136,31 @@ export default async function ParentPage() {
|
||||
id: s.id,
|
||||
owner: s.role === "parent" ? `${s.owner}(家长)` : s.owner,
|
||||
deviceLabel: s.deviceLabel,
|
||||
createdAt: fmtDateTime(s.createdAt),
|
||||
expiresAt: fmtDateTime(s.expiresAt),
|
||||
createdAt: dstr(s.createdAt),
|
||||
expiresAt: dstr(s.expiresAt),
|
||||
isCurrent: s.tokenHash === tokenHash,
|
||||
})),
|
||||
};
|
||||
|
||||
return <ParentDashboard overview={overview} templates={templates} devices={devices} />;
|
||||
// ===== 周测成绩(课程管理) =====
|
||||
const weeklyRows = await db
|
||||
.select({
|
||||
childName: users.displayName,
|
||||
weekKey: weeklyTest.weekKey,
|
||||
score: weeklyTest.score,
|
||||
passed: weeklyTest.passed,
|
||||
})
|
||||
.from(weeklyTest)
|
||||
.innerJoin(users, eq(users.id, weeklyTest.childUserId))
|
||||
.where(eq(users.familyId, parent.familyId))
|
||||
.orderBy(desc(weeklyTest.takenAt))
|
||||
.limit(10);
|
||||
const weekly: WeeklyRow[] = weeklyRows.map((w) => ({
|
||||
childName: w.childName,
|
||||
weekKey: w.weekKey,
|
||||
score: w.score ?? 0,
|
||||
passed: w.passed,
|
||||
}));
|
||||
|
||||
return <ParentDashboard overview={overview} templates={templates} devices={devices} weekly={weekly} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user