/** * 游民社区 · 列表页(无页内 Tab;侧栏二级菜单切入) * 整行可进详情;分页;软删除进存档。 */ import { useCallback, useEffect, useMemo, useState } from 'react' import { Link, Navigate, useLocation, useNavigate, useParams, useSearchParams, } from 'react-router-dom' import { api } from '../api/client' import { useSharedSocialPresence, type PresencePeer, } from '../lib/SocialPresenceContext' import { OVERVIEW_STATS, SECTIONS, SECTION_API, SECTION_DESC, SECTION_TITLE, type SectionKey, fmtTime, joinFaceOk, joinFaceOkLabel, joinLivenessLabel, joinPaidLabel, joinStageLabel, joinStageTone, pickId, short, } from './socialMeta' import { looksLikeUrl, MediaValue } from './MediaValue' function rowLivePeer( row: Record, peers: PresencePeer[], ): PresencePeer | null { if (!peers.length) return null const gid = String(row.guestId || row.guest_id || '').trim().toLowerCase() const name = String(row.name || '').trim().toLowerCase() const email = String(row.email || '').trim().toLowerCase() const local = email.includes('@') ? email.split('@')[0] : email // Strict only — never prefix-match (nick "test" used to light up test8/test7/…) for (const p of peers) { const pid = String(p.guestId || '').trim().toLowerCase() const nick = String(p.nick || '').trim().toLowerCase() if (gid && pid && gid === pid) return p if (name && nick && name === nick) return p if (local && nick && local === nick) return p if (email && nick && email === nick) return p } return null } type Stats = { ok?: boolean counts?: Record softDeleted?: Record activeRoster?: number byCity?: Array<{ name: string; value: number }> rosterByDay?: Array<{ date: string; value: number }> } type Overview = { path?: string exists?: boolean writable?: boolean backend?: string counts?: Record } const PAGE = 40 function BarChart({ data, color = '#f59e0b', }: { data: Array<{ name: string; value: number }> color?: string }) { const max = Math.max(1, ...data.map((d) => d.value)) if (!data.length) return

暂无分布数据

return (
{data.map((d) => (
{short(d.name, 10)}
{d.value}
))}
) } function Sparkline({ data }: { data: Array<{ date: string; value: number }> }) { if (!data.length) return

暂无时间序列

const max = Math.max(1, ...data.map((d) => d.value)) const w = 320 const h = 72 const pts = data .map((d, i) => { const x = data.length === 1 ? w / 2 : (i / (data.length - 1)) * w const y = h - (d.value / max) * (h - 8) - 4 return `${x},${y}` }) .join(' ') return ( {data.map((d, i) => { const x = data.length === 1 ? w / 2 : (i / (data.length - 1)) * w const y = h - (d.value / max) * (h - 8) - 4 return })} ) } function Donut({ segments, }: { segments: Array<{ label: string; value: number; color: string }> }) { const total = segments.reduce((s, x) => s + x.value, 0) || 1 let acc = 0 const r = 42 const c = 2 * Math.PI * r return (
{segments.map((seg) => { const len = (seg.value / total) * c const dash = `${len} ${c - len}` const rot = (acc / total) * 360 - 90 acc += seg.value return ( ) })} {total} records
    {segments.map((s) => (
  • {s.label} · {s.value}
  • ))}
) } function feedbackPersonLabel(row: Record): string { const meta = row.meta && typeof row.meta === 'object' && !Array.isArray(row.meta) ? (row.meta as Record) : {} const email = String(meta.email || '').trim() const contact = String(row.contact || '').trim() const name = String(meta.name || '').trim() const key = String(row.userKey || '') if (email) return email if (contact) return contact if (name) return name if (key.startsWith('email:')) return key.slice(6) if (key.startsWith('contact:')) return key.slice(8) if (key.startsWith('guest:')) return `访客 ${key.slice(6, 18)}` if (key.startsWith('weak:')) return `未登录 · ${key.slice(5, 13)}` return key || String(row.guestId || row.guest_id || '未知访客') } export default function Social() { const { lane = 'intl', section: sectionParam } = useParams() const { pathname } = useLocation() const navigate = useNavigate() const [searchParams, setSearchParams] = useSearchParams() const base = `/${lane}/social` const fromPath = pathname.split('/').filter(Boolean)[2] || 'overview' const sectionRaw = (sectionParam || fromPath || 'overview') as SectionKey const sectionValid = SECTIONS.includes(sectionRaw) const section: SectionKey = sectionValid ? sectionRaw : 'overview' const personKey = section === 'feedback' ? (searchParams.get('person') || '').trim() : '' const [overview, setOverview] = useState(null) const [stats, setStats] = useState(null) const [items, setItems] = useState[]>([]) const [total, setTotal] = useState(0) const [q, setQ] = useState('') const [qDraft, setQDraft] = useState('') const [offset, setOffset] = useState(0) const [loading, setLoading] = useState(false) const [busyId, setBusyId] = useState('') const [busy, setBusy] = useState(false) const [err, setErr] = useState('') const [msg, setMsg] = useState('') const [catalogJson, setCatalogJson] = useState('') const [editRoster, setEditRoster] = useState | null>(null) const presence = useSharedSocialPresence() const loadOverview = useCallback(async () => { const data = await api('/api/admin/social/ugc/overview') setOverview(data) }, []) const loadStats = useCallback(async () => { try { const data = await api('/api/admin/social/ugc/stats') setStats(data) } catch { setStats(null) } }, []) const loadList = useCallback(async (opts?: { silent?: boolean }) => { if (section === 'overview') return const silent = Boolean(opts?.silent) if (!silent) { setLoading(true) setErr('') } try { if (section === 'catalog') { const data = await api<{ catalogs?: Record }>( '/api/admin/social/ugc/catalog', ) setCatalogJson(JSON.stringify(data.catalogs || {}, null, 2)) setItems([]) setTotal(0) return } const qs = new URLSearchParams() if (section === 'feedback' && personKey) { qs.set('userKey', personKey) qs.set('limit', '100') qs.set('offset', '0') } else if (section === 'feedback') { // Pull a wide window so we can fold into per-person rows. qs.set('limit', '200') qs.set('offset', '0') } else { qs.set('limit', String(PAGE)) qs.set('offset', String(offset)) } if (q.trim()) qs.set('q', q.trim()) const apiSeg = SECTION_API[section] if (!apiSeg) { setItems([]) setTotal(0) return } const path = `/api/admin/social/ugc/${apiSeg}?${qs}` const data = await api<{ items?: Record[]; total?: number }>(path) let rows = Array.isArray(data.items) ? data.items : [] if (section === 'joins') { const byEmail = new Map>() for (const row of rows) { const em = String(row.email || '') .trim() .toLowerCase() if (!em) continue const prev = byEmail.get(em) const ta = String(row.updatedAt || row.updated_at || '') const tb = String(prev?.updatedAt || prev?.updated_at || '') if (!prev || ta >= tb) byEmail.set(em, row) } rows = [...byEmail.values()] } setItems(rows) setTotal(section === 'joins' ? rows.length : Number(data.total || 0)) } catch (e: unknown) { if (!silent) { setErr(e instanceof Error ? e.message : '加载失败') setItems([]) setTotal(0) } } finally { if (!silent) setLoading(false) } }, [section, q, offset, personKey]) useEffect(() => { setQ('') setQDraft('') setOffset(0) setMsg('') setErr('') setEditRoster(null) }, [section]) useEffect(() => { setOffset(0) }, [personKey]) function openFeedbackPerson(key: string) { const k = key.trim() if (!k) return const next = new URLSearchParams(searchParams) next.set('person', k) setSearchParams(next, { replace: false }) } function clearFeedbackPerson() { const next = new URLSearchParams(searchParams) next.delete('person') setSearchParams(next, { replace: false }) } useEffect(() => { loadOverview().catch((e: Error) => setErr(e.message || '概览失败')) loadStats().catch(() => undefined) }, [loadOverview, loadStats]) useEffect(() => { void loadList() }, [loadList]) // 语音厅录像:每 3s 静默刷新状态(录制中/上传中 → 已上传) useEffect(() => { if (section !== 'roomArchives') return const tick = window.setInterval(() => { void loadList({ silent: true }) }, 3000) return () => window.clearInterval(tick) }, [section, loadList]) const donutSegs = useMemo(() => { const c = stats?.counts || overview?.counts || {} const palette = [ '#f59e0b', '#4ecdc4', '#a78bfa', '#fb7185', '#38bdf8', '#84cc16', '#f472b6', '#22d3ee', '#eab308', '#c084fc', ] return OVERVIEW_STATS.map(([label, key], i) => ({ label, value: Number(c[key] || 0), color: palette[i % palette.length], })).filter((x) => x.value > 0) }, [stats, overview]) function detailPath(row: Record) { const id = pickId(row, section) if (!id || section === 'overview' || section === 'catalog') return '' if (section === 'gigs') return `${base}/gigs/${encodeURIComponent(id)}` if (section === 'joins') return `${base}/joins/${encodeURIComponent(id)}` if (section === 'coffee') return `${base}/coffee/${encodeURIComponent(id)}` return `${base}/${section}/${encodeURIComponent(id)}` } function openDetail(row: Record) { const href = detailPath(row) if (href) navigate(href) } const canSoftDelete = section === 'messages' || section === 'roster' || section === 'reviews' || section === 'gigs' || section === 'feedback' async function removeRow(row: Record) { if (!canSoftDelete) return const id = pickId(row, section) if (!id) return if (!window.confirm(`软删除这条记录?会写入 social_archives,不会物理抹除。`)) return setBusyId(id) setMsg('') setErr('') try { const path = section === 'messages' ? `/api/admin/social/ugc/messages/${encodeURIComponent(id)}` : section === 'roster' ? `/api/admin/social/ugc/roster/${encodeURIComponent(id)}` : section === 'reviews' ? `/api/admin/social/ugc/reviews/${encodeURIComponent(id)}` : section === 'gigs' ? `/api/admin/social/ugc/gig-apps/${encodeURIComponent(id)}` : `/api/admin/social/ugc/feedback/${encodeURIComponent(id)}` await api(path, { method: 'DELETE' }) setMsg('已软删除并写入存档') await loadList() await loadOverview().catch(() => undefined) await loadStats().catch(() => undefined) } catch (e: unknown) { setErr(e instanceof Error ? e.message : '删除失败') } finally { setBusyId('') } } async function saveRoster() { if (!editRoster?.guestId && !editRoster?.guest_id) return const gid = String(editRoster.guestId || editRoster.guest_id) setBusy(true) setErr('') try { await api(`/api/admin/social/ugc/roster/${encodeURIComponent(gid)}`, { method: 'PUT', body: JSON.stringify({ name: editRoster.name, title: editRoster.title, city: editRoster.city, phone: editRoster.phone, linktree: editRoster.linktree, skills: editRoster.skills, bio: editRoster.bio, }), }) setMsg('已保存') setEditRoster(null) await loadList() await loadStats().catch(() => undefined) } catch (e: unknown) { setErr(e instanceof Error ? e.message : '保存失败') } finally { setBusy(false) } } async function saveCatalog() { setBusy(true) setMsg('') setErr('') try { const parsed = JSON.parse(catalogJson) as Record await api('/api/admin/social/ugc/catalog', { method: 'PUT', body: JSON.stringify(parsed), }) setMsg('目录已保存') await loadList() } catch (e: unknown) { setErr(e instanceof Error ? e.message : '目录保存失败(检查 JSON)') } finally { setBusy(false) } } const counts = stats?.counts || overview?.counts || {} const pageFrom = total === 0 ? 0 : offset + 1 const pageTo = Math.min(offset + items.length, total) const canPrev = offset > 0 const canNext = offset + PAGE < total if (!sectionValid) { return } return (

{SECTION_TITLE[section]}

{SECTION_DESC[section]}

{section === 'overview' ? (
{overview?.exists === false ? '数据未就绪' : '数据在线'} 活跃成员 {stats?.activeRoster ?? '—'} 存档 {counts.archives ?? '—'}
) : section === 'feedback' && personKey ? (
{feedbackPersonLabel(items[0] || { userKey: personKey })} 共 {items.length} 条反馈 上限 10
) : section === 'feedback' ? (
点「访客」看全部归类 共 {total} 条
) : section !== 'catalog' ? (
共 {total} 条 本页 {pageFrom}-{pageTo}
) : null}
{msg ?
{msg}
: null} {err ?
{err}
: null} {section === 'overview' ? ( <>

Today

先处理这几件事

加入、自拍、举报优先。改价走侧栏「动态价格」→{' '} { e.preventDefault(); navigate(`/${lane}/pricing`) }}> 打开定价

{( [ ['joins', 'joinLeads', '加入线索', '谁在付钱 / 填资料'], ['liveness', 'liveness', '自拍确认', '等你过一眼'], ['reports', 'reports', '举报', '安全优先'], ['roster', 'roster', '花名册', `活跃 ${stats?.activeRoster ?? '—'}`], ] as const ).map(([key, countKey, title, sub]) => ( ))}

内容构成

城市分布

花名册活跃

已归档

{( [ ['roster', '花名册'], ['messages', '聊天'], ['reviews', '评价'], ['gigApps', '接单'], ['feedback', '反馈'], ] as const ).map(([k, label]) => (
{label} {stats?.softDeleted?.[k] ?? 0}
))}

全部模块

{OVERVIEW_STATS.map(([label, countKey, key]) => ( ))}
) : null} {section === 'catalog' ? (

社区目录

活动 · 接单 · 咖啡馆 · 花名册 · 小册 · 视频