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,148 @@
|
||||
import Link from "next/link";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { fmtDate } 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 { buildCustomerWhere } from "./query";
|
||||
|
||||
const PAGE_SIZE = 15;
|
||||
|
||||
type SearchParams = {
|
||||
keyword?: string;
|
||||
start?: string;
|
||||
end?: string;
|
||||
page?: string;
|
||||
};
|
||||
|
||||
export default async function CustomersPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>;
|
||||
}) {
|
||||
const sp = await searchParams;
|
||||
const keyword = (sp.keyword ?? "").trim();
|
||||
const page = Math.max(1, Number(sp.page) || 1);
|
||||
const where = buildCustomerWhere(sp);
|
||||
|
||||
const [rows, total] = await Promise.all([
|
||||
prisma.customer.findMany({
|
||||
where,
|
||||
orderBy: { reportDate: "desc" },
|
||||
skip: (page - 1) * PAGE_SIZE,
|
||||
take: PAGE_SIZE,
|
||||
}),
|
||||
prisma.customer.count({ where }),
|
||||
]);
|
||||
|
||||
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
|
||||
const exportQs = new URLSearchParams();
|
||||
if (sp.keyword) exportQs.set("keyword", sp.keyword);
|
||||
if (sp.start) exportQs.set("start", sp.start);
|
||||
if (sp.end) exportQs.set("end", sp.end);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<CustomerToolbar
|
||||
defaultKeyword={keyword}
|
||||
defaultStart={sp.start}
|
||||
defaultEnd={sp.end}
|
||||
exportHref={`/customers/export?${exportQs.toString()}`}
|
||||
/>
|
||||
|
||||
<Card className="overflow-hidden">
|
||||
<Table>
|
||||
<THead>
|
||||
<tr>
|
||||
<TH>客户名称</TH>
|
||||
<TH>联系人</TH>
|
||||
<TH>电话</TH>
|
||||
<TH>业务员</TH>
|
||||
<TH>报单时间</TH>
|
||||
<TH>生日</TH>
|
||||
<TH className="text-right">操作</TH>
|
||||
</tr>
|
||||
</THead>
|
||||
<tbody>
|
||||
{rows.length === 0 && (
|
||||
<tr>
|
||||
<TD colSpan={7} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
||||
暂无数据
|
||||
</TD>
|
||||
</tr>
|
||||
)}
|
||||
{rows.map((c) => (
|
||||
<TR key={c.id}>
|
||||
<TD className="font-medium">{c.customerName}</TD>
|
||||
<TD>{c.contacts}</TD>
|
||||
<TD className="tabular-nums">{c.phone}</TD>
|
||||
<TD>{c.salesman}</TD>
|
||||
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
|
||||
<TD>
|
||||
<span className="tabular-nums">{fmtDate(c.birthday)}</span>
|
||||
{c.birthday && (
|
||||
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="ml-2">
|
||||
{c.birthdayType === 2 ? "农历" : "阳历"}
|
||||
</Badge>
|
||||
)}
|
||||
</TD>
|
||||
<TD>
|
||||
<div className="flex justify-end gap-1.5">
|
||||
<Link href={`/customers/${c.id}/edit`}>
|
||||
<Button variant="outline" size="sm">编辑</Button>
|
||||
</Link>
|
||||
<DeleteButton id={c.id} name={c.customerName ?? ""} />
|
||||
</div>
|
||||
</TD>
|
||||
</TR>
|
||||
))}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Card>
|
||||
|
||||
{/* 分页 */}
|
||||
<div className="flex items-center justify-between text-sm text-[var(--color-muted-foreground)]">
|
||||
<span>共 <span className="font-medium text-[var(--color-foreground)]">{total.toLocaleString()}</span> 条</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<PageLink page={page - 1} disabled={page <= 1} sp={sp} label="上一页" />
|
||||
<span className="px-1 tabular-nums">{page} / {totalPages}</span>
|
||||
<PageLink page={page + 1} disabled={page >= totalPages} sp={sp} label="下一页" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PageLink({
|
||||
page,
|
||||
disabled,
|
||||
sp,
|
||||
label,
|
||||
}: {
|
||||
page: number;
|
||||
disabled: boolean;
|
||||
sp: SearchParams;
|
||||
label: string;
|
||||
}) {
|
||||
if (disabled) {
|
||||
return (
|
||||
<span className="rounded-md border px-3 py-1.5 opacity-40">{label}</span>
|
||||
);
|
||||
}
|
||||
const params = new URLSearchParams();
|
||||
if (sp.keyword) params.set("keyword", sp.keyword);
|
||||
if (sp.start) params.set("start", sp.start);
|
||||
if (sp.end) params.set("end", sp.end);
|
||||
params.set("page", String(page));
|
||||
return (
|
||||
<Link
|
||||
href={`/customers?${params.toString()}`}
|
||||
className="rounded-md border bg-[var(--color-surface)] px-3 py-1.5 hover:bg-[var(--color-muted)]"
|
||||
>
|
||||
{label}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user