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,119 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState } from "react";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input, Textarea, Select } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { fmtDate } from "@/lib/utils";
|
||||
import type { ActionState } from "./actions";
|
||||
|
||||
type CustomerValues = {
|
||||
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;
|
||||
};
|
||||
|
||||
function Field({
|
||||
label,
|
||||
name,
|
||||
defaultValue,
|
||||
required,
|
||||
type = "text",
|
||||
}: {
|
||||
label: string;
|
||||
name: string;
|
||||
defaultValue?: string | null;
|
||||
required?: boolean;
|
||||
type?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor={name}>
|
||||
{label}
|
||||
{required && <span className="ml-0.5 text-[var(--color-danger)]">*</span>}
|
||||
</Label>
|
||||
<Input id={name} name={name} type={type} defaultValue={defaultValue ?? ""} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CustomerForm({
|
||||
action,
|
||||
defaultValues,
|
||||
submitLabel = "保存",
|
||||
}: {
|
||||
action: (prev: ActionState, formData: FormData) => Promise<ActionState>;
|
||||
defaultValues?: CustomerValues;
|
||||
submitLabel?: string;
|
||||
}) {
|
||||
const [state, formAction, pending] = useActionState(action, {});
|
||||
const v = defaultValues ?? {};
|
||||
|
||||
return (
|
||||
<form action={formAction} className="space-y-6">
|
||||
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<Field label="客户名称" name="customerName" defaultValue={v.customerName} required />
|
||||
<Field label="联系人" name="contacts" defaultValue={v.contacts} required />
|
||||
<Field label="结算人" name="balanceUser" defaultValue={v.balanceUser} required />
|
||||
<Field label="业务员" name="salesman" defaultValue={v.salesman} required />
|
||||
<Field label="电话" name="phone" defaultValue={v.phone} />
|
||||
<Field
|
||||
label="报单时间"
|
||||
name="reportDate"
|
||||
type="date"
|
||||
defaultValue={fmtDate(v.reportDate)}
|
||||
required
|
||||
/>
|
||||
<Field label="押金" name="deposit" defaultValue={v.deposit} />
|
||||
<Field label="买断" name="buy" defaultValue={v.buy} />
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="birthdayType">生日类型</Label>
|
||||
<Select id="birthdayType" name="birthdayType" defaultValue={String(v.birthdayType ?? 1)}>
|
||||
<option value="1">阳历</option>
|
||||
<option value="2">阴历</option>
|
||||
</Select>
|
||||
</div>
|
||||
<Field label="生日" name="birthday" type="date" defaultValue={fmtDate(v.birthday)} />
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="detail">
|
||||
详情<span className="ml-0.5 text-[var(--color-danger)]">*</span>
|
||||
</Label>
|
||||
<Textarea id="detail" name="detail" defaultValue={v.detail ?? ""} rows={3} />
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="remark">备注</Label>
|
||||
<Textarea id="remark" name="remark" defaultValue={v.remark ?? ""} rows={2} />
|
||||
</div>
|
||||
|
||||
{state.error && (
|
||||
<p className="rounded-md bg-[var(--color-danger-soft)] px-3 py-2 text-sm text-[var(--color-danger)]">
|
||||
{state.error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2 border-t pt-4">
|
||||
<Button type="submit" disabled={pending}>
|
||||
{pending ? "保存中…" : submitLabel}
|
||||
</Button>
|
||||
<Link href="/customers">
|
||||
<Button type="button" variant="outline">
|
||||
取消
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user