"use client"
import { useState, useEffect } from "react"
import { useRouter } from "next/navigation"
import { User, ChevronRight, Home, List, Gift, Star, Info, Users, Wallet, Footprints, Eye, BookOpen, Clock, ArrowUpRight, Phone, MessageCircle, CreditCard, X, Check, Loader2, Settings } from "lucide-react"
import { useStore } from "@/lib/store"
import { AuthModal } from "@/components/modules/auth/auth-modal"
import { getFullBookPrice, getTotalSectionCount } from "@/lib/book-data"
export default function MyPage() {
const router = useRouter()
const { user, isLoggedIn, logout, getAllPurchases, settings, updateUser } = useStore()
const [showAuthModal, setShowAuthModal] = useState(false)
const [mounted, setMounted] = useState(false)
const [activeTab, setActiveTab] = useState<"overview" | "footprint">("overview")
// 绑定弹窗状态
const [showBindModal, setShowBindModal] = useState(false)
const [bindType, setBindType] = useState<"phone" | "wechat" | "alipay">("phone")
const [bindValue, setBindValue] = useState("")
const [isBinding, setIsBinding] = useState(false)
const [bindError, setBindError] = useState("")
useEffect(() => {
setMounted(true)
}, [])
if (!mounted) {
return (
)
}
const totalSections = getTotalSectionCount()
const purchasedCount = user?.hasFullBook ? totalSections : user?.purchasedSections?.length || 0
// 绑定账号
const handleBind = async () => {
if (!bindValue.trim()) {
setBindError("请输入内容")
return
}
if (bindType === "phone" && !/^1[3-9]\d{9}$/.test(bindValue)) {
setBindError("请输入正确的手机号")
return
}
if (bindType === "wechat" && bindValue.length < 6) {
setBindError("微信号至少6位")
return
}
if (bindType === "alipay" && !bindValue.includes("@") && !/^1[3-9]\d{9}$/.test(bindValue)) {
setBindError("请输入正确的支付宝账号")
return
}
setIsBinding(true)
setBindError("")
try {
// 模拟API调用
await new Promise(resolve => setTimeout(resolve, 1000))
// 更新用户信息
if (updateUser && user) {
const updates: any = {}
if (bindType === "phone") updates.phone = bindValue
if (bindType === "wechat") updates.wechat = bindValue
if (bindType === "alipay") updates.alipay = bindValue
updateUser(user.id, updates)
}
setShowBindModal(false)
setBindValue("")
alert("绑定成功!")
} catch (error) {
setBindError("绑定失败,请重试")
} finally {
setIsBinding(false)
}
}
// 打开绑定弹窗
const openBindModal = (type: "phone" | "wechat" | "alipay") => {
setBindType(type)
setBindValue("")
setBindError("")
setShowBindModal(true)
}
// 底部导航组件
const BottomNavBar = () => (
)
// 未登录状态
if (!isLoggedIn) {
return (
我的
{/* 用户卡片 */}
解锁专属权益
{/* 分销入口 */}
{/* 菜单列表 */}
setShowAuthModal(false)} />
)
}
// 已登录状态
const userPurchases = getAllPurchases().filter((p) => p.userId === user?.id)
const completedOrders = userPurchases.filter((p) => p.status === "completed").length
// 模拟足迹数据(实际应从数据库获取)
const footprintData = {
recentChapters: user?.purchasedSections?.slice(-5) || [],
matchHistory: [], // 匹配历史
totalReadTime: Math.floor(Math.random() * 200) + 50, // 阅读时长(分钟)
}
return (
我的
{/* 用户卡片 */}
{user?.nickname?.charAt(0) || "U"}
{user?.nickname || "用户"}
ID: {user?.id?.slice(-8) || "---"}
创业伙伴
{user?.referralCount || 0}
推荐好友
{(user?.earnings || 0) > 0 ? `¥${(user?.earnings || 0).toFixed(0)}` : '--'}
待领收益
{/* 收益卡片 - 艺术化设计 */}
{/* 背景装饰 */}
我的收益
累计收益
¥{(user?.earnings || 0).toFixed(2)}
可提现
¥{(user?.pendingEarnings || 0).toFixed(2)}
{/* Tab切换 */}
{activeTab === "overview" ? (
<>
{/* 菜单列表 */}
>
) : (
<>
{/* 足迹内容 */}
{/* 阅读统计 */}
阅读统计
{footprintData.totalReadTime}
阅读分钟
{footprintData.matchHistory.length || 0}
匹配伙伴
{/* 最近阅读 */}
最近阅读
{footprintData.recentChapters.length > 0 ? (
{footprintData.recentChapters.map((sectionId, index) => (
{index + 1}
章节 {sectionId}
))}
) : (
暂无阅读记录
)}
{/* 匹配记录 */}
匹配记录
暂无匹配记录
>
)}
{/* 绑定弹窗 */}
{showBindModal && (
!isBinding && setShowBindModal(false)} />
绑定{bindType === "phone" ? "手机号" : bindType === "wechat" ? "微信号" : "支付宝"}
setBindValue(e.target.value)}
placeholder={
bindType === "phone" ? "请输入11位手机号" :
bindType === "wechat" ? "请输入微信号" :
"请输入支付宝账号"
}
className="w-full px-4 py-3 rounded-xl bg-black/30 border border-white/10 text-white placeholder-white/30 focus:outline-none focus:border-[#00CED1]/50"
disabled={isBinding}
/>
{bindError && (
{bindError}
)}
{bindType === "phone" && "绑定手机号后可用于找伙伴匹配"}
{bindType === "wechat" && "绑定微信号后可用于找伙伴匹配和好友添加"}
{bindType === "alipay" && "绑定支付宝后可用于提现收益"}
)}
)
}