nomadro/apps/com/admin/src/pages/Social.tsx
Eric 893526942c Ship social theme switching, feedback image ops, and local skin debug ball.
Save current look as theme 1, add admin experience skin controls for themes 1-4, fix feedback image sync/lightbox, move hiring to the home bottom, and expose a localhost-only debug orb for instant skin preview.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 13:02:04 +08:00

1560 lines
60 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 游民社区 · 列表页(无页内 Tab;侧栏二级菜单切入)
* 整行可进详情;分页;软删除进存档。
*/
import {
useCallback,
useEffect,
useMemo,
useState,
type MouseEvent as ReactMouseEvent,
} 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'
import {
ImageLightbox,
feedbackImageUrls,
} from './ImageLightbox'
function rowLivePeer(
row: Record<string, unknown>,
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<string, number>
softDeleted?: Record<string, number>
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<string, number>
}
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 <p className="com-muted">暂无分布数据</p>
return (
<div className="com-bars" role="img" aria-label="分布图">
{data.map((d) => (
<div className="com-bar-row" key={d.name}>
<span className="com-bar-label" title={d.name}>
{short(d.name, 10)}
</span>
<div className="com-bar-track">
<i style={{ width: `${(d.value / max) * 100}%`, background: color }} />
</div>
<strong className="com-bar-val">{d.value}</strong>
</div>
))}
</div>
)
}
function Sparkline({ data }: { data: Array<{ date: string; value: number }> }) {
if (!data.length) return <p className="com-muted">暂无时间序列</p>
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 (
<svg className="com-spark" viewBox={`0 0 ${w} ${h}`} width="100%" height={h} aria-hidden>
<polyline
fill="none"
stroke="#f59e0b"
strokeWidth="2.5"
strokeLinejoin="round"
points={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 <circle key={d.date} cx={x} cy={y} r="2.5" fill="#fbbf24" />
})}
</svg>
)
}
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 (
<div className="com-donut-wrap">
<svg viewBox="0 0 120 120" width="120" height="120" aria-hidden>
<circle cx="60" cy="60" r={r} fill="none" stroke="rgba(255,255,255,0.06)" strokeWidth="14" />
{segments.map((seg) => {
const len = (seg.value / total) * c
const dash = `${len} ${c - len}`
const rot = (acc / total) * 360 - 90
acc += seg.value
return (
<circle
key={seg.label}
cx="60"
cy="60"
r={r}
fill="none"
stroke={seg.color}
strokeWidth="14"
strokeDasharray={dash}
strokeLinecap="butt"
transform={`rotate(${rot} 60 60)`}
/>
)
})}
<text x="60" y="58" textAnchor="middle" fill="var(--text)" fontSize="16" fontWeight="700">
{total}
</text>
<text x="60" y="74" textAnchor="middle" fill="#94a3b8" fontSize="9">
records
</text>
</svg>
<ul className="com-donut-legend">
{segments.map((s) => (
<li key={s.label}>
<i style={{ background: s.color }} />
{s.label} · {s.value}
</li>
))}
</ul>
</div>
)
}
function feedbackPersonLabel(row: Record<string, unknown>): string {
const meta =
row.meta && typeof row.meta === 'object' && !Array.isArray(row.meta)
? (row.meta as Record<string, unknown>)
: {}
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<Overview | null>(null)
const [stats, setStats] = useState<Stats | null>(null)
const [items, setItems] = useState<Record<string, unknown>[]>([])
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<Record<string, unknown> | null>(null)
const [lightbox, setLightbox] = useState<{ urls: string[]; index: number } | null>(
null,
)
const presence = useSharedSocialPresence()
const openFeedbackImages = (
row: Record<string, unknown>,
index = 0,
e?: ReactMouseEvent,
) => {
e?.stopPropagation()
const urls = feedbackImageUrls(row)
if (!urls.length) return
setLightbox({ urls, index: Math.max(0, Math.min(index, urls.length - 1)) })
}
const renderFeedbackImageCell = (row: Record<string, unknown>) => {
const urls = feedbackImageUrls(row)
if (!urls.length) {
return <span className="com-muted">—</span>
}
return (
<div
className="com-feedback-thumbs"
onClick={(e) => e.stopPropagation()}
>
{urls.slice(0, 4).map((url, i) => (
<button
key={`${url}-${i}`}
type="button"
className="com-feedback-thumb"
title="点击放大"
onClick={(e) => openFeedbackImages(row, i, e)}
>
<img src={url} alt="" loading="lazy" />
</button>
))}
{urls.length > 4 ? (
<button
type="button"
className="com-feedback-thumb-more"
onClick={(e) => openFeedbackImages(row, 0, e)}
>
+{urls.length - 4}
</button>
) : null}
</div>
)
}
const loadOverview = useCallback(async () => {
const data = await api<Overview>('/api/admin/social/ugc/overview')
setOverview(data)
}, [])
const loadStats = useCallback(async () => {
try {
const data = await api<Stats>('/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<string, unknown> }>(
'/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<string, unknown>[]; total?: number }>(path)
let rows = Array.isArray(data.items) ? data.items : []
if (section === 'joins') {
const byEmail = new Map<string, Record<string, unknown>>()
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<string, unknown>) {
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<string, unknown>) {
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<string, unknown>) {
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<string, unknown>
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 <Navigate to={`${base}/overview`} replace />
}
return (
<div className="com-page">
<header className="com-page-head com-page-head-row">
<div>
<h1>{SECTION_TITLE[section]}</h1>
<p>{SECTION_DESC[section]}</p>
{section === 'overview' ? (
<div className="com-chip-row">
<span className={`com-chip${overview?.exists ? ' com-chip-ok' : ''}`}>
{overview?.exists === false ? '数据未就绪' : '数据在线'}
</span>
<span className="com-chip">活跃成员 {stats?.activeRoster ?? '—'}</span>
<span className="com-chip">存档 {counts.archives ?? '—'}</span>
</div>
) : section === 'feedback' && personKey ? (
<div className="com-chip-row">
<button type="button" className="com-chip" onClick={clearFeedbackPerson}>
← 全部访客
</button>
<span className="com-chip com-chip-ok">
{feedbackPersonLabel(items[0] || { userKey: personKey })}
</span>
<span className="com-chip">共 {items.length} 条反馈</span>
<span className="com-chip">上限 10</span>
</div>
) : section === 'feedback' ? (
<div className="com-chip-row">
<span className="com-chip">点「访客」看全部归类</span>
<span className="com-chip">共 {total} 条</span>
</div>
) : section !== 'catalog' ? (
<div className="com-chip-row">
<span className="com-chip">共 {total} 条</span>
<span className="com-chip">
本页 {pageFrom}-{pageTo}
</span>
</div>
) : null}
</div>
<button
type="button"
className="com-btn com-btn-ghost"
onClick={() => {
void loadOverview()
void loadStats()
void loadList()
}}
disabled={loading}
>
{loading ? '刷新中…' : '刷新'}
</button>
</header>
{msg ? <div className="com-toast com-toast-ok">{msg}</div> : null}
{err ? <div className="com-toast com-toast-err">{err}</div> : null}
{section === 'overview' ? (
<>
<section className="com-cmd-hero" aria-label="今日优先">
<div className="com-cmd-hero-copy">
<p className="com-cmd-kicker">Today</p>
<h2>先处理这几件事</h2>
<p>
加入、自拍、举报优先。改价走侧栏「动态价格」→{' '}
<a href={`/${lane}/pricing`} onClick={(e) => { e.preventDefault(); navigate(`/${lane}/pricing`) }}>
打开定价
</a>
</p>
</div>
<div className="com-cmd-priority">
{(
[
['joins', 'joinLeads', '加入线索', '谁在付钱 / 填资料'],
['liveness', 'liveness', '自拍确认', '等你过一眼'],
['reports', 'reports', '举报', '安全优先'],
['roster', 'roster', '花名册', `活跃 ${stats?.activeRoster ?? '—'}`],
] as const
).map(([key, countKey, title, sub]) => (
<button
key={key}
type="button"
className="com-cmd-card"
onClick={() => navigate(`${base}/${key}`)}
>
<span className="com-cmd-card-sub">{sub}</span>
<strong>{counts[countKey] ?? '—'}</strong>
<span className="com-cmd-card-title">{title}</span>
</button>
))}
</div>
</section>
<section className="com-viz-grid" aria-label="数据可视化">
<article className="com-panel com-viz-card">
<h2>内容构成</h2>
<Donut
segments={
donutSegs.length
? donutSegs
: [{ label: '空', value: 1, color: 'rgba(255,255,255,0.12)' }]
}
/>
</article>
<article className="com-panel com-viz-card">
<h2>城市分布</h2>
<BarChart data={stats?.byCity || []} />
</article>
<article className="com-panel com-viz-card">
<h2>花名册活跃</h2>
<Sparkline data={stats?.rosterByDay || []} />
</article>
<article className="com-panel com-viz-card">
<h2>已归档</h2>
<div className="com-stat-grid com-stat-grid-compact">
{(
[
['roster', '花名册'],
['messages', '聊天'],
['reviews', '评价'],
['gigApps', '接单'],
['feedback', '反馈'],
] as const
).map(([k, label]) => (
<div className="com-stat" key={k}>
<span className="com-stat-label">{label}</span>
<strong>{stats?.softDeleted?.[k] ?? 0}</strong>
</div>
))}
</div>
</article>
</section>
<h2 className="com-section-title">全部模块</h2>
<div className="com-stat-grid">
{OVERVIEW_STATS.map(([label, countKey, key]) => (
<button
key={key}
type="button"
className="com-stat com-stat-link"
onClick={() => navigate(`${base}/${key}`)}
>
<span className="com-stat-label">{label}</span>
<strong>{counts[countKey] ?? '—'}</strong>
</button>
))}
</div>
</>
) : null}
{section === 'catalog' ? (
<section className="com-panel">
<div className="com-panel-head">
<div>
<h2>社区目录</h2>
<p>活动 · 接单 · 咖啡馆 · 花名册 · 小册 · 视频</p>
</div>
<button type="button" className="com-btn" disabled={busy} onClick={() => void saveCatalog()}>
{busy ? '保存中…' : '保存目录'}
</button>
</div>
<textarea
aria-label="社区目录 JSON 配置"
className="com-pre"
style={{ width: '100%', minHeight: 420, resize: 'vertical', fontFamily: 'ui-monospace, monospace' }}
value={catalogJson}
onChange={(e) => setCatalogJson(e.target.value)}
spellCheck={false}
/>
</section>
) : null}
{section !== 'overview' && section !== 'catalog' ? (
<>
<div className="com-toolbar">
{section !== 'archives' && (
<>
<input
className="com-input"
placeholder={
section === 'messages'
? '搜正文 / 昵称 / guestId'
: section === 'joins'
? '搜邮箱 / 阶段 / guestId'
: section === 'coffee'
? '搜出席人 / 邮箱 / 状态'
: section === 'roster'
? '搜名字 / 城市 / 技能 / guestId'
: '搜索'
}
value={qDraft}
onChange={(e) => setQDraft(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') {
setOffset(0)
setQ(qDraft)
}
}}
/>
<button
type="button"
className="com-btn com-btn-ghost"
onClick={() => {
setOffset(0)
setQ(qDraft)
}}
>
搜索
</button>
</>
)}
<span className="com-muted" style={{ marginLeft: 'auto' }}>
{loading
? '加载中…'
: section === 'feedback' && personKey
? `该访客 ${items.length} 条`
: section === 'feedback'
? `共 ${total} 条 · 点访客看归类`
: `第 ${pageFrom || 0}–${pageTo} / ${total}`}
</span>
{section === 'feedback' && personKey ? (
<button
type="button"
className="com-btn com-btn-ghost"
onClick={clearFeedbackPerson}
>
返回访客列表
</button>
) : null}
{section !== 'feedback' ? (
<>
<button
type="button"
className="com-btn com-btn-ghost"
disabled={!canPrev || loading}
onClick={() => setOffset((o) => Math.max(0, o - PAGE))}
>
上一页
</button>
<button
type="button"
className="com-btn com-btn-ghost"
disabled={!canNext || loading}
onClick={() => setOffset((o) => o + PAGE)}
>
下一页
</button>
</>
) : null}
</div>
<section className="com-panel com-table-wrap">
{loading && !items.length ? (
<p className="com-muted">加载中…</p>
) : section === 'feedback' && personKey && !items.length ? (
<div className="com-empty">
<p className="com-muted">该访客暂无反馈</p>
<button
type="button"
className="com-btn com-btn-ghost"
onClick={clearFeedbackPerson}
>
返回列表
</button>
</div>
) : !items.length ? (
<div className="com-empty">
<p className="com-muted">本列表暂无数据</p>
<p className="com-muted" style={{ fontSize: 12 }}>
有写入后点刷新;软删记录在「存档」里。
</p>
</div>
) : (
<>
{section === 'feedback' && personKey && items[0] ? (
<div
className="com-panel"
style={{ marginBottom: 12, padding: 14 }}
>
<div className="com-chip-row" style={{ marginBottom: 8 }}>
<strong>{feedbackPersonLabel(items[0])}</strong>
<span className="com-chip">
{items.length}/{String(items[0].userMax || 10)} 条
</span>
<button
type="button"
className="com-btn com-btn-ghost com-btn-sm"
onClick={clearFeedbackPerson}
>
← 返回
</button>
</div>
<div
className="com-muted"
style={{ fontSize: 12, lineHeight: 1.55, wordBreak: 'break-all' }}
>
<div>
userKey <code>{personKey}</code>
</div>
<div>
guestId{' '}
<code>
{String(items[0].guestId || items[0].guest_id || '—')}
</code>
</div>
<div>联系 {String(items[0].contact || '—')}</div>
{(() => {
const meta =
items[0].meta &&
typeof items[0].meta === 'object' &&
!Array.isArray(items[0].meta)
? (items[0].meta as Record<string, unknown>)
: {}
const bits = [
meta.email ? `邮箱 ${meta.email}` : '',
meta.name ? `昵称 ${meta.name}` : '',
meta.href ? `页面 ${meta.href}` : '',
meta.timezone ? `时区 ${meta.timezone}` : '',
meta.platform ? `平台 ${meta.platform}` : '',
meta.serverIp ? `IP ${meta.serverIp}` : '',
meta.userAgent
? `UA ${String(meta.userAgent).slice(0, 100)}`
: '',
].filter(Boolean)
return bits.length ? (
<div style={{ marginTop: 6 }}>
{bits.map((b) => (
<div key={String(b)}>{String(b)}</div>
))}
<details style={{ marginTop: 6 }}>
<summary>全部 meta</summary>
<pre
className="com-pre com-pre-sm"
style={{ marginTop: 6 }}
>
{JSON.stringify(meta, null, 2)}
</pre>
</details>
</div>
) : null
})()}
</div>
</div>
) : null}
<table className="com-table com-table-click">
<thead>
{section === 'messages' ? (
<tr>
<th>频道</th>
<th>作者</th>
<th>内容</th>
<th>访客</th>
<th>时间</th>
<th>操作</th>
</tr>
) : null}
{section === 'roster' ? (
<tr>
<th>名字</th>
<th>城市</th>
<th>头衔</th>
<th>技能</th>
<th>更新</th>
<th>操作</th>
</tr>
) : null}
{section === 'reviews' ? (
<tr>
<th>咖啡馆</th>
<th>作者</th>
<th>分</th>
<th>评语</th>
<th>时间</th>
<th>操作</th>
</tr>
) : null}
{section === 'gigs' ? (
<tr>
<th>岗位</th>
<th>姓名</th>
<th>联系</th>
<th>备注</th>
<th>时间</th>
<th>操作</th>
</tr>
) : null}
{section === 'feedback' ? (
<tr>
<th>{personKey ? '#' : '类型'}</th>
<th>{personKey ? '类型' : '内容'}</th>
<th>图片</th>
<th>{personKey ? '内容' : '联系'}</th>
<th>{personKey ? '联系' : '访客'}</th>
<th>时间</th>
<th>操作</th>
</tr>
) : null}
{section === 'joins' ? (
<tr>
<th>头像</th>
<th>谁</th>
<th>当前进度</th>
<th>支付</th>
<th>人脸</th>
<th>真人核验</th>
<th>最近更新</th>
<th>操作</th>
</tr>
) : null}
{section === 'archives' ? (
<tr>
<th>实体</th>
<th>动作</th>
<th>对象 ID</th>
<th>访客</th>
<th>时间</th>
<th>操作</th>
</tr>
) : null}
{section === 'skills' ? (
<tr>
<th>作者</th>
<th>城市</th>
<th>能提供</th>
<th>想换</th>
<th>状态</th>
<th>操作</th>
</tr>
) : null}
{section === 'liveness' ? (
<tr>
<th>访客</th>
<th>状态</th>
<th>正面</th>
<th>视频</th>
<th>时间</th>
<th>操作</th>
</tr>
) : null}
{section === 'meetupReviews' ? (
<tr>
<th>被评人</th>
<th>准时</th>
<th>化学反应</th>
<th>专业</th>
<th>评语</th>
<th>操作</th>
</tr>
) : null}
{section === 'coffee' ? (
<tr>
<th>标题</th>
<th>出席人</th>
<th>邮箱</th>
<th>状态</th>
<th>开始</th>
<th>操作</th>
</tr>
) : null}
{section === 'trips' ? (
<tr>
<th>城市</th>
<th>访客</th>
<th>抵达 / 离开</th>
<th>可见</th>
<th>状态</th>
<th>操作</th>
</tr>
) : null}
{section === 'reports' ? (
<tr>
<th>被举报</th>
<th>原因</th>
<th>状态</th>
<th>举报人</th>
<th>时间</th>
<th>操作</th>
</tr>
) : null}
{section === 'blocks' ? (
<tr>
<th>拉黑人</th>
<th>被拉黑</th>
<th>原因</th>
<th>时间</th>
<th>操作</th>
</tr>
) : null}
{section === 'files' || section === 'roomArchives' ? (
<tr>
<th>{section === 'roomArchives' ? '录像' : '文件名'}</th>
{section === 'roomArchives' ? <th>状态</th> : null}
{section === 'roomArchives' ? <th>时长</th> : null}
<th>类型</th>
<th>频道 / 厅</th>
<th>访客</th>
<th>时间</th>
<th>操作</th>
</tr>
) : null}
</thead>
<tbody>
{items.map((row) => {
const id = pickId(row, section)
const href = detailPath(row)
const live =
section === 'joins' || section === 'roster'
? Boolean(rowLivePeer(row, presence.peers))
: false
const feedbackPersonMode = section === 'feedback' && !!personKey
const feedbackFlatMode = section === 'feedback' && !personKey
const visitorKey = String(row.userKey || '')
return (
<tr
key={id || JSON.stringify(row).slice(0, 40)}
className={`com-tr-link${live ? ' is-live-row' : ''}${
feedbackPersonMode && row.isGroupHead ? ' is-group-head' : ''
}`}
onClick={() => openDetail(row)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault()
openDetail(row)
}
}}
tabIndex={href ? 0 : undefined}
role={href ? 'link' : undefined}
>
{section === 'messages' ? (
<>
<td>
<code>{String(row.channelId || row.channel_id || '—')}</code>
</td>
<td>
<strong>{String(row.author || '—')}</strong>
</td>
<td title={String(row.text || '')}>{short(row.text, 64)}</td>
<td>
<code className="com-id">{short(row.guestId || row.guest_id, 16)}</code>
</td>
<td>{fmtTime(row.at || row.created_at || row.createdAt)}</td>
</>
) : null}
{section === 'roster' ? (
<>
<td>
<strong className="com-who-live">
{rowLivePeer(row, presence.peers) ? (
<i className="com-row-live" title="在线" aria-label="在线" />
) : null}
{String(row.name || '—')}
</strong>
<div className="com-muted" style={{ fontSize: 11 }}>
<code>{String(row.guestId || row.guest_id || '')}</code>
</div>
</td>
<td>{String(row.city || '—')}</td>
<td>{short(row.title, 28)}</td>
<td>{short(row.skills, 28)}</td>
<td>{fmtTime(row.updatedAt || row.updated_at)}</td>
</>
) : null}
{section === 'reviews' ? (
<>
<td>
<code>{String(row.cafeId || row.cafe_id || '—')}</code>
</td>
<td>{String(row.author || '—')}</td>
<td>
<strong>{String(row.score ?? '—')}</strong>
</td>
<td>{short(row.text, 48)}</td>
<td>{fmtTime(row.at || row.created_at)}</td>
</>
) : null}
{section === 'gigs' ? (
<>
<td>
<code>{String(row.gigId || row.gig_id || '—')}</code>
</td>
<td>
<strong>{String(row.name || '—')}</strong>
</td>
<td>{short(row.contact, 28)}</td>
<td>{short(row.note, 36)}</td>
<td>{fmtTime(row.at || row.created_at)}</td>
</>
) : null}
{feedbackFlatMode ? (
<>
<td>
<span className="com-badge tone-info">{String(row.kind || '—')}</span>
{Number(row.userCount || 0) > 1 ? (
<div className="com-muted" style={{ fontSize: 11, marginTop: 4 }}>
同人 {String(row.userIndex)}/{String(row.userCount)}
</div>
) : null}
</td>
<td>{short(row.text, 56)}</td>
<td>{renderFeedbackImageCell(row)}</td>
<td>{short(row.contact, 24) || '—'}</td>
<td
onClick={(e) => {
e.stopPropagation()
if (visitorKey) openFeedbackPerson(visitorKey)
}}
>
<button
type="button"
className="com-btn com-btn-ghost com-btn-sm"
title="查看该访客全部反馈与归类信息"
disabled={!visitorKey}
onClick={(e) => {
e.stopPropagation()
if (visitorKey) openFeedbackPerson(visitorKey)
}}
>
{feedbackPersonLabel(row)}
</button>
<div className="com-muted" style={{ fontSize: 11, marginTop: 4 }}>
{Number(row.userCount || 1)} 条 · 点访客看全部
</div>
</td>
<td>{fmtTime(row.created_at || row.createdAt || row.at)}</td>
</>
) : null}
{feedbackPersonMode ? (
<>
<td>
<span className="com-muted">
{String(row.userIndex || '—')}/{String(row.userCount || items.length)}
</span>
</td>
<td>
<span className="com-badge tone-info">{String(row.kind || '—')}</span>
</td>
<td>{renderFeedbackImageCell(row)}</td>
<td>{short(row.text, 72)}</td>
<td>{short(row.contact, 24) || '—'}</td>
<td>{fmtTime(row.created_at || row.createdAt || row.at)}</td>
</>
) : null}
{section === 'joins' ? (
<>
<td>
{looksLikeUrl(row.avatar) ? (
<div className="com-join-avatar">
<MediaValue
value={row.avatar}
fieldKey="avatar"
compact
/>
</div>
) : (
<span className="com-join-avatar-empty" title="无头像">
—
</span>
)}
</td>
<td>
<strong className="com-who-live">
{rowLivePeer(row, presence.peers) ? (
<i className="com-row-live" title="在线" aria-label="在线" />
) : null}
{String(row.name || row.email || '—')}
</strong>
<div className="com-muted" style={{ fontSize: 12 }}>
{String(row.email || '')}
</div>
</td>
<td>
<span
className={`com-badge tone-${joinStageTone(row.stage)}`}
>
{joinStageLabel(row.stage, row)}
</span>
</td>
<td>
{(() => {
const label = joinPaidLabel(row)
if (label === '已付')
return <span className="com-badge tone-ok">已付</span>
if (label === '免费')
return <span className="com-badge">免费</span>
return <span className="com-muted">未付</span>
})()}
</td>
<td>
{joinFaceOk(row) ? (
<span className="com-badge tone-ok">
{joinFaceOkLabel(row)}
</span>
) : (
<span className="com-badge tone-bad">
{joinFaceOkLabel(row)}
</span>
)}
</td>
<td>
{joinLivenessLabel(row) === '已过' ? (
<span className="com-badge tone-ok">已过</span>
) : (
<span className="com-muted">未核验</span>
)}
</td>
<td>{fmtTime(row.updatedAt || row.updated_at || row.createdAt)}</td>
</>
) : null}
{section === 'archives' ? (
<>
<td>{String(row.entity || '—')}</td>
<td>
<span className={`com-badge tone-${joinStageTone(row.action)}`}>
{joinStageLabel(row.action)}
</span>
</td>
<td title={String(row.entityId || row.entity_id || '')}>
{short(row.entityId || row.entity_id, 22)}
</td>
<td>
<code className="com-id">{short(row.guestId || row.guest_id, 14)}</code>
</td>
<td>{fmtTime(row.at || row.created_at)}</td>
</>
) : null}
{section === 'skills' ? (
<>
<td>
<strong>{String(row.author || '—')}</strong>
<div className="com-muted" style={{ fontSize: 11 }}>
<code>{short(row.guestId, 14)}</code>
</div>
</td>
<td>{String(row.city || '—')}</td>
<td>{short(row.offer, 28)}</td>
<td>{short(row.want, 28)}</td>
<td>
<span className="com-badge tone-info">{String(row.status || '—')}</span>
</td>
</>
) : null}
{section === 'liveness' ? (
<>
<td>
<code className="com-id">{short(row.guestId, 16)}</code>
</td>
<td>
<span className={`com-badge tone-${joinStageTone(row.status)}`}>
{String(row.status || '—')}
</span>
</td>
<td>{row.frontUrl ? '有' : '—'}</td>
<td>{row.videoUrl ? '有' : '—'}</td>
<td>{fmtTime(row.at)}</td>
</>
) : null}
{section === 'meetupReviews' ? (
<>
<td>
<strong>{String(row.toName || row.toGuest || '—')}</strong>
</td>
<td>{String(row.punctuality ?? '—')}</td>
<td>{String(row.chemistry ?? '—')}</td>
<td>{String(row.professionalism ?? '—')}</td>
<td>{short(row.text, 36)}</td>
</>
) : null}
{section === 'coffee' ? (
<>
<td>
<strong>{short(row.title, 28)}</strong>
</td>
<td>{String(row.attendeeName || '—')}</td>
<td>{short(row.attendeeEmail, 28)}</td>
<td>
<span className={`com-badge tone-${joinStageTone(row.status)}`}>
{String(row.status || '—')}
</span>
</td>
<td>{fmtTime(row.startUtc || row.at)}</td>
</>
) : null}
{section === 'trips' ? (
<>
<td>
<strong>
{String(row.city || '—')}
{row.country ? ` · ${row.country}` : ''}
</strong>
</td>
<td>
<code className="com-id">{short(row.guestId, 14)}</code>
</td>
<td>
{String(row.arrivalDate || '—')} → {String(row.departureDate || '—')}
</td>
<td>{String(row.visibility || '—')}</td>
<td>{String(row.status || '—')}</td>
</>
) : null}
{section === 'reports' ? (
<>
<td>
<strong>{String(row.targetName || row.targetGuest || '—')}</strong>
</td>
<td>{short(row.reason, 28)}</td>
<td>
<span className="com-badge tone-warn">{String(row.status || '—')}</span>
</td>
<td>
<code className="com-id">{short(row.guestId, 12)}</code>
</td>
<td>{fmtTime(row.at)}</td>
</>
) : null}
{section === 'blocks' ? (
<>
<td>
<code className="com-id">{short(row.guestId, 14)}</code>
</td>
<td>
<code className="com-id">{short(row.blockedGuest, 14)}</code>
</td>
<td>{short(row.reason, 36)}</td>
<td>{fmtTime(row.at)}</td>
</>
) : null}
{section === 'files' || section === 'roomArchives' ? (
<>
<td>
<strong>{short(row.name || row.fileId, 28)}</strong>
{section === 'roomArchives' && row.url ? (
<div className="com-muted" style={{ fontSize: 12, marginTop: 4 }}>
S3 / 可播放
</div>
) : null}
{section === 'roomArchives' && row.roomId ? (
<div className="com-muted" style={{ fontSize: 11, marginTop: 2 }}>
厅 {String(row.roomId)}
</div>
) : null}
</td>
{section === 'roomArchives' ? (
<td>
<span
className={`com-badge tone-${
row.status === 'uploaded'
? 'ok'
: row.status === 'uploading' || row.status === 'recording'
? 'warn'
: row.status === 'failed' || row.status === 'denied'
? 'danger'
: 'muted'
}`}
>
{String(
row.statusLabel ||
({
pending: '待上传',
recording: '录制中',
uploading: '上传中',
uploaded: '已上传',
failed: '失败',
denied: '未开摄像头',
} as Record<string, string>)[String(row.status || '')] ||
row.status ||
'—',
)}
</span>
</td>
) : null}
{section === 'roomArchives' ? (
<td>
<strong>
{String(
row.durationLabel ||
(Number(row.durationSec) > 0
? `${row.durationSec}秒`
: '—'),
)}
</strong>
</td>
) : null}
<td>{String(row.kind || row.mime || '—')}</td>
<td>
<code>{short(row.channelId, 12)}</code>
</td>
<td>
{section === 'roomArchives' &&
(row.guestLabel || row.guestNick || row.nick) ? (
<div>
<strong>
{short(
String(row.guestLabel || row.guestNick || row.nick),
18,
)}
</strong>
{row.guestEmail ? (
<div className="com-muted" style={{ fontSize: 11 }}>
{short(String(row.guestEmail), 22)}
</div>
) : null}
<div className="com-muted" style={{ fontSize: 10 }}>
<code className="com-id">{short(row.guestId, 12)}</code>
</div>
</div>
) : (
<code className="com-id">{short(row.guestId, 12)}</code>
)}
</td>
<td>{fmtTime(row.at)}</td>
</>
) : null}
<td onClick={(e) => e.stopPropagation()}>
<div className="com-row-actions">
{feedbackFlatMode && visitorKey ? (
<button
type="button"
className="com-btn com-btn-ghost com-btn-sm"
onClick={() => openFeedbackPerson(visitorKey)}
>
该访客全部
</button>
) : null}
{href ? (
<Link className="com-btn com-btn-ghost com-btn-sm" to={href}>
详情
</Link>
) : null}
{section === 'roster' ? (
<button
type="button"
className="com-btn com-btn-ghost com-btn-sm"
onClick={() => setEditRoster({ ...row })}
>
编辑
</button>
) : null}
{canSoftDelete ? (
<button
type="button"
className="com-btn com-btn-danger com-btn-sm"
disabled={!id || busyId === id}
onClick={() => void removeRow(row)}
>
{busyId === id ? '…' : '软删除'}
</button>
) : null}
{section === 'joins' && !href ? (
<span className="com-muted" style={{ fontSize: 12 }}>
无详情
</span>
) : null}
</div>
</td>
</tr>
)
})}
</tbody>
</table>
</>
)}
</section>
</>
) : null}
{lightbox ? (
<ImageLightbox
urls={lightbox.urls}
index={lightbox.index}
onClose={() => setLightbox(null)}
onIndex={(i) => setLightbox((cur) => (cur ? { ...cur, index: i } : cur))}
/>
) : null}
{editRoster ? (
<div className="com-modal-mask" onClick={() => setEditRoster(null)}>
<div className="com-modal" onClick={(e) => e.stopPropagation()}>
<h3>编辑花名册 · {String(editRoster.guestId || editRoster.guest_id)}</h3>
{(['name', 'title', 'city', 'phone', 'linktree', 'skills'] as const).map((k) => (
<label key={k} className="com-field">
<span>{k}</span>
<input
className="com-input"
value={String(editRoster[k] ?? '')}
onChange={(e) => setEditRoster({ ...editRoster, [k]: e.target.value })}
/>
</label>
))}
<label className="com-field">
<span>bio</span>
<textarea
className="com-input"
rows={5}
value={String(editRoster.bio ?? '')}
onChange={(e) => setEditRoster({ ...editRoster, bio: e.target.value })}
/>
</label>
<div className="com-row-actions">
<button type="button" className="com-btn com-btn-ghost" onClick={() => setEditRoster(null)}>
取消
</button>
<button type="button" className="com-btn" disabled={busy} onClick={() => void saveRoster()}>
保存
</button>
</div>
</div>
</div>
) : null}
</div>
)
}