feat: add system configuration platform
This commit is contained in:
@@ -1,21 +1,234 @@
|
||||
import { BedDouble } from "lucide-react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { BedDouble, DoorOpen, History, Wrench } from "lucide-react";
|
||||
|
||||
import { ModulePage } from "@/modules/shared/components/ModulePage";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { getCurrentAuthContext } from "@/modules/core/server/auth";
|
||||
import { hasPermission } from "@/modules/core/server/permissions";
|
||||
import { readData } from "@/modules/core/server/store";
|
||||
|
||||
export default async function BedsPage(): Promise<React.ReactElement> {
|
||||
const context = await getCurrentAuthContext();
|
||||
if (!context) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
if (!hasPermission(context.permissions, "facility:read")) {
|
||||
redirect("/app/dashboard");
|
||||
}
|
||||
|
||||
const data = await readData();
|
||||
const organizationId = context.organization?.id;
|
||||
const rooms = organizationId ? data.rooms.filter((room) => room.organizationId === organizationId) : data.rooms;
|
||||
const beds = organizationId ? data.beds.filter((bed) => bed.organizationId === organizationId) : data.beds;
|
||||
const admissions = organizationId
|
||||
? data.admissions.filter((admission) => admission.organizationId === organizationId)
|
||||
: data.admissions;
|
||||
|
||||
const occupiedBeds = beds.filter((bed) => bed.status === "occupied").length;
|
||||
const maintenanceBeds = beds.filter((bed) => bed.status === "maintenance").length;
|
||||
const occupancyRate = beds.length > 0 ? Math.round((occupiedBeds / beds.length) * 100) : 0;
|
||||
|
||||
export default function BedsPage(): React.ReactElement {
|
||||
return (
|
||||
<ModulePage
|
||||
title="床位房间"
|
||||
eyebrow="房间与床位状态"
|
||||
description="维护楼栋、楼层、房间、床位编号和空闲、占用、维修状态流转。"
|
||||
icon={BedDouble}
|
||||
phase="一期"
|
||||
metrics={[
|
||||
{ label: "总床位", value: "154", detail: "护理区 96 张,康复区 58 张" },
|
||||
{ label: "占用率", value: "82%", detail: "低于阈值时支持入住调度" },
|
||||
{ label: "维修床位", value: "3", detail: "维修完成后恢复可用" },
|
||||
]}
|
||||
workflows={["维护楼栋与房间", "新增床位编号", "入住时占用床位", "退住或维修后释放床位"]}
|
||||
/>
|
||||
<div className="mx-auto flex w-full max-w-7xl flex-col gap-5">
|
||||
<section className="flex flex-col gap-4 border-b pb-5 lg:flex-row lg:items-end lg:justify-between">
|
||||
<div>
|
||||
<Badge variant="success">Facility + Admission</Badge>
|
||||
<h1 className="mt-3 text-3xl font-semibold tracking-normal">床位房间</h1>
|
||||
<p className="mt-2 text-sm text-muted-foreground">房间主数据、床位状态、当前占用和入住历史。</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||
<div>
|
||||
<CardDescription>房间</CardDescription>
|
||||
<CardTitle className="mt-2 text-3xl">{rooms.length}</CardTitle>
|
||||
</div>
|
||||
<DoorOpen className="size-5 text-primary" aria-hidden="true" />
|
||||
</CardHeader>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||
<div>
|
||||
<CardDescription>床位</CardDescription>
|
||||
<CardTitle className="mt-2 text-3xl">{beds.length}</CardTitle>
|
||||
</div>
|
||||
<BedDouble className="size-5 text-primary" aria-hidden="true" />
|
||||
</CardHeader>
|
||||
<CardContent className="pt-0">
|
||||
<p className="text-sm text-muted-foreground">占用率 {occupancyRate}%</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className={maintenanceBeds > 0 ? "border-amber-200 bg-amber-50/70" : undefined}>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||
<div>
|
||||
<CardDescription className={maintenanceBeds > 0 ? "text-amber-700" : undefined}>维修床位</CardDescription>
|
||||
<CardTitle className={maintenanceBeds > 0 ? "mt-2 text-3xl text-amber-700" : "mt-2 text-3xl"}>
|
||||
{maintenanceBeds}
|
||||
</CardTitle>
|
||||
</div>
|
||||
<Wrench className={maintenanceBeds > 0 ? "size-5 text-amber-700" : "size-5 text-primary"} aria-hidden="true" />
|
||||
</CardHeader>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||
<div>
|
||||
<CardDescription>入住历史</CardDescription>
|
||||
<CardTitle className="mt-2 text-3xl">{admissions.length}</CardTitle>
|
||||
</div>
|
||||
<History className="size-5 text-primary" aria-hidden="true" />
|
||||
</CardHeader>
|
||||
</Card>
|
||||
</section>
|
||||
|
||||
<section className="grid gap-4 xl:grid-cols-[0.9fr_1.1fr]">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>房间台账</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="overflow-x-auto rounded-md border">
|
||||
<table className="w-full min-w-[620px] text-sm">
|
||||
<thead className="bg-secondary text-left text-xs text-muted-foreground">
|
||||
<tr>
|
||||
<th className="px-4 py-3 font-medium">房间</th>
|
||||
<th className="px-4 py-3 font-medium">编号</th>
|
||||
<th className="px-4 py-3 font-medium">容量</th>
|
||||
<th className="px-4 py-3 font-medium">床位</th>
|
||||
<th className="px-4 py-3 font-medium">状态</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y bg-card">
|
||||
{rooms.map((room) => (
|
||||
<tr key={room.id}>
|
||||
<td className="px-4 py-3 font-medium">{room.name}</td>
|
||||
<td className="px-4 py-3 text-muted-foreground">{room.code}</td>
|
||||
<td className="px-4 py-3">{room.capacity}</td>
|
||||
<td className="px-4 py-3">
|
||||
{room.occupiedBedCount}/{room.bedCount}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<Badge variant={room.status === "active" ? "success" : "danger"}>{room.status}</Badge>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{rooms.length === 0 ? (
|
||||
<tr>
|
||||
<td className="px-4 py-8 text-center text-muted-foreground" colSpan={5}>
|
||||
暂无房间,请通过 /api/facilities/rooms 创建
|
||||
</td>
|
||||
</tr>
|
||||
) : null}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>床位状态</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="overflow-x-auto rounded-md border">
|
||||
<table className="w-full min-w-[700px] text-sm">
|
||||
<thead className="bg-secondary text-left text-xs text-muted-foreground">
|
||||
<tr>
|
||||
<th className="px-4 py-3 font-medium">房间</th>
|
||||
<th className="px-4 py-3 font-medium">床位</th>
|
||||
<th className="px-4 py-3 font-medium">状态</th>
|
||||
<th className="px-4 py-3 font-medium">当前老人</th>
|
||||
<th className="px-4 py-3 font-medium">备注</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y bg-card">
|
||||
{beds.map((bed) => (
|
||||
<tr key={bed.id}>
|
||||
<td className="px-4 py-3">{bed.roomName}</td>
|
||||
<td className="px-4 py-3 font-medium">{bed.code}</td>
|
||||
<td className="px-4 py-3">
|
||||
<Badge
|
||||
variant={
|
||||
bed.status === "available"
|
||||
? "success"
|
||||
: bed.status === "occupied"
|
||||
? "secondary"
|
||||
: bed.status === "maintenance"
|
||||
? "warning"
|
||||
: "danger"
|
||||
}
|
||||
>
|
||||
{bed.status}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="px-4 py-3">{bed.currentElderName ?? "-"}</td>
|
||||
<td className="px-4 py-3 text-muted-foreground">{bed.notes || "-"}</td>
|
||||
</tr>
|
||||
))}
|
||||
{beds.length === 0 ? (
|
||||
<tr>
|
||||
<td className="px-4 py-8 text-center text-muted-foreground" colSpan={5}>
|
||||
暂无床位,请通过 /api/facilities/beds 创建
|
||||
</td>
|
||||
</tr>
|
||||
) : null}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</section>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>入住与换床历史</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="overflow-x-auto rounded-md border">
|
||||
<table className="w-full min-w-[820px] text-sm">
|
||||
<thead className="bg-secondary text-left text-xs text-muted-foreground">
|
||||
<tr>
|
||||
<th className="px-4 py-3 font-medium">老人</th>
|
||||
<th className="px-4 py-3 font-medium">床位</th>
|
||||
<th className="px-4 py-3 font-medium">状态</th>
|
||||
<th className="px-4 py-3 font-medium">入住时间</th>
|
||||
<th className="px-4 py-3 font-medium">结束时间</th>
|
||||
<th className="px-4 py-3 font-medium">备注</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y bg-card">
|
||||
{admissions.map((admission) => (
|
||||
<tr key={admission.id}>
|
||||
<td className="px-4 py-3 font-medium">{admission.elderName}</td>
|
||||
<td className="px-4 py-3">
|
||||
{admission.roomName}-{admission.bedCode}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<Badge variant={admission.status === "active" ? "success" : "secondary"}>{admission.status}</Badge>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-muted-foreground">
|
||||
{new Date(admission.admittedAt).toLocaleString("zh-CN")}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-muted-foreground">
|
||||
{admission.dischargedAt ? new Date(admission.dischargedAt).toLocaleString("zh-CN") : "-"}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-muted-foreground">{admission.notes || "-"}</td>
|
||||
</tr>
|
||||
))}
|
||||
{admissions.length === 0 ? (
|
||||
<tr>
|
||||
<td className="px-4 py-8 text-center text-muted-foreground" colSpan={6}>
|
||||
暂无入住历史
|
||||
</td>
|
||||
</tr>
|
||||
) : null}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { redirect } from "next/navigation";
|
||||
import { getBootstrapState, getCurrentAuthContext } from "@/modules/core/server/auth";
|
||||
import { AppShell } from "@/modules/shared/components/AppShell";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
type AppLayoutProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { getCurrentAuthContext, toPublicAccount } from "@/modules/core/server/auth";
|
||||
import { hasPermission, ROLE_DEFINITIONS } from "@/modules/core/server/permissions";
|
||||
import { getRoleDefinitions, hasPermission } from "@/modules/core/server/permissions";
|
||||
import { readData } from "@/modules/core/server/store";
|
||||
import { SettingsOverview } from "@/modules/settings/components/SettingsOverview";
|
||||
|
||||
@@ -11,16 +11,20 @@ export default async function SettingsPage(): Promise<React.ReactElement> {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
if (!hasPermission(context.account.role, "account:read")) {
|
||||
if (!hasPermission(context.permissions, "account:read")) {
|
||||
redirect("/app/dashboard");
|
||||
}
|
||||
|
||||
const data = await readData();
|
||||
const roles = await getRoleDefinitions(context.organization?.id);
|
||||
return (
|
||||
<SettingsOverview
|
||||
accounts={data.accounts.map((account) => toPublicAccount(account))}
|
||||
roles={ROLE_DEFINITIONS}
|
||||
roles={roles}
|
||||
auditLogs={data.auditLogs.slice(0, 100)}
|
||||
organizations={data.organizations}
|
||||
memberships={data.memberships}
|
||||
incidents={data.incidents}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user