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
+63
View File
@@ -0,0 +1,63 @@
import { brand } from "@/lib/brand";
import { cn } from "@/lib/utils";
/**
* 品牌标识(自绘 SVG):两个相扣的环 = “联动”,靛蓝渐变。
* 纯矢量,无需图片资源,可任意缩放。
*/
export function BrandMark({ size = 36, className }: { size?: number; className?: string }) {
return (
<svg
width={size}
height={size}
viewBox="0 0 48 48"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={cn("shrink-0", className)}
aria-hidden
>
<defs>
<linearGradient id="ld-brand" x1="0" y1="0" x2="48" y2="48" gradientUnits="userSpaceOnUse">
<stop stopColor="#6366f1" />
<stop offset="1" stopColor="#4338ca" />
</linearGradient>
</defs>
<rect width="48" height="48" rx="12" fill="url(#ld-brand)" />
{/* 相扣双环 */}
<circle cx="19" cy="24" r="8.5" stroke="#fff" strokeWidth="3.2" opacity="0.95" />
<circle cx="29" cy="24" r="8.5" stroke="#c7d2fe" strokeWidth="3.2" />
</svg>
);
}
/** 品牌标识 + 文字,用于登录/侧边栏 */
export function BrandLogo({
size = 36,
subtitle,
className,
invert = false,
}: {
size?: number;
subtitle?: string;
className?: string;
invert?: boolean;
}) {
return (
<div className={cn("flex items-center gap-2.5", className)}>
<BrandMark size={size} />
<div className="leading-tight">
<div className={cn("font-semibold", invert ? "text-white" : "text-[var(--color-foreground)]")}>
{brand.name}
</div>
<div
className={cn(
"text-[11px]",
invert ? "text-[var(--color-sidebar-muted)]" : "text-[var(--color-muted-foreground)]"
)}
>
{subtitle ?? brand.product}
</div>
</div>
</div>
);
}
+51
View File
@@ -0,0 +1,51 @@
import {
LayoutDashboard,
Users,
Cake,
UserCog,
ShieldCheck,
KeyRound,
type LucideIcon,
} from "lucide-react";
export type NavItem = {
href: string;
label: string;
icon: LucideIcon;
};
export type NavSection = {
title: string;
items: NavItem[];
};
export const navSections: NavSection[] = [
{
title: "主菜单",
items: [
{ href: "/", label: "控制台", icon: LayoutDashboard },
{ href: "/customers", label: "客户管理", icon: Users },
{ href: "/customers/birthday", label: "生日提醒", icon: Cake },
],
},
{
title: "系统管理",
items: [
{ href: "/rbac/admins", label: "管理员", icon: UserCog },
{ href: "/rbac/roles", label: "角色", icon: ShieldCheck },
{ href: "/rbac/permissions", label: "权限菜单", icon: KeyRound },
],
},
];
/** 在给定 pathname 下,返回应高亮的导航 href(最长前缀匹配) */
export function activeHref(pathname: string): string {
const all = navSections.flatMap((s) => s.items.map((i) => i.href));
let best = "";
for (const href of all) {
const match =
href === "/" ? pathname === "/" : pathname === href || pathname.startsWith(href + "/");
if (match && href.length > best.length) best = href;
}
return best;
}
+59
View File
@@ -0,0 +1,59 @@
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { cn } from "@/lib/utils";
import { copyright } from "@/lib/brand";
import { BrandLogo } from "./brand-logo";
import { navSections, activeHref } from "./nav";
export function Sidebar() {
const pathname = usePathname();
const active = activeHref(pathname);
return (
<aside className="flex w-60 shrink-0 flex-col bg-[var(--color-sidebar)] text-[var(--color-sidebar-foreground)]">
{/* 品牌 */}
<div className="flex h-16 items-center px-5">
<Link href="/">
<BrandLogo size={36} invert />
</Link>
</div>
<nav className="flex-1 space-y-6 overflow-y-auto px-3 py-4">
{navSections.map((section) => (
<div key={section.title}>
<div className="px-3 pb-2 text-[11px] font-medium uppercase tracking-wider text-[var(--color-sidebar-muted)]">
{section.title}
</div>
<div className="space-y-1">
{section.items.map((item) => {
const Icon = item.icon;
const isActive = active === item.href;
return (
<Link
key={item.href}
href={item.href}
className={cn(
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm transition-colors",
isActive
? "bg-[var(--color-primary)] text-white shadow-sm"
: "text-[var(--color-sidebar-muted)] hover:bg-[var(--color-sidebar-hover)] hover:text-white"
)}
>
<Icon className="h-[18px] w-[18px]" />
{item.label}
</Link>
);
})}
</div>
</div>
))}
</nav>
<div className="px-5 py-4 text-[11px] text-[var(--color-sidebar-muted)]">
{copyright()}
</div>
</aside>
);
}
+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>
);
}
+45
View File
@@ -0,0 +1,45 @@
import { cn } from "@/lib/utils";
/** 文字头像:取昵称首字,稳定生成柔和背景色 */
export function Avatar({
name,
src,
size = 36,
className,
}: {
name?: string | null;
src?: string | null;
size?: number;
className?: string;
}) {
const label = (name ?? "?").trim().charAt(0).toUpperCase() || "?";
const palette = [
"#6366f1", "#0ea5e9", "#10b981", "#f59e0b", "#ec4899", "#8b5cf6", "#ef4444",
];
let hash = 0;
for (const ch of name ?? "") hash = (hash * 31 + ch.charCodeAt(0)) >>> 0;
const bg = palette[hash % palette.length];
if (src) {
// eslint-disable-next-line @next/next/no-img-element
return (
<img
src={src}
alt={label}
style={{ width: size, height: size }}
className={cn("rounded-full object-cover", className)}
/>
);
}
return (
<span
style={{ width: size, height: size, background: bg, fontSize: size * 0.42 }}
className={cn(
"inline-flex shrink-0 items-center justify-center rounded-full font-semibold text-white",
className
)}
>
{label}
</span>
);
}
+28
View File
@@ -0,0 +1,28 @@
import * as React from "react";
import { cn } from "@/lib/utils";
const tones = {
neutral: "bg-[var(--color-muted)] text-[var(--color-muted-foreground)]",
primary: "bg-[var(--color-primary-soft)] text-[var(--color-primary)]",
success: "bg-[var(--color-success-soft)] text-[var(--color-success)]",
warning: "bg-[var(--color-warning-soft)] text-[var(--color-warning)]",
danger: "bg-[var(--color-danger-soft)] text-[var(--color-danger)]",
info: "bg-[var(--color-info-soft)] text-[var(--color-info)]",
} as const;
export function Badge({
tone = "neutral",
className,
...props
}: React.HTMLAttributes<HTMLSpanElement> & { tone?: keyof typeof tones }) {
return (
<span
className={cn(
"inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",
tones[tone],
className
)}
{...props}
/>
);
}
+42
View File
@@ -0,0 +1,42 @@
import * as React from "react";
import { cn } from "@/lib/utils";
const base =
"inline-flex items-center justify-center gap-2 rounded-[var(--radius)] text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-ring)] disabled:pointer-events-none disabled:opacity-50 whitespace-nowrap active:scale-[0.98]";
const variants = {
primary:
"bg-[var(--color-primary)] text-[var(--color-primary-foreground)] shadow-sm hover:bg-[var(--color-primary-hover)]",
outline:
"border bg-[var(--color-surface)] text-[var(--color-foreground)] hover:bg-[var(--color-muted)]",
ghost: "text-[var(--color-foreground)] hover:bg-[var(--color-muted)]",
soft: "bg-[var(--color-primary-soft)] text-[var(--color-primary)] hover:bg-[#e0e7ff]",
danger:
"bg-[var(--color-danger)] text-white shadow-sm hover:brightness-95",
"danger-ghost":
"text-[var(--color-danger)] hover:bg-[var(--color-danger-soft)]",
} as const;
const sizes = {
default: "h-9 px-4",
sm: "h-8 px-3 text-[13px]",
lg: "h-10 px-5",
icon: "h-9 w-9",
} as const;
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: keyof typeof variants;
size?: keyof typeof sizes;
}
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant = "primary", size = "default", ...props }, ref) => (
<button
ref={ref}
className={cn(base, variants[variant], sizes[size], className)}
{...props}
/>
)
);
Button.displayName = "Button";
+40
View File
@@ -0,0 +1,40 @@
import * as React from "react";
import { cn } from "@/lib/utils";
export function Card({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn(
"rounded-[var(--radius)] border bg-[var(--color-surface)] shadow-sm",
className
)}
{...props}
/>
);
}
export function CardHeader({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn("flex items-center justify-between border-b px-5 py-4", className)}
{...props}
/>
);
}
export function CardTitle({
className,
...props
}: React.HTMLAttributes<HTMLHeadingElement>) {
return <h3 className={cn("text-sm font-semibold", className)} {...props} />;
}
export function CardContent({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return <div className={cn("p-5", className)} {...props} />;
}
+35
View File
@@ -0,0 +1,35 @@
import * as React from "react";
import { cn } from "@/lib/utils";
const fieldCls =
"flex h-9 w-full rounded-[var(--radius)] border bg-[var(--color-surface)] px-3 text-sm shadow-sm transition-colors placeholder:text-[var(--color-muted-foreground)] focus-visible:outline-none focus-visible:border-[var(--color-primary)] focus-visible:ring-2 focus-visible:ring-[var(--color-ring)] disabled:cursor-not-allowed disabled:opacity-50";
export const Input = React.forwardRef<
HTMLInputElement,
React.InputHTMLAttributes<HTMLInputElement>
>(({ className, ...props }, ref) => (
<input ref={ref} className={cn(fieldCls, className)} {...props} />
));
Input.displayName = "Input";
export const Textarea = React.forwardRef<
HTMLTextAreaElement,
React.TextareaHTMLAttributes<HTMLTextAreaElement>
>(({ className, ...props }, ref) => (
<textarea
ref={ref}
className={cn(fieldCls, "h-auto min-h-[76px] py-2 leading-relaxed", className)}
{...props}
/>
));
Textarea.displayName = "Textarea";
export const Select = React.forwardRef<
HTMLSelectElement,
React.SelectHTMLAttributes<HTMLSelectElement>
>(({ className, children, ...props }, ref) => (
<select ref={ref} className={cn(fieldCls, "pr-8", className)} {...props}>
{children}
</select>
));
Select.displayName = "Select";
+17
View File
@@ -0,0 +1,17 @@
import * as React from "react";
import { cn } from "@/lib/utils";
export function Label({
className,
...props
}: React.LabelHTMLAttributes<HTMLLabelElement>) {
return (
<label
className={cn(
"text-[13px] font-medium text-[var(--color-foreground)]",
className
)}
{...props}
/>
);
}
+37
View File
@@ -0,0 +1,37 @@
import * as React from "react";
import { cn } from "@/lib/utils";
/** 统一表格外观:外层 Card 内使用 */
export function Table({ className, ...props }: React.TableHTMLAttributes<HTMLTableElement>) {
return (
<div className="w-full overflow-x-auto">
<table className={cn("w-full text-sm", className)} {...props} />
</div>
);
}
export function THead(props: React.HTMLAttributes<HTMLTableSectionElement>) {
return (
<thead
className="bg-[var(--color-muted)] text-left text-xs uppercase tracking-wide text-[var(--color-muted-foreground)]"
{...props}
/>
);
}
export function TR({ className, ...props }: React.HTMLAttributes<HTMLTableRowElement>) {
return (
<tr
className={cn("border-b last:border-0 hover:bg-[var(--color-muted)]/60", className)}
{...props}
/>
);
}
export function TH({ className, ...props }: React.ThHTMLAttributes<HTMLTableCellElement>) {
return <th className={cn("px-4 py-3 font-medium", className)} {...props} />;
}
export function TD({ className, ...props }: React.TdHTMLAttributes<HTMLTableCellElement>) {
return <td className={cn("px-4 py-3 align-middle", className)} {...props} />;
}