import { useEffect, useState } from 'react' import { Shield, Activity, Briefcase } from 'lucide-react' import { PieChart, Pie, Cell, BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid, LineChart, Line, Legend, } from 'recharts' import { PageLayout } from '@/components/common/PageLayout' import { EmptyState } from '@/components/common/EmptyState' import { LoadingState } from '@/components/common/LoadingState' import { Card, CardContent } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { api } from '@/lib/api' import { CATEGORY_LABELS, STATUS_LABELS, PIE_COLORS } from './constants' type ExpertActivity = Awaited> /** 管理后台 - 专家沟通情况:咨询统计、状态/分类分布、专家统计、趋势、用户排行(不含具体内容) */ export function AdminExpertActivity() { const [data, setData] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { api.adminExpertActivity() .then(setData) .catch(() => {}) .finally(() => setLoading(false)) }, []) if (loading || !data) { return ( ) } return (
{/* 概览数字 */}

{data.total}

总咨询数

{data.replied}

已回复

{data.pending}

待回复

{/* 趋势图 */} {data.daily_trend.length > 0 && (

近 7 天咨询趋势

({ date: d.date.slice(5), count: d.count }))}>
)}
{/* 状态分布 */}

按状态分布

{data.by_status.length > 0 ? ( ({ name: STATUS_LABELS[s.status] || s.status, value: s.count }))} dataKey="value" nameKey="name" cx="50%" cy="50%" outerRadius={70} label> {data.by_status.map((_, i) => )} ) : } />}
{/* 分类分布 */}

按分类分布

{data.by_category.length > 0 ? ( ({ name: CATEGORY_LABELS[c.category] || c.category, count: c.count }))}> ) : } />}
{/* 专家咨询统计 */} {data.by_expert.length > 0 && (

专家咨询统计

{data.by_expert.filter(e => e.total > 0).map((e, i) => (
{i + 1} {e.name} {CATEGORY_LABELS[e.category] || e.category} {e.rating_count > 0 && ( ★ {e.avg_rating} )}
总 {e.total} 已回 {e.replied} 待回 {e.pending}
))} {data.by_expert.every(e => e.total === 0) && ( } /> )}
)} {/* 用户咨询排行 */} {data.by_user.length > 0 && (

用户咨询情况(脱敏,Top 50)

{data.by_user.map((u, i) => (
{i + 1} {u.phone_masked}
咨询 {u.consultations} {u.last_active ? u.last_active.slice(0, 10) : '-'}
))}
)}
) }