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:
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user