From 2bb29456788548b28393c8a0b217951c8728377b Mon Sep 17 00:00:00 2001 From: luishou Date: Sun, 12 Jul 2026 00:06:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=9A=E5=8A=A1=E5=91=98=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E6=9D=83=E9=99=90=E9=99=90=E5=88=B6=20+=20=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E6=9F=A5=E7=9C=8B=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 acl.ts 工具:isSuperAdmin/SUPER_ADMIN;utils.ts 加 maskPhone - 侧边栏按角色过滤:系统管理菜单仅超管可见 - /rbac 路由服务端拦截:非超管访问重定向首页 - 客户列表:业务员手机号脱敏(中间5位星号)、删除按钮隐藏、新增查看按钮 - 删除服务端校验:仅超管可执行 - 新增 customer-view.tsx 查看弹窗,展示完整商户信息(含完整手机号) Co-Authored-By: Claude Opus 4.8 --- src/app/(dashboard)/customers/actions.ts | 4 +- .../(dashboard)/customers/customer-view.tsx | 107 ++++++++++++++++++ src/app/(dashboard)/customers/page.tsx | 12 +- src/app/(dashboard)/layout.tsx | 4 +- src/app/(dashboard)/rbac/layout.tsx | 16 +++ src/components/app/nav.ts | 3 + src/components/app/sidebar.tsx | 5 +- src/lib/acl.ts | 14 +++ src/lib/utils.ts | 8 ++ 9 files changed, 166 insertions(+), 7 deletions(-) create mode 100644 src/app/(dashboard)/customers/customer-view.tsx create mode 100644 src/app/(dashboard)/rbac/layout.tsx create mode 100644 src/lib/acl.ts 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 (