"use client" import { useState, useEffect } from "react" import { Sparkles, Users, BookOpen } from "lucide-react" import { getAllSections } from "@/lib/book-data" import { useStore } from "@/lib/store" export function MatchingCircle() { const [isMatching, setIsMatching] = useState(false) const [matchProgress, setMatchProgress] = useState(0) const [matchResult, setMatchResult] = useState<{ section: { id: string; title: string } reason: string compatibility: number } | null>(null) const { user, isLoggedIn } = useStore() const allSections = getAllSections() // 开始匹配 const startMatching = () => { if (isMatching) return setIsMatching(true) setMatchProgress(0) setMatchResult(null) // 模拟匹配进度 const interval = setInterval(() => { setMatchProgress((prev) => { if (prev >= 100) { clearInterval(interval) // 匹配完成,生成结果 const randomSection = allSections[Math.floor(Math.random() * allSections.length)] const reasons = [ "与你的创业方向高度匹配", "适合你当前的发展阶段", "契合你的商业思维模式", "与你的行业背景相关", "符合你的学习偏好", ] setMatchResult({ section: { id: randomSection.id, title: randomSection.title }, reason: reasons[Math.floor(Math.random() * reasons.length)], compatibility: Math.floor(Math.random() * 20) + 80, }) setIsMatching(false) return 100 } return prev + 2 }) }, 50) } // 保存匹配结果到本地 useEffect(() => { if (matchResult && isLoggedIn) { const savedResults = JSON.parse(localStorage.getItem("match_results") || "[]") savedResults.unshift({ ...matchResult, userId: user?.id, matchedAt: new Date().toISOString(), }) // 只保留最近10条 localStorage.setItem("match_results", JSON.stringify(savedResults.slice(0, 10))) } }, [matchResult, isLoggedIn, user?.id]) return (
{matchProgress}%
正在匹配...
> ) : matchResult ? ( <>匹配度
{matchResult.reason}
> ) : ( <>寻找合作伙伴
智能匹配商业故事
> )}{matchResult.section.id}
{matchResult.section.title}
基于你的阅读偏好,智能推荐适合你的商业故事