ContactPage.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. import { Globe, Mail, MapPin } from "lucide-react";
  2. import { motion } from "motion/react";
  3. import { useEffect, useRef, useState } from "react";
  4. import { Button, Checkbox, Form, Input, message } from "antd";
  5. import { apiRequest, type ApiResponse } from "../../services/request";
  6. const sectionReveal = {
  7. initial: { opacity: 0, y: 40 },
  8. whileInView: { opacity: 1, y: 0 },
  9. viewport: { once: true, amount: 0.25 },
  10. transition: { duration: 0.7, ease: "easeOut" as const },
  11. };
  12. /** 与 Tailwind lg 断点一致:窄屏下表单在首屏下方,whileInView 可能长期不触发,改为进场动画直接播放 */
  13. const formColumnRevealMobile = {
  14. initial: { opacity: 0, y: 40 },
  15. animate: { opacity: 1, y: 0 },
  16. transition: { duration: 0.7, ease: "easeOut" as const },
  17. };
  18. type SubmittedLeadSnapshot = {
  19. user_name: string;
  20. company_name: string;
  21. phone: string;
  22. code: string;
  23. position?: string;
  24. };
  25. export default function ContactPage() {
  26. const [form] = Form.useForm();
  27. const [messageApi, contextHolder] = message.useMessage();
  28. const [sendingCode, setSendingCode] = useState(false);
  29. const [countdown, setCountdown] = useState(0);
  30. const [submitting, setSubmitting] = useState(false);
  31. const [sentJustNow, setSentJustNow] = useState(false);
  32. const [submitSuccess, setSubmitSuccess] = useState(false);
  33. const [submittedSnapshot, setSubmittedSnapshot] = useState<SubmittedLeadSnapshot | null>(
  34. null,
  35. );
  36. const [isNarrowViewport, setIsNarrowViewport] = useState(() =>
  37. typeof window !== "undefined"
  38. ? window.matchMedia("(max-width: 1023px)").matches
  39. : false,
  40. );
  41. const sentTimerRef = useRef<number | null>(null);
  42. useEffect(() => {
  43. if (countdown <= 0) return;
  44. const timer = window.setInterval(() => {
  45. setCountdown((prev) => (prev <= 1 ? 0 : prev - 1));
  46. }, 1000);
  47. return () => window.clearInterval(timer);
  48. }, [countdown]);
  49. useEffect(() => {
  50. return () => {
  51. if (sentTimerRef.current) window.clearTimeout(sentTimerRef.current);
  52. };
  53. }, []);
  54. useEffect(() => {
  55. const mq = window.matchMedia("(max-width: 1023px)");
  56. const sync = () => setIsNarrowViewport(mq.matches);
  57. sync();
  58. mq.addEventListener("change", sync);
  59. return () => mq.removeEventListener("change", sync);
  60. }, []);
  61. const isSuccessResponse = (res: ApiResponse) => {
  62. if (res?.code === undefined || res?.code === null || res?.code === "")
  63. return true;
  64. return ["success"].includes(res.code as string);
  65. };
  66. const handleSendCode = async () => {
  67. try {
  68. const { phone } = await form.validateFields(["phone"]);
  69. setSendingCode(true);
  70. const res = await apiRequest("/api/website/lead_message/send_code", {
  71. method: "POST",
  72. data: { phone },
  73. });
  74. if (!isSuccessResponse(res)) {
  75. messageApi.error(res?.msg || "验证码发送失败,请稍后重试");
  76. return;
  77. }
  78. messageApi.success(res?.msg || "验证码发送成功");
  79. setSentJustNow(true);
  80. if (sentTimerRef.current) window.clearTimeout(sentTimerRef.current);
  81. sentTimerRef.current = window.setTimeout(() => {
  82. setSentJustNow(false);
  83. setCountdown(60);
  84. }, 900);
  85. } catch {
  86. // form 校验失败时不提示额外文案
  87. } finally {
  88. setSendingCode(false);
  89. }
  90. };
  91. const handleSubmit = async (values: {
  92. user_name: string;
  93. position?: string;
  94. phone: string;
  95. code: string;
  96. company_name: string;
  97. privacy: boolean;
  98. }) => {
  99. try {
  100. setSubmitting(true);
  101. const { privacy, ...payload } = values;
  102. const res = await apiRequest("/api/website/lead_message/add", {
  103. method: "POST",
  104. data: payload,
  105. });
  106. if (!isSuccessResponse(res)) {
  107. messageApi.error(res?.msg || "提交失败,请稍后重试");
  108. return;
  109. }
  110. messageApi.success(res?.msg || "提交成功");
  111. setSubmittedSnapshot({
  112. user_name: payload.user_name,
  113. company_name: payload.company_name,
  114. phone: payload.phone,
  115. code: payload.code,
  116. position: payload.position,
  117. });
  118. setSubmitSuccess(true);
  119. } finally {
  120. setSubmitting(false);
  121. }
  122. };
  123. const handleBackFromSuccess = () => {
  124. form.resetFields([
  125. "user_name",
  126. "position",
  127. "phone",
  128. "code",
  129. "company_name",
  130. "privacy",
  131. ]);
  132. setSubmittedSnapshot(null);
  133. setSubmitSuccess(false);
  134. setCountdown(0);
  135. };
  136. return (
  137. <div className="pb-16 px-6 max-w-7xl mx-auto text-slate-100 max-lg:pt-[calc(5rem+env(safe-area-inset-top,0px)+2.75rem)] lg:pt-32 lg:pb-24">
  138. {contextHolder}
  139. <div className="grid grid-cols-1 lg:grid-cols-12 gap-6 lg:gap-12 items-start">
  140. <motion.div
  141. className="mt-0 lg:mt-[82px] lg:col-span-5 space-y-10"
  142. {...sectionReveal}
  143. >
  144. <motion.div
  145. initial={{ opacity: 0, y: 20 }}
  146. animate={{ opacity: 1, y: 0 }}
  147. className="flex flex-col gap-3 lg:gap-0"
  148. >
  149. <h1 className="font-headline text-5xl font-extrabold tracking-tight text-white leading-tight">
  150. 联系我们
  151. <div className="mt-3 text-secondary lg:mt-9">
  152. 开启企微私域一体化增长之旅
  153. </div>
  154. </h1>
  155. <p className="mt-4 text-lg text-slate-300 leading-relaxed max-w-md lg:mt-[76px]">
  156. 填写您的信息,专业顾问将在24小时内与您取得联系,为您提供专属的解决方案。
  157. </p>
  158. </motion.div>
  159. {/* <div className="space-y-8">
  160. {[
  161. // {
  162. // icon: Globe,
  163. // title: "公司名称",
  164. // value: "深圳大方无隅科技有限公司",
  165. // color: "bg-blue-500/15 text-blue-400",
  166. // },
  167. // {
  168. // icon: MapPin,
  169. // title: "公司地址",
  170. // value: "深圳市龙华区",
  171. // color: "bg-slate-800 text-slate-300",
  172. // },
  173. {
  174. icon: Mail,
  175. title: "商务合作",
  176. value: "bd@dotouch.tech",
  177. color: "bg-slate-800 text-slate-300",
  178. },
  179. ].map((item, i) => (
  180. <div key={i} className="flex items-start gap-6 group">
  181. <div
  182. className={`w-14 h-14 rounded-xl ${item.color} flex items-center justify-center shrink-0 transition-transform group-hover:-translate-y-1`}
  183. >
  184. <item.icon className="w-7 h-7" />
  185. </div>
  186. <div>
  187. <h3 className="font-headline font-bold text-white mb-1">{item.title}</h3>
  188. <p className="text-slate-300 font-medium">{item.value}</p>
  189. </div>
  190. </div>
  191. ))}
  192. </div> */}
  193. </motion.div>
  194. <motion.div
  195. className="lg:col-span-7"
  196. {...(isNarrowViewport ? formColumnRevealMobile : sectionReveal)}
  197. >
  198. <motion.div
  199. initial={{ opacity: 0, y: 16 }}
  200. animate={{ opacity: 1, y: 0 }}
  201. className="bg-slate-900 rounded-2xl p-8 md:p-12 shadow-xl border border-slate-800"
  202. >
  203. {submitSuccess && submittedSnapshot ? (
  204. <div className="space-y-8">
  205. <h2 className="font-headline text-2xl md:text-3xl font-bold text-white leading-snug">
  206. 信息提交成功,专业顾问将在24小时内与您取得联系,为您提供专属的解决方案。
  207. </h2>
  208. <div className="rounded-xl border border-slate-800 bg-slate-950/80 p-6 space-y-4">
  209. <p className="text-xs font-semibold uppercase tracking-wider text-slate-500">
  210. 您提交的信息
  211. </p>
  212. <dl className="space-y-3 text-sm">
  213. <div className="flex flex-col gap-0.5 sm:flex-row sm:gap-3">
  214. <dt className="shrink-0 text-slate-500 w-28">姓名</dt>
  215. <dd className="text-slate-100 font-medium">{submittedSnapshot.user_name}</dd>
  216. </div>
  217. <div className="flex flex-col gap-0.5 sm:flex-row sm:gap-3">
  218. <dt className="shrink-0 text-slate-500 w-28">公司名称</dt>
  219. <dd className="text-slate-100 font-medium">{submittedSnapshot.company_name}</dd>
  220. </div>
  221. <div className="flex flex-col gap-0.5 sm:flex-row sm:gap-3">
  222. <dt className="shrink-0 text-slate-500 w-28">手机号</dt>
  223. <dd className="text-slate-100 font-medium">{submittedSnapshot.phone}</dd>
  224. </div>
  225. <div className="flex flex-col gap-0.5 sm:flex-row sm:gap-3">
  226. <dt className="shrink-0 text-slate-500 w-28">部门和职务</dt>
  227. <dd className="text-slate-100 font-medium">
  228. {submittedSnapshot.position?.trim()
  229. ? submittedSnapshot.position
  230. : "—"}
  231. </dd>
  232. </div>
  233. </dl>
  234. </div>
  235. <Button
  236. type="default"
  237. size="large"
  238. onClick={handleBackFromSuccess}
  239. className="!h-auto !w-full !py-4 !rounded-lg !font-headline !text-base !font-bold !bg-slate-800 !text-white !border-slate-600 hover:!bg-slate-700 hover:!text-white hover:!border-slate-500"
  240. >
  241. 返回
  242. </Button>
  243. </div>
  244. ) : (
  245. <>
  246. <div className="mb-10">
  247. <h2 className="font-headline text-3xl font-bold text-white mb-2">
  248. 留下您的信息
  249. </h2>
  250. </div>
  251. <Form
  252. form={form}
  253. layout="vertical"
  254. className="space-y-6"
  255. onFinish={handleSubmit}
  256. initialValues={{
  257. privacy: true,
  258. }}
  259. >
  260. <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
  261. <div className="space-y-2">
  262. <label className="text-xs font-semibold uppercase tracking-wider text-slate-500 ml-1">
  263. 姓名(必填)
  264. </label>
  265. <Form.Item
  266. name="user_name"
  267. className="!mb-0"
  268. rules={[{ required: true, message: "请输入称呼" }]}
  269. >
  270. <Input
  271. className="!w-full !bg-slate-950 !border !border-slate-800 !rounded-lg !px-4 !py-3 !text-slate-100 placeholder:!text-slate-500"
  272. placeholder="请输入您的姓名"
  273. />
  274. </Form.Item>
  275. </div>
  276. <div className="space-y-2">
  277. <label className="text-xs font-semibold uppercase tracking-wider text-slate-500 ml-1">
  278. 公司名称(必填)
  279. </label>
  280. <Form.Item
  281. name="company_name"
  282. className="!mb-0"
  283. rules={[{ required: true, message: "请输入公司名称" }]}
  284. >
  285. <Input
  286. className="!w-full !bg-slate-950 !border !border-slate-800 !rounded-lg !px-4 !py-3 !text-slate-100 placeholder:!text-slate-500"
  287. placeholder="请输入您的公司全称"
  288. />
  289. </Form.Item>
  290. </div>
  291. </div>
  292. <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
  293. <div className="space-y-2">
  294. <label className="text-xs font-semibold uppercase tracking-wider text-slate-500 ml-1">
  295. 手机号(必填)
  296. </label>
  297. <Form.Item
  298. name="phone"
  299. className="!mb-0"
  300. rules={[
  301. { required: true, message: "请输入手机号" },
  302. {
  303. pattern: /^1\d{10}$/,
  304. message: "请输入正确的11位手机号",
  305. },
  306. ]}
  307. >
  308. <Input
  309. className="!w-full !bg-slate-950 !border !border-slate-800 !rounded-lg !px-4 !py-3 !text-slate-100 placeholder:!text-slate-500"
  310. placeholder="请输入手机号码"
  311. />
  312. </Form.Item>
  313. </div>
  314. <div className="space-y-2">
  315. <label className="text-xs font-semibold uppercase tracking-wider text-slate-500 ml-1">
  316. 验证码(必填)
  317. </label>
  318. <div className="relative">
  319. <Form.Item
  320. name="code"
  321. className="!mb-0"
  322. rules={[{ required: true, message: "请输入验证码" }]}
  323. >
  324. <Input
  325. className="!w-full !bg-slate-950 !border !border-slate-800 !rounded-lg !px-4 !py-3 !pr-24 !text-slate-100 placeholder:!text-slate-500"
  326. placeholder="请输入验证码"
  327. maxLength={6}
  328. />
  329. </Form.Item>
  330. <Button
  331. type="text"
  332. loading={sendingCode}
  333. disabled={sendingCode || sentJustNow || countdown > 0}
  334. onClick={handleSendCode}
  335. className="!absolute !right-2 !top-1.5 !bottom-1.5 !px-3 !text-xs !font-bold !text-blue-300 !bg-slate-800 !rounded-md hover:!bg-secondary hover:!text-white !transition-all"
  336. >
  337. {sentJustNow
  338. ? "已发送"
  339. : countdown > 0
  340. ? `${countdown}s`
  341. : "获取验证码"}
  342. </Button>
  343. </div>
  344. </div>
  345. </div>
  346. <div className="space-y-2">
  347. <label className="text-xs font-semibold uppercase tracking-wider text-slate-500 ml-1">
  348. 部门和职务(可选)
  349. </label>
  350. <Form.Item name="position" className="!mb-0">
  351. <Input
  352. className="!w-full !bg-slate-950 !border !border-slate-800 !rounded-lg !px-4 !py-3 !text-slate-100 placeholder:!text-slate-500"
  353. placeholder="例如:销售部 总监"
  354. />
  355. </Form.Item>
  356. </div>
  357. <div className="flex items-center gap-3 py-2">
  358. <Form.Item
  359. name="privacy"
  360. valuePropName="checked"
  361. className="!mb-0"
  362. rules={[
  363. {
  364. validator: (_, value) =>
  365. value
  366. ? Promise.resolve()
  367. : Promise.reject(
  368. new Error("请先阅读并同意隐私协议与用户协议"),
  369. ),
  370. },
  371. ]}
  372. >
  373. <Checkbox className="[&_.ant-checkbox-inner]:!bg-slate-900 [&_.ant-checkbox-inner]:!border-slate-600">
  374. <span className="text-xs text-slate-400">
  375. 我已阅读并同意
  376. <a
  377. className="text-secondary hover:underline"
  378. href="/privacy"
  379. target="_blank"
  380. rel="noreferrer"
  381. >
  382. 《隐私协议》
  383. </a>
  384. <a
  385. className="text-secondary hover:underline"
  386. href="/agreement"
  387. target="_blank"
  388. rel="noreferrer"
  389. >
  390. 《用户协议》
  391. </a>
  392. </span>
  393. </Checkbox>
  394. </Form.Item>
  395. </div>
  396. <button
  397. type="submit"
  398. disabled={submitting}
  399. className="w-full bg-primary text-white py-4 rounded-lg font-bold text-lg shadow-lg hover:bg-secondary transition-all active:scale-95 disabled:opacity-60 disabled:cursor-not-allowed"
  400. >
  401. 提交信息
  402. </button>
  403. </Form>
  404. </>
  405. )}
  406. </motion.div>
  407. </motion.div>
  408. </div>
  409. </div>
  410. );
  411. }