import Link from "next/link"; import { redirect } from "next/navigation"; import { bindDeviceToCaregiver } from "@/lib/monitor-data"; import { buildCaregiverLoginPath, getCaregiverSession, } from "@/lib/session"; export const dynamic = "force-dynamic"; type BindPageProps = { searchParams: Promise>; }; export default async function BindPage({ searchParams }: BindPageProps) { const params = await searchParams; const rawDeviceValue = typeof params.deviceUuid === "string" ? params.deviceUuid : typeof params.device === "string" ? params.device : ""; if (!rawDeviceValue) { return (

连接设备

还没有收到设备信息

请让长辈打开手机上的「家人连接」页面,把二维码给您扫一下,或将设备码复制过来。

去扫码 返回设备页
); } const caregiver = await getCaregiverSession(); if (!caregiver) { redirect( buildCaregiverLoginPath( `/bind?deviceUuid=${encodeURIComponent(rawDeviceValue)}`, ), ); } let device: Awaited> | null = null; let bindError: string | null = null; try { device = await bindDeviceToCaregiver(caregiver.id, rawDeviceValue); } catch (error) { bindError = error instanceof Error ? error.message : "绑定失败,请稍后再试。"; } if (!device) { return (

暂时没连上

这次还没能完成设备连接

{bindError || "请重新扫码,或请长辈重新打开设备连接页面后再试一次。"}

重新扫码 返回设备页
); } return (

连接成功

已成功连接长辈的设备

现在可以查看长辈的留言、了解使用动态,也可以随时给长辈写一句问候。

设备标识

{device.deviceUuid}

查看设备详情 返回设备列表
); }