优化ui
This commit is contained in:
parent
b68bfc6287
commit
bbfc055c21
@ -1,50 +1,52 @@
|
|||||||
# 安智伴家属端设计规范 v2
|
# 安智伴家属端设计规范 v2
|
||||||
|
|
||||||
本规范以移动版原型为唯一视觉基准,设计目标是「安静、可信、清晰」:减少装饰,优先呈现长辈状态、留言与陪伴动态。
|
本规范以 2026-07-19 最新移动版原型为唯一视觉基准,设计目标是「安静、可信、清晰」。保留暖纸底色与铜橙主色,优先呈现长辈状态、家庭协作和可执行动作。
|
||||||
|
|
||||||
## 画布与布局
|
## 画布与布局
|
||||||
|
|
||||||
- 移动端内容宽度:`100%`,最大 `430px`;原型验收尺寸为 `390 × 844`。
|
- 移动端内容宽度:`100%`,最大 `430px`;原型画板为 `430 × 912px`。
|
||||||
- 页面背景:`#F4F3F1`;桌面居中画布:`#E9E7E3`。
|
- 页面背景:`#F5F4F2`;桌面居中画布:`#E7E4DF`。
|
||||||
- 页面水平留白:`14px`;模块垂直间距:`12px`,首页可用 `14px`。
|
- 页面水平留白:`18px`;主模块垂直间距:`18px`。
|
||||||
- 主页面预留 `84px` 底部导航空间;详情页使用顶部返回栏,不显示底部导航。
|
- 主页面顶部留白 `22px`,底部为五项固定导航,内容预留 `110px`。
|
||||||
|
- 桌面端画板圆角 `30px`,移动端贴合视口,不保留外部装饰。
|
||||||
|
|
||||||
## 颜色
|
## 颜色
|
||||||
|
|
||||||
| 语义 | 值 | 用途 |
|
| 语义 | 值 | 用途 |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| 主文字 | `#201D1A` | 标题、正文、深色按钮 |
|
| 主文字 | `#211E1A` | 标题、正文、深色按钮 |
|
||||||
| 次文字 | `#3D3833` | 列表正文 |
|
| 次文字 | `#3D3833` | 列表正文 |
|
||||||
| 辅助文字 | `#8A857E` | 时间、状态、说明 |
|
| 辅助文字 | `#8B857C` | 时间、状态、说明 |
|
||||||
| 弱辅助文字 | `#B3AEA6` | 次级时间、图标 |
|
| 弱辅助文字 | `#B5AFA6` | 次级时间、图标 |
|
||||||
| 品牌强调 | `#C05A1E` | 主按钮、未读、当前导航 |
|
| 品牌强调 | `#C05A1E` | 主按钮、未读、当前导航 |
|
||||||
| 成功/在线 | `#3F9D63` | 在线状态、成功反馈 |
|
| 成功/在线 | `#3F9D63` | 在线状态、成功反馈 |
|
||||||
| 危险操作 | `#B4482C` | 退出、解绑 |
|
| 危险操作 | `#B4482C` | 退出、风险状态 |
|
||||||
| 分隔线 | `rgba(32,29,26,.08)` | 卡片与列表分隔 |
|
| 橄榄辅助 | `#65765A` | 设备、陪伴类图标 |
|
||||||
|
| 分隔线 | `rgba(33,30,26,.08)` | 卡片与列表分隔 |
|
||||||
|
|
||||||
所有值均定义在 `app/globals.css` 的 CSS 变量中,页面不得自行引入新的近似色。
|
所有值均定义在 `app/globals.css`,页面不要自行引入近似色。
|
||||||
|
|
||||||
## 字体与信息层级
|
## 字体与信息层级
|
||||||
|
|
||||||
- 字体栈:系统无衬线字体,中文优先苹方、冬青黑体、微软雅黑。
|
- 字体栈:系统无衬线字体,中文优先苹方、冬青黑体、微软雅黑。
|
||||||
- 页面标题:`20px / 700`;详情标题:`16px / 700`。
|
- 页面标题:`21px / 700`;详情标题:`16px / 700`。
|
||||||
- 区块标题:`14px / 700`;列表正文:`14px / 1.5`。
|
- 区块标题:`15px / 700`;列表正文:`13–14px / 1.6`。
|
||||||
- 元信息:`11–12px`;数字指标:`18–20px / 700`。
|
- 元信息:`11.5–12.5px`;数字指标:`21px / 700`。
|
||||||
- 不使用全大写眉题、衬线展示字体或大面积超大标题。
|
|
||||||
|
|
||||||
## 组件规则
|
## 组件规则
|
||||||
|
|
||||||
- 卡片:白色背景、`12px` 圆角、`1px` 弱边框,不使用重阴影。
|
- 卡片:白色背景、`14px` 圆角、`1px` 弱边框,不使用重阴影。
|
||||||
- 列表:左右 `14px`、上下 `11–13px`;列表内部使用弱分隔线。
|
- 列表:左右 `16px`、上下 `13px`,内部使用弱分隔线。
|
||||||
- 按钮:高度 `40px`,圆角 `10px`;小按钮高度 `32px`、圆角 `8px`。
|
- 主按钮与输入框:统一 `44px` 高、`10–11px` 圆角。
|
||||||
- 输入框:高度 `44px`,圆角 `10px`;聚焦时使用品牌色边框与轻微外环。
|
- 小按钮:`32px` 高、`8px` 圆角。
|
||||||
- 标签:仅用于「重要」等高价值状态,字号 `10px`,浅品牌色背景。
|
- 表单字段必须有标签;下拉框隐藏系统箭头并使用统一箭头。
|
||||||
- 底部导航:固定四项——概览、留言、设备、我的;当前项使用品牌色。
|
- 标签只用于重要状态,使用浅品牌色或浅成功色背景。
|
||||||
- 分段控件:浅灰底,选中项为白底并带极轻阴影。
|
- 底部导航固定五项:守护、家庭、照护、陪伴、我的。
|
||||||
|
- 照护页使用浅灰分段控件,选中项为白底并带极轻阴影。
|
||||||
|
|
||||||
## 交互与可访问性
|
## 交互与可访问性
|
||||||
|
|
||||||
- 页面跳转使用 Next.js `Link`,保留客户端导航与预取能力。
|
- 页面跳转使用 Next.js `Link`,保留客户端导航与预取能力。
|
||||||
- 可点击区域不小于 `32px`;主要操作不小于 `40px`。
|
- 主要点击区域不小于 `40px`,小型操作不小于 `32px`。
|
||||||
- 状态不能只依赖颜色,在线、未读、重要均同时提供文字或数量。
|
- 状态不能只依赖颜色,在线、未读、重要均同时提供文字或数量。
|
||||||
- 动效只用于导航进度、扫码线和必要反馈;尊重系统减少动态设置。
|
- 动效仅用于在线呼吸点、导航进度和必要反馈,并尊重系统减少动态设置。
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
import { MedicationForm, MemoForm, TaskActions, TaskForm } from "@/components/family-guard-actions";
|
import { MedicationForm, MemoForm, TaskActions, TaskForm } from "@/components/family-guard-actions";
|
||||||
import { PanelShell } from "@/components/panel-shell";
|
import { PanelShell } from "@/components/panel-shell";
|
||||||
import { requireFamilyWorkspace } from "@/lib/family-page";
|
import { requireFamilyWorkspace } from "@/lib/family-page";
|
||||||
@ -6,10 +8,71 @@ import { requireCaregiverSession } from "@/lib/page-auth";
|
|||||||
import { getCaregiverDisplayName } from "@/lib/session";
|
import { getCaregiverDisplayName } from "@/lib/session";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export default async function CarePage({ searchParams }: PageProps<"/care">) {
|
export default async function CarePage({ searchParams }: PageProps<"/care">) {
|
||||||
const caregiver = await requireCaregiverSession("/care"); const workspace = await requireFamilyWorkspace(caregiver.id); const tab = String((await searchParams).tab || "tasks"); const uuid = workspace.elderProfile.elderDevice.deviceUuid;
|
const caregiver = await requireCaregiverSession("/care");
|
||||||
return <PanelShell currentPath="/care" title="共同照护" description="家人分工、老人确认、结果共享" caregiverLabel={getCaregiverDisplayName(caregiver)}>
|
const workspace = await requireFamilyWorkspace(caregiver.id);
|
||||||
<div className="segment"><a className={tab === "tasks" ? "active" : ""} href="/care?tab=tasks">任务</a><a className={tab === "medications" ? "active" : ""} href="/care?tab=medications">用药</a><a className={tab === "memos" ? "active" : ""} href="/care?tab=memos">备忘</a></div>
|
const tab = String((await searchParams).tab || "tasks");
|
||||||
{tab === "medications" ? <><MedicationForm deviceUuid={uuid} /><section><div className="section-title"><h2>用药计划</h2><span>仅提醒与记录,不替代医嘱</span></div><div className="card">{workspace.medicationPlans.length ? workspace.medicationPlans.map((plan) => <article className="timeline-item" key={plan.id}><div className="timeline-top">{plan.name}<span className="tag">{plan.active ? "进行中" : "已暂停"}</span></div><p className="timeline-body">每次 {plan.dosage} · {JSON.parse(plan.timesJson).join("、")}{plan.instructions ? ` · ${plan.instructions}` : ""}</p><p className="row-meta">信息来源:{plan.source === "PRESCRIPTION" ? "医生处方" : plan.source === "PACKAGE_LABEL" ? "药盒标签" : "家属录入"}</p></article>) : <div className="empty">还没有用药计划。</div>}</div></section></> : tab === "memos" ? <><MemoForm deviceUuid={uuid} /><section><div className="section-title"><h2>家庭备忘录</h2></div><div className="card">{workspace.memos.length ? workspace.memos.map((memo) => <article className="timeline-item" key={memo.id}><div className="timeline-top">{memo.title}<span className="tag">{memo.priority === "PINNED" ? "长期置顶" : memo.priority === "IMPORTANT" ? "重要" : "普通"}</span></div><p className="timeline-body">{memo.content}</p><p className="row-meta">{memo.visibility === "FAMILY_ONLY" ? "仅家人可见" : "可由数字人告诉长辈"}</p></article>) : <div className="empty">还没有家庭备忘。</div>}</div></section></> : <><TaskForm deviceUuid={uuid} /><section><div className="section-title"><h2>照护交接</h2></div><div className="card">{workspace.tasks.length ? workspace.tasks.map((task) => <article className="timeline-item" key={task.id}><div className="timeline-top">{task.title}<span className="timeline-time">{task.dueAt ? formatDateTime(task.dueAt) : "未设期限"}</span></div><p className="timeline-body">{task.description || "等待家人认领"}</p><p className="row-meta">{task.assignedTo ? `负责人:${task.assignedTo.nickname || task.assignedTo.username || "家人"}` : "尚未认领"}</p><TaskActions taskId={task.id} status={task.status} /></article>) : <div className="empty">还没有照护任务。</div>}</div></section></>}
|
const deviceUuid = workspace.elderProfile.elderDevice.deviceUuid;
|
||||||
</PanelShell>;
|
|
||||||
|
return (
|
||||||
|
<PanelShell currentPath="/care" title="共同照护" description="家人分工、老人确认、结果共享" caregiverLabel={getCaregiverDisplayName(caregiver)} caregiverId={caregiver.id}>
|
||||||
|
<div className="segment">
|
||||||
|
<Link className={tab === "tasks" ? "active" : ""} href="/care?tab=tasks">任务</Link>
|
||||||
|
<Link className={tab === "medications" ? "active" : ""} href="/care?tab=medications">用药</Link>
|
||||||
|
<Link className={tab === "memos" ? "active" : ""} href="/care?tab=memos">备忘</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{tab === "medications" ? (
|
||||||
|
<>
|
||||||
|
<MedicationForm deviceUuid={deviceUuid} />
|
||||||
|
<section>
|
||||||
|
<div className="section-title"><h2>用药计划</h2><span>仅提醒与记录,不替代医嘱</span></div>
|
||||||
|
<div className="card">
|
||||||
|
{workspace.medicationPlans.length ? workspace.medicationPlans.map((plan) => (
|
||||||
|
<article className="timeline-item" key={plan.id}>
|
||||||
|
<div className="timeline-top strong">{plan.name}<span className="tag">{plan.active ? "进行中" : "已暂停"}</span></div>
|
||||||
|
<p className="timeline-body">每次 {plan.dosage} · {JSON.parse(plan.timesJson).join("、")}{plan.instructions ? ` · ${plan.instructions}` : ""}</p>
|
||||||
|
<p className="row-meta">信息来源:{plan.source === "PRESCRIPTION" ? "医生处方" : plan.source === "PACKAGE_LABEL" ? "药盒标签" : "家属录入"}</p>
|
||||||
|
</article>
|
||||||
|
)) : <div className="empty">还没有用药计划。</div>}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
) : tab === "memos" ? (
|
||||||
|
<>
|
||||||
|
<MemoForm deviceUuid={deviceUuid} />
|
||||||
|
<section>
|
||||||
|
<div className="section-title"><h2>家庭备忘录</h2></div>
|
||||||
|
<div className="card">
|
||||||
|
{workspace.memos.length ? workspace.memos.map((memo) => (
|
||||||
|
<article className="timeline-item" key={memo.id}>
|
||||||
|
<div className="timeline-top strong">{memo.title}<span className="tag">{memo.priority === "PINNED" ? "长期置顶" : memo.priority === "IMPORTANT" ? "重要" : "普通"}</span></div>
|
||||||
|
<p className="timeline-body">{memo.content}</p>
|
||||||
|
<p className="row-meta">{memo.visibility === "FAMILY_ONLY" ? "仅家人可见" : "可由数字人告诉长辈"}</p>
|
||||||
|
</article>
|
||||||
|
)) : <div className="empty">还没有家庭备忘。</div>}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<TaskForm deviceUuid={deviceUuid} />
|
||||||
|
<section>
|
||||||
|
<div className="section-title"><h2>照护交接</h2><span>认领后全家可见</span></div>
|
||||||
|
<div className="card">
|
||||||
|
{workspace.tasks.length ? workspace.tasks.map((task) => (
|
||||||
|
<article className="timeline-item" key={task.id}>
|
||||||
|
<div className="timeline-top strong">{task.title}<span className="timeline-time">{task.dueAt ? formatDateTime(task.dueAt) : "未设期限"}</span></div>
|
||||||
|
<p className="timeline-body">{task.description || "等待家人认领"}</p>
|
||||||
|
<p className="row-meta">{task.assignedTo ? `负责人:${task.assignedTo.nickname || task.assignedTo.username || "家人"}` : "尚未认领"}</p>
|
||||||
|
<TaskActions taskId={task.id} status={task.status} />
|
||||||
|
</article>
|
||||||
|
)) : <div className="empty">还没有照护任务。</div>}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</PanelShell>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,68 @@
|
|||||||
|
import { ChevronRight, Heart, MessageCircle, MessagesSquare } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { BookHeart, MessageCircle, MessagesSquare } from "lucide-react";
|
|
||||||
import { PanelShell } from "@/components/panel-shell";
|
import { PanelShell } from "@/components/panel-shell";
|
||||||
import { requireFamilyWorkspace as getFamilyWorkspace } from "@/lib/family-page";
|
import { getCaregiverMessages } from "@/lib/caregiver-panel";
|
||||||
|
import { requireFamilyWorkspace } from "@/lib/family-page";
|
||||||
import { requireCaregiverSession } from "@/lib/page-auth";
|
import { requireCaregiverSession } from "@/lib/page-auth";
|
||||||
import { getCaregiverDisplayName } from "@/lib/session";
|
import { getCaregiverDisplayName } from "@/lib/session";
|
||||||
|
|
||||||
export default async function CompanionPage() { const caregiver = await requireCaregiverSession("/companion"); const workspace = await getFamilyWorkspace(caregiver.id); return <PanelShell currentPath="/companion" title="温暖陪伴" description="留言、回忆和每一次认真回应" caregiverLabel={getCaregiverDisplayName(caregiver)}><div className="card"><Link className="list-row" href="/messages"><MessageCircle /><span className="row-main"><span className="row-title">双向留言</span><span className="row-meta">家人问候由数字人口播,长辈口述实时送达</span></span></Link><Link className="list-row" href="/activity"><MessagesSquare /><span className="row-main"><span className="row-title">陪伴动态</span><span className="row-meta">查看数字人对话和智能服务记录</span></span></Link><div className="list-row"><BookHeart /><span className="row-main"><span className="row-title">家庭记忆册</span><span className="row-meta">数据结构已预留,作为下一阶段增强功能</span></span></div></div><section className="card card-pad"><h2 style={{ marginTop: 0 }}>本周家庭连接</h2><p className="timeline-body">家庭发布了 {workspace.posts.length} 条动态,留下 {workspace.memos.length} 条共同记忆与备忘。</p></section></PanelShell>; }
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export default async function CompanionPage() {
|
||||||
|
const caregiver = await requireCaregiverSession("/companion");
|
||||||
|
const [workspace, messageOverview] = await Promise.all([
|
||||||
|
requireFamilyWorkspace(caregiver.id),
|
||||||
|
getCaregiverMessages(caregiver.id),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PanelShell
|
||||||
|
currentPath="/companion"
|
||||||
|
title="温暖陪伴"
|
||||||
|
description="留言、回忆和每一次认真回应"
|
||||||
|
caregiverLabel={getCaregiverDisplayName(caregiver)}
|
||||||
|
unreadCount={messageOverview.unreadIncomingCount}
|
||||||
|
>
|
||||||
|
<section className="card">
|
||||||
|
<Link className="list-row feature-row" href="/messages">
|
||||||
|
<span className="feature-icon"><MessageCircle size={19} strokeWidth={1.8} /></span>
|
||||||
|
<span className="row-main">
|
||||||
|
<span className="row-title">双向留言</span>
|
||||||
|
<span className="row-meta">家人问候由数字人口播,长辈口述实时送达</span>
|
||||||
|
</span>
|
||||||
|
<span style={{ display: "flex", alignItems: "center", gap: 6 }}>
|
||||||
|
{messageOverview.unreadIncomingCount > 0 ? <span className="count-badge">{messageOverview.unreadIncomingCount}</span> : null}
|
||||||
|
<ChevronRight className="chevron" size={16} strokeWidth={2} />
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
<Link className="list-row feature-row" href="/activity">
|
||||||
|
<span className="feature-icon olive"><MessagesSquare size={19} strokeWidth={1.8} /></span>
|
||||||
|
<span className="row-main">
|
||||||
|
<span className="row-title">陪伴动态</span>
|
||||||
|
<span className="row-meta">查看数字人对话和智能服务记录</span>
|
||||||
|
</span>
|
||||||
|
<ChevronRight className="chevron" size={16} strokeWidth={2} />
|
||||||
|
</Link>
|
||||||
|
<div className="list-row feature-row feature-disabled">
|
||||||
|
<span className="feature-icon muted"><Heart size={19} strokeWidth={1.8} /></span>
|
||||||
|
<span className="row-main">
|
||||||
|
<span className="row-title">家庭记忆册</span>
|
||||||
|
<span className="row-meta">收藏长辈的语音与照片故事</span>
|
||||||
|
</span>
|
||||||
|
<span className="member-role">即将上线</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<div className="section-title"><h2>本周家庭连接</h2></div>
|
||||||
|
<div className="stats" style={{ gridTemplateColumns: "repeat(3, 1fr)" }}>
|
||||||
|
<div className="stat accent"><strong>{workspace.posts.length}</strong><span>家庭动态</span></div>
|
||||||
|
<div className="stat"><strong>{workspace.memos.length}</strong><span>共同备忘</span></div>
|
||||||
|
<div className="stat"><strong>{messageOverview.messages.length}</strong><span>留言往来</span></div>
|
||||||
|
</div>
|
||||||
|
<p className="muted-note" style={{ margin: "10px 2px 0" }}>数字人每天会把家人的问候念给长辈听,长辈的回应会同步到留言板。</p>
|
||||||
|
</section>
|
||||||
|
</PanelShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@ -6,13 +6,72 @@ import { requireCaregiverSession } from "@/lib/page-auth";
|
|||||||
import { getCaregiverDisplayName } from "@/lib/session";
|
import { getCaregiverDisplayName } from "@/lib/session";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
const roleLabel = { ADMIN: "管理员", CAREGIVER: "照护成员", CARING: "关怀成员" } as const;
|
||||||
|
const avatarStyles = [
|
||||||
|
{ background: "rgba(192,90,30,.1)", color: "var(--accent)" },
|
||||||
|
{ background: "rgba(101,118,90,.12)", color: "var(--olive)" },
|
||||||
|
{ background: "rgba(33,30,26,.06)", color: "var(--muted)" },
|
||||||
|
];
|
||||||
|
|
||||||
export default async function FamilyPage() {
|
export default async function FamilyPage() {
|
||||||
const caregiver = await requireCaregiverSession("/family"); const workspace = await requireFamilyWorkspace(caregiver.id); const deviceUuid = workspace.elderProfile.elderDevice.deviceUuid;
|
const caregiver = await requireCaregiverSession("/family");
|
||||||
const roleLabel = { ADMIN: "管理员", CAREGIVER: "照护成员", CARING: "关怀成员" } as const;
|
const workspace = await requireFamilyWorkspace(caregiver.id);
|
||||||
return <PanelShell currentPath="/family" title={workspace.name} description={`${workspace.memberships.length} 位家人共同参与`} caregiverLabel={getCaregiverDisplayName(caregiver)}>
|
const deviceUuid = workspace.elderProfile.elderDevice.deviceUuid;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PanelShell
|
||||||
|
currentPath="/family"
|
||||||
|
title={workspace.name}
|
||||||
|
description={`${workspace.memberships.length} 位家人共同参与`}
|
||||||
|
caregiverLabel={getCaregiverDisplayName(caregiver)}
|
||||||
|
caregiverId={caregiver.id}
|
||||||
|
>
|
||||||
<FamilyPostForm deviceUuid={deviceUuid} />
|
<FamilyPostForm deviceUuid={deviceUuid} />
|
||||||
<section><div className="section-title"><h2>家庭动态</h2></div><div className="card">{workspace.posts.length ? workspace.posts.map((post) => <article key={post.id} className="timeline-item"><div className="timeline-top">{post.elderAuthored ? `${workspace.elderProfile.preferredName}通过安智伴说` : post.author?.nickname || post.author?.username || "家里人"}<span className="timeline-time">{formatDateTime(post.createdAt)}</span></div><p className="timeline-body">{post.content}</p><span className="tag">{post.visibility === "FAMILY_ONLY" ? "仅家人" : post.visibility === "ELDER_ONLY" ? "只给长辈" : "全家可见"}</span></article>) : <div className="empty">发出第一条家庭动态,让关心流动起来。</div>}</div></section>
|
|
||||||
<section><div className="section-title"><h2>家庭成员</h2></div><div className="card">{workspace.memberships.map((member) => <div key={member.id} className="list-row"><span className="avatar">{(member.caregiver.nickname || member.caregiver.username || "家").slice(-1)}</span><span className="row-main"><span className="row-title">{member.caregiver.nickname || member.caregiver.username || "家庭成员"}{member.relationLabel ? ` · ${member.relationLabel}` : ""}</span><span className="row-meta">{roleLabel[member.role]}{member.dutyOrder ? ` · 值守顺序 ${member.dutyOrder}` : ""}</span></span></div>)}</div></section>
|
<section>
|
||||||
<section><div className="section-title"><h2>邀请家人</h2><span>链接 24 小时有效</span></div><InviteMemberForm deviceUuid={deviceUuid} /></section>
|
<div className="section-title"><h2>家庭动态</h2></div>
|
||||||
</PanelShell>;
|
<div className="card">
|
||||||
|
{workspace.posts.length ? workspace.posts.map((post) => (
|
||||||
|
<article key={post.id} className="timeline-item">
|
||||||
|
<div className="timeline-top">
|
||||||
|
{post.elderAuthored ? `${workspace.elderProfile.preferredName}通过安智伴说` : post.author?.nickname || post.author?.username || "家里人"}
|
||||||
|
<span className="timeline-time">{formatDateTime(post.createdAt)}</span>
|
||||||
|
</div>
|
||||||
|
<p className="timeline-body">{post.content}</p>
|
||||||
|
<span className="tag" style={{ marginTop: 8 }}>
|
||||||
|
{post.visibility === "FAMILY_ONLY" ? "仅家人" : post.visibility === "ELDER_ONLY" ? "只给长辈" : "全家可见"}
|
||||||
|
</span>
|
||||||
|
</article>
|
||||||
|
)) : <div className="empty">发出第一条家庭动态,让关心流动起来。</div>}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<div className="section-title"><h2>家庭成员</h2></div>
|
||||||
|
<div className="card">
|
||||||
|
{workspace.memberships.map((member, index) => {
|
||||||
|
const name = member.caregiver.nickname || member.caregiver.username || "家庭成员";
|
||||||
|
return (
|
||||||
|
<div key={member.id} className="list-row" style={{ alignItems: "center" }}>
|
||||||
|
<span className="member-avatar" style={avatarStyles[index % avatarStyles.length]}>{name.slice(-1)}</span>
|
||||||
|
<span className="row-main">
|
||||||
|
<span className="row-title">{name}</span>
|
||||||
|
<span className="row-meta">
|
||||||
|
{member.relationLabel || "家人"}{member.dutyOrder ? ` · 值守顺序 ${member.dutyOrder}` : ""}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<span className="member-role">{roleLabel[member.role]}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<div className="section-title"><h2>邀请家人</h2><span>链接 24 小时有效</span></div>
|
||||||
|
<InviteMemberForm deviceUuid={deviceUuid} />
|
||||||
|
</section>
|
||||||
|
</PanelShell>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
241
app/globals.css
241
app/globals.css
@ -1,19 +1,19 @@
|
|||||||
@import "tailwindcss";
|
@import "tailwindcss";
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--canvas: #e9e7e3;
|
--canvas: #e7e4df;
|
||||||
--paper: #f4f3f1;
|
--paper: #f5f4f2;
|
||||||
--surface: #ffffff;
|
--surface: #ffffff;
|
||||||
--surface-soft: #faf9f8;
|
--surface-soft: #faf9f8;
|
||||||
--ink: #201d1a;
|
--ink: #211e1a;
|
||||||
--ink-soft: #3d3833;
|
--ink-soft: #3d3833;
|
||||||
--muted: #8a857e;
|
--muted: #8b857c;
|
||||||
--muted-light: #b3aea6;
|
--muted-light: #b5afa6;
|
||||||
--line: rgba(32, 29, 26, 0.08);
|
--line: rgba(33, 30, 26, 0.08);
|
||||||
--line-strong: rgba(32, 29, 26, 0.14);
|
--line-strong: rgba(33, 30, 26, 0.15);
|
||||||
--accent: #c05a1e;
|
--accent: #c05a1e;
|
||||||
--accent-hover: #96431a;
|
--accent-hover: #96431a;
|
||||||
--accent-soft: rgba(192, 90, 30, 0.1);
|
--accent-soft: rgba(192, 90, 30, 0.09);
|
||||||
--copper: var(--accent);
|
--copper: var(--accent);
|
||||||
--copper-deep: var(--accent-hover);
|
--copper-deep: var(--accent-hover);
|
||||||
--paper-soft: var(--surface-soft);
|
--paper-soft: var(--surface-soft);
|
||||||
@ -23,7 +23,7 @@
|
|||||||
--danger: #b4482c;
|
--danger: #b4482c;
|
||||||
--radius-sm: 8px;
|
--radius-sm: 8px;
|
||||||
--radius-md: 10px;
|
--radius-md: 10px;
|
||||||
--radius-lg: 12px;
|
--radius-lg: 14px;
|
||||||
--font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
--font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
||||||
--font-display: var(--font-body);
|
--font-display: var(--font-body);
|
||||||
}
|
}
|
||||||
@ -40,6 +40,7 @@ body { margin: 0; color: var(--ink); background: var(--canvas); font-family: var
|
|||||||
a { color: inherit; text-decoration: none; }
|
a { color: inherit; text-decoration: none; }
|
||||||
button, input, textarea, select { font: inherit; }
|
button, input, textarea, select { font: inherit; }
|
||||||
button { cursor: pointer; }
|
button { cursor: pointer; }
|
||||||
|
button:disabled { cursor: not-allowed; opacity: .6; }
|
||||||
textarea { resize: none; }
|
textarea { resize: none; }
|
||||||
*::-webkit-scrollbar { display: none; }
|
*::-webkit-scrollbar { display: none; }
|
||||||
::selection { background: rgba(192, 90, 30, 0.18); }
|
::selection { background: rgba(192, 90, 30, 0.18); }
|
||||||
@ -52,81 +53,157 @@ textarea { resize: none; }
|
|||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: var(--paper);
|
background: var(--paper);
|
||||||
box-shadow: 0 0 0 1px rgba(32,29,26,.03);
|
box-shadow: 0 0 0 1px rgba(33, 30, 26, .03);
|
||||||
}
|
}
|
||||||
.app-content { min-height: 100dvh; padding: 14px 14px 84px; }
|
.app-content { min-height: 100dvh; padding: 22px 18px 110px; }
|
||||||
.app-content.detail { padding-top: 0; padding-bottom: 24px; }
|
.app-content.detail { padding-top: 0; padding-bottom: 28px; }
|
||||||
.app-stack { display: flex; flex-direction: column; gap: 12px; }
|
.app-stack { display: flex; flex-direction: column; gap: 18px; }
|
||||||
.page-heading { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:2px 2px 0; }
|
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 2px; }
|
||||||
.page-heading h1 { margin:0; font-size:20px; line-height:1.35; font-weight:700; letter-spacing:.01em; }
|
.page-heading h1 { margin: 0; font-size: 21px; line-height: 1.35; font-weight: 700; letter-spacing: .01em; }
|
||||||
.page-heading p { margin:3px 0 0; color:var(--muted); font-size:12px; line-height:1.5; }
|
.page-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
|
||||||
.avatar { display:flex; width:34px; height:34px; flex:none; align-items:center; justify-content:center; border:0; border-radius:50%; background:var(--ink); color:var(--paper); font-size:14px; font-weight:600; }
|
.avatar { display: flex; width: 36px; height: 36px; flex: none; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: var(--ink); color: var(--paper); font-size: 14px; font-weight: 600; }
|
||||||
.detail-header { position:sticky; top:0; z-index:5; display:flex; min-height:54px; align-items:center; gap:6px; padding:10px 0; background:rgba(244,243,241,.96); backdrop-filter:blur(10px); }
|
.detail-header { position: sticky; top: 0; z-index: 5; display: flex; min-height: 58px; align-items: center; gap: 7px; padding: 11px 0; background: rgba(245, 244, 242, .96); backdrop-filter: blur(10px); }
|
||||||
.detail-header h1 { margin:0; flex:1; font-size:16px; font-weight:700; }
|
.detail-header h1 { margin: 0; flex: 1; font-size: 16px; font-weight: 700; }
|
||||||
.back-button { display:flex; width:30px; height:30px; align-items:center; justify-content:center; border:0; background:transparent; color:var(--ink); }
|
.back-button { display: flex; width: 32px; height: 32px; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--ink); }
|
||||||
.card { overflow:hidden; border:1px solid var(--line); border-radius:var(--radius-lg); background:var(--surface); }
|
|
||||||
.card-pad { padding:13px 14px; }
|
|
||||||
.list-row { display:flex; width:100%; align-items:flex-start; gap:10px; padding:11px 14px; border:0; border-top:1px solid var(--line); background:transparent; color:var(--ink); text-align:left; }
|
|
||||||
.list-row:first-child { border-top:0; }
|
|
||||||
.list-row:hover { background:var(--surface-soft); }
|
|
||||||
.row-main { flex:1; min-width:0; }
|
|
||||||
.row-title { display:block; color:var(--ink); font-size:14px; line-height:1.5; font-weight:600; }
|
|
||||||
.row-meta { display:flex; align-items:center; gap:6px; margin-top:4px; color:var(--muted); font-size:12px; line-height:1.45; }
|
|
||||||
.dot { width:7px; height:7px; flex:none; margin-top:6px; border-radius:50%; background:var(--accent); }
|
|
||||||
.dot.online { background:var(--success); }
|
|
||||||
.dot.offline { background:#c7c2ba; }
|
|
||||||
.tag { display:inline-flex; align-items:center; border-radius:4px; padding:1px 5px; background:var(--accent-soft); color:var(--accent); font-size:10px; font-weight:600; }
|
|
||||||
.section-title { display:flex; align-items:baseline; justify-content:space-between; padding:0 2px 8px; }
|
|
||||||
.section-title h2 { margin:0; font-size:14px; font-weight:700; }
|
|
||||||
.section-title a { color:var(--accent); font-size:13px; font-weight:500; }
|
|
||||||
.stats { display:grid; overflow:hidden; border:1px solid var(--line); border-radius:var(--radius-lg); background:var(--surface); }
|
|
||||||
.stat { padding:11px 4px; text-align:center; }
|
|
||||||
.stat + .stat { border-left:1px solid var(--line); }
|
|
||||||
.stat strong { display:block; font-size:20px; line-height:1.2; font-weight:700; }
|
|
||||||
.stat:first-child strong, .stat.accent strong { color:var(--accent); }
|
|
||||||
.stat span { display:block; margin-top:3px; color:var(--muted); font-size:11px; }
|
|
||||||
.button-row { display:flex; gap:10px; }
|
|
||||||
.btn { display:inline-flex; min-height:40px; align-items:center; justify-content:center; gap:6px; border:1px solid var(--line-strong); border-radius:var(--radius-md); padding:0 14px; background:var(--surface); color:var(--ink); font-size:13.5px; font-weight:600; }
|
|
||||||
.btn:hover { background:var(--surface-soft); }
|
|
||||||
.btn.primary { border-color:var(--accent); background:var(--accent); color:#fff; }
|
|
||||||
.btn.primary:hover { background:var(--accent-hover); }
|
|
||||||
.btn.dark { border-color:var(--ink); background:var(--ink); color:#fff; }
|
|
||||||
.btn.small { min-height:32px; border-radius:8px; padding:0 12px; font-size:13px; }
|
|
||||||
.btn.block { width:100%; }
|
|
||||||
.segment { display:flex; padding:2px; border-radius:9px; background:rgba(32,29,26,.06); }
|
|
||||||
.segment a, .segment button { flex:1; height:30px; border:0; border-radius:7px; background:transparent; color:var(--muted); font-size:13px; font-weight:600; text-align:center; line-height:30px; }
|
|
||||||
.segment .active { background:#fff; color:var(--ink); box-shadow:0 1px 2px rgba(0,0,0,.06); }
|
|
||||||
.field { width:100%; height:44px; border:1px solid rgba(32,29,26,.12); border-radius:10px; padding:0 13px; outline:0; background:#fff; color:var(--ink); font-size:14px; }
|
|
||||||
.field:focus { border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft); }
|
|
||||||
textarea.field { height:auto; min-height:84px; padding:9px 11px; line-height:1.5; background:var(--surface-soft); }
|
|
||||||
.empty { padding:34px 20px; color:var(--muted); text-align:center; font-size:13px; line-height:1.7; }
|
|
||||||
.muted-note { margin:0; color:var(--muted-light); font-size:11.5px; line-height:1.6; }
|
|
||||||
.bottom-nav { position:fixed; z-index:20; right:0; bottom:0; left:0; display:grid; grid-template-columns:repeat(4,1fr); width:100%; max-width:430px; margin:0 auto; padding:6px 0 calc(10px + env(safe-area-inset-bottom)); border-top:1px solid var(--line); background:rgba(255,255,255,.96); backdrop-filter:blur(10px); }
|
|
||||||
.nav-item { position:relative; display:flex; flex-direction:column; align-items:center; gap:3px; padding:4px 0; color:var(--muted); font-size:10px; font-weight:600; }
|
|
||||||
.nav-item.active { color:var(--accent); }
|
|
||||||
.nav-badge { position:absolute; top:0; left:calc(50% + 6px); min-width:16px; height:16px; border-radius:8px; padding:0 4px; background:var(--accent); color:#fff; font-size:10px; line-height:16px; text-align:center; }
|
|
||||||
.device-icon { display:flex; width:40px; height:40px; flex:none; align-items:center; justify-content:center; border-radius:10px; background:rgba(192,90,30,.08); color:var(--accent); }
|
|
||||||
.timeline-item { padding:11px 14px; border-top:1px solid var(--line); }
|
|
||||||
.timeline-item:first-child { border-top:0; }
|
|
||||||
.timeline-top { display:flex; align-items:baseline; gap:8px; color:var(--muted); font-size:12px; font-weight:600; }
|
|
||||||
.timeline-time { margin-left:auto; color:var(--muted-light); font-size:11.5px; font-weight:400; white-space:nowrap; }
|
|
||||||
.timeline-body { margin:4px 0 0; color:var(--ink-soft); font-size:13.5px; line-height:1.55; }
|
|
||||||
.settings-controls > * { border:1px solid var(--line)!important; border-radius:12px!important; background:#fff!important; padding:14px!important; box-shadow:none!important; }
|
|
||||||
.settings-controls h2, .settings-controls h3 { font-family:var(--font-body)!important; font-size:15px!important; line-height:1.45!important; }
|
|
||||||
.settings-controls p { font-size:12px!important; line-height:1.65!important; }
|
|
||||||
.device-manage summary { list-style:none; }
|
|
||||||
.device-manage[open] summary { margin-bottom:10px; }
|
|
||||||
.device-manage > :not(summary) { border:1px solid var(--line)!important; border-radius:12px!important; background:#fff!important; padding:14px!important; box-shadow:none!important; }
|
|
||||||
.scan-panel > div { border:0!important; border-radius:0!important; background:transparent!important; padding:0!important; box-shadow:none!important; }
|
|
||||||
.scan-panel > div > p:first-child, .scan-panel > div > h2, .scan-panel > div > h2 + p { display:none!important; }
|
|
||||||
.scan-panel video { border-radius:14px; }
|
|
||||||
|
|
||||||
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.45} }
|
.card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
|
||||||
@keyframes route-progress-slide { 0%{transform:translateX(-140%)} 100%{transform:translateX(240%)} }
|
.card-pad { padding: 15px 16px; }
|
||||||
.route-progress-bar { animation:route-progress-slide 1.15s ease-in-out infinite; background:var(--accent)!important; }
|
.list-row { display: flex; width: 100%; align-items: flex-start; gap: 11px; padding: 12px 16px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; }
|
||||||
|
.list-row:first-child { border-top: 0; }
|
||||||
|
.list-row:hover { background: var(--surface-soft); }
|
||||||
|
.row-main { flex: 1; min-width: 0; }
|
||||||
|
.row-title { display: block; color: var(--ink); font-size: 14px; line-height: 1.5; font-weight: 600; }
|
||||||
|
.row-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.5; }
|
||||||
|
.dot { width: 7px; height: 7px; flex: none; margin-top: 6px; border-radius: 50%; background: var(--accent); }
|
||||||
|
.dot.online { background: var(--success); animation: pulse 2.4s ease-in-out infinite; }
|
||||||
|
.dot.offline { background: #c7c2ba; }
|
||||||
|
.tag { display: inline-flex; align-items: center; border-radius: 5px; padding: 2px 7px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600; }
|
||||||
|
.tag.success { background: rgba(63, 157, 99, .1); color: var(--success); }
|
||||||
|
.section-title { display: flex; align-items: baseline; justify-content: space-between; padding: 0 2px 9px; }
|
||||||
|
.section-title h2 { margin: 0; font-size: 15px; font-weight: 700; }
|
||||||
|
.section-title > span { color: var(--muted-light); font-size: 12px; }
|
||||||
|
.section-title a { color: var(--accent); font-size: 12.5px; font-weight: 600; }
|
||||||
|
|
||||||
|
.stats { display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
|
||||||
|
.stat { padding: 13px 4px; text-align: center; }
|
||||||
|
.stat + .stat { border-left: 1px solid var(--line); }
|
||||||
|
.stat strong { display: block; font-size: 21px; line-height: 1.2; font-weight: 700; }
|
||||||
|
.stat:first-child strong, .stat.accent strong { color: var(--accent); }
|
||||||
|
.stat span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
|
||||||
|
|
||||||
|
.button-row { display: flex; gap: 8px; }
|
||||||
|
.btn { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line-strong); border-radius: var(--radius-md); padding: 0 13px; background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; white-space: nowrap; }
|
||||||
|
.btn:hover { background: var(--surface-soft); }
|
||||||
|
.btn.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
|
||||||
|
.btn.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
|
||||||
|
.btn.dark { border-color: var(--ink); background: var(--ink); color: #fff; }
|
||||||
|
.btn.small { min-height: 32px; border-radius: 8px; padding: 0 13px; font-size: 12.5px; }
|
||||||
|
.btn.block { width: 100%; }
|
||||||
|
.btn.muted { color: var(--muted); }
|
||||||
|
|
||||||
|
.segment { display: flex; gap: 2px; padding: 3px; border-radius: 11px; background: rgba(33, 30, 26, .06); }
|
||||||
|
.segment a, .segment button { flex: 1; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; text-align: center; line-height: 34px; }
|
||||||
|
.segment .active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
|
||||||
|
|
||||||
|
.field-label { display: block; margin: 0 0 7px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .02em; }
|
||||||
|
.field { width: 100%; height: 44px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 0 13px; outline: 0; background: #fff; color: var(--ink); font-size: 14px; }
|
||||||
|
.field::placeholder { color: var(--muted-light); }
|
||||||
|
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
|
||||||
|
textarea.field { height: auto; min-height: 78px; padding: 11px 13px; line-height: 1.6; background: var(--surface-soft); }
|
||||||
|
select.field {
|
||||||
|
appearance: none;
|
||||||
|
padding-right: 34px;
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: #fff;
|
||||||
|
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%238b857c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
|
||||||
|
background-position: right 11px center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
||||||
|
.form-stack { display: flex; flex-direction: column; gap: 10px; }
|
||||||
|
.form-grid { display: grid; gap: 10px; }
|
||||||
|
.form-grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
|
||||||
|
.form-grid.action { grid-template-columns: minmax(0, 1fr) 110px; }
|
||||||
|
.form-grid.publish { grid-template-columns: minmax(0, 1fr) 96px; }
|
||||||
|
.form-grid.memo-actions { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 82px; }
|
||||||
|
.form-notice { margin: 9px 0 0; color: var(--success); font-size: 12px; line-height: 1.5; }
|
||||||
|
|
||||||
|
.elder-status { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
|
||||||
|
.elder-status-main { display: flex; align-items: center; gap: 12px; padding: 15px 16px; }
|
||||||
|
.elder-avatar { display: flex; width: 46px; height: 46px; flex: none; align-items: center; justify-content: center; border-radius: 50%; background: rgba(101, 118, 90, .12); color: var(--olive); font-size: 18px; font-weight: 700; }
|
||||||
|
.elder-name { display: flex; align-items: center; gap: 7px; font-size: 15px; font-weight: 700; }
|
||||||
|
.online-label { font-size: 12px; font-weight: 600; }
|
||||||
|
.elder-meta { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
|
||||||
|
.checkin-action { border-top: 1px solid var(--line); padding: 12px 16px 14px; }
|
||||||
|
.checkin-action .form-notice { text-align: center; }
|
||||||
|
|
||||||
|
.timeline-item { padding: 13px 16px; border-top: 1px solid var(--line); }
|
||||||
|
.timeline-item:first-child { border-top: 0; }
|
||||||
|
.timeline-top { display: flex; align-items: baseline; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; }
|
||||||
|
.timeline-top.strong { color: var(--ink); font-size: 13.5px; font-weight: 700; }
|
||||||
|
.timeline-time { margin-left: auto; color: var(--muted-light); font-size: 11.5px; font-weight: 400; white-space: nowrap; }
|
||||||
|
.timeline-body { margin: 5px 0 0; color: var(--ink-soft); font-size: 13px; line-height: 1.6; }
|
||||||
|
.timeline-item > .row-meta { margin-top: 5px; }
|
||||||
|
.timeline-item > .button-row { margin-top: 10px; }
|
||||||
|
.alert-title { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-size: 13.5px; font-weight: 700; }
|
||||||
|
.alert-title.red { color: #b33a2b; }
|
||||||
|
|
||||||
|
.member-avatar { display: flex; width: 36px; height: 36px; flex: none; align-items: center; justify-content: center; border-radius: 50%; font-size: 14px; font-weight: 700; }
|
||||||
|
.member-role { flex: none; border-radius: 5px; padding: 2px 7px; background: rgba(33, 30, 26, .05); color: var(--muted); font-size: 11px; font-weight: 600; }
|
||||||
|
.feature-row { align-items: center; gap: 12px; padding: 14px 16px; }
|
||||||
|
.feature-icon { display: flex; width: 40px; height: 40px; flex: none; align-items: center; justify-content: center; border-radius: 11px; background: var(--accent-soft); color: var(--accent); }
|
||||||
|
.feature-icon.olive { background: rgba(101, 118, 90, .1); color: var(--olive); }
|
||||||
|
.feature-icon.muted { background: rgba(33, 30, 26, .05); color: var(--muted); }
|
||||||
|
.feature-disabled { opacity: .55; }
|
||||||
|
.chevron { flex: none; color: var(--muted-light); }
|
||||||
|
.count-badge { min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
|
||||||
|
|
||||||
|
.settings-profile { display: flex; align-items: center; gap: 13px; padding: 16px; }
|
||||||
|
.settings-profile .avatar { width: 48px; height: 48px; font-size: 18px; }
|
||||||
|
.settings-row { display: flex; width: 100%; align-items: center; gap: 12px; padding: 13px 16px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; }
|
||||||
|
.settings-row:first-child { border-top: 0; }
|
||||||
|
.settings-row:hover { background: var(--surface-soft); }
|
||||||
|
.settings-icon { display: flex; width: 36px; height: 36px; flex: none; align-items: center; justify-content: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
|
||||||
|
.settings-icon.olive { background: rgba(101, 118, 90, .1); color: var(--olive); }
|
||||||
|
.settings-icon.muted { background: rgba(33, 30, 26, .05); color: var(--muted); }
|
||||||
|
.toggle { width: 46px; height: 27px; flex: none; position: relative; border: 0; border-radius: 14px; background: rgba(33, 30, 26, .18); transition: background .2s; }
|
||||||
|
.toggle.on { background: var(--success); }
|
||||||
|
.toggle-knob { position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: left .2s; }
|
||||||
|
.toggle.on .toggle-knob { left: 22px; }
|
||||||
|
|
||||||
|
.empty { padding: 34px 20px; color: var(--muted); text-align: center; font-size: 13px; line-height: 1.7; }
|
||||||
|
.muted-note { margin: 0; color: var(--muted-light); font-size: 11.5px; line-height: 1.6; }
|
||||||
|
.bottom-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 430px; margin: 0 auto; padding: 8px 4px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255, 255, 255, .94); backdrop-filter: blur(12px); }
|
||||||
|
.nav-item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 5px 0; color: #9a948b; font-size: 10.5px; font-weight: 600; }
|
||||||
|
.nav-item.active { color: var(--accent); }
|
||||||
|
.nav-badge { position: absolute; top: 1px; left: calc(50% + 7px); min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; }
|
||||||
|
.device-icon { display: flex; width: 40px; height: 40px; flex: none; align-items: center; justify-content: center; border-radius: 10px; background: rgba(192, 90, 30, .08); color: var(--accent); }
|
||||||
|
|
||||||
|
.settings-controls > * { border: 1px solid var(--line) !important; border-radius: 14px !important; background: #fff !important; padding: 15px 16px !important; box-shadow: none !important; }
|
||||||
|
.settings-controls h2, .settings-controls h3 { font-family: var(--font-body) !important; font-size: 15px !important; line-height: 1.45 !important; }
|
||||||
|
.settings-controls p { font-size: 12px !important; line-height: 1.65 !important; }
|
||||||
|
.device-manage summary { list-style: none; }
|
||||||
|
.device-manage[open] summary { margin-bottom: 10px; }
|
||||||
|
.device-manage > :not(summary) { border: 1px solid var(--line) !important; border-radius: 14px !important; background: #fff !important; padding: 15px 16px !important; box-shadow: none !important; }
|
||||||
|
.scan-panel > div { border: 0 !important; border-radius: 0 !important; background: transparent !important; padding: 0 !important; box-shadow: none !important; }
|
||||||
|
.scan-panel > div > p:first-child, .scan-panel > div > h2, .scan-panel > div > h2 + p { display: none !important; }
|
||||||
|
.scan-panel video { border-radius: 14px; }
|
||||||
|
|
||||||
|
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
|
||||||
|
@keyframes route-progress-slide { 0% { transform: translateX(-140%); } 100% { transform: translateX(240%); } }
|
||||||
|
.route-progress-bar { animation: route-progress-slide 1.15s ease-in-out infinite; background: var(--accent) !important; }
|
||||||
|
|
||||||
|
@media (max-width: 390px) {
|
||||||
|
.form-grid.memo-actions { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
|
||||||
|
.form-grid.memo-actions .btn { grid-column: 1 / -1; }
|
||||||
|
.stats .stat strong { font-size: 19px; }
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 700px) {
|
@media (min-width: 700px) {
|
||||||
.app-frame { min-height:calc(100dvh - 32px); margin:16px auto; border-radius:18px; box-shadow:0 18px 60px rgba(32,29,26,.12); }
|
.app-frame { min-height: calc(100dvh - 72px); margin: 36px auto; border-radius: 30px; box-shadow: 0 24px 70px rgba(33, 30, 26, .16), 0 0 0 1px rgba(33, 30, 26, .05); }
|
||||||
.app-content { min-height:calc(100dvh - 32px); }
|
.app-content { min-height: calc(100dvh - 72px); }
|
||||||
.bottom-nav { bottom:16px; border-radius:0 0 18px 18px; }
|
.bottom-nav { bottom: 36px; border-radius: 0 0 30px 30px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
*, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { AlertTriangle, CheckCircle2, HeartPulse, PhoneCall } from "lucide-react";
|
import { AlertTriangle, CheckCircle2, HeartPulse, PhoneCall } from "lucide-react";
|
||||||
|
|
||||||
import { AlertActions, CheckInButton } from "@/components/family-guard-actions";
|
import { AlertActions, CheckInButton } from "@/components/family-guard-actions";
|
||||||
import { PanelShell } from "@/components/panel-shell";
|
import { PanelShell } from "@/components/panel-shell";
|
||||||
import { requireFamilyWorkspace } from "@/lib/family-page";
|
import { requireFamilyWorkspace } from "@/lib/family-page";
|
||||||
@ -7,17 +8,92 @@ import { requireCaregiverSession } from "@/lib/page-auth";
|
|||||||
import { getCaregiverDisplayName } from "@/lib/session";
|
import { getCaregiverDisplayName } from "@/lib/session";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export default async function GuardPage() {
|
export default async function GuardPage() {
|
||||||
const caregiver = await requireCaregiverSession("/guard"); const workspace = await requireFamilyWorkspace(caregiver.id);
|
const caregiver = await requireCaregiverSession("/guard");
|
||||||
const openAlerts = workspace.alerts.filter((a) => a.status === "OPEN" || a.status === "ACKNOWLEDGED");
|
const workspace = await requireFamilyWorkspace(caregiver.id);
|
||||||
const todayDoses = workspace.medicationPlans.flatMap((p) => p.doses).filter((d) => d.scheduledFor.toDateString() === new Date().toDateString());
|
const elder = workspace.elderProfile;
|
||||||
const doneDoses = todayDoses.filter((d) => d.status === "TAKEN").length;
|
const device = elder.elderDevice;
|
||||||
const openTasks = workspace.tasks.filter((t) => t.status !== "COMPLETED" && t.status !== "CANCELLED");
|
const lastSeenAt = device.lastSeenAt;
|
||||||
const pendingCheckIns = workspace.checkIns.filter((c) => c.status === "PENDING");
|
const isOnline = Boolean(lastSeenAt);
|
||||||
return <PanelShell currentPath="/guard" title="家庭守护" description={`${workspace.elderProfile.preferredName} · 风险线索不是医疗诊断`} caregiverLabel={getCaregiverDisplayName(caregiver)}>
|
const openAlerts = workspace.alerts.filter((alert) => alert.status === "OPEN" || alert.status === "ACKNOWLEDGED");
|
||||||
<section className="stats" style={{ gridTemplateColumns: "repeat(4,1fr)" }}><div className="stat accent"><strong>{openAlerts.length}</strong><span>待处理提醒</span></div><div className="stat"><strong>{doneDoses}/{todayDoses.length}</strong><span>今日用药</span></div><div className="stat"><strong>{openTasks.length}</strong><span>照护事项</span></div><div className="stat"><strong>{pendingCheckIns.length}</strong><span>待报平安</span></div></section>
|
const today = new Date().toDateString();
|
||||||
<CheckInButton deviceUuid={workspace.elderProfile.elderDevice.deviceUuid} />
|
const todayDoses = workspace.medicationPlans.flatMap((plan) => plan.doses).filter((dose) => dose.scheduledFor.toDateString() === today);
|
||||||
<section><div className="section-title"><h2>风险提醒</h2><span>人工确认后再处置</span></div><div className="card">{workspace.alerts.length ? workspace.alerts.map((alert) => <article id={`alert-${alert.id}`} key={alert.id} className="timeline-item"><div className="timeline-top"><span style={{ color: alert.level === "RED" ? "#b33a2b" : "var(--accent)" }}><AlertTriangle size={15} style={{ verticalAlign: -3, marginRight: 5 }} />{alert.title}</span><span className="timeline-time">{formatDateTime(alert.createdAt)}</span></div><p className="timeline-body">{alert.summary}</p><p className="row-meta">{alert.claimedBy ? `已由 ${alert.claimedBy.nickname || alert.claimedBy.username || "家人"} 接手` : "尚未认领"}</p><AlertActions alertId={alert.id} status={alert.status} /></article>) : <div className="empty"><CheckCircle2 size={26} /><br />当前没有待处理的风险提醒</div>}</div></section>
|
const doneDoses = todayDoses.filter((dose) => dose.status === "TAKEN").length;
|
||||||
<section><div className="section-title"><h2>今日状态</h2></div><div className="card"><div className="timeline-item"><div className="timeline-top"><HeartPulse size={15} />设备最近在线<span className="timeline-time">{formatDateTime(workspace.elderProfile.elderDevice.lastSeenAt)}</span></div><p className="timeline-body">仅根据终端在线和主动交互记录展示,不代表生命体征状态。</p></div><div className="timeline-item"><div className="timeline-top"><PhoneCall size={15} />家庭值守</div><p className="timeline-body">{workspace.memberships.filter((m) => m.emergencyPush).map((m) => m.caregiver.nickname || m.caregiver.username || "家人").join("、") || "尚未设置"}</p></div></div></section>
|
const openTasks = workspace.tasks.filter((task) => task.status !== "COMPLETED" && task.status !== "CANCELLED");
|
||||||
</PanelShell>;
|
const pendingCheckIns = workspace.checkIns.filter((checkIn) => checkIn.status === "PENDING");
|
||||||
|
const dutyNames = workspace.memberships
|
||||||
|
.filter((membership) => membership.emergencyPush)
|
||||||
|
.map((membership) => membership.caregiver.nickname || membership.caregiver.username || "家人");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PanelShell
|
||||||
|
currentPath="/guard"
|
||||||
|
title="家庭守护"
|
||||||
|
description={`${elder.preferredName} · 风险线索不是医疗诊断`}
|
||||||
|
caregiverLabel={getCaregiverDisplayName(caregiver)}
|
||||||
|
caregiverId={caregiver.id}
|
||||||
|
>
|
||||||
|
<section className="elder-status">
|
||||||
|
<div className="elder-status-main">
|
||||||
|
<span className="elder-avatar">{elder.preferredName.slice(0, 1)}</span>
|
||||||
|
<span className="row-main">
|
||||||
|
<span className="elder-name">
|
||||||
|
{elder.preferredName}
|
||||||
|
<span className={`dot ${isOnline ? "online" : "offline"}`} style={{ marginTop: 0 }} />
|
||||||
|
<span className="online-label" style={{ color: isOnline ? "var(--success)" : "var(--muted-light)" }}>
|
||||||
|
{isOnline ? "在线" : "离线"}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<span className="elder-meta">
|
||||||
|
{isOnline ? `最近与数字人互动 · ${device.displayName || "长辈终端"}` : `最近在线:${formatDateTime(lastSeenAt)} · ${device.displayName || "长辈终端"}`}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<CheckInButton deviceUuid={device.deviceUuid} />
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="stats" style={{ gridTemplateColumns: "repeat(4, 1fr)" }}>
|
||||||
|
<div className="stat accent"><strong>{openAlerts.length}</strong><span>待处理提醒</span></div>
|
||||||
|
<div className="stat"><strong>{doneDoses}/{todayDoses.length}</strong><span>今日用药</span></div>
|
||||||
|
<div className="stat"><strong>{openTasks.length}</strong><span>照护事项</span></div>
|
||||||
|
<div className="stat"><strong>{pendingCheckIns.length}</strong><span>待报平安</span></div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<div className="section-title"><h2>风险提醒</h2><span>人工确认后再处置</span></div>
|
||||||
|
<div className="card">
|
||||||
|
{workspace.alerts.length ? workspace.alerts.map((alert) => (
|
||||||
|
<article id={`alert-${alert.id}`} key={alert.id} className="timeline-item">
|
||||||
|
<div className="timeline-top">
|
||||||
|
<span className={`alert-title${alert.level === "RED" ? " red" : ""}`}>
|
||||||
|
<AlertTriangle size={15} strokeWidth={2} />{alert.title}
|
||||||
|
</span>
|
||||||
|
<span className="timeline-time">{formatDateTime(alert.createdAt)}</span>
|
||||||
|
</div>
|
||||||
|
<p className="timeline-body">{alert.summary}</p>
|
||||||
|
<p className="row-meta">{alert.claimedBy ? `已由 ${alert.claimedBy.nickname || alert.claimedBy.username || "家人"} 接手` : "尚未认领"}</p>
|
||||||
|
<AlertActions alertId={alert.id} status={alert.status} />
|
||||||
|
</article>
|
||||||
|
)) : (
|
||||||
|
<div className="empty"><CheckCircle2 size={26} /><br />当前没有待处理的风险提醒</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<div className="section-title"><h2>今日状态</h2></div>
|
||||||
|
<div className="card">
|
||||||
|
<article className="timeline-item">
|
||||||
|
<div className="timeline-top"><HeartPulse size={15} />设备最近在线<span className="timeline-time">{formatDateTime(lastSeenAt)}</span></div>
|
||||||
|
<p className="timeline-body">仅根据终端在线和主动交互记录展示,不代表生命体征状态。</p>
|
||||||
|
</article>
|
||||||
|
<article className="timeline-item">
|
||||||
|
<div className="timeline-top"><PhoneCall size={15} />家庭值守</div>
|
||||||
|
<p className="timeline-body">{dutyNames.length ? `${dutyNames.join("、")}已开启紧急推送` : "尚未设置家庭值守"}</p>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</PanelShell>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ export const metadata: Metadata = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const viewport: Viewport = {
|
export const viewport: Viewport = {
|
||||||
themeColor: "#F4F3F1",
|
themeColor: "#F5F4F2",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
|
import { ChevronRight } from "lucide-react";
|
||||||
|
|
||||||
import { PanelShell } from "@/components/panel-shell";
|
import { PanelShell } from "@/components/panel-shell";
|
||||||
import { PwaControls } from "@/components/pwa-controls";
|
import { PwaControls } from "@/components/pwa-controls";
|
||||||
import { PushTestPanel } from "@/components/push-test-panel";
|
|
||||||
import { getCaregiverSettingsOverview } from "@/lib/caregiver-panel";
|
import { getCaregiverSettingsOverview } from "@/lib/caregiver-panel";
|
||||||
import { requireCaregiverSession } from "@/lib/page-auth";
|
import { requireCaregiverSession } from "@/lib/page-auth";
|
||||||
import { getCaregiverDisplayName } from "@/lib/session";
|
import { getCaregiverDisplayName } from "@/lib/session";
|
||||||
@ -13,17 +14,23 @@ export default async function SettingsPage() {
|
|||||||
const name = getCaregiverDisplayName(caregiver);
|
const name = getCaregiverDisplayName(caregiver);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PanelShell currentPath="/settings" title="我的" caregiverLabel={name}>
|
<PanelShell currentPath="/settings" title="我的" description="账号、通知与设备" caregiverLabel={name} caregiverId={caregiver.id}>
|
||||||
<section className="card card-pad" style={{ display: "flex", alignItems: "center", gap: 12 }}>
|
<section className="card settings-profile">
|
||||||
<span className="avatar" style={{ width: 44, height: 44, fontSize: 17 }}>{name.slice(-1)}</span>
|
<span className="avatar">{name.slice(-1)}</span>
|
||||||
<span className="row-main"><strong style={{ display: "block", fontSize: 15 }}>{name}</strong><span className="row-meta">已绑定 {overview.deviceCount} 台设备 · {overview.pushSubscriptionCount} 台设备已开启提醒</span></span>
|
<span className="row-main">
|
||||||
|
<strong style={{ display: "block", fontSize: 15.5 }}>{name}</strong>
|
||||||
|
<span className="row-meta">已绑定 {overview.deviceCount} 台设备 · {overview.pushSubscriptionCount} 台设备已开启提醒</span>
|
||||||
|
</span>
|
||||||
|
<ChevronRight className="chevron" size={16} strokeWidth={2} />
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div className="settings-controls"><PwaControls /></div>
|
<section>
|
||||||
<div className="settings-controls"><PushTestPanel initialSubscriptionCount={overview.pushSubscriptionCount} deviceCount={overview.deviceCount} /></div>
|
<div className="section-title"><h2>通知与设备</h2></div>
|
||||||
|
<PwaControls deviceCount={overview.deviceCount} />
|
||||||
|
</section>
|
||||||
|
|
||||||
<form action="/api/account/logout" method="post" className="card">
|
<form action="/api/account/logout" method="post" className="card">
|
||||||
<button type="submit" className="list-row" style={{ justifyContent: "center", color: "var(--danger)", fontWeight: 500 }}>退出登录</button>
|
<button type="submit" className="settings-row" style={{ justifyContent: "center", color: "var(--danger)", fontSize: 14, fontWeight: 600 }}>退出登录</button>
|
||||||
</form>
|
</form>
|
||||||
<p className="muted-note" style={{ textAlign: "center" }}>安智伴 · AI 数字人陪护 · 家属端 v2</p>
|
<p className="muted-note" style={{ textAlign: "center" }}>安智伴 · AI 数字人陪护 · 家属端 v2</p>
|
||||||
</PanelShell>
|
</PanelShell>
|
||||||
|
|||||||
@ -1,73 +1,350 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { ShieldCheck } from "lucide-react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { FormEvent, useState } from "react";
|
import { type FormEvent, useState } from "react";
|
||||||
|
|
||||||
async function api(path: string, method: string, body: Record<string, unknown>) {
|
async function api(path: string, method: string, body: Record<string, unknown>) {
|
||||||
const response = await fetch(path, { method, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
|
const response = await fetch(path, {
|
||||||
|
method,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
const payload = await response.json().catch(() => ({}));
|
const payload = await response.json().catch(() => ({}));
|
||||||
if (!response.ok) throw new Error(payload.error || "操作失败,请稍后再试。");
|
if (!response.ok) throw new Error(payload.error || "操作失败,请稍后再试。");
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Notice({ text }: { text: string }) { return text ? <p style={{ margin: "8px 0 0", color: "var(--success)", fontSize: 12 }}>{text}</p> : null; }
|
function Notice({ text }: { text: string }) {
|
||||||
|
return text ? <p className="form-notice">{text}</p> : null;
|
||||||
|
}
|
||||||
|
|
||||||
export function FamilyPostForm({ deviceUuid }: { deviceUuid: string }) {
|
export function FamilyPostForm({ deviceUuid }: { deviceUuid: string }) {
|
||||||
const router = useRouter(); const [notice, setNotice] = useState(""); const [busy, setBusy] = useState(false);
|
const router = useRouter();
|
||||||
|
const [notice, setNotice] = useState("");
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
async function submit(event: FormEvent<HTMLFormElement>) {
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||||
event.preventDefault(); setBusy(true); const form = new FormData(event.currentTarget);
|
event.preventDefault();
|
||||||
try { await api("/api/family-feed", "POST", { deviceUuid, content: form.get("content"), visibility: form.get("visibility") }); event.currentTarget.reset(); setNotice("已发布到家庭动态。"); router.refresh(); }
|
setBusy(true);
|
||||||
catch (e) { setNotice(e instanceof Error ? e.message : "发布失败。"); } finally { setBusy(false); }
|
const form = new FormData(event.currentTarget);
|
||||||
|
try {
|
||||||
|
await api("/api/family-feed", "POST", {
|
||||||
|
deviceUuid,
|
||||||
|
content: form.get("content"),
|
||||||
|
visibility: form.get("visibility"),
|
||||||
|
});
|
||||||
|
event.currentTarget.reset();
|
||||||
|
setNotice("已发布到家庭动态。");
|
||||||
|
router.refresh();
|
||||||
|
} catch (error) {
|
||||||
|
setNotice(error instanceof Error ? error.message : "发布失败。");
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
}
|
}
|
||||||
return <form className="card card-pad" onSubmit={submit}><textarea className="field" name="content" required maxLength={1000} placeholder="分享一句问候,或和家人同步今天的情况……" /><div className="button-row" style={{ marginTop: 8 }}><select className="field" name="visibility" defaultValue="FAMILY_AND_ELDER"><option value="FAMILY_AND_ELDER">老人和全家可见</option><option value="ELDER_ONLY">只发给老人</option><option value="FAMILY_ONLY">仅家庭内部</option></select><button className="btn primary" disabled={busy}>{busy ? "发布中" : "发布"}</button></div><Notice text={notice} /></form>;
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="card card-pad" onSubmit={submit}>
|
||||||
|
<label className="field-label" htmlFor="family-post-content">发一条家庭动态</label>
|
||||||
|
<textarea id="family-post-content" className="field" name="content" required maxLength={1000} placeholder="分享一句问候,或和家人同步今天的情况……" style={{ minHeight: 88 }} />
|
||||||
|
<div className="form-grid publish" style={{ marginTop: 10 }}>
|
||||||
|
<select className="field" name="visibility" defaultValue="FAMILY_AND_ELDER" aria-label="动态可见范围">
|
||||||
|
<option value="FAMILY_AND_ELDER">老人和全家可见</option>
|
||||||
|
<option value="ELDER_ONLY">只发给老人</option>
|
||||||
|
<option value="FAMILY_ONLY">仅家庭内部</option>
|
||||||
|
</select>
|
||||||
|
<button className="btn primary" disabled={busy}>{busy ? "发布中" : "发布"}</button>
|
||||||
|
</div>
|
||||||
|
<Notice text={notice} />
|
||||||
|
</form>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MemoForm({ deviceUuid }: { deviceUuid: string }) {
|
export function MemoForm({ deviceUuid }: { deviceUuid: string }) {
|
||||||
const router = useRouter(); const [notice, setNotice] = useState("");
|
const router = useRouter();
|
||||||
async function submit(event: FormEvent<HTMLFormElement>) { event.preventDefault(); const form = new FormData(event.currentTarget); try { await api("/api/memos", "POST", { deviceUuid, title: form.get("title"), content: form.get("content"), priority: form.get("priority"), visibility: form.get("visibility") }); event.currentTarget.reset(); setNotice("家庭备忘已保存。"); router.refresh(); } catch (e) { setNotice(e instanceof Error ? e.message : "保存失败。"); } }
|
const [notice, setNotice] = useState("");
|
||||||
return <form className="card card-pad" onSubmit={submit}><input className="field" name="title" required maxLength={80} placeholder="备忘标题,如:医保卡位置" /><textarea className="field" style={{ marginTop: 8 }} name="content" required maxLength={1000} placeholder="写下家人需要共同记住的信息" /><div className="button-row" style={{ marginTop: 8 }}><select className="field" name="priority"><option value="NORMAL">普通</option><option value="IMPORTANT">重要</option><option value="PINNED">长期置顶</option></select><select className="field" name="visibility"><option value="FAMILY_AND_ELDER">可告诉老人</option><option value="FAMILY_ONLY">仅家人可见</option></select><button className="btn primary">保存</button></div><Notice text={notice} /></form>;
|
|
||||||
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = new FormData(event.currentTarget);
|
||||||
|
try {
|
||||||
|
await api("/api/memos", "POST", {
|
||||||
|
deviceUuid,
|
||||||
|
title: form.get("title"),
|
||||||
|
content: form.get("content"),
|
||||||
|
priority: form.get("priority"),
|
||||||
|
visibility: form.get("visibility"),
|
||||||
|
});
|
||||||
|
event.currentTarget.reset();
|
||||||
|
setNotice("家庭备忘已保存。");
|
||||||
|
router.refresh();
|
||||||
|
} catch (error) {
|
||||||
|
setNotice(error instanceof Error ? error.message : "保存失败。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="card card-pad" onSubmit={submit}>
|
||||||
|
<label className="field-label" htmlFor="memo-title">新建家庭备忘</label>
|
||||||
|
<div className="form-stack">
|
||||||
|
<input id="memo-title" className="field" name="title" required maxLength={80} placeholder="备忘标题,如:医保卡位置" />
|
||||||
|
<textarea className="field" name="content" required maxLength={1000} placeholder="写下家人需要共同记住的信息" />
|
||||||
|
<div className="form-grid memo-actions">
|
||||||
|
<select className="field" name="priority" aria-label="备忘优先级">
|
||||||
|
<option value="NORMAL">普通</option>
|
||||||
|
<option value="IMPORTANT">重要</option>
|
||||||
|
<option value="PINNED">长期置顶</option>
|
||||||
|
</select>
|
||||||
|
<select className="field" name="visibility" aria-label="备忘可见范围">
|
||||||
|
<option value="FAMILY_AND_ELDER">可告诉老人</option>
|
||||||
|
<option value="FAMILY_ONLY">仅家人可见</option>
|
||||||
|
</select>
|
||||||
|
<button className="btn primary">保存</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Notice text={notice} />
|
||||||
|
</form>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TaskForm({ deviceUuid }: { deviceUuid: string }) {
|
export function TaskForm({ deviceUuid }: { deviceUuid: string }) {
|
||||||
const router = useRouter(); const [notice, setNotice] = useState("");
|
const router = useRouter();
|
||||||
async function submit(event: FormEvent<HTMLFormElement>) { event.preventDefault(); const form = new FormData(event.currentTarget); try { await api("/api/care-tasks", "POST", { deviceUuid, title: form.get("title"), description: form.get("description"), dueAt: form.get("dueAt") }); event.currentTarget.reset(); setNotice("照护任务已创建。"); router.refresh(); } catch (e) { setNotice(e instanceof Error ? e.message : "创建失败。"); } }
|
const [notice, setNotice] = useState("");
|
||||||
return <form className="card card-pad" onSubmit={submit}><input className="field" name="title" required maxLength={100} placeholder="任务,如:陪爷爷周三复诊" /><input className="field" style={{ marginTop: 8 }} name="description" maxLength={500} placeholder="补充说明(可选)" /><div className="button-row" style={{ marginTop: 8 }}><input className="field" name="dueAt" type="datetime-local" /><button className="btn primary">创建任务</button></div><Notice text={notice} /></form>;
|
|
||||||
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = new FormData(event.currentTarget);
|
||||||
|
try {
|
||||||
|
await api("/api/care-tasks", "POST", {
|
||||||
|
deviceUuid,
|
||||||
|
title: form.get("title"),
|
||||||
|
description: form.get("description"),
|
||||||
|
dueAt: form.get("dueAt"),
|
||||||
|
});
|
||||||
|
event.currentTarget.reset();
|
||||||
|
setNotice("照护任务已创建,等待家人认领。");
|
||||||
|
router.refresh();
|
||||||
|
} catch (error) {
|
||||||
|
setNotice(error instanceof Error ? error.message : "创建失败。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="card card-pad" onSubmit={submit}>
|
||||||
|
<label className="field-label" htmlFor="task-title">新建照护任务</label>
|
||||||
|
<div className="form-stack">
|
||||||
|
<input id="task-title" className="field" name="title" required maxLength={100} placeholder="任务,如:陪爷爷周三复诊" />
|
||||||
|
<input className="field" name="description" maxLength={500} placeholder="补充说明(可选)" />
|
||||||
|
<div className="form-grid action">
|
||||||
|
<input className="field" name="dueAt" type="datetime-local" aria-label="任务期限" />
|
||||||
|
<button className="btn primary">创建任务</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Notice text={notice} />
|
||||||
|
</form>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TaskActions({ taskId, status }: { taskId: string; status: string }) {
|
export function TaskActions({ taskId, status }: { taskId: string; status: string }) {
|
||||||
const router = useRouter(); const [busy, setBusy] = useState(false);
|
const router = useRouter();
|
||||||
async function act(action: string) { setBusy(true); try { let note: string | undefined; if (action === "complete") note = window.prompt("补充完成说明(可留空)") || undefined; await api("/api/care-tasks", "PATCH", { taskId, action, note }); router.refresh(); } finally { setBusy(false); } }
|
const [busy, setBusy] = useState(false);
|
||||||
if (status === "COMPLETED") return <span className="tag">已完成</span>;
|
|
||||||
return <div className="button-row"><button className="btn small" disabled={busy} onClick={() => void act("claim")}>{status === "CLAIMED" ? "接手人" : "我来处理"}</button><button className="btn primary small" disabled={busy} onClick={() => void act("complete")}>完成</button></div>;
|
async function act(action: string) {
|
||||||
|
setBusy(true);
|
||||||
|
try {
|
||||||
|
let note: string | undefined;
|
||||||
|
if (action === "complete") note = window.prompt("补充完成说明(可留空)") || undefined;
|
||||||
|
await api("/api/care-tasks", "PATCH", { taskId, action, note });
|
||||||
|
router.refresh();
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === "COMPLETED") return <span className="tag success" style={{ marginTop: 9 }}>已完成</span>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="button-row">
|
||||||
|
<button className="btn small" disabled={busy} onClick={() => void act("claim")}>{status === "CLAIMED" ? "接手人" : "我来处理"}</button>
|
||||||
|
<button className="btn primary small" disabled={busy} onClick={() => void act("complete")}>完成</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MedicationForm({ deviceUuid }: { deviceUuid: string }) {
|
export function MedicationForm({ deviceUuid }: { deviceUuid: string }) {
|
||||||
const router = useRouter(); const [notice, setNotice] = useState("");
|
const router = useRouter();
|
||||||
async function submit(event: FormEvent<HTMLFormElement>) { event.preventDefault(); const form = new FormData(event.currentTarget); try { await api("/api/medications", "POST", { deviceUuid, name: form.get("name"), dosage: form.get("dosage"), times: form.get("times"), instructions: form.get("instructions"), source: form.get("source"), stockCount: Number(form.get("stockCount") || 0) || undefined }); event.currentTarget.reset(); setNotice("未来 7 天的用药提醒已建立。"); router.refresh(); } catch (e) { setNotice(e instanceof Error ? e.message : "创建失败。"); } }
|
const [notice, setNotice] = useState("");
|
||||||
return <form className="card card-pad" onSubmit={submit}><div className="button-row"><input className="field" name="name" required placeholder="药品名称" /><input className="field" name="dosage" required placeholder="单次用量,如:1片" /></div><div className="button-row" style={{ marginTop: 8 }}><input className="field" name="times" required placeholder="时间,如:08:00,20:00" /><select className="field" name="source"><option value="PRESCRIPTION">医生处方</option><option value="PACKAGE_LABEL">药盒标签</option><option value="FAMILY_ENTRY">家属录入</option></select></div><input className="field" style={{ marginTop: 8 }} name="instructions" placeholder="饭前/饭后及其他注意事项" /><input className="field" style={{ marginTop: 8 }} name="stockCount" type="number" min="0" placeholder="当前库存(可选)" /><button className="btn primary block" style={{ marginTop: 8 }}>建立提醒</button><Notice text={notice} /></form>;
|
|
||||||
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = new FormData(event.currentTarget);
|
||||||
|
try {
|
||||||
|
await api("/api/medications", "POST", {
|
||||||
|
deviceUuid,
|
||||||
|
name: form.get("name"),
|
||||||
|
dosage: form.get("dosage"),
|
||||||
|
times: form.get("times"),
|
||||||
|
instructions: form.get("instructions"),
|
||||||
|
source: form.get("source"),
|
||||||
|
});
|
||||||
|
event.currentTarget.reset();
|
||||||
|
setNotice("未来 7 天的用药提醒已建立。");
|
||||||
|
router.refresh();
|
||||||
|
} catch (error) {
|
||||||
|
setNotice(error instanceof Error ? error.message : "创建失败。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="card card-pad" onSubmit={submit}>
|
||||||
|
<label className="field-label" htmlFor="medication-name">新建用药提醒</label>
|
||||||
|
<div className="form-stack">
|
||||||
|
<div className="form-grid two">
|
||||||
|
<input id="medication-name" className="field" name="name" required placeholder="药品名称" />
|
||||||
|
<input className="field" name="dosage" required placeholder="单次用量,如 1 片" />
|
||||||
|
</div>
|
||||||
|
<div className="form-grid two">
|
||||||
|
<input className="field" name="times" required placeholder="时间,如 08:00, 20:00" />
|
||||||
|
<select className="field" name="source" aria-label="用药信息来源">
|
||||||
|
<option value="PRESCRIPTION">医生处方</option>
|
||||||
|
<option value="PACKAGE_LABEL">药盒标签</option>
|
||||||
|
<option value="FAMILY_ENTRY">家属录入</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<input className="field" name="instructions" placeholder="饭前 / 饭后及其他注意事项(可选)" />
|
||||||
|
<button className="btn primary block">建立未来 7 天提醒</button>
|
||||||
|
</div>
|
||||||
|
<Notice text={notice} />
|
||||||
|
</form>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CheckInButton({ deviceUuid }: { deviceUuid: string }) {
|
export function CheckInButton({ deviceUuid }: { deviceUuid: string }) {
|
||||||
const router = useRouter(); const [notice, setNotice] = useState("");
|
const router = useRouter();
|
||||||
async function create() { try { await api("/api/check-ins", "POST", { deviceUuid, prompt: "家里人想知道您今天是否安好。" }); setNotice("报平安请求已送到长辈终端。"); router.refresh(); } catch (e) { setNotice(e instanceof Error ? e.message : "发送失败。"); } }
|
const [notice, setNotice] = useState("");
|
||||||
return <div><button className="btn primary block" onClick={() => void create()}>请长辈报个平安</button><Notice text={notice} /></div>;
|
|
||||||
|
async function create() {
|
||||||
|
try {
|
||||||
|
await api("/api/check-ins", "POST", { deviceUuid, prompt: "家里人想知道您今天是否安好。" });
|
||||||
|
setNotice("报平安请求已送到长辈终端,回应后会通知全家。");
|
||||||
|
router.refresh();
|
||||||
|
} catch (error) {
|
||||||
|
setNotice(error instanceof Error ? error.message : "发送失败。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="checkin-action">
|
||||||
|
<button className="btn primary block" onClick={() => void create()}><ShieldCheck size={16} strokeWidth={2} />请长辈报个平安</button>
|
||||||
|
<Notice text={notice} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AlertActions({ alertId, status }: { alertId: string; status: string }) {
|
export function AlertActions({ alertId, status }: { alertId: string; status: string }) {
|
||||||
const router = useRouter(); const [busy, setBusy] = useState(false);
|
const router = useRouter();
|
||||||
async function act(action: string) { setBusy(true); try { let note; if (action !== "claim") { note = window.prompt(action === "resolve" ? "请填写处理结果" : "请填写忽略原因") || ""; if (!note && action === "resolve") return; } await api("/api/alerts", "PATCH", { alertId, action, note }); router.refresh(); } finally { setBusy(false); } }
|
const [busy, setBusy] = useState(false);
|
||||||
if (status === "RESOLVED" || status === "DISMISSED") return <span className="tag">已处理</span>;
|
|
||||||
return <div className="button-row"><button className="btn small" disabled={busy} onClick={() => void act("claim")}>我来处理</button><button className="btn primary small" disabled={busy} onClick={() => void act("resolve")}>填写结果</button><button className="btn small" disabled={busy} onClick={() => void act("dismiss")}>误报</button></div>;
|
async function act(action: string) {
|
||||||
|
setBusy(true);
|
||||||
|
try {
|
||||||
|
let note;
|
||||||
|
if (action !== "claim") {
|
||||||
|
note = window.prompt(action === "resolve" ? "请填写处理结果" : "请填写忽略原因") || "";
|
||||||
|
if (!note && action === "resolve") return;
|
||||||
|
}
|
||||||
|
await api("/api/alerts", "PATCH", { alertId, action, note });
|
||||||
|
router.refresh();
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === "RESOLVED" || status === "DISMISSED") return <span className="tag success" style={{ marginTop: 9 }}>已处理</span>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="button-row">
|
||||||
|
<button className="btn small" disabled={busy} onClick={() => void act("claim")}>我来处理</button>
|
||||||
|
<button className="btn primary small" disabled={busy} onClick={() => void act("resolve")}>填写结果</button>
|
||||||
|
<button className="btn small muted" disabled={busy} onClick={() => void act("dismiss")}>误报</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function InviteMemberForm({ deviceUuid }: { deviceUuid: string }) {
|
export function InviteMemberForm({ deviceUuid }: { deviceUuid: string }) {
|
||||||
const [url, setUrl] = useState(""); const [notice, setNotice] = useState("");
|
const [url, setUrl] = useState("");
|
||||||
async function submit(event: FormEvent<HTMLFormElement>) { event.preventDefault(); const form = new FormData(event.currentTarget); try { const result = await api("/api/family-circle/invite", "POST", { deviceUuid, relationLabel: form.get("relationLabel"), role: form.get("role") }); setUrl(result.inviteUrl); setNotice("邀请链接 24 小时内有效。"); } catch (e) { setNotice(e instanceof Error ? e.message : "邀请失败。"); } }
|
const [notice, setNotice] = useState("");
|
||||||
return <form className="card card-pad" onSubmit={submit}><div className="button-row"><input className="field" name="relationLabel" placeholder="关系,如:儿子" /><select className="field" name="role"><option value="CAREGIVER">照护成员</option><option value="CARING">关怀成员</option></select><button className="btn primary">生成邀请</button></div>{url ? <div className="button-row" style={{ marginTop: 8 }}><input className="field" readOnly value={url} /><button type="button" className="btn" onClick={() => void navigator.clipboard.writeText(url)}>复制</button></div> : null}<Notice text={notice} /></form>;
|
const [copied, setCopied] = useState(false);
|
||||||
|
|
||||||
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = new FormData(event.currentTarget);
|
||||||
|
try {
|
||||||
|
const result = await api("/api/family-circle/invite", "POST", {
|
||||||
|
deviceUuid,
|
||||||
|
relationLabel: form.get("relationLabel"),
|
||||||
|
role: form.get("role"),
|
||||||
|
});
|
||||||
|
setUrl(result.inviteUrl);
|
||||||
|
setCopied(false);
|
||||||
|
setNotice("邀请链接 24 小时内有效,发给家人即可加入。");
|
||||||
|
} catch (error) {
|
||||||
|
setNotice(error instanceof Error ? error.message : "邀请失败。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyInvite() {
|
||||||
|
await navigator.clipboard.writeText(url);
|
||||||
|
setCopied(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="card card-pad" onSubmit={submit}>
|
||||||
|
<div className="form-grid two">
|
||||||
|
<span>
|
||||||
|
<label className="field-label" htmlFor="invite-relation">与长辈的关系</label>
|
||||||
|
<input id="invite-relation" className="field" name="relationLabel" placeholder="如:儿子" />
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<label className="field-label" htmlFor="invite-role">成员角色</label>
|
||||||
|
<select id="invite-role" className="field" name="role">
|
||||||
|
<option value="CAREGIVER">照护成员</option>
|
||||||
|
<option value="CARING">关怀成员</option>
|
||||||
|
</select>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<button className="btn dark block" style={{ marginTop: 10 }}>生成邀请链接</button>
|
||||||
|
{url ? (
|
||||||
|
<div className="form-grid" style={{ gridTemplateColumns: "minmax(0, 1fr) 68px", marginTop: 10 }}>
|
||||||
|
<input className="field" readOnly value={url} style={{ height: 40, background: "var(--surface-soft)", color: "var(--muted)", fontSize: 12 }} />
|
||||||
|
<button type="button" className="btn" style={{ minHeight: 40, padding: 0 }} onClick={() => void copyInvite()}>{copied ? "已复制" : "复制"}</button>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<Notice text={notice} />
|
||||||
|
</form>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function JoinFamilyButton({ token }: { token: string }) {
|
export function JoinFamilyButton({ token }: { token: string }) {
|
||||||
const router = useRouter(); const [notice, setNotice] = useState("");
|
const router = useRouter();
|
||||||
async function join() { try { await api("/api/family-circle/join", "POST", { token }); setNotice("已加入家庭守护圈,正在打开家庭页……"); router.push("/family"); router.refresh(); } catch (e) { setNotice(e instanceof Error ? e.message : "加入失败。"); } }
|
const [notice, setNotice] = useState("");
|
||||||
return <div><button className="btn primary block" onClick={() => void join()}>接受邀请并加入</button><Notice text={notice} /></div>;
|
|
||||||
|
async function join() {
|
||||||
|
try {
|
||||||
|
await api("/api/family-circle/join", "POST", { token });
|
||||||
|
setNotice("已加入家庭守护圈,正在打开家庭页……");
|
||||||
|
router.push("/family");
|
||||||
|
router.refresh();
|
||||||
|
} catch (error) {
|
||||||
|
setNotice(error instanceof Error ? error.message : "加入失败。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button className="btn primary block" onClick={() => void join()}>接受邀请并加入</button>
|
||||||
|
<Notice text={notice} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,8 @@ import Link from "next/link";
|
|||||||
import { ChevronLeft, HeartHandshake, House, ShieldCheck, Stethoscope, UserRound } from "lucide-react";
|
import { ChevronLeft, HeartHandshake, House, ShieldCheck, Stethoscope, UserRound } from "lucide-react";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
|
|
||||||
|
import { getCaregiverUnreadIncomingCount } from "@/lib/caregiver-panel";
|
||||||
|
|
||||||
const navigationItems = [
|
const navigationItems = [
|
||||||
{ href: "/guard", label: "守护", icon: ShieldCheck },
|
{ href: "/guard", label: "守护", icon: ShieldCheck },
|
||||||
{ href: "/family", label: "家庭", icon: House },
|
{ href: "/family", label: "家庭", icon: House },
|
||||||
@ -19,6 +21,7 @@ type PanelShellProps = {
|
|||||||
title: string;
|
title: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
caregiverLabel: string;
|
caregiverLabel: string;
|
||||||
|
caregiverId?: string;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
actions?: ReactNode;
|
actions?: ReactNode;
|
||||||
backHref?: string;
|
backHref?: string;
|
||||||
@ -26,18 +29,22 @@ type PanelShellProps = {
|
|||||||
unreadCount?: number;
|
unreadCount?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function PanelShell({
|
export async function PanelShell({
|
||||||
currentPath,
|
currentPath,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
caregiverLabel,
|
caregiverLabel,
|
||||||
|
caregiverId,
|
||||||
children,
|
children,
|
||||||
actions,
|
actions,
|
||||||
backHref,
|
backHref,
|
||||||
showTabs = !backHref,
|
showTabs = !backHref,
|
||||||
unreadCount = 0,
|
unreadCount,
|
||||||
}: PanelShellProps) {
|
}: PanelShellProps) {
|
||||||
const initial = caregiverLabel.trim().slice(-1) || "安";
|
const initial = caregiverLabel.trim().slice(-1) || "安";
|
||||||
|
const resolvedUnreadCount = unreadCount ?? (showTabs && caregiverId
|
||||||
|
? await getCaregiverUnreadIncomingCount(caregiverId)
|
||||||
|
: 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="app-frame">
|
<main className="app-frame">
|
||||||
@ -76,7 +83,7 @@ export function PanelShell({
|
|||||||
<Link key={item.href} href={item.href} className={`nav-item${active ? " active" : ""}`}>
|
<Link key={item.href} href={item.href} className={`nav-item${active ? " active" : ""}`}>
|
||||||
<Icon size={22} strokeWidth={1.8} />
|
<Icon size={22} strokeWidth={1.8} />
|
||||||
<span>{item.label}</span>
|
<span>{item.label}</span>
|
||||||
{item.href === "/family" && unreadCount > 0 ? <span className="nav-badge">{unreadCount}</span> : null}
|
{item.href === "/family" && resolvedUnreadCount > 0 ? <span className="nav-badge">{resolvedUnreadCount}</span> : null}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@ -1,43 +1,29 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { Bell, ChevronRight, PenLine, Smartphone } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
const PWA_INSTALL_MARKER_KEY = "dh-pwa-installed";
|
const PWA_INSTALL_MARKER_KEY = "dh-pwa-installed";
|
||||||
|
|
||||||
type BeforeInstallPromptEvent = Event & {
|
type BeforeInstallPromptEvent = Event & {
|
||||||
prompt: () => Promise<void>;
|
prompt: () => Promise<void>;
|
||||||
userChoice: Promise<{
|
userChoice: Promise<{ outcome: "accepted" | "dismissed"; platform: string }>;
|
||||||
outcome: "accepted" | "dismissed";
|
|
||||||
platform: string;
|
|
||||||
}>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type NotificationState =
|
type NotificationState = "checking" | "idle" | "pending" | "enabled" | "blocked" | "unsupported";
|
||||||
| "checking"
|
|
||||||
| "idle"
|
|
||||||
| "pending"
|
|
||||||
| "enabled"
|
|
||||||
| "blocked"
|
|
||||||
| "unsupported";
|
|
||||||
|
|
||||||
function urlBase64ToUint8Array(base64String: string) {
|
function urlBase64ToUint8Array(base64String: string) {
|
||||||
const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
|
const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
|
||||||
const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
|
const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
|
||||||
const rawData = window.atob(base64);
|
const rawData = window.atob(base64);
|
||||||
const outputArray = new Uint8Array(rawData.length);
|
const outputArray = new Uint8Array(rawData.length);
|
||||||
|
for (let index = 0; index < rawData.length; index += 1) outputArray[index] = rawData.charCodeAt(index);
|
||||||
for (let index = 0; index < rawData.length; index += 1) {
|
|
||||||
outputArray[index] = rawData.charCodeAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
return outputArray;
|
return outputArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isStandaloneDisplayMode() {
|
function isStandaloneDisplayMode() {
|
||||||
const navigatorWithStandalone = navigator as Navigator & {
|
const navigatorWithStandalone = navigator as Navigator & { standalone?: boolean };
|
||||||
standalone?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
window.matchMedia("(display-mode: standalone)").matches ||
|
window.matchMedia("(display-mode: standalone)").matches ||
|
||||||
window.matchMedia("(display-mode: fullscreen)").matches ||
|
window.matchMedia("(display-mode: fullscreen)").matches ||
|
||||||
@ -63,99 +49,35 @@ function writeInstalledMarker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PwaControls() {
|
export function PwaControls({ deviceCount }: { deviceCount: number }) {
|
||||||
const vapidPublicKey = process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY || "";
|
const vapidPublicKey = process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY || "";
|
||||||
const [installPromptEvent, setInstallPromptEvent] =
|
const [installPromptEvent, setInstallPromptEvent] = useState<BeforeInstallPromptEvent | null>(null);
|
||||||
useState<BeforeInstallPromptEvent | null>(null);
|
const [isInstalled, setIsInstalled] = useState(false);
|
||||||
const [installing, setInstalling] = useState(false);
|
const [installing, setInstalling] = useState(false);
|
||||||
const [isStandalone, setIsStandalone] = useState(false);
|
const [notificationState, setNotificationState] = useState<NotificationState>("checking");
|
||||||
const [hasInstalledHint, setHasInstalledHint] = useState(false);
|
|
||||||
const [notificationState, setNotificationState] =
|
|
||||||
useState<NotificationState>("checking");
|
|
||||||
const [notice, setNotice] = useState<string | null>(null);
|
const [notice, setNotice] = useState<string | null>(null);
|
||||||
const isInstalled = hasInstalledHint || isStandalone;
|
|
||||||
const notificationLabel =
|
|
||||||
notificationState === "enabled"
|
|
||||||
? "消息提醒已开启"
|
|
||||||
: notificationState === "blocked"
|
|
||||||
? "通知权限已被拒绝"
|
|
||||||
: "消息提醒未开启";
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let active = true;
|
let active = true;
|
||||||
let delayedSyncTimer: number | null = null;
|
|
||||||
|
|
||||||
function syncInstallState() {
|
function syncInstallState() {
|
||||||
const standalone = isStandaloneDisplayMode();
|
const standalone = isStandaloneDisplayMode();
|
||||||
const installed = standalone || readInstalledMarker();
|
if (standalone) writeInstalledMarker();
|
||||||
|
if (active) setIsInstalled(standalone || readInstalledMarker());
|
||||||
if (standalone) {
|
|
||||||
writeInstalledMarker();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!active) {
|
|
||||||
return standalone;
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsStandalone(standalone);
|
|
||||||
setHasInstalledHint(installed);
|
|
||||||
|
|
||||||
return standalone;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleBeforeInstallPrompt(event: Event) {
|
function handleBeforeInstallPrompt(event: Event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (!active) {
|
if (active) setInstallPromptEvent(event as BeforeInstallPromptEvent);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setInstallPromptEvent(event as BeforeInstallPromptEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAppInstalled() {
|
function handleAppInstalled() {
|
||||||
writeInstalledMarker();
|
writeInstalledMarker();
|
||||||
|
if (active) setIsInstalled(true);
|
||||||
if (!active) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setHasInstalledHint(true);
|
async function bootstrapNotifications() {
|
||||||
}
|
if (!("serviceWorker" in navigator) || !("PushManager" in window) || typeof Notification === "undefined") {
|
||||||
|
|
||||||
function handleVisibilityChange() {
|
|
||||||
if (!document.hidden) {
|
|
||||||
syncInstallState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handlePageShow() {
|
|
||||||
syncInstallState();
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleFocus() {
|
|
||||||
syncInstallState();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function syncExistingSubscription(subscription: PushSubscription) {
|
|
||||||
await fetch("/api/push/subscribe", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
subscription: subscription.toJSON(),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function bootstrap() {
|
|
||||||
syncInstallState();
|
|
||||||
|
|
||||||
if (
|
|
||||||
!("serviceWorker" in navigator) ||
|
|
||||||
!("PushManager" in window) ||
|
|
||||||
typeof Notification === "undefined"
|
|
||||||
) {
|
|
||||||
setNotificationState("unsupported");
|
setNotificationState("unsupported");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -163,103 +85,74 @@ export function PwaControls() {
|
|||||||
try {
|
try {
|
||||||
await navigator.serviceWorker.register("/sw.js");
|
await navigator.serviceWorker.register("/sw.js");
|
||||||
const registration = await navigator.serviceWorker.ready;
|
const registration = await navigator.serviceWorker.ready;
|
||||||
const existingSubscription = await registration.pushManager.getSubscription();
|
const subscription = await registration.pushManager.getSubscription();
|
||||||
|
if (!active) return;
|
||||||
|
|
||||||
if (!active) {
|
if (subscription) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingSubscription) {
|
|
||||||
if (vapidPublicKey) {
|
if (vapidPublicKey) {
|
||||||
await syncExistingSubscription(existingSubscription);
|
await fetch("/api/push/subscribe", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ subscription: subscription.toJSON() }),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setNotificationState("enabled");
|
setNotificationState("enabled");
|
||||||
return;
|
} else {
|
||||||
|
setNotificationState(Notification.permission === "denied" ? "blocked" : "idle");
|
||||||
}
|
}
|
||||||
|
|
||||||
setNotificationState(
|
|
||||||
Notification.permission === "denied" ? "blocked" : "idle",
|
|
||||||
);
|
|
||||||
} catch {
|
} catch {
|
||||||
if (active) {
|
if (active) setNotificationState("unsupported");
|
||||||
setNotificationState("unsupported");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syncInstallState();
|
||||||
window.addEventListener("beforeinstallprompt", handleBeforeInstallPrompt);
|
window.addEventListener("beforeinstallprompt", handleBeforeInstallPrompt);
|
||||||
window.addEventListener("appinstalled", handleAppInstalled);
|
window.addEventListener("appinstalled", handleAppInstalled);
|
||||||
window.addEventListener("pageshow", handlePageShow);
|
window.addEventListener("focus", syncInstallState);
|
||||||
window.addEventListener("focus", handleFocus);
|
void bootstrapNotifications();
|
||||||
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
||||||
|
|
||||||
void bootstrap();
|
|
||||||
delayedSyncTimer = window.setTimeout(() => {
|
|
||||||
syncInstallState();
|
|
||||||
}, 350);
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
active = false;
|
active = false;
|
||||||
window.removeEventListener("beforeinstallprompt", handleBeforeInstallPrompt);
|
window.removeEventListener("beforeinstallprompt", handleBeforeInstallPrompt);
|
||||||
window.removeEventListener("appinstalled", handleAppInstalled);
|
window.removeEventListener("appinstalled", handleAppInstalled);
|
||||||
window.removeEventListener("pageshow", handlePageShow);
|
window.removeEventListener("focus", syncInstallState);
|
||||||
window.removeEventListener("focus", handleFocus);
|
|
||||||
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
||||||
|
|
||||||
if (delayedSyncTimer) {
|
|
||||||
window.clearTimeout(delayedSyncTimer);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}, [vapidPublicKey]);
|
}, [vapidPublicKey]);
|
||||||
|
|
||||||
async function enableNotifications() {
|
async function enableNotifications() {
|
||||||
if (!vapidPublicKey) {
|
if (!vapidPublicKey) {
|
||||||
setNotice("当前还没有配置推送服务,先将应用安装到桌面即可。\n");
|
setNotice("当前还没有配置推送服务。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setNotificationState("pending");
|
setNotificationState("pending");
|
||||||
setNotice(null);
|
setNotice(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const permission = await Notification.requestPermission();
|
const permission = await Notification.requestPermission();
|
||||||
|
|
||||||
if (permission !== "granted") {
|
if (permission !== "granted") {
|
||||||
setNotificationState(permission === "denied" ? "blocked" : "idle");
|
setNotificationState(permission === "denied" ? "blocked" : "idle");
|
||||||
setNotice(
|
setNotice(permission === "denied" ? "浏览器已拒绝通知权限,请在系统设置中重新开启。" : "这次没有开启通知,稍后仍可再次尝试。");
|
||||||
permission === "denied"
|
|
||||||
? "浏览器已经拒绝消息提醒,请在系统设置里重新打开通知权限。\n"
|
|
||||||
: "这次没有打开通知权限,稍后仍可再次开启。\n",
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const registration = await navigator.serviceWorker.ready;
|
const registration = await navigator.serviceWorker.ready;
|
||||||
let subscription = await registration.pushManager.getSubscription();
|
let subscription = await registration.pushManager.getSubscription();
|
||||||
|
|
||||||
if (!subscription) {
|
if (!subscription) {
|
||||||
subscription = await registration.pushManager.subscribe({
|
subscription = await registration.pushManager.subscribe({
|
||||||
userVisibleOnly: true,
|
userVisibleOnly: true,
|
||||||
applicationServerKey: urlBase64ToUint8Array(vapidPublicKey),
|
applicationServerKey: urlBase64ToUint8Array(vapidPublicKey),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetch("/api/push/subscribe", {
|
await fetch("/api/push/subscribe", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { "Content-Type": "application/json" },
|
||||||
"Content-Type": "application/json",
|
body: JSON.stringify({ subscription: subscription.toJSON() }),
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
subscription: subscription.toJSON(),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setNotificationState("enabled");
|
setNotificationState("enabled");
|
||||||
setNotice("已开启消息提醒,长辈的新留言会直接推送到您的设备。\n");
|
setNotice("已开启紧急提醒推送。");
|
||||||
} catch {
|
} catch {
|
||||||
setNotificationState("idle");
|
setNotificationState("idle");
|
||||||
setNotice("打开消息提醒失败,请稍后再试。\n");
|
setNotice("打开消息提醒失败,请稍后再试。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,135 +160,89 @@ export function PwaControls() {
|
|||||||
try {
|
try {
|
||||||
const registration = await navigator.serviceWorker.ready;
|
const registration = await navigator.serviceWorker.ready;
|
||||||
const subscription = await registration.pushManager.getSubscription();
|
const subscription = await registration.pushManager.getSubscription();
|
||||||
|
|
||||||
if (subscription) {
|
if (subscription) {
|
||||||
await fetch("/api/push/unsubscribe", {
|
await fetch("/api/push/unsubscribe", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { "Content-Type": "application/json" },
|
||||||
"Content-Type": "application/json",
|
body: JSON.stringify({ endpoint: subscription.endpoint }),
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
endpoint: subscription.endpoint,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
await subscription.unsubscribe();
|
await subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
setNotificationState("idle");
|
setNotificationState("idle");
|
||||||
setNotice("这台设备的消息提醒已关闭。\n");
|
setNotice("这台设备的紧急提醒已关闭。");
|
||||||
} catch {
|
} catch {
|
||||||
setNotice("关闭消息提醒失败,请稍后再试。\n");
|
setNotice("关闭消息提醒失败,请稍后再试。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installApp() {
|
async function installApp() {
|
||||||
|
if (isInstalled) {
|
||||||
|
setNotice("安智伴已经添加到这台设备的主屏幕。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!installPromptEvent) {
|
if (!installPromptEvent) {
|
||||||
setNotice("如果浏览器没有弹出安装按钮,可以从菜单里选择“安装应用”或“添加到主屏幕”。\n");
|
setNotice("请从浏览器菜单中选择“安装应用”或“添加到主屏幕”。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setInstalling(true);
|
setInstalling(true);
|
||||||
setNotice(null);
|
setNotice(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await installPromptEvent.prompt();
|
await installPromptEvent.prompt();
|
||||||
const choice = await installPromptEvent.userChoice;
|
const choice = await installPromptEvent.userChoice;
|
||||||
|
|
||||||
if (choice.outcome === "accepted") {
|
if (choice.outcome === "accepted") {
|
||||||
|
writeInstalledMarker();
|
||||||
setInstallPromptEvent(null);
|
setInstallPromptEvent(null);
|
||||||
setHasInstalledHint(true);
|
setIsInstalled(true);
|
||||||
setNotice("安装提示已经确认,完成后就能像应用一样直接打开。\n");
|
setNotice("已确认添加到主屏幕。");
|
||||||
} else {
|
|
||||||
setNotice("这次先关闭了安装提示,之后仍可从浏览器菜单安装。\n");
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setInstalling(false);
|
setInstalling(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pushOn = notificationState === "enabled";
|
||||||
|
const toggleDisabled = notificationState === "checking" || notificationState === "pending" || notificationState === "unsupported";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="rounded-[28px] border border-white/80 bg-white/88 p-5 shadow-[0_22px_55px_rgba(53,84,141,0.12)]">
|
<section className="card">
|
||||||
<p className="text-sm font-medium tracking-[0.18em] text-[var(--copper)] uppercase">
|
<div className="settings-row">
|
||||||
{isInstalled ? "桌面版" : "快捷设置"}
|
<span className="settings-icon"><Bell size={17} strokeWidth={1.8} /></span>
|
||||||
</p>
|
<span className="row-main">
|
||||||
<h2 className="mt-2 font-[family-name:var(--font-display)] text-2xl text-[var(--ink)]">
|
<span className="row-title">紧急提醒推送</span>
|
||||||
{isInstalled
|
<span className="row-meta">红色风险提醒将第一时间通知本机</span>
|
||||||
? isStandalone
|
|
||||||
? "已从桌面版打开"
|
|
||||||
: "这台设备已添加到主屏幕"
|
|
||||||
: "安装到桌面,随时收到长辈的消息"}
|
|
||||||
</h2>
|
|
||||||
<p className="mt-3 text-sm leading-7 text-[var(--muted)]">
|
|
||||||
{isInstalled
|
|
||||||
? notificationState === "enabled"
|
|
||||||
? "新留言会直接推送到这台设备。"
|
|
||||||
: "如需新留言提醒,可在下方开启通知。"
|
|
||||||
: "安装后打开更快,开启提醒后,长辈每次留言都能立刻收到通知。"}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="mt-4 flex flex-wrap gap-3 text-sm text-[var(--muted)]">
|
|
||||||
{isInstalled ? (
|
|
||||||
<span className="rounded-full border border-[var(--line)] bg-[var(--paper-soft)] px-4 py-2">
|
|
||||||
{isStandalone ? "桌面版运行中" : "已添加到主屏幕"}
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<span className="rounded-full border border-[var(--line)] bg-[var(--paper-soft)] px-4 py-2">
|
|
||||||
{isStandalone ? "当前正以桌面应用方式运行" : "当前正以浏览器方式运行"}
|
|
||||||
</span>
|
|
||||||
<span className="rounded-full border border-[var(--line)] bg-[var(--paper-soft)] px-4 py-2">
|
|
||||||
{hasInstalledHint ? "这台设备已有主屏幕安装记录" : "暂未检测到主屏幕安装记录"}
|
|
||||||
</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<span className="rounded-full border border-[var(--line)] bg-[var(--paper-soft)] px-4 py-2">
|
|
||||||
{notificationLabel}
|
|
||||||
</span>
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`toggle${pushOn ? " on" : ""}`}
|
||||||
|
disabled={toggleDisabled}
|
||||||
|
onClick={() => void (pushOn ? disableNotifications() : enableNotifications())}
|
||||||
|
aria-label={pushOn ? "关闭紧急提醒推送" : "开启紧急提醒推送"}
|
||||||
|
aria-pressed={pushOn}
|
||||||
|
>
|
||||||
|
<span className="toggle-knob" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-5 flex flex-wrap gap-3">
|
<Link className="settings-row" href="/devices">
|
||||||
{!isInstalled ? (
|
<span className="settings-icon olive"><Smartphone size={17} strokeWidth={1.8} /></span>
|
||||||
<button
|
<span className="row-main">
|
||||||
type="button"
|
<span className="row-title">设备管理</span>
|
||||||
onClick={() => {
|
<span className="row-meta">{deviceCount > 0 ? `已连接 ${deviceCount} 台长辈设备` : "绑定长辈的安智伴设备"}</span>
|
||||||
void installApp();
|
</span>
|
||||||
}}
|
<ChevronRight className="chevron" size={16} strokeWidth={2} />
|
||||||
disabled={installing || isStandalone}
|
</Link>
|
||||||
className="inline-flex h-12 items-center justify-center rounded-full bg-[var(--ink)] px-5 text-sm font-semibold text-white transition hover:bg-[var(--ink-soft)] disabled:cursor-not-allowed disabled:opacity-60"
|
|
||||||
>
|
|
||||||
{installing ? "正在呼起安装" : "安装到桌面"}
|
|
||||||
</button>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{notificationState === "enabled" ? (
|
<button type="button" className="settings-row" onClick={() => void installApp()} disabled={installing}>
|
||||||
<button
|
<span className="settings-icon muted"><PenLine size={17} strokeWidth={1.8} /></span>
|
||||||
type="button"
|
<span className="row-main">
|
||||||
onClick={() => {
|
<span className="row-title">添加到主屏幕</span>
|
||||||
void disableNotifications();
|
<span className="row-meta">{isInstalled ? "已添加,可像 App 一样直接打开" : installing ? "正在呼起安装" : "像 App 一样从桌面直接打开"}</span>
|
||||||
}}
|
</span>
|
||||||
className="inline-flex h-12 items-center justify-center rounded-full border border-[var(--line)] bg-white px-5 text-sm font-semibold text-[var(--ink)] transition hover:bg-[var(--paper-soft)]"
|
<ChevronRight className="chevron" size={16} strokeWidth={2} />
|
||||||
>
|
|
||||||
关闭消息提醒
|
|
||||||
</button>
|
</button>
|
||||||
) : (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => {
|
|
||||||
void enableNotifications();
|
|
||||||
}}
|
|
||||||
disabled={notificationState === "pending" || notificationState === "unsupported"}
|
|
||||||
className="inline-flex h-12 items-center justify-center rounded-full bg-[var(--olive)] px-5 text-sm font-semibold text-white transition hover:bg-[var(--olive-deep)] disabled:cursor-not-allowed disabled:opacity-60"
|
|
||||||
>
|
|
||||||
{notificationState === "pending" ? "正在开启提醒" : "打开消息提醒"}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{notice ? (
|
{notice ? <p className="form-notice" style={{ margin: 0, padding: "0 16px 13px" }}>{notice}</p> : null}
|
||||||
<p className="mt-4 whitespace-pre-line text-sm leading-7 text-[var(--muted)]">
|
|
||||||
{notice}
|
|
||||||
</p>
|
|
||||||
) : null}
|
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -123,6 +123,20 @@ export async function getCaregiverOverview(caregiverId: string) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCaregiverUnreadIncomingCount(caregiverId: string) {
|
||||||
|
return prisma.familyMessage.count({
|
||||||
|
where: {
|
||||||
|
direction: MessageDirection.ELDER_TO_FAMILY,
|
||||||
|
elderDevice: {
|
||||||
|
bindings: {
|
||||||
|
some: { caregiverId },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
readAt: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function getCaregiverMessages(caregiverId: string) {
|
export async function getCaregiverMessages(caregiverId: string) {
|
||||||
const [messages, unreadIncomingCount, unreadOutgoingCount] = await prisma.$transaction([
|
const [messages, unreadIncomingCount, unreadOutgoingCount] = await prisma.$transaction([
|
||||||
prisma.familyMessage.findMany({
|
prisma.familyMessage.findMany({
|
||||||
@ -141,17 +155,7 @@ export async function getCaregiverMessages(caregiverId: string) {
|
|||||||
orderBy: [{ createdAt: "desc" }, { publicId: "desc" }],
|
orderBy: [{ createdAt: "desc" }, { publicId: "desc" }],
|
||||||
take: 120,
|
take: 120,
|
||||||
}),
|
}),
|
||||||
prisma.familyMessage.count({
|
getCaregiverUnreadIncomingCount(caregiverId),
|
||||||
where: {
|
|
||||||
direction: MessageDirection.ELDER_TO_FAMILY,
|
|
||||||
elderDevice: {
|
|
||||||
bindings: {
|
|
||||||
some: { caregiverId },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
readAt: null,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
prisma.familyMessage.count({
|
prisma.familyMessage.count({
|
||||||
where: {
|
where: {
|
||||||
direction: MessageDirection.FAMILY_TO_ELDER,
|
direction: MessageDirection.FAMILY_TO_ELDER,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user