"use client" import type React from "react" import { useState, useEffect, useRef } from "react" import { type Part, getAllSections, getFullBookPrice, specialSections } from "@/lib/book-data" import { useStore } from "@/lib/store" import { BookOpen, Lock, Check, Sparkles, ChevronRight, User, TrendingUp } from "lucide-react" import { AuthModal } from "./modules/auth/auth-modal" import { PaymentModal } from "./modules/payment/payment-modal" import { ReadingModal } from "./reading-modal" import { MatchingCircle } from "./matching-circle" interface HomeScreenProps { parts: Part[] } export function HomeScreen({ parts }: HomeScreenProps) { const [activeTab, setActiveTab] = useState<"home" | "match" | "my">("home") const [selectedSection, setSelectedSection] = useState<{ id: string; title: string; filePath: string } | null>(null) const [isAuthOpen, setIsAuthOpen] = useState(false) const [isPaymentOpen, setIsPaymentOpen] = useState(false) const [paymentType, setPaymentType] = useState<"section" | "fullbook">("section") const [paymentSectionId, setPaymentSectionId] = useState("") const [paymentSectionTitle, setPaymentSectionTitle] = useState("") const [paymentAmount, setPaymentAmount] = useState(1) const { user, isLoggedIn, hasPurchased } = useStore() const [mounted, setMounted] = useState(false) const allSections = getAllSections() const fullBookPrice = getFullBookPrice() const totalSections = allSections.length const purchasedCount = user?.hasFullBook ? totalSections : user?.purchasedSections?.length || 0 useEffect(() => { setMounted(true) }, []) // 点击章节 const handleSectionClick = (section: { id: string title: string filePath: string isFree: boolean price: number }) => { const canAccess = section.isFree || (isLoggedIn && hasPurchased(section.id)) if (canAccess) { // 直接打开阅读弹窗 setSelectedSection({ id: section.id, title: section.title, filePath: section.filePath }) } else { // 需要购买 if (!isLoggedIn) { setIsAuthOpen(true) } else { setPaymentSectionId(section.id) setPaymentSectionTitle(section.title) setPaymentAmount(section.price) setPaymentType("section") setIsPaymentOpen(true) } } } // 购买全书 const handleBuyFullBook = () => { if (!isLoggedIn) { setIsAuthOpen(true) return } setPaymentType("fullbook") setPaymentAmount(fullBookPrice) setIsPaymentOpen(true) } if (!mounted) { return (
) } return (
{/* 主内容区域 - 根据Tab切换 */}
{activeTab === "home" && ( )} {activeTab === "match" && } {activeTab === "my" && ( setIsAuthOpen(true)} /> )}
{/* 底部导航 - 固定三个Tab */} {/* 阅读弹窗 - 原地展示内容 */} {selectedSection && ( setSelectedSection(null)} onPurchase={(sectionId, title, price) => { setPaymentSectionId(sectionId) setPaymentSectionTitle(title) setPaymentAmount(price) setPaymentType("section") setIsPaymentOpen(true) }} /> )} {/* 弹窗 */} setIsAuthOpen(false)} /> setIsPaymentOpen(false)} type={paymentType} sectionId={paymentSectionId} sectionTitle={paymentSectionTitle} amount={paymentAmount} onSuccess={() => { setIsPaymentOpen(false) window.location.reload() }} />
) } // Tab按钮组件 function TabButton({ active, onClick, icon, label, }: { active: boolean onClick: () => void icon: React.ReactNode label: string }) { return ( ) } // 首页Tab - 书籍总览+完整目录 function HomeTab({ parts, totalSections, fullBookPrice, purchasedCount, isLoggedIn, hasPurchased, onSectionClick, onBuyFullBook, }: { parts: Part[] totalSections: number fullBookPrice: number purchasedCount: number isLoggedIn: boolean hasPurchased: (id: string) => boolean onSectionClick: (section: any) => void onBuyFullBook: () => void }) { const scrollRef = useRef(null) return (
{/* 书籍总览区 - 精简版 */}
Soul · 派对房

一场SOUL的创业实验场

来自Soul派对房的真实商业故事

{/* 价格信息 */}

¥{fullBookPrice}

整本价格

{totalSections}

商业案例

{/* 完整目录 - 一次性展示所有章节 */}

全书目录

已购 {purchasedCount}/{totalSections}
{/* 序言 */} onSectionClick({ id: "preface", title: specialSections.preface.title, filePath: specialSections.preface.filePath, isFree: true, price: 0, }) } /> {/* 所有篇章和小节 */} {parts.map((part) => (
{/* 篇章标题 */}
{part.number}

{part.title}

{part.subtitle}

{/* 该篇章下的所有小节 */}
{part.chapters.map((chapter) => chapter.sections.map((section, sectionIndex) => { const isPurchased = isLoggedIn && hasPurchased(section.id) return ( onSectionClick(section)} /> ) }), )}
))} {/* 尾声 */} onSectionClick({ id: "epilogue", title: specialSections.epilogue.title, filePath: specialSections.epilogue.filePath, isFree: true, price: 0, }) } />
) } // 章节列表项 function SectionItem({ id, number, title, isFree, isPurchased, price = 1, isLast = false, onClick, }: { id: string number: string title: string isFree: boolean isPurchased: boolean price?: number isLast?: boolean onClick: () => void }) { const canAccess = isFree || isPurchased return ( ) } // 匹配Tab - 圆形UI,高级感 function MatchTab() { return (
) } // 我的Tab - 数据中心 function MyTab({ user, isLoggedIn, totalSections, purchasedCount, onLogin, }: { user: any isLoggedIn: boolean totalSections: number purchasedCount: number onLogin: () => void }) { if (!isLoggedIn) { return (

登录查看更多

查看购买记录、阅读进度、分销收益

) } const readingProgress = user?.hasFullBook ? 100 : Math.round((purchasedCount / totalSections) * 100) const earnings = user?.earnings || 0 return (
{/* 用户信息 */}

{user?.nickname || "用户"}

{user?.phone}

{/* 数据卡片 - 清晰可视化 */}
{/* 已购章节 */}
已购章节

{user?.hasFullBook ? "全部" : purchasedCount}

共 {totalSections} 章

{/* 累计收益 */}
累计收益

¥{earnings.toFixed(1)}

分销所得

{/* 阅读进度 */}
阅读进度 {readingProgress}%

{user?.hasFullBook ? "已拥有全书" : `还差 ${totalSections - purchasedCount} 章解锁全部内容`}

{/* 邀请码 */}

我的邀请码

{user?.referralCode}

分享给好友,他人购买你可获得 90% 返利

{/* 退出登录 */}
) }