ai-chatbot/components/home/lovart-home.tsx
Your Name 459dc5ccbb
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
重做新版首页布局并完善项目首页交互
2026-02-13 19:52:09 +08:00

874 lines
34 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { Fragment, useEffect, useMemo, useRef, useState } from "react";
import { useRouter } from "next/navigation";
import useSWR from "swr";
import {
Bell,
ChevronDown,
Folder,
Globe,
Heart,
Hexagon,
Home,
Info,
MapPin,
Plus,
Send,
Sparkles,
Upload,
User,
Zap,
} from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/ui/hover-card";
import { Textarea } from "@/components/ui/textarea";
import { fetcher } from "@/lib/utils";
import {
type CanvasLaunchAttachment,
getCanvasLaunchStorageKey,
} from "@/lib/canvas-launch";
import type { MembershipConfig } from "@/lib/membership/config";
type HomeUser = {
id: string;
email?: string | null;
name?: string | null;
image?: string | null;
};
type CanvasProject = {
id: string;
title: string;
thumbnail?: string | null;
createdAt?: string;
updatedAt?: string;
};
type FeaturedImage = {
id: string;
thumbnailUrl: string;
originalUrl: string;
prompt?: string | null;
user?: {
name?: string;
department?: string;
};
};
type MembershipSummaryResponse = {
config: MembershipConfig;
currentPlanId: string;
currentPlan: {
id: string;
name: string;
monthlyPrice: number;
annualPrice: number;
monthlyCredits: number;
dailyFreeCredits: number;
features: string[];
badge?: string;
highlighted?: boolean;
};
summary: {
currentCredits: number;
dailyFreeCredits: number;
usedThisMonth: number;
monthlyLimit: number | null;
remainingThisMonth: number | null;
totalImages: number;
};
};
type LovartHomeProps = {
user: HomeUser;
siteName: string;
siteLogo?: string | null;
surpriseCategories: string[];
};
type UploadFileItem = {
id: string;
file: File;
previewUrl: string;
};
const DISCOVERY_DEFAULT_TABS = [
"品牌设计",
"海报与广告",
"插画",
"UI设计",
"角色设计",
"影片与分镜",
"产品设计",
"建筑设计",
];
const PROMPT_TAGS = [
"Nano Banana Pro",
"Design",
"Branding",
"Illustration",
"E-Commerce",
"Video",
];
const MASONRY_HEIGHTS = [420, 290, 340, 470, 300, 360, 430, 320];
function formatRelativeTime(value?: string) {
if (!value) return "更新于今天";
const date = new Date(value);
if (Number.isNaN(date.getTime())) return "更新于今天";
const diffMs = Date.now() - date.getTime();
const minute = 60 * 1000;
const hour = 60 * minute;
const day = 24 * hour;
if (diffMs < hour) return `更新于 ${Math.max(1, Math.round(diffMs / minute))} 分钟前`;
if (diffMs < day) return `更新于 ${Math.round(diffMs / hour)} 小时前`;
return `更新于 ${Math.round(diffMs / day)} 天前`;
}
function formatPrice(currency: string, value: number) {
if (value <= 0) return "免费";
return `${currency}${value}`;
}
export function LovartHome({
user,
siteName,
siteLogo,
surpriseCategories,
}: LovartHomeProps) {
const router = useRouter();
const [prompt, setPrompt] = useState("");
const [files, setFiles] = useState<UploadFileItem[]>([]);
const [isSubmitting, setIsSubmitting] = useState(false);
const [activeCategory, setActiveCategory] = useState("全部");
const [upgradeDialogOpen, setUpgradeDialogOpen] = useState(false);
const [billingCycle, setBillingCycle] = useState<"monthly" | "annual">("monthly");
const projectSectionRef = useRef<HTMLDivElement | null>(null);
const filesRef = useRef<UploadFileItem[]>([]);
const { data: canvasData, mutate: mutateCanvas } = useSWR<{
success: boolean;
data: CanvasProject[];
}>("/api/canvas", fetcher);
const { data: featuredData } = useSWR<{
images: FeaturedImage[];
}>("/api/featured?page=1&pageSize=40", fetcher);
const { data: membershipData } = useSWR<MembershipSummaryResponse>(
"/api/user/membership-summary",
fetcher
);
const membershipConfig = membershipData?.config;
const membershipPlans = membershipConfig?.plans || [];
const currentPlan = membershipData?.currentPlan;
const groupedModelRows = useMemo(() => {
const rows = membershipConfig?.modelRows || [];
return rows.reduce<Record<string, typeof rows>>((acc, row) => {
if (!acc[row.category]) {
acc[row.category] = [];
}
acc[row.category].push(row);
return acc;
}, {});
}, [membershipConfig?.modelRows]);
const discoveryTabs = useMemo(() => {
const merged = [
"全部",
...surpriseCategories.filter((item) => item && item !== "全部"),
...DISCOVERY_DEFAULT_TABS,
];
return Array.from(new Set(merged)).slice(0, 12);
}, [surpriseCategories]);
const featuredItems = useMemo(() => {
const images = featuredData?.images || [];
if (activeCategory === "全部") {
return images;
}
const keyword = activeCategory.toLowerCase();
return images.filter((item) =>
String(item.prompt || "").toLowerCase().includes(keyword)
);
}, [featuredData?.images, activeCategory]);
const recentProjects = useMemo(() => {
return (canvasData?.data || []).slice(0, 7);
}, [canvasData?.data]);
useEffect(() => {
filesRef.current = files;
}, [files]);
useEffect(() => {
return () => {
filesRef.current.forEach((item) => URL.revokeObjectURL(item.previewUrl));
};
}, []);
const handleAddFiles = (targetFiles: FileList | null) => {
if (!targetFiles || targetFiles.length === 0) return;
const accepted = Array.from(targetFiles)
.filter((file) => file.type.startsWith("image/"))
.slice(0, 6);
if (accepted.length === 0) {
toast.error("请上传图片文件");
return;
}
const next = accepted.map((file) => ({
id: `${file.name}-${Date.now()}-${Math.random().toString(16).slice(2)}`,
file,
previewUrl: URL.createObjectURL(file),
}));
setFiles((prev) => [...prev, ...next].slice(0, 6));
};
const removeFile = (id: string) => {
setFiles((prev) => {
const target = prev.find((item) => item.id === id);
if (target) {
URL.revokeObjectURL(target.previewUrl);
}
return prev.filter((item) => item.id !== id);
});
};
const uploadSelectedFiles = async (): Promise<CanvasLaunchAttachment[]> => {
const result: CanvasLaunchAttachment[] = [];
for (const item of files) {
const formData = new FormData();
formData.append("file", item.file);
const response = await fetch("/api/files/upload", {
method: "POST",
body: formData,
});
const data = await response.json();
if (!response.ok || !data?.url) {
throw new Error(data?.error || "上传失败");
}
result.push({
url: data.url,
name: item.file.name,
contentType: item.file.type || "image/jpeg",
});
}
return result;
};
const createCanvasFromComposer = async () => {
if (!prompt.trim() && files.length === 0) return;
setIsSubmitting(true);
try {
const uploadedAttachments = await uploadSelectedFiles();
const title = prompt.trim()
? prompt.trim().slice(0, 24)
: `新建项目 ${new Date().toLocaleDateString("zh-CN")}`;
const canvasResponse = await fetch("/api/canvas", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ title }),
});
const canvasResult = await canvasResponse.json();
if (!canvasResponse.ok || !canvasResult?.data?.id) {
throw new Error(canvasResult?.error || "创建项目失败");
}
const canvasId: string = canvasResult.data.id;
if (typeof window !== "undefined") {
sessionStorage.setItem(
getCanvasLaunchStorageKey(canvasId),
JSON.stringify({
prompt:
prompt.trim() ||
(uploadedAttachments.length > 0
? "请基于这些图片继续生成设计方案"
: ""),
attachments: uploadedAttachments,
autoSend: true,
createdAt: Date.now(),
})
);
}
files.forEach((item) => URL.revokeObjectURL(item.previewUrl));
setFiles([]);
setPrompt("");
await mutateCanvas();
router.push(`/canvas/${canvasId}`);
} catch (error) {
toast.error(error instanceof Error ? error.message : "创建项目失败");
} finally {
setIsSubmitting(false);
}
};
const openNewCanvas = () => {
router.push("/canvas?new=1");
};
return (
<div className="min-h-svh bg-[#f4f4f4] text-[#171717]">
<header className="fixed left-0 top-0 z-40 h-[68px] w-full border-b border-black/5 bg-[#f4f4f4]/90 backdrop-blur">
<div className="mx-auto flex h-full max-w-[1360px] items-center justify-between px-6">
<button
type="button"
className="flex items-center gap-2"
onClick={() => window.scrollTo({ top: 0, behavior: "smooth" })}
>
{siteLogo ? (
<img src={siteLogo} alt={siteName} className="h-8 w-8 rounded-full object-cover" />
) : (
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-black text-white">
<Sparkles className="h-4 w-4" />
</div>
)}
<span className="text-[34px] font-semibold leading-none tracking-tight">
{siteName || "Lovart"}
</span>
</button>
<div className="flex items-center gap-3">
<button className="inline-flex items-center gap-1 rounded-full px-2 py-1 text-sm text-black/80 hover:bg-black/5">
简体中文
<ChevronDown className="h-3.5 w-3.5" />
</button>
<button className="flex h-9 w-9 items-center justify-center rounded-xl bg-black/5 text-black/75 hover:bg-black/10">
<Bell className="h-4 w-4" />
</button>
<HoverCard openDelay={100} closeDelay={120}>
<HoverCardTrigger asChild>
<Button
variant="ghost"
onClick={() => setUpgradeDialogOpen(true)}
className="h-10 rounded-xl bg-[#1c1c1e] px-3 text-white hover:bg-black"
>
<span className="mr-2 text-base">升级</span>
<div className="inline-flex items-center gap-1 rounded-[10px] bg-white/10 px-2 py-1 text-sm">
<Zap className="h-3.5 w-3.5 text-amber-300" />
{membershipData?.summary?.currentCredits ?? 0}
</div>
</Button>
</HoverCardTrigger>
<HoverCardContent align="end" sideOffset={10} className="w-[430px] rounded-3xl border border-black/10 bg-white p-0 shadow-xl">
<div className="p-6">
<div className="mb-4 flex items-start justify-between">
<div>
<div className="text-[42px] font-semibold leading-none text-black">
{currentPlan?.name || "Free"}
</div>
</div>
<Button
size="sm"
className="rounded-2xl bg-[#2f3542] px-5 text-white hover:bg-[#242a36]"
onClick={() => setUpgradeDialogOpen(true)}
>
升级
</Button>
</div>
<div className="space-y-3 border-t border-black/10 pt-4 text-[34px]">
<div className="flex items-center justify-between">
<span className="inline-flex items-center gap-2 text-black/80">
<Sparkles className="h-4 w-4" />
积分
</span>
<span>{membershipData?.summary?.currentCredits ?? 0}</span>
</div>
<div className="flex items-center justify-between">
<span className="inline-flex items-center gap-2 text-black/80">
<Upload className="h-4 w-4" />
每日免费积分
</span>
<span>{membershipData?.summary?.dailyFreeCredits ?? 0}</span>
</div>
</div>
<button
type="button"
className="mt-6 inline-flex items-center gap-1 text-sm font-medium text-black/80 hover:text-black"
onClick={() => setUpgradeDialogOpen(true)}
>
使用详情
<ChevronDown className="h-4 w-4 -rotate-90" />
</button>
</div>
</HoverCardContent>
</HoverCard>
<button className="flex h-10 w-10 items-center justify-center rounded-full bg-[#d4551f] text-base font-semibold text-white">
{(user.name || user.email || "mu").slice(0, 2).toLowerCase()}
</button>
</div>
</div>
</header>
<aside className="fixed left-6 top-[310px] z-30 hidden flex-col items-center gap-3 lg:flex">
<button
type="button"
onClick={openNewCanvas}
className="flex h-[62px] w-[62px] items-center justify-center rounded-full border border-black/10 bg-white shadow"
>
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-black text-white">
<Plus className="h-5 w-5" />
</div>
</button>
<div className="flex w-[62px] flex-col items-center gap-1 rounded-[30px] border border-black/10 bg-white px-2 py-2 shadow">
<button
type="button"
className="flex h-10 w-10 items-center justify-center rounded-full bg-black/5"
onClick={() => window.scrollTo({ top: 0, behavior: "smooth" })}
>
<Home className="h-4 w-4" />
</button>
<button
type="button"
className="flex h-10 w-10 items-center justify-center rounded-full hover:bg-black/5"
onClick={() =>
projectSectionRef.current?.scrollIntoView({ behavior: "smooth", block: "start" })
}
>
<Folder className="h-4 w-4" />
</button>
<button
type="button"
className="flex h-10 w-10 items-center justify-center rounded-full hover:bg-black/5"
onClick={() => toast.info("个人主页模块后续开放")}
>
<User className="h-4 w-4" />
</button>
<button
type="button"
className="flex h-10 w-10 items-center justify-center rounded-full hover:bg-black/5"
onClick={() => toast.info("帮助中心后续开放")}
>
<Info className="h-4 w-4" />
</button>
</div>
</aside>
<main className="mx-auto max-w-[1360px] px-6 pb-20 pt-[88px]">
<section className="mt-10 text-center">
<button
type="button"
onClick={() => setUpgradeDialogOpen(true)}
className="inline-flex items-center gap-2 rounded-full bg-[#fde8bf] px-4 py-2 text-sm text-black/80"
>
<span className="rounded-full bg-[#ff9d3d] px-2 py-0.5 text-[10px] font-semibold text-white">NEW</span>
现在升级,立享 Kling 3.0 与 Nano Banana Pro,最高 5 折优惠
<span className="text-[#ff7a00]">立即升级</span>
</button>
<div className="mt-9 flex items-center justify-center gap-2">
{siteLogo ? (
<img src={siteLogo} alt={siteName} className="h-10 w-10 rounded-full object-cover" />
) : (
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-black text-white">
<Sparkles className="h-4 w-4" />
</div>
)}
<h1 className="text-[54px] font-semibold tracking-tight">
{siteName || "Lovart"} 让设计更简单
</h1>
</div>
<p className="mt-2 text-lg text-black/35">懂你的设计代理,帮你搞定一切</p>
<div className="mx-auto mt-7 w-full max-w-[900px] rounded-[26px] border border-black/10 bg-white px-4 pb-3 pt-4 shadow-[0_10px_24px_rgba(0,0,0,0.05)]">
<Textarea
value={prompt}
onChange={(event) => setPrompt(event.target.value)}
placeholder="让 Lovart 打造引人注目的社交媒体视觉"
className="min-h-[92px] resize-none border-0 bg-transparent px-1 text-base shadow-none focus-visible:ring-0"
/>
{files.length > 0 && (
<div className="mb-3 flex flex-wrap gap-2 px-1">
{files.map((item) => (
<div key={item.id} className="group relative h-12 w-12 overflow-hidden rounded-lg border border-black/10">
<img src={item.previewUrl} alt={item.file.name} className="h-full w-full object-cover" />
<button
type="button"
className="absolute right-0 top-0 hidden h-5 w-5 items-center justify-center rounded-bl bg-black/60 text-xs text-white group-hover:flex"
onClick={() => removeFile(item.id)}
>
x
</button>
</div>
))}
</div>
)}
<div className="flex items-center justify-between border-t border-black/8 pt-3">
<label className="inline-flex h-9 w-9 cursor-pointer items-center justify-center rounded-full border border-black/10 text-black/60 hover:bg-black/5">
<Upload className="h-4 w-4" />
<input
type="file"
accept="image/*"
multiple
className="hidden"
onChange={(event) => {
handleAddFiles(event.target.files);
event.target.value = "";
}}
/>
</label>
<div className="flex items-center gap-1.5">
<button className="flex h-8 w-8 items-center justify-center rounded-full border border-black/10 text-black/50 hover:bg-black/5">
<MapPin className="h-3.5 w-3.5" />
</button>
<button className="flex h-8 w-8 items-center justify-center rounded-full border border-black/10 text-black/50 hover:bg-black/5">
<Zap className="h-3.5 w-3.5" />
</button>
<button className="flex h-8 w-8 items-center justify-center rounded-full border border-black/10 text-black/50 hover:bg-black/5">
<Globe className="h-3.5 w-3.5" />
</button>
<button className="flex h-8 w-8 items-center justify-center rounded-full border border-[#72a3ff] text-[#3a78f2]">
<Hexagon className="h-3.5 w-3.5" />
</button>
<Button
onClick={createCanvasFromComposer}
disabled={isSubmitting || (!prompt.trim() && files.length === 0)}
className="h-8 w-8 rounded-full bg-[#9ca3af] p-0 text-white hover:bg-black"
>
<Send className="h-3.5 w-3.5" />
</Button>
</div>
</div>
</div>
<div className="mt-5 flex flex-wrap items-center justify-center gap-2">
{PROMPT_TAGS.map((tag, index) => (
<button
key={tag}
type="button"
className={`rounded-full border px-3 py-1.5 text-sm ${
index === 0
? "border-[#ffb15f] bg-[#fff4e7] text-[#ff8c1f]"
: "border-black/15 bg-white text-black/70"
}`}
>
{tag}
</button>
))}
</div>
</section>
<section ref={projectSectionRef} className="mt-20">
<div className="mb-4 flex items-center justify-between">
<h2 className="text-3xl font-semibold tracking-tight">最近项目</h2>
<button
type="button"
className="text-base text-black/45 hover:text-black"
onClick={() => router.push("/canvas")}
>
查看全部
</button>
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4">
<button
type="button"
onClick={openNewCanvas}
className="rounded-[22px] border border-black/8 bg-white p-3 text-left shadow-sm transition hover:-translate-y-0.5"
>
<div className="flex aspect-[4/3] items-center justify-center rounded-2xl bg-[#efefef]">
<div className="text-center">
<div className="mb-2 text-4xl">+</div>
<div className="text-base">新建项目</div>
</div>
</div>
</button>
{recentProjects.map((item) => (
<button
key={item.id}
type="button"
onClick={() => router.push(`/canvas/${item.id}`)}
className="rounded-[22px] border border-black/8 bg-white p-3 text-left shadow-sm transition hover:-translate-y-0.5"
>
<div className="aspect-[4/3] overflow-hidden rounded-2xl bg-[#efefef]">
{item.thumbnail ? (
<img src={item.thumbnail} alt={item.title} className="h-full w-full object-cover" />
) : (
<div className="flex h-full w-full items-center justify-center text-black/35">Untitled</div>
)}
</div>
<div className="mt-3 text-xl font-medium">{item.title || "Untitled"}</div>
<div className="mt-1 text-sm text-black/35">{formatRelativeTime(item.updatedAt || item.createdAt)}</div>
</button>
))}
{recentProjects.length === 0 && (
<div className="rounded-[22px] border border-dashed border-black/15 bg-white p-6 text-center text-black/40 md:col-span-3">
还没有项目,点击“新建项目”开始。
</div>
)}
</div>
</section>
<section className="mt-16">
<h2 className="text-3xl font-semibold tracking-tight">灵感发现</h2>
<div className="mt-4 flex flex-wrap gap-2">
{discoveryTabs.map((category) => (
<button
key={category}
type="button"
onClick={() => setActiveCategory(category)}
className={`rounded-xl px-4 py-2 text-sm ${
activeCategory === category
? "bg-[#ececec] text-black"
: "text-black/55 hover:bg-white"
}`}
>
{category}
</button>
))}
</div>
<div className="mt-5 columns-1 gap-4 md:columns-2 xl:columns-4">
{featuredItems.slice(0, 20).map((item, index) => (
<button
key={item.id}
type="button"
onClick={() => window.open(item.originalUrl || item.thumbnailUrl, "_blank")}
className="mb-4 block w-full break-inside-avoid rounded-2xl border border-black/8 bg-white text-left shadow-sm"
>
<div
className="overflow-hidden rounded-t-2xl bg-[#e8e8e8]"
style={{ height: `${MASONRY_HEIGHTS[index % MASONRY_HEIGHTS.length]}px` }}
>
<img
src={item.thumbnailUrl || item.originalUrl}
alt={item.prompt || "灵感图"}
className="h-full w-full object-cover"
/>
</div>
<div className="flex items-center justify-between px-3 py-2 text-sm text-black/60">
<div className="line-clamp-1 font-medium text-black/85">
{item.user?.name || "创作者"}
</div>
<div className="inline-flex items-center gap-2 text-xs">
<span className="inline-flex items-center gap-1">
<Sparkles className="h-3 w-3" />
{(1200 + index * 37).toLocaleString()}
</span>
<span className="inline-flex items-center gap-1">
<Heart className="h-3 w-3" />
{(20 + (index % 9) * 11).toLocaleString()}
</span>
</div>
</div>
</button>
))}
{featuredItems.length === 0 && (
<div className="rounded-xl border border-dashed border-black/15 bg-white p-10 text-center text-black/35">
当前没有可展示的灵感数据。
</div>
)}
</div>
</section>
</main>
<button
type="button"
className="fixed bottom-8 right-8 z-20 flex h-11 w-11 items-center justify-center rounded-full border border-black/10 bg-white text-black/50 shadow hover:text-black"
onClick={() => window.scrollTo({ top: 0, behavior: "smooth" })}
>
<Send className="h-4 w-4 -rotate-90" />
</button>
<Dialog open={upgradeDialogOpen} onOpenChange={setUpgradeDialogOpen}>
<DialogContent className="max-h-[92vh] w-[95vw] max-w-[1240px] overflow-hidden rounded-3xl border-black/10 bg-[#f7f7f7] p-0">
<div className="flex h-full max-h-[92vh] flex-col">
<DialogHeader className="border-b border-black/6 px-6 py-5">
<DialogTitle className="text-center text-5xl font-bold text-black">升级您的套餐</DialogTitle>
<div className="mt-3 flex items-center justify-center gap-2">
<Button
variant={billingCycle === "monthly" ? "default" : "outline"}
className="h-8 rounded-full px-4 text-xs"
onClick={() => setBillingCycle("monthly")}
>
月付
</Button>
<Button
variant={billingCycle === "annual" ? "default" : "outline"}
className="h-8 rounded-full px-4 text-xs"
onClick={() => setBillingCycle("annual")}
>
年付
</Button>
<span className="rounded-full bg-[#ffe68f] px-2 py-1 text-xs text-[#8b5e00]">
{membershipConfig?.annualDiscountLabel || "限时优惠"}
</span>
</div>
</DialogHeader>
<div className="flex-1 overflow-y-auto px-5 pb-8 pt-4">
{membershipPlans.length > 0 ? (
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-5">
{membershipPlans.map((plan) => {
const isCurrent = currentPlan?.id === plan.id;
const annualMonthlyPrice =
plan.annualPrice > 0 ? Number((plan.annualPrice / 12).toFixed(2)) : 0;
return (
<div
key={plan.id}
className={`rounded-2xl border bg-white p-4 ${
plan.highlighted
? "border-[#7d87ff] shadow-[0_0_0_2px_rgba(125,135,255,0.25)]"
: "border-black/10"
}`}
>
<div className="mb-3 flex items-center justify-between">
<h3 className="text-3xl font-semibold text-black">{plan.name}</h3>
{plan.badge ? (
<span className="rounded-full bg-[#eef0ff] px-2 py-1 text-[10px] text-[#5b65db]">
{plan.badge}
</span>
) : null}
</div>
<div className="mb-3">
{plan.monthlyPrice <= 0 ? (
<div className="text-4xl font-bold text-black">免费</div>
) : billingCycle === "monthly" ? (
<div className="text-4xl font-bold text-black">
{formatPrice(membershipConfig?.currency || "$", plan.monthlyPrice)}
<span className="ml-1 text-sm font-normal text-black/45">/月</span>
</div>
) : (
<div>
<div className="text-4xl font-bold text-black">
{formatPrice(membershipConfig?.currency || "$", plan.annualPrice)}
<span className="ml-1 text-sm font-normal text-black/45">/年</span>
</div>
<div className="mt-1 text-xs text-black/45">
折合 {formatPrice(membershipConfig?.currency || "$", annualMonthlyPrice)}/月
</div>
</div>
)}
</div>
<div className="mb-4 text-sm text-black/60">
每月 {plan.monthlyCredits.toLocaleString()} 快速积分
</div>
<Button
className="mb-4 h-9 w-full rounded-xl bg-black text-white hover:bg-black/90"
disabled={isCurrent}
onClick={() => {
if (isCurrent) return;
toast.info("支付能力后续接入,已预留套餐配置接口");
}}
>
{isCurrent ? "当前套餐" : "升级"}
</Button>
<ul className="space-y-1.5 text-xs text-black/65">
{plan.features.map((feature) => (
<li key={feature} className="flex items-start gap-2">
<span className="mt-1 h-1.5 w-1.5 rounded-full bg-black/40" />
<span>{feature}</span>
</li>
))}
</ul>
</div>
);
})}
</div>
) : (
<div className="rounded-xl border border-dashed border-black/15 bg-white p-8 text-center text-sm text-black/40">
会员配置暂未启用,请在系统设置中完善会员 JSON 配置。
</div>
)}
<section className="mt-10">
<h4 className="mb-4 text-center text-4xl font-semibold text-black">常见问题</h4>
<div className="space-y-2">
{(membershipConfig?.faqs || []).map((faq) => (
<details
key={faq.question}
className="rounded-xl border border-black/8 bg-white px-4 py-3 text-sm text-black/70"
>
<summary className="cursor-pointer list-none font-medium">{faq.question}</summary>
<p className="mt-2 text-black/60">{faq.answer}</p>
</details>
))}
</div>
</section>
<section className="mt-10">
<h4 className="mb-2 text-center text-4xl font-semibold text-black">
模型积分消耗 & 每月生成数量
</h4>
<p className="mb-4 text-center text-xs text-black/45">
以下表格基于系统设置中的会员配置,可直接在后台调整。
</p>
<div className="overflow-x-auto rounded-2xl border border-black/10 bg-white">
<table className="min-w-[900px] w-full text-sm">
<thead>
<tr className="bg-black/[0.03]">
<th className="px-3 py-3 text-left font-semibold text-black/75">模型</th>
{membershipPlans.map((plan) => (
<th key={plan.id} className="px-3 py-3 text-left font-semibold text-black/75">
{plan.name}
</th>
))}
</tr>
</thead>
<tbody>
{Object.entries(groupedModelRows).map(([category, rows]) => (
<Fragment key={category}>
<tr className="bg-black/[0.045]">
<td
colSpan={membershipPlans.length + 1}
className="px-3 py-2 text-xs font-semibold text-black/60"
>
{category}
</td>
</tr>
{rows.map((row) => (
<tr key={`${category}-${row.model}`} className="border-t border-black/[0.06]">
<td className="px-3 py-2 text-black/70">{row.model}</td>
{membershipPlans.map((plan) => (
<td key={`${row.model}-${plan.id}`} className="px-3 py-2 text-black/60">
{row.values[plan.id] ?? "-"}
{row.values[plan.id] && row.values[plan.id] !== "-" ? row.unit : ""}
</td>
))}
</tr>
))}
</Fragment>
))}
</tbody>
</table>
</div>
</section>
</div>
</div>
</DialogContent>
</Dialog>
</div>
);
}