Add InsightFace/OpenCV challenge upload, PC vs mobile capture branching, and fix avatar persistence into roster/profile pages. Co-authored-by: Cursor <cursoragent@cursor.com>
303 lines
9.4 KiB
TypeScript
303 lines
9.4 KiB
TypeScript
/**
|
|
* 单受众模块运营台:/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 (
|
|
<label className="com-switch" title={label}>
|
|
<input
|
|
type="checkbox"
|
|
checked={checked}
|
|
disabled={disabled}
|
|
onChange={(e) => onChange(e.target.checked)}
|
|
aria-label={label}
|
|
/>
|
|
<span className="com-switch-track">
|
|
<span className="com-switch-thumb" />
|
|
</span>
|
|
</label>
|
|
)
|
|
}
|
|
|
|
export default function LaneHub({ lane }: { lane: LaneKey }) {
|
|
const meta = META[lane]
|
|
const [cfg, setCfg] = useState<AudienceCfg | null>(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<AudienceCfg>('/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<Lane>, okHint: string) {
|
|
setBusy(true)
|
|
setMsg('')
|
|
setErr('')
|
|
try {
|
|
const data = await api<AudienceCfg>('/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<Record<string, number> | null>(null)
|
|
const [socialCounts, setSocialCounts] = useState<Record<string, number> | null>(null)
|
|
|
|
useEffect(() => {
|
|
api<Record<string, number>>('/api/admin/stats')
|
|
.then(setStats)
|
|
.catch(() => setStats(null))
|
|
api<{ counts?: Record<string, number> }>('/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 (
|
|
<div className={`com-page com-lane-hub com-lane-hub--${meta.accent}`}>
|
|
<header className="com-page-head com-page-head-row">
|
|
<div>
|
|
<div className="com-lane-eyebrow">{meta.eyebrow}</div>
|
|
<h1>
|
|
{meta.title} <span className="com-lane-en">{meta.titleEn}</span>
|
|
</h1>
|
|
<p>
|
|
{meta.detect}
|
|
<br />
|
|
支付 {meta.pay} · 关注 {meta.follow}
|
|
</p>
|
|
<div className="com-chip-row">
|
|
<span className="com-chip com-chip-ok">模块 /{lane}</span>
|
|
{cfg?.defaultLane === lane ? <span className="com-chip">识别失败时默认</span> : null}
|
|
{cfg?.version != null ? <span className="com-chip">v{cfg.version}</span> : null}
|
|
</div>
|
|
</div>
|
|
<Link className="com-btn com-btn-ghost" to="/">
|
|
换模块 · {META[other].title}
|
|
</Link>
|
|
</header>
|
|
|
|
{msg ? <div className="com-toast com-toast-ok">{msg}</div> : null}
|
|
{err ? <div className="com-toast com-toast-err">{err}</div> : null}
|
|
|
|
{(stats || socialCounts) && (
|
|
<div className="com-stat-grid" style={{ marginBottom: 18 }}>
|
|
<article className="com-stat">
|
|
<span className="com-stat-label">已付订单</span>
|
|
<strong>{stats?.paid_orders ?? '—'}</strong>
|
|
</article>
|
|
<article className="com-stat">
|
|
<span className="com-stat-label">用户</span>
|
|
<strong>{stats?.users ?? '—'}</strong>
|
|
</article>
|
|
<article className="com-stat">
|
|
<span className="com-stat-label">社群聊天</span>
|
|
<strong>{socialCounts?.messages ?? '—'}</strong>
|
|
</article>
|
|
<article className="com-stat">
|
|
<span className="com-stat-label">花名册</span>
|
|
<strong>{socialCounts?.roster ?? '—'}</strong>
|
|
</article>
|
|
</div>
|
|
)}
|
|
|
|
<div className="com-hub-grid" style={{ marginBottom: 18 }}>
|
|
{tools.map((t) => (
|
|
<Link key={t.to} to={t.to} className="com-hub com-hub-primary">
|
|
<span className="com-hub-ico" aria-hidden>
|
|
{t.ico}
|
|
</span>
|
|
<strong>{t.title}</strong>
|
|
<span>{t.desc}</span>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
|
|
{!L ? (
|
|
<div className="com-panel">加载本轨配置…</div>
|
|
) : (
|
|
<section className="com-panel">
|
|
<div className="com-panel-head">
|
|
<h2>本轨开关与文案</h2>
|
|
<p>{L.note || '写入 remote-config.audience.' + lane}</p>
|
|
</div>
|
|
|
|
<div className="com-flag-list">
|
|
<div className="com-flag-row">
|
|
<div>
|
|
<strong>支付 CTA</strong>
|
|
<p>{meta.pay}</p>
|
|
</div>
|
|
<Switch
|
|
checked={L.payEnabled}
|
|
disabled={busy}
|
|
label="pay"
|
|
onChange={(v) => void patchLane({ payEnabled: v }, `支付已${v ? '开' : '关'}`)}
|
|
/>
|
|
</div>
|
|
<div className="com-flag-row">
|
|
<div>
|
|
<strong>关注引导</strong>
|
|
<p>{meta.follow}</p>
|
|
</div>
|
|
<Switch
|
|
checked={L.socialFollow}
|
|
disabled={busy}
|
|
label="follow"
|
|
onChange={(v) => void patchLane({ socialFollow: v }, `关注已${v ? '开' : '关'}`)}
|
|
/>
|
|
</div>
|
|
<div className="com-flag-row">
|
|
<div>
|
|
<strong>关注渠道</strong>
|
|
<p>本轨默认渠道</p>
|
|
</div>
|
|
<select
|
|
className="com-select"
|
|
disabled={busy}
|
|
value={L.followChannel}
|
|
onChange={(e) =>
|
|
void patchLane(
|
|
{ followChannel: e.target.value as Lane['followChannel'] },
|
|
`渠道 → ${e.target.value}`,
|
|
)
|
|
}
|
|
>
|
|
<option value="wechat">微信公众号</option>
|
|
<option value="x">X / Twitter</option>
|
|
<option value="none">不弹</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="com-form-grid" style={{ marginTop: 14 }}>
|
|
<label className="com-field">
|
|
<span>VIP CTA</span>
|
|
<input value={vipCta} disabled={busy} onChange={(e) => setVipCta(e.target.value)} />
|
|
</label>
|
|
<label className="com-field" style={{ gridColumn: '1 / -1' }}>
|
|
<span>首页导语</span>
|
|
<textarea
|
|
className="com-textarea"
|
|
rows={3}
|
|
value={homeLead}
|
|
disabled={busy}
|
|
onChange={(e) => setHomeLead(e.target.value)}
|
|
/>
|
|
</label>
|
|
</div>
|
|
<div className="com-actions">
|
|
<button
|
|
type="button"
|
|
className="com-btn"
|
|
disabled={busy}
|
|
onClick={() => void patchLane({ vipCta, homeLead }, '文案已保存')}
|
|
>
|
|
保存文案
|
|
</button>
|
|
</div>
|
|
</section>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|