import { useMemo, useState } from "react";
import { useNavigate, Link } from "react-router";
import {
Hexagon,
ArrowLeft,
ArrowRight,
UploadCloud,
CheckCircle2,
Loader2,
XCircle,
Building2,
UserRound,
ShieldCheck,
X,
Eye,
EyeOff,
Info,
} from "lucide-react";
import { toast } from "sonner";
import { Button } from "../components/ui/button";
import { cn } from "../components/ui/utils";
type Registrant = "supplier" | "expert";
type AuditState = "idle" | "auditing" | "success" | "rejected";
const SUPPLIER_STEPS = ["企业信息", "联系人", "提交 / 自动审核"];
const EXPERT_STEPS = ["基本信息", "专业资质 / 收款", "提交审核"];
interface PwdRule {
label: string;
test: (v: string) => boolean;
}
const PWD_RULES: PwdRule[] = [
{ label: "长度 8~20 位", test: (v) => v.length >= 8 && v.length <= 20 },
{ label: "包含大写字母(A-Z)与小写字母(a-z)", test: (v) => /[A-Z]/.test(v) && /[a-z]/.test(v) },
{ label: "包含数字(0-9)与特殊字符(!@#$%^&*)", test: (v) => /\d/.test(v) && /[!@#$%^&*()_+\-=]/.test(v) },
{ label: "禁止连续/重复字符(如 12345678、aaaa)", test: (v) => !/(.)\1{3,}/.test(v) && !/0123|1234|2345|3456|4567|5678|6789/.test(v) },
{ label: "非常见弱口令(password、admin123 等)", test: (v) => !["password", "admin123", "12345678", "qwerty"].includes(v.toLowerCase()) },
];
function Field({
label,
placeholder,
required,
hint,
className,
type = "text",
readOnly,
}: {
label: string;
placeholder?: string;
required?: boolean;
hint?: string;
className?: string;
type?: string;
readOnly?: boolean;
}) {
return (
{hint &&
{hint}
}
);
}
function StepBar({ steps, current }: { steps: string[]; current: number }) {
return (
{steps.map((s, i) => (
{i < current ? : i + 1}
{s}
{i < steps.length - 1 && (
)}
))}
);
}
function Notice({ items }: { items: string[] }) {
return (
注册须知
{items.map((t, i) => (
-
{i + 1}. {t}
))}
);
}
export function RegisterPage() {
const navigate = useNavigate();
const [registrant, setRegistrant] = useState("supplier");
const [step, setStep] = useState(0);
const [ocr, setOcr] = useState<"none" | "scanning" | "done">("none");
const [audit, setAudit] = useState("idle");
const [products, setProducts] = useState(["工业阀门", "管道配件"]);
const [productInput, setProductInput] = useState("");
const [pwd, setPwd] = useState("");
const [confirmPwd, setConfirmPwd] = useState("");
const [showPwd, setShowPwd] = useState(false);
const [smsCountdown, setSmsCountdown] = useState(0);
const steps = registrant === "supplier" ? SUPPLIER_STEPS : EXPERT_STEPS;
const passedRules = useMemo(() => PWD_RULES.map((r) => r.test(pwd)), [pwd]);
const passedCount = passedRules.filter(Boolean).length;
const strength: 0 | 1 | 2 = passedCount >= 5 && pwd.length >= 12 ? 2 : passedCount >= 4 ? 1 : 0;
function switchRegistrant(r: Registrant) {
setRegistrant(r);
setStep(0);
setAudit("idle");
setOcr("none");
}
function triggerOcr() {
setOcr("scanning");
setTimeout(() => {
setOcr("done");
toast.success("营业执照识别完成,已自动回填企业信息");
}, 1500);
}
function addProduct() {
const v = productInput.trim();
if (v && products.length < 20 && !products.includes(v)) {
setProducts((p) => [...p, v]);
}
setProductInput("");
}
function sendSms() {
toast.success("验证码已发送");
setSmsCountdown(60);
const t = setInterval(() => {
setSmsCountdown((c) => {
if (c <= 1) {
clearInterval(t);
return 0;
}
return c - 1;
});
}, 1000);
}
function submitAudit() {
setStep(steps.length - 1);
setAudit("auditing");
setTimeout(() => {
setAudit("success");
}, 3800);
}
const isLastFormStep = step === steps.length - 2;
return (
{/* 注册对象选择 */}
{(
[
{ id: "supplier" as Registrant, label: "供应商注册", icon: Building2 },
{ id: "expert" as Registrant, label: "外部专家注册", icon: UserRound },
]
).map((r) => {
const Icon = r.icon;
return (
);
})}
{/* ============ 供应商注册 ============ */}
{registrant === "supplier" && (
<>
{step === 0 && (
供应商注册
请填写企业真实信息,上传营业执照,系统将自动识别并回填
{/* 营业执照上传 */}
上传营业执照(JPG/PNG/PDF,≤10MB)
支持拖拽或点击上传,AI 将自动识别企业信息并填充表单
{ocr === "scanning" && (
正在识别营业执照...
)}
{ocr === "done" && (
已识别:营业执照信息提取成功(统一信用代码:91370100XXXXXXXXXX)
)}
)}
{step === 1 && (
联系人信息
{/* 密码 */}
{/* 密码复杂度要求 */}
密码复杂度要求
{PWD_RULES.map((r, i) => (
-
{passedRules[i] ? "✔" : "✘"}
{r.label}
))}
{/* 强度条 */}
密码强度
{strength === 0 ? "弱" : strength === 1 ? "中" : "强"}
)}
>
)}
{/* ============ 外部专家注册 ============ */}
{registrant === "expert" && (
<>
{step === 0 && (
外部专家注册
请完整填写以下信息,所有数据将受到严格加密保护
点击上传或拖拽文件(支持 PDF/JPG/PNG,≤20MB)
)}
{step === 1 && (
)}
>
)}
{/* ============ 提交 / 自动审核态(两种注册对象共用最后一步) ============ */}
{step === steps.length - 1 && (
{audit === "auditing" && (
{registrant === "supplier" ? "AI 正在审核企业信息..." : "已提交,AI 正在初审..."}
预计 3~8 秒,请勿关闭页面
✓ 工商信息核验 ✓ 风险扫描 ✓ 唯一性检查
)}
{audit === "success" && (
🎉 注册成功!
{registrant === "supplier" ? "您的供应商账号已激活,正在自动登录..." : "您的专家账号已创建,请留意激活通知短信/邮件。"}
{registrant === "supplier" ? "供应商编号" : "专家编号"}:
{registrant === "supplier" ? "SUP_20260709_0158" : "EXP_20260709_002"}
登录账号:138****8001
📌 温馨提示:参与具体项目投标时,需按招标公告要求提交资质审核材料
)}
{audit === "rejected" && (
审核未通过
• 统一社会信用代码与工商登记信息不匹配
• 企业状态为“注销”,不符合注册条件
💡 请核对信息后重新提交,如有疑问请联系客服
)}
)}
{/* 底部导航按钮 */}
{audit === "idle" && (
{step > 0 && (
)}
{isLastFormStep ? (
) : (
)}
)}
);
}