import Link from "next/link"; import { ChevronRight, PenLine, ScanLine } from "lucide-react"; import { PanelShell } from "@/components/panel-shell"; import { getCaregiverOverview } from "@/lib/caregiver-panel"; import { formatDateTime, getDeviceName, getMessageHref, truncateText } from "@/lib/panel-format"; import { requireCaregiverSession } from "@/lib/page-auth"; import { getCaregiverDisplayName } from "@/lib/session"; export const dynamic = "force-dynamic"; function greeting() { const hour = new Date().getHours(); if (hour < 11) return "早上好"; if (hour < 14) return "中午好"; if (hour < 18) return "下午好"; return "晚上好"; } export default async function Home() { const caregiver = await requireCaregiverSession("/"); const { dashboard, recentIncomingMessages } = await getCaregiverOverview(caregiver.id); const name = getCaregiverDisplayName(dashboard.caregiver); const unreadIn = dashboard.devices.reduce((n, d) => n + d.elderUnreadCount, 0); const unreadOut = dashboard.devices.reduce((n, d) => n + d.familyUnreadCount, 0); const conversations = dashboard.devices.reduce((n, d) => n + d.elderDevice._count.conversationTurns, 0); const date = new Intl.DateTimeFormat("zh-CN", { month: "numeric", day: "numeric", weekday: "short" }).format(new Date()); return (
{dashboard.devices.length ? dashboard.devices.map((binding) => ( {getDeviceName(binding.alias, binding.elderDevice.displayName)} {binding.elderDevice.lastSeenAt ? "在线" : "未连接"} )) :
还没有连接设备,扫码即可开始守护。
}
{unreadIn}新留言 {unreadOut}待长辈听 {conversations}陪伴对话 {dashboard.devices.length}设备
给长辈留言 扫码绑定

长辈的新留言

全部
{recentIncomingMessages.length ? recentIncomingMessages.slice(0, 3).map((message) => ( {truncateText(message.content, 62)} {message.importance !== "NORMAL" ? 重要 : null}{getDeviceName(message.elderDevice.displayName)} · {formatDateTime(message.createdAt)} )) :
暂时还没有收到新留言。
}

陪伴动态

全部
设备连接情况现在

{dashboard.devices.length} 台长辈设备已加入家人守护。

陪伴对话累计

数字人已完成 {conversations} 轮陪伴对话。

); }