import { z } from "zod" function requiredTextField(label: string, maxLength: number) { return z.preprocess( (value) => typeof value === "string" ? value.trim() : "", z.string() .min(1, `请填写${label}`) .max(maxLength, `${label}不能超过 ${maxLength} 个字符`) ) } function optionalTextField(label: string, maxLength: number) { return z.preprocess( (value) => typeof value === "string" ? value.trim() : "", z.string().max(maxLength, `${label}不能超过 ${maxLength} 个字符`) ) } export const contactFormSchema = z.object({ name: requiredTextField("姓名", 80), company: requiredTextField("公司 / 品牌", 120), phone: requiredTextField("联系电话", 40), scale: optionalTextField("门店规模", 120), message: optionalTextField("需求描述", 2000), }) export type ContactFormData = z.infer