HomePageClient.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. "use client";
  2. import { useEffect, useState } from "react";
  3. import Link from "next/link";
  4. import { Button } from "@/components/ui/button";
  5. import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
  6. import {
  7. Bot,
  8. BookOpen,
  9. Users,
  10. Wand2,
  11. LineChart,
  12. ScrollText,
  13. Globe,
  14. LayoutDashboard,
  15. FileText,
  16. ArrowRight,
  17. ChevronLeft,
  18. ChevronRight,
  19. MessageSquare,
  20. Github,
  21. Mail,
  22. } from "lucide-react";
  23. import { ScreenshotDisplay } from "@/components/ScreenshotDisplay";
  24. import { ChatWidget } from "@/components/visitor/ChatWidget";
  25. import { FloatingButton } from "@/components/visitor/FloatingButton";
  26. import { Header } from "@/components/layout/Header";
  27. import { Footer } from "@/components/layout/Footer";
  28. import { FadeIn, FadeInStagger, FadeInItem } from "@/components/ui/fade-in";
  29. import { websiteConfig } from "@/lib/website-config";
  30. import { getOrCreateVisitorId } from "@/lib/visitor-id";
  31. import { stats } from "@/lib/stats-config";
  32. import type { I18nKey } from "@/lib/i18n/dict";
  33. import { useI18n } from "@/lib/i18n/provider";
  34. import type { LucideIcon } from "lucide-react";
  35. const CAPABILITY_ITEMS: {
  36. icon: LucideIcon;
  37. titleKey: I18nKey;
  38. descKey: I18nKey;
  39. }[] = [
  40. { icon: Bot, titleKey: "home.cap.multimodel.title", descKey: "home.cap.multimodel.desc" },
  41. { icon: BookOpen, titleKey: "home.cap.kb.title", descKey: "home.cap.kb.desc" },
  42. { icon: Wand2, titleKey: "home.cap.prompt.title", descKey: "home.cap.prompt.desc" },
  43. { icon: Users, titleKey: "home.cap.human.title", descKey: "home.cap.human.desc" },
  44. { icon: LineChart, titleKey: "home.cap.reports.title", descKey: "home.cap.reports.desc" },
  45. { icon: ScrollText, titleKey: "home.cap.logs.title", descKey: "home.cap.logs.desc" },
  46. ];
  47. const QUICK_STEPS: { titleKey: I18nKey; bodyKey: I18nKey }[] = [
  48. { titleKey: "home.step1.title", bodyKey: "home.step1.body" },
  49. { titleKey: "home.step2.title", bodyKey: "home.step2.body" },
  50. { titleKey: "home.step3.title", bodyKey: "home.step3.body" },
  51. ];
  52. const SCREENSHOT_ITEMS: {
  53. slug: string;
  54. imageName: string;
  55. placeholderIcon: LucideIcon;
  56. titleKey: I18nKey;
  57. placeholderKey: I18nKey;
  58. altKey: I18nKey;
  59. }[] = [
  60. {
  61. slug: "dashboard",
  62. imageName: "dashboard.png",
  63. placeholderIcon: LayoutDashboard,
  64. titleKey: "home.ss.dashboard.title",
  65. placeholderKey: "home.ss.dashboard.placeholder",
  66. altKey: "home.ss.dashboard.alt",
  67. },
  68. {
  69. slug: "visitor",
  70. imageName: "visitor.png",
  71. placeholderIcon: Globe,
  72. titleKey: "home.ss.visitor.title",
  73. placeholderKey: "home.ss.visitor.placeholder",
  74. altKey: "home.ss.visitor.alt",
  75. },
  76. {
  77. slug: "ai-config",
  78. imageName: "ai-config.png",
  79. placeholderIcon: Bot,
  80. titleKey: "home.ss.aiconfig.title",
  81. placeholderKey: "home.ss.aiconfig.placeholder",
  82. altKey: "home.ss.aiconfig.alt",
  83. },
  84. {
  85. slug: "users",
  86. imageName: "users.png",
  87. placeholderIcon: Users,
  88. titleKey: "home.ss.users.title",
  89. placeholderKey: "home.ss.users.placeholder",
  90. altKey: "home.ss.users.alt",
  91. },
  92. {
  93. slug: "faq",
  94. imageName: "faq.png",
  95. placeholderIcon: FileText,
  96. titleKey: "home.ss.faq.title",
  97. placeholderKey: "home.ss.faq.placeholder",
  98. altKey: "home.ss.faq.alt",
  99. },
  100. {
  101. slug: "knowledge",
  102. imageName: "knowledge.png",
  103. placeholderIcon: BookOpen,
  104. titleKey: "home.ss.knowledge.title",
  105. placeholderKey: "home.ss.knowledge.placeholder",
  106. altKey: "home.ss.knowledge.alt",
  107. },
  108. {
  109. slug: "conversations",
  110. imageName: "conversations.png",
  111. placeholderIcon: MessageSquare,
  112. titleKey: "home.ss.kbtest.title",
  113. placeholderKey: "home.ss.kbtest.placeholder",
  114. altKey: "home.ss.kbtest.alt",
  115. },
  116. {
  117. slug: "prompts",
  118. imageName: "prompts.png",
  119. placeholderIcon: Wand2,
  120. titleKey: "home.ss.prompts.title",
  121. placeholderKey: "home.ss.prompts.placeholder",
  122. altKey: "home.ss.prompts.alt",
  123. },
  124. {
  125. slug: "logs",
  126. imageName: "logs.png",
  127. placeholderIcon: ScrollText,
  128. titleKey: "home.ss.logs.title",
  129. placeholderKey: "home.ss.logs.placeholder",
  130. altKey: "home.ss.logs.alt",
  131. },
  132. {
  133. slug: "analytics",
  134. imageName: "analytics.png",
  135. placeholderIcon: LineChart,
  136. titleKey: "home.ss.analytics.title",
  137. placeholderKey: "home.ss.analytics.placeholder",
  138. altKey: "home.ss.analytics.alt",
  139. },
  140. ];
  141. export function HomePageClient() {
  142. const { t } = useI18n();
  143. const [visitorId, setVisitorId] = useState<number | null>(null);
  144. const [isChatOpen, setIsChatOpen] = useState(false);
  145. const [activeScreenshot, setActiveScreenshot] = useState(0);
  146. useEffect(() => {
  147. setVisitorId(getOrCreateVisitorId());
  148. }, []);
  149. useEffect(() => {
  150. const params = new URLSearchParams(window.location.search);
  151. if (params.get("openChat") === "1") {
  152. handleOpenChat();
  153. params.delete("openChat");
  154. const next = `${window.location.pathname}${params.toString() ? `?${params}` : ""}`;
  155. window.history.replaceState(null, "", next);
  156. }
  157. // eslint-disable-next-line react-hooks/exhaustive-deps -- 仅响应 URL 参数
  158. }, [visitorId]);
  159. const handleToggleChat = () => setIsChatOpen((prev) => !prev);
  160. const handleOpenChat = () => {
  161. if (visitorId === null) {
  162. setTimeout(() => setIsChatOpen(true), 500);
  163. } else {
  164. setIsChatOpen(true);
  165. }
  166. };
  167. const totalScreenshots = SCREENSHOT_ITEMS.length;
  168. const prevScreenshotIndex =
  169. (activeScreenshot - 1 + totalScreenshots) % totalScreenshots;
  170. const nextScreenshotIndex = (activeScreenshot + 1) % totalScreenshots;
  171. const goPrevScreenshot = () => {
  172. setActiveScreenshot((prev) => (prev - 1 + totalScreenshots) % totalScreenshots);
  173. };
  174. const goNextScreenshot = () => {
  175. setActiveScreenshot((prev) => (prev + 1) % totalScreenshots);
  176. };
  177. useEffect(() => {
  178. const timer = window.setInterval(() => {
  179. setActiveScreenshot((prev) => (prev + 1) % totalScreenshots);
  180. }, 4800);
  181. return () => window.clearInterval(timer);
  182. }, [totalScreenshots]);
  183. return (
  184. <div className="min-h-screen bg-background text-foreground">
  185. <Header />
  186. {/* Hero(回归旧版文案气质,保留新版三按钮) */}
  187. <section className="relative overflow-hidden border-b border-border/40">
  188. <div
  189. className="pointer-events-none absolute inset-0 bg-[radial-gradient(120%_80%_at_50%_-20%,rgba(37,99,235,0.14),transparent_55%)]"
  190. aria-hidden
  191. />
  192. <div
  193. className="pointer-events-none absolute inset-0 bg-gradient-to-b from-blue-50/80 via-background to-background"
  194. aria-hidden
  195. />
  196. <div className="container relative mx-auto px-6 pb-32 pt-20 md:pb-40 md:pt-28 lg:pt-28 xl:max-w-[1280px]">
  197. <FadeIn>
  198. <div className="mx-auto max-w-4xl text-center">
  199. <p className="mb-4 text-sm font-medium text-muted-foreground tracking-wide uppercase">
  200. {t("home.hero.tagline")}
  201. </p>
  202. <h1 className="mb-6 text-balance text-4xl font-bold tracking-tight text-foreground sm:text-5xl md:text-6xl md:leading-[1.12]">
  203. {t("home.hero.title")}
  204. </h1>
  205. <p className="mx-auto mb-10 max-w-3xl text-pretty text-lg sm:text-xl text-muted-foreground leading-relaxed">
  206. {t("home.hero.subtitle")}
  207. </p>
  208. <div className="flex flex-col items-stretch justify-center gap-3 sm:flex-row sm:flex-wrap sm:items-center">
  209. <Button
  210. size="lg"
  211. className="rounded-xl bg-blue-600 px-8 py-6 text-[15px] shadow-sm transition-all hover:bg-blue-500 hover:shadow-md"
  212. onClick={handleOpenChat}
  213. >
  214. {t("home.hero.cta.tryNow")}
  215. <ArrowRight className="ml-2 h-4 w-4" />
  216. </Button>
  217. <Button
  218. size="lg"
  219. variant="outline"
  220. className="rounded-xl border-border/80 px-8 py-6 text-[15px] bg-background/60 backdrop-blur-sm"
  221. asChild
  222. >
  223. <Link
  224. href="/agent/login"
  225. target="_blank"
  226. rel="noopener noreferrer"
  227. className="inline-flex items-center justify-center gap-2"
  228. >
  229. {t("home.hero.cta.agentLogin")}
  230. </Link>
  231. </Button>
  232. </div>
  233. <p className="mt-4 text-sm text-muted-foreground">{t("home.hero.hint")}</p>
  234. </div>
  235. </FadeIn>
  236. </div>
  237. </section>
  238. {/* 数字条(沿用旧版) */}
  239. <section className="py-16 md:py-20 border-t border-border/50">
  240. <FadeIn>
  241. <div className="container mx-auto px-6">
  242. <p className="text-xs font-medium text-muted-foreground text-center mb-8 tracking-wide">
  243. {t("home.stats.trustedBy")}
  244. </p>
  245. <div className="grid grid-cols-2 md:grid-cols-4 gap-10 max-w-6xl mx-auto">
  246. {stats.map((stat) => (
  247. <div key={stat.labelKey} className="text-center">
  248. <div className="text-3xl md:text-4xl font-semibold text-foreground">
  249. {t(stat.valueKey)}
  250. </div>
  251. <div className="mt-1 text-sm text-muted-foreground">{t(stat.labelKey)}</div>
  252. </div>
  253. ))}
  254. </div>
  255. </div>
  256. </FadeIn>
  257. </section>
  258. {/* 核心能力 */}
  259. <section id="features" className="relative scroll-mt-20">
  260. <div className="pointer-events-none absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-blue-200/50 to-transparent" aria-hidden />
  261. <div className="container mx-auto px-6 py-20 md:py-28">
  262. <FadeIn>
  263. <div className="mb-14 text-center px-4">
  264. <h2 className="mb-3 text-3xl font-semibold tracking-tight text-foreground sm:text-4xl">
  265. {t("home.features.title")}
  266. </h2>
  267. <p className="mx-auto max-w-xl text-base text-muted-foreground">
  268. {t("home.features.lead")}
  269. </p>
  270. </div>
  271. </FadeIn>
  272. <FadeInStagger className="mx-auto grid max-w-6xl grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 lg:gap-6">
  273. {CAPABILITY_ITEMS.map((item) => {
  274. const Icon = item.icon;
  275. return (
  276. <FadeInItem key={item.titleKey}>
  277. <Card className="group h-full border border-border/60 bg-card/90 shadow-sm backdrop-blur-sm transition-all duration-300 hover:-translate-y-0.5 hover:border-blue-200/70 hover:shadow-md">
  278. <CardHeader className="pb-3">
  279. <div className="mb-4 flex h-11 w-11 items-center justify-center rounded-xl border border-blue-100/80 bg-gradient-to-br from-blue-50 to-background text-blue-700 transition-transform duration-300 group-hover:scale-[1.03]">
  280. <Icon className="h-5 w-5" />
  281. </div>
  282. <CardTitle className="text-lg font-semibold tracking-tight">
  283. {t(item.titleKey)}
  284. </CardTitle>
  285. <CardDescription className="text-sm leading-relaxed text-muted-foreground">
  286. {t(item.descKey)}
  287. </CardDescription>
  288. </CardHeader>
  289. </Card>
  290. </FadeInItem>
  291. );
  292. })}
  293. </FadeInStagger>
  294. </div>
  295. </section>
  296. {/* 界面展示 */}
  297. <FadeIn>
  298. <section
  299. id="screenshots"
  300. className="scroll-mt-20 border-t border-border/40 bg-muted/20 py-20 md:py-28"
  301. >
  302. <div className="container mx-auto px-6">
  303. <div className="mb-14 text-center px-4">
  304. <h2 className="mb-3 text-3xl font-semibold tracking-tight sm:text-4xl">
  305. {t("home.screenshots.title")}
  306. </h2>
  307. <p className="mx-auto max-w-xl text-muted-foreground">
  308. {t("home.screenshots.lead")}
  309. </p>
  310. </div>
  311. <div className="mx-auto max-w-6xl">
  312. <div className="mb-8 flex flex-wrap justify-center gap-2">
  313. {SCREENSHOT_ITEMS.map((item, idx) => (
  314. <button
  315. key={item.slug}
  316. type="button"
  317. onClick={() => setActiveScreenshot(idx)}
  318. className={`rounded-full px-4 py-1.5 text-sm transition-all ${
  319. idx === activeScreenshot
  320. ? "bg-blue-600 text-white shadow-sm"
  321. : "bg-background text-muted-foreground border border-border/70 hover:text-foreground hover:border-blue-200"
  322. }`}
  323. >
  324. {t(item.titleKey)}
  325. </button>
  326. ))}
  327. </div>
  328. <div className="relative mx-auto max-w-6xl px-4 md:px-8">
  329. <div className="pointer-events-none absolute inset-0 -z-10 bg-[radial-gradient(80%_60%_at_50%_40%,rgba(37,99,235,0.14),transparent_70%)]" />
  330. <div className="relative h-[290px] md:h-[420px] lg:h-[510px]">
  331. <button
  332. type="button"
  333. onClick={goPrevScreenshot}
  334. className="absolute left-0 top-1/2 z-40 -translate-y-1/2 rounded-full border border-border/70 bg-background/90 p-2.5 shadow-sm backdrop-blur transition hover:border-blue-200 hover:bg-background"
  335. aria-label={t("home.screenshots.prevAria")}
  336. >
  337. <ChevronLeft className="h-5 w-5" />
  338. </button>
  339. <button
  340. type="button"
  341. onClick={goNextScreenshot}
  342. className="absolute right-0 top-1/2 z-40 -translate-y-1/2 rounded-full border border-border/70 bg-background/90 p-2.5 shadow-sm backdrop-blur transition hover:border-blue-200 hover:bg-background"
  343. aria-label={t("home.screenshots.nextAria")}
  344. >
  345. <ChevronRight className="h-5 w-5" />
  346. </button>
  347. {/* 左侧半露卡片 */}
  348. <div className="absolute left-6 right-[42%] top-7 z-10 hidden overflow-hidden rounded-2xl border border-border/60 bg-background/85 shadow-md md:block">
  349. <div className="pointer-events-none absolute inset-0 z-10 bg-background/18" />
  350. <ScreenshotDisplay
  351. imageName={SCREENSHOT_ITEMS[prevScreenshotIndex].imageName}
  352. placeholderIcon={SCREENSHOT_ITEMS[prevScreenshotIndex].placeholderIcon}
  353. placeholderText={t(SCREENSHOT_ITEMS[prevScreenshotIndex].placeholderKey)}
  354. alt={t(SCREENSHOT_ITEMS[prevScreenshotIndex].altKey)}
  355. />
  356. </div>
  357. {/* 右侧半露卡片 */}
  358. <div className="absolute left-[42%] right-6 top-7 z-10 hidden overflow-hidden rounded-2xl border border-border/60 bg-background/85 shadow-md md:block">
  359. <div className="pointer-events-none absolute inset-0 z-10 bg-background/18" />
  360. <ScreenshotDisplay
  361. imageName={SCREENSHOT_ITEMS[nextScreenshotIndex].imageName}
  362. placeholderIcon={SCREENSHOT_ITEMS[nextScreenshotIndex].placeholderIcon}
  363. placeholderText={t(SCREENSHOT_ITEMS[nextScreenshotIndex].placeholderKey)}
  364. alt={t(SCREENSHOT_ITEMS[nextScreenshotIndex].altKey)}
  365. />
  366. </div>
  367. {/* 中间主卡片 */}
  368. <div className="absolute inset-x-8 top-0 z-30 overflow-hidden rounded-2xl border border-border/70 bg-background shadow-xl ring-1 ring-blue-100/60 md:inset-x-16 lg:inset-x-24">
  369. <ScreenshotDisplay
  370. imageName={SCREENSHOT_ITEMS[activeScreenshot].imageName}
  371. placeholderIcon={SCREENSHOT_ITEMS[activeScreenshot].placeholderIcon}
  372. placeholderText={t(SCREENSHOT_ITEMS[activeScreenshot].placeholderKey)}
  373. alt={t(SCREENSHOT_ITEMS[activeScreenshot].altKey)}
  374. />
  375. </div>
  376. </div>
  377. </div>
  378. </div>
  379. </div>
  380. </section>
  381. </FadeIn>
  382. {/* 快速接入 */}
  383. <section id="quick-start" className="relative scroll-mt-20 border-t border-border/40">
  384. <div
  385. className="pointer-events-none absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-border to-transparent"
  386. aria-hidden
  387. />
  388. <div className="container mx-auto px-6 py-20 md:py-28">
  389. <FadeIn>
  390. <div className="mb-12 text-center px-4">
  391. <h2 className="mb-3 text-3xl font-semibold tracking-tight sm:text-4xl">
  392. {t("home.quickStart.title")}
  393. </h2>
  394. <p className="text-muted-foreground">{t("home.quickStart.lead")}</p>
  395. </div>
  396. </FadeIn>
  397. <FadeInStagger className="mx-auto grid max-w-4xl grid-cols-1 gap-8 md:grid-cols-3">
  398. {QUICK_STEPS.map((step, i) => (
  399. <FadeInItem key={step.titleKey}>
  400. <div className="relative rounded-2xl border border-border/60 bg-card/50 p-6 text-center md:text-left transition-all duration-300 hover:border-blue-200/70 hover:shadow-md hover:-translate-y-0.5">
  401. <div className="mx-auto mb-4 flex h-10 w-10 items-center justify-center rounded-full border border-blue-200/80 bg-blue-50/80 text-sm font-semibold text-blue-800 md:mx-0">
  402. {i + 1}
  403. </div>
  404. <h3 className="mb-2 font-semibold">{t(step.titleKey)}</h3>
  405. <p className="text-sm leading-relaxed text-muted-foreground">{t(step.bodyKey)}</p>
  406. </div>
  407. </FadeInItem>
  408. ))}
  409. </FadeInStagger>
  410. </div>
  411. </section>
  412. {/* 收尾 CTA */}
  413. <section className="relative border-t border-border/40 overflow-hidden">
  414. <div
  415. className="pointer-events-none absolute inset-0 bg-gradient-to-br from-blue-600/[0.07] via-transparent to-blue-400/[0.06]"
  416. aria-hidden
  417. />
  418. <div className="container relative mx-auto px-6 py-20 text-center md:py-28">
  419. <FadeIn>
  420. <h2 className="mb-4 text-3xl font-semibold tracking-tight sm:text-4xl">
  421. {t("home.cta.title")}
  422. </h2>
  423. <p className="mx-auto mb-10 max-w-lg text-muted-foreground leading-relaxed">
  424. {t("home.cta.subtitle")}
  425. </p>
  426. <div className="flex flex-col items-stretch justify-center gap-3 sm:flex-row sm:flex-wrap sm:justify-center">
  427. <Button size="lg" className="rounded-xl bg-blue-600 px-8 shadow-sm hover:bg-blue-500" asChild>
  428. <a
  429. href={websiteConfig.github.repo}
  430. target="_blank"
  431. rel="noopener noreferrer"
  432. className="inline-flex items-center justify-center gap-2"
  433. >
  434. <Github className="h-4 w-4" />
  435. {t("home.cta.starRepo")}
  436. </a>
  437. </Button>
  438. <Button size="lg" variant="outline" className="rounded-xl border-border/80 px-8 bg-background/80" asChild>
  439. <a
  440. href={`mailto:2930134478@qq.com?subject=${encodeURIComponent(t("home.cta.mailSubject"))}&body=${encodeURIComponent(t("home.cta.mailBody"))}`}
  441. className="inline-flex items-center justify-center gap-2"
  442. >
  443. {t("home.cta.feedback")}
  444. <Mail className="h-3.5 w-3.5" />
  445. </a>
  446. </Button>
  447. </div>
  448. </FadeIn>
  449. </div>
  450. </section>
  451. <Footer onOpenChat={handleOpenChat} />
  452. {visitorId !== null && (
  453. <>
  454. <FloatingButton onClick={handleToggleChat} isOpen={isChatOpen} />
  455. {isChatOpen && (
  456. <ChatWidget visitorId={visitorId} isOpen={isChatOpen} onToggle={handleToggleChat} />
  457. )}
  458. </>
  459. )}
  460. </div>
  461. );
  462. }