家长中心重组:学习概览+功能管理;孩子可增删;详情页头部加间距
- 顶部两标签:学习概览(合并查看已完成/需完成任务,日历点某天看明细) 与功能管理 - 功能管理含:任务管理(原任务模板日历)、课程管理(语法编辑+周测)、 孩子管理(增/删孩子)、设备管理(新设备激活+当前登录设备) - 孩子端英语知识点详情页头部增加元素间距,不再拥挤 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
053f818158
commit
bd04401b12
@@ -162,3 +162,38 @@ export async function revokeSession(sessionId: number) {
|
||||
await db.delete(sessions).where(eq(sessions.id, sessionId));
|
||||
revalidatePath("/parent");
|
||||
}
|
||||
|
||||
// ===== 孩子管理:增/删 =====
|
||||
export async function addChild(formData: FormData): Promise<string | null> {
|
||||
const parent = await getSessionUser();
|
||||
if (!parent || parent.role !== "parent") return "请先以家长身份登录";
|
||||
const name = String(formData.get("name") ?? "").trim();
|
||||
if (!name) return "请填写孩子称呼";
|
||||
const [mx] = await db
|
||||
.select({ m: sql<number>`COALESCE(MAX(${users.sortOrder}), -1)` })
|
||||
.from(users)
|
||||
.where(eq(users.familyId, parent.familyId));
|
||||
await db.insert(users).values({
|
||||
familyId: parent.familyId,
|
||||
role: "child",
|
||||
displayName: name,
|
||||
sortOrder: mx.m + 1,
|
||||
});
|
||||
revalidatePath("/parent");
|
||||
revalidatePath("/learn");
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function removeChild(childId: number): Promise<void> {
|
||||
const parent = await getSessionUser();
|
||||
if (!parent || parent.role !== "parent") return;
|
||||
const [row] = await db
|
||||
.select({ id: users.id })
|
||||
.from(users)
|
||||
.where(and(eq(users.id, childId), eq(users.familyId, parent.familyId), eq(users.role, "child")))
|
||||
.limit(1);
|
||||
if (!row) return;
|
||||
await db.delete(users).where(eq(users.id, childId));
|
||||
revalidatePath("/parent");
|
||||
revalidatePath("/learn");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user