feat: 新增客户表单强制必填校验(名称无空格/手机号11位/押金买断生日)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-11 21:17:59 +08:00
co-authored by Claude Opus 4.8
parent 1e8396d0d3
commit 228c37c897
3 changed files with 69 additions and 12 deletions
@@ -29,12 +29,18 @@ function Field({
defaultValue,
required,
type = "text",
pattern,
inputMode,
title,
}: {
label: string;
name: string;
defaultValue?: string | null;
required?: boolean;
type?: string;
pattern?: string;
inputMode?: React.HTMLAttributes<HTMLInputElement>["inputMode"];
title?: string;
}) {
return (
<div className="space-y-1.5">
@@ -42,7 +48,16 @@ function Field({
{label}
{required && <span className="ml-0.5 text-[var(--color-danger)]">*</span>}
</Label>
<Input id={name} name={name} type={type} defaultValue={defaultValue ?? ""} />
<Input
id={name}
name={name}
type={type}
defaultValue={defaultValue ?? ""}
required={required}
pattern={pattern}
inputMode={inputMode}
title={title}
/>
</div>
);
}
@@ -51,10 +66,12 @@ export function CustomerForm({
action,
defaultValues,
submitLabel = "保存",
requireAll = false,
}: {
action: (prev: ActionState, formData: FormData) => Promise<ActionState>;
defaultValues?: CustomerValues;
submitLabel?: string;
requireAll?: boolean;
}) {
const [state, formAction, pending] = useActionState(action, {});
const v = defaultValues ?? {};
@@ -62,11 +79,26 @@ export function CustomerForm({
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="customerName"
defaultValue={v.customerName}
required
pattern={requireAll ? "\\S+" : undefined}
title={requireAll ? "客户名称不能包含空格" : undefined}
/>
<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="phone"
defaultValue={v.phone}
required={requireAll}
pattern={requireAll ? "1\\d{10}" : undefined}
inputMode={requireAll ? "numeric" : undefined}
title={requireAll ? "请输入 11 位手机号" : undefined}
/>
<Field
label="报单时间"
name="reportDate"
@@ -74,8 +106,8 @@ export function CustomerForm({
defaultValue={fmtDate(v.reportDate)}
required
/>
<Field label="押金" name="deposit" defaultValue={v.deposit} />
<Field label="买断" name="buy" defaultValue={v.buy} />
<Field label="押金" name="deposit" defaultValue={v.deposit} required={requireAll} />
<Field label="买断" name="buy" defaultValue={v.buy} required={requireAll} />
<div className="space-y-1.5">
<Label htmlFor="birthdayType">生日类型</Label>
<Select id="birthdayType" name="birthdayType" defaultValue={String(v.birthdayType ?? 1)}>
@@ -83,7 +115,13 @@ export function CustomerForm({
<option value="2">阴历</option>
</Select>
</div>
<Field label="生日" name="birthday" type="date" defaultValue={fmtDate(v.birthday)} />
<Field
label="生日"
name="birthday"
type="date"
defaultValue={fmtDate(v.birthday)}
required={requireAll}
/>
</div>
<div className="space-y-1.5">