feat: 联动支付 CRM 后台(Next.js + TS + Prisma 重构)

从旧 Laravel 5.7 重构为现代技术栈,对接现有 MySQL。

- 技术栈: Next.js 15 App Router + TypeScript + Prisma + Auth.js + Tailwind v4
- 认证: 复用旧库 admins 的 bcrypt 密码,Auth.js Credentials
- 客户管理: 列表(搜索/报单区间/分页)、增改删、Excel 导入导出
- 生日提醒: 阴阳历(lunar-typescript),口径对齐旧 overtrue 库
- RBAC: 管理员/角色/权限(菜单树) 完整 CRUD + 分配
- 控制台: 统计卡 + 月度新增报单柱状图
- 个人中心: 改昵称/改密码
- 现代 CMS 界面 + 联动支付品牌(logo/登录/底部/icon)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-08 15:02:03 +08:00
co-authored by Claude Opus 4.8
commit 5d46afe439
68 changed files with 6998 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
"use client";
import { useEffect, useRef, useState } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { signOut } from "next-auth/react";
import { ChevronDown, User, LogOut } from "lucide-react";
import { Avatar } from "@/components/ui/avatar";
import { navSections } from "./nav";
function pageTitle(pathname: string): string {
if (pathname === "/") return "控制台";
if (pathname.startsWith("/me")) return "个人中心";
const flat = navSections.flatMap((s) => s.items);
const hit = flat
.filter((i) => i.href !== "/" && pathname.startsWith(i.href))
.sort((a, b) => b.href.length - a.href.length)[0];
if (pathname.includes("/new")) return "新增" + (hit?.label ?? "");
if (pathname.includes("/edit")) return "编辑" + (hit?.label ?? "");
return hit?.label ?? "";
}
export function Topbar({
user,
}: {
user: { name?: string | null; username: string; roles: string[]; image?: string | null };
}) {
const pathname = usePathname();
const [open, setOpen] = useState(false);
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
function onClick(e: MouseEvent) {
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
}
document.addEventListener("mousedown", onClick);
return () => document.removeEventListener("mousedown", onClick);
}, []);
const roleLabel = user.roles.includes("super admin") ? "超级管理员" : "业务员";
return (
<header className="sticky top-0 z-20 flex h-16 items-center justify-between border-b bg-[var(--color-surface)]/90 px-6 backdrop-blur">
<h1 className="text-base font-semibold">{pageTitle(pathname)}</h1>
<div className="relative" ref={ref}>
<button
onClick={() => setOpen((v) => !v)}
className="flex items-center gap-2.5 rounded-full py-1 pl-1 pr-2.5 transition-colors hover:bg-[var(--color-muted)]"
>
<Avatar name={user.name ?? user.username} src={user.image} size={32} />
<div className="hidden text-left leading-tight sm:block">
<div className="text-[13px] font-medium">{user.name ?? user.username}</div>
<div className="text-[11px] text-[var(--color-muted-foreground)]">{roleLabel}</div>
</div>
<ChevronDown className="h-4 w-4 text-[var(--color-muted-foreground)]" />
</button>
{open && (
<div className="absolute right-0 mt-2 w-48 overflow-hidden rounded-[var(--radius)] border bg-[var(--color-surface)] py-1 shadow-lg">
<Link
href="/me"
onClick={() => setOpen(false)}
className="flex items-center gap-2.5 px-4 py-2 text-sm hover:bg-[var(--color-muted)]"
>
<User className="h-4 w-4" /> 个人中心
</Link>
<button
onClick={() => signOut({ callbackUrl: "/login" })}
className="flex w-full items-center gap-2.5 px-4 py-2 text-sm text-[var(--color-danger)] hover:bg-[var(--color-danger-soft)]"
>
<LogOut className="h-4 w-4" /> 退出登录
</button>
</div>
)}
</div>
</header>
);
}