diff --git a/src/app/(dashboard)/customers/actions.ts b/src/app/(dashboard)/customers/actions.ts index 04fbf05..31281a3 100644 --- a/src/app/(dashboard)/customers/actions.ts +++ b/src/app/(dashboard)/customers/actions.ts @@ -7,6 +7,7 @@ import * as XLSX from "xlsx"; import { Prisma } from "@prisma/client"; import { prisma } from "@/lib/prisma"; import { auth } from "@/lib/auth"; +import { isSuperAdmin } from "@/lib/acl"; import { parseDate } from "@/lib/utils"; // 校验规则对齐老系统必填项(customer_name/contacts/balance_user/detail/salesman/report_date) @@ -105,7 +106,8 @@ export async function updateCustomer( } export async function deleteCustomer(id: number): Promise { - if (!(await auth())) return; + const session = await auth(); + if (!isSuperAdmin(session?.user?.roles)) return; // 软删除,对齐老系统 deleted_at await prisma.customer.update({ where: { id }, diff --git a/src/app/(dashboard)/customers/customer-view.tsx b/src/app/(dashboard)/customers/customer-view.tsx new file mode 100644 index 0000000..28eb847 --- /dev/null +++ b/src/app/(dashboard)/customers/customer-view.tsx @@ -0,0 +1,107 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { Eye, X } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { fmtDate } from "@/lib/utils"; + +type CustomerViewProps = { + customer: { + customerName?: string | null; + contacts?: string | null; + balanceUser?: string | null; + phone?: string | null; + detail?: string | null; + deposit?: string | null; + buy?: string | null; + birthdayType?: number | null; + birthday?: Date | null; + salesman?: string | null; + reportDate?: Date | null; + remark?: string | null; + }; +}; + +export function CustomerView({ customer }: CustomerViewProps) { + const [open, setOpen] = useState(false); + + // Esc 键关闭弹窗 + useEffect(() => { + if (!open) return; + const handleEsc = (e: KeyboardEvent) => { + if (e.key === "Escape") setOpen(false); + }; + window.addEventListener("keydown", handleEsc); + return () => window.removeEventListener("keydown", handleEsc); + }, [open]); + + const birthdayLabel = customer.birthdayType === 2 ? "阴历" : "阳历"; + + return ( + <> + + + {open && ( +
setOpen(false)} + > + e.stopPropagation()} + > + +
+ 商户信息 + +
+
+ + + + + + + + + + + + + + +
+
+ )} + + ); +} + +function InfoRow({ + label, + value, + className, +}: { + label: string; + value?: string | null; + className?: string; +}) { + if (!value) return null; + return ( +
+ {label} + {value} +
+ ); +} diff --git a/src/app/(dashboard)/customers/page.tsx b/src/app/(dashboard)/customers/page.tsx index ad1bfe8..d58ee76 100644 --- a/src/app/(dashboard)/customers/page.tsx +++ b/src/app/(dashboard)/customers/page.tsx @@ -1,12 +1,15 @@ import Link from "next/link"; import { prisma } from "@/lib/prisma"; -import { fmtDate } from "@/lib/utils"; +import { auth } from "@/lib/auth"; +import { isSuperAdmin } from "@/lib/acl"; +import { fmtDate, maskPhone } from "@/lib/utils"; import { Card } from "@/components/ui/card"; import { Table, THead, TR, TH, TD } from "@/components/ui/table"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { CustomerToolbar } from "./customer-toolbar"; import { DeleteButton } from "./delete-button"; +import { CustomerView } from "./customer-view"; import { buildCustomerWhere } from "./query"; const PAGE_SIZE = 15; @@ -23,6 +26,8 @@ export default async function CustomersPage({ }: { searchParams: Promise; }) { + const session = await auth(); + const superAdmin = isSuperAdmin(session?.user?.roles); const sp = await searchParams; const keyword = (sp.keyword ?? "").trim(); const page = Math.max(1, Number(sp.page) || 1); @@ -84,7 +89,7 @@ export default async function CustomersPage({ {c.customerName} {c.contacts} {c.balanceUser} - {c.phone} + {superAdmin ? c.phone : maskPhone(c.phone)} {c.detail} {c.deposit} {c.buy} @@ -101,10 +106,11 @@ export default async function CustomersPage({ {c.remark}
+ - + {superAdmin && }
diff --git a/src/app/(dashboard)/layout.tsx b/src/app/(dashboard)/layout.tsx index 7f839b4..dcb62d6 100644 --- a/src/app/(dashboard)/layout.tsx +++ b/src/app/(dashboard)/layout.tsx @@ -1,5 +1,6 @@ import { redirect } from "next/navigation"; import { auth } from "@/lib/auth"; +import { isSuperAdmin } from "@/lib/acl"; import { Sidebar } from "@/components/app/sidebar"; import { Topbar } from "@/components/app/topbar"; import { SidebarProvider } from "@/components/app/sidebar-context"; @@ -13,11 +14,12 @@ export default async function DashboardLayout({ const session = await auth(); if (!session?.user) redirect("/login"); const u = session.user; + const superAdmin = isSuperAdmin(u.roles); return (
- +
{children}; +} diff --git a/src/components/app/nav.ts b/src/components/app/nav.ts index 8885dac..6a7948b 100644 --- a/src/components/app/nav.ts +++ b/src/components/app/nav.ts @@ -17,6 +17,8 @@ export type NavItem = { export type NavSection = { title: string; items: NavItem[]; + /** 是否仅超级管理员可见 */ + superAdminOnly?: boolean; }; export const navSections: NavSection[] = [ @@ -35,6 +37,7 @@ export const navSections: NavSection[] = [ { href: "/rbac/roles", label: "角色", icon: ShieldCheck }, { href: "/rbac/permissions", label: "权限菜单", icon: KeyRound }, ], + superAdminOnly: true, }, ]; diff --git a/src/components/app/sidebar.tsx b/src/components/app/sidebar.tsx index c716a55..fc19e38 100644 --- a/src/components/app/sidebar.tsx +++ b/src/components/app/sidebar.tsx @@ -8,10 +8,11 @@ import { BrandLogo } from "./brand-logo"; import { navSections, activeHref } from "./nav"; import { useSidebar } from "./sidebar-context"; -export function Sidebar() { +export function Sidebar({ isSuperAdmin }: { isSuperAdmin: boolean }) { const pathname = usePathname(); const active = activeHref(pathname); const { collapsed } = useSidebar(); + const sections = navSections.filter((s) => !s.superAdminOnly || isSuperAdmin); return (