/** * 单受众模块运营台:/cn 或 /intl * 入口级区分中文用户 vs 国际(英语为主),再进开关 / 埋点等。 */ import { useCallback, useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { api } from '../api/client' export type LaneKey = 'cn' | 'intl' type Lane = { payEnabled: boolean socialFollow: boolean followChannel: 'wechat' | 'x' | 'none' vipCta: string homeLead: string note?: string } type AudienceCfg = { defaultLane: 'cn' | 'intl' cn: Lane intl: Lane version?: number updatedAt?: string } const META: Record< LaneKey, { title: string titleEn: string eyebrow: string detect: string pay: string follow: string accent: string } > = { cn: { title: '中文用户', titleEn: 'Chinese', eyebrow: '特殊对待 · Special lane', detect: '微信内置 MicroMessenger / is-china-user → 本模块', pay: 'zpay · 微信内 xpay', follow: '公众号二维码', accent: 'cn', }, intl: { title: '国际用户', titleEn: 'International', eyebrow: '.com 默认 · English-first', detect: '非中文信号 → 本模块(日/越/泰可切语言)', pay: 'Creem · NOWPayments', follow: 'X / Twitter', accent: 'intl', }, } function Switch({ checked, onChange, label, disabled, }: { checked: boolean onChange: (v: boolean) => void label: string disabled?: boolean }) { return ( ) } export default function LaneHub({ lane }: { lane: LaneKey }) { const meta = META[lane] const [cfg, setCfg] = useState(null) const [busy, setBusy] = useState(false) const [msg, setMsg] = useState('') const [err, setErr] = useState('') const [vipCta, setVipCta] = useState('') const [homeLead, setHomeLead] = useState('') const load = useCallback(async () => { setErr('') const data = await api('/api/admin/audience') setCfg(data) const L = data[lane] setVipCta(L.vipCta) setHomeLead(L.homeLead) }, [lane]) useEffect(() => { load().catch((e: Error) => setErr(e.message || '加载失败')) }, [load]) async function patchLane(partial: Partial, okHint: string) { setBusy(true) setMsg('') setErr('') try { const data = await api('/api/admin/audience', { method: 'PUT', body: JSON.stringify({ [lane]: partial }), }) setCfg(data) setVipCta(data[lane].vipCta) setHomeLead(data[lane].homeLead) setMsg(okHint) } catch (e: unknown) { setErr(e instanceof Error ? e.message : '保存失败') await load().catch(() => undefined) } finally { setBusy(false) } } const L = cfg?.[lane] const other: LaneKey = lane === 'cn' ? 'intl' : 'cn' const [stats, setStats] = useState | null>(null) const [socialCounts, setSocialCounts] = useState | null>(null) useEffect(() => { api>('/api/admin/stats') .then(setStats) .catch(() => setStats(null)) api<{ counts?: Record }>('/api/admin/social/ugc/overview') .then((d) => setSocialCounts(d.counts || null)) .catch(() => setSocialCounts(null)) }, [lane]) const tools = [ { to: `/${lane}/switches`, ico: '⏻', title: '动态开关', desc: '页面 / flag / VIP 入口' }, { to: `/${lane}/social`, ico: '💕', title: '游民社区', desc: '聊天 / 花名册 / 反馈审核' }, { to: `/${lane}/blog`, ico: '📝', title: 'Nomad Blog', desc: '文章显隐 / AdSense / 置顶' }, { to: `/${lane}/events`, ico: '📊', title: '埋点', desc: '本轨相关行为回放' }, { to: `/${lane}/orders`, ico: '🧾', title: '订单', desc: '支付与发货' }, { to: `/${lane}/users`, ico: '👥', title: '用户', desc: '解锁与干预' }, { to: `/${lane}/ntfy`, ico: '🔔', title: 'ntfy', desc: '通知试推' }, ] return (
{meta.eyebrow}

{meta.title} {meta.titleEn}

{meta.detect}
支付 {meta.pay} · 关注 {meta.follow}

模块 /{lane} {cfg?.defaultLane === lane ? 识别失败时默认 : null} {cfg?.version != null ? v{cfg.version} : null}
换模块 · {META[other].title}
{msg ?
{msg}
: null} {err ?
{err}
: null} {(stats || socialCounts) && (
已付订单 {stats?.paid_orders ?? '—'}
用户 {stats?.users ?? '—'}
社群聊天 {socialCounts?.messages ?? '—'}
花名册 {socialCounts?.roster ?? '—'}
)}
{tools.map((t) => ( {t.ico} {t.title} {t.desc} ))}
{!L ? (
加载本轨配置…
) : (

本轨开关与文案

{L.note || '写入 remote-config.audience.' + lane}

支付 CTA

{meta.pay}

void patchLane({ payEnabled: v }, `支付已${v ? '开' : '关'}`)} />
关注引导

{meta.follow}

void patchLane({ socialFollow: v }, `关注已${v ? '开' : '关'}`)} />
关注渠道

本轨默认渠道