'use client' import React, { useState, useEffect } from 'react' import { useRouter } from 'next/navigation' import { CircleUser, Settings, BellRing, History, MessageCircleQuestion, ChevronRight, LogOut, Copy, Check, Building2, Users, FileCheck } from 'lucide-react' import { cn } from '@/lib/utils' import { useToast } from '@/components/ui/Toast' import { useAuth } from '@/contexts/AuthContext' import { USE_MOCK } from '@/contexts/AuthContext' import { api } from '@/lib/api' import type { AgencyDashboard } from '@/types/dashboard' // Mock 数据(USE_MOCK 模式) const mockAgency = { name: '星辰传媒', initial: '星', agencyId: 'AG789012', companyName: '上海星辰文化传媒有限公司', role: '官方认证代理商', stats: { creators: 156, reviewed: 1280, passRate: 88, monthlyTasks: 45, }, } // 菜单项数据 const menuItems = [ { id: 'company', icon: Building2, iconColor: 'text-accent-indigo', bgColor: 'bg-accent-indigo', title: '公司信息', subtitle: '公司名称、营业执照、联系方式', }, { id: 'personal', icon: CircleUser, iconColor: 'text-accent-blue', bgColor: 'bg-accent-blue', title: '个人信息', subtitle: '头像、昵称、负责人信息', }, { id: 'account', icon: Settings, iconColor: 'text-accent-green', bgColor: 'bg-accent-green', title: '账户设置', subtitle: '修改密码、账号安全', }, { id: 'notification', icon: BellRing, iconColor: 'text-accent-amber', bgColor: 'bg-accent-amber', title: '消息设置', subtitle: '通知开关、提醒偏好', }, { id: 'history', icon: History, iconColor: 'text-accent-coral', bgColor: 'bg-accent-coral', title: '审核历史', subtitle: '查看历史审核记录', }, { id: 'help', icon: MessageCircleQuestion, iconColor: 'text-text-secondary', bgColor: 'bg-bg-elevated', title: '帮助与反馈', subtitle: '常见问题、联系客服', }, ] // 代理商卡片组件 function AgencyCard() { const toast = useToast() const { user } = useAuth() const [copied, setCopied] = useState(false) const [stats, setStats] = useState({ creators: 0, totalTasks: 0, passRate: 0, pendingReview: 0 }) useEffect(() => { const loadStats = async () => { if (USE_MOCK) { setStats({ creators: mockAgency.stats.creators, totalTasks: mockAgency.stats.reviewed, passRate: mockAgency.stats.passRate, pendingReview: mockAgency.stats.monthlyTasks, }) return } try { const dashboard = await api.getAgencyDashboard() const totalPassed = dashboard.today_passed.script + dashboard.today_passed.video const totalPending = dashboard.pending_review.script + dashboard.pending_review.video setStats({ creators: dashboard.total_creators, totalTasks: dashboard.total_tasks, passRate: dashboard.total_tasks > 0 ? Math.round((totalPassed / Math.max(totalPassed + totalPending, 1)) * 100) : 0, pendingReview: totalPending, }) } catch { // 静默失败 } } loadStats() }, []) const displayName = USE_MOCK ? mockAgency.name : (user?.name || '代理商') const displayInitial = USE_MOCK ? mockAgency.initial : (user?.name?.[0] || '?') const displayAgencyId = USE_MOCK ? mockAgency.agencyId : (user?.agency_id || '--') const displayRole = USE_MOCK ? mockAgency.role : (user?.is_verified ? '认证代理商' : '代理商') const displayCompany = USE_MOCK ? mockAgency.companyName : (user?.tenant_name || '--') // 复制代理商ID const handleCopyId = async () => { try { await navigator.clipboard.writeText(displayAgencyId) setCopied(true) setTimeout(() => setCopied(false), 2000) } catch { toast.error('复制失败,请重试') } } return (
{/* 头像和信息 */}
{/* 头像 */}
{displayInitial}
{/* 代理商信息 */}
{displayName} {displayRole} {/* 代理商ID */}
代理商ID:
{displayAgencyId}
{copied && ( 已复制 )}
{/* 公司名称 */}
{displayCompany}
{/* 统计数据 */}
{stats.creators}
管理达人
{stats.totalTasks}
总任务数
{stats.passRate}% 通过率
{stats.pendingReview} 待审核
) } // 菜单项组件 function MenuItem({ item, onClick }: { item: typeof menuItems[0]; onClick: () => void }) { const Icon = item.icon const isPlainBg = item.bgColor === 'bg-bg-elevated' return ( ) } // 菜单卡片组件 function MenuCard({ onMenuClick }: { onMenuClick: (id: string) => void }) { return (
{menuItems.map((item, index) => (
onMenuClick(item.id)} /> {index < menuItems.length - 1 && (
)}
))}
) } // 退出卡片组件 function LogoutCard({ onLogout }: { onLogout: () => void }) { return (
) } export default function AgencyProfilePage() { const router = useRouter() const { logout } = useAuth() // 菜单项点击处理 const handleMenuClick = (menuId: string) => { const routes: Record = { company: '/agency/profile/company', personal: '/agency/profile/edit', account: '/agency/settings/account', notification: '/agency/settings/notification', history: '/agency/review/history', help: '/agency/help', } const route = routes[menuId] if (route) { router.push(route) } } // 退出登录 const handleLogout = () => { logout() router.push('/login') } return (
{/* 顶部栏 */}

个人中心

管理代理商账户信息和偏好设置

{/* 内容区 - 响应式布局 */}
{/* 代理商卡片 */}
{/* 菜单和退出 */}
) }