Spaces:
Running
Running
Download ui-src/src/rooms/Sources.tsx from Ethscriptions/xiaoshuo: direct link, hf CLI and curl.
- Browser
- Download file 45.1 kB
-
https://huggingface.co/spaces/Ethscriptions/xiaoshuo/resolve/main/ui-src/src/rooms/Sources.tsx
- Command line
-
hf download hf://spaces/Ethscriptions/xiaoshuo/ui-src/src/rooms/Sources.tsx
-
curl -L -o Sources.tsx https://huggingface.co/spaces/Ethscriptions/xiaoshuo/resolve/main/ui-src/src/rooms/Sources.tsx
45.1 kB
| import React, { useEffect, useMemo, useState } from 'react' | |
| import { | |
| Radio, Plus, RefreshCw, History, Trash2, Search, Star, StarOff, Eye, Heart, BarChart3, Lightbulb, List, Bookmark, Compass, Gauge, | |
| UserCircle2, X, ExternalLink, Play, Square, EyeOff, RotateCw, ChevronDown, ChevronUp, Image as ImageIcon, | |
| } from 'lucide-react' | |
| import { del, get, post, qs } from '../api' | |
| import { copyText, cx, fmtAgo, fmtDate, fmtNum, go, useAsync, useDebounced } from '../lib' | |
| import { VaultGate, VaultTools } from './Vault' | |
| import { Empty, ErrorNote, Field, Loading, Modal, Pager, Segmented, Spinner, Tabs, Tag, useConfirm, useToast } from '../ui' | |
| type Channel = { | |
| channel: string; title: string; description?: string; avatar?: string; added_at?: string; last_synced_at?: string | |
| backfill_status?: string; backfilling?: boolean; annotated?: number; posts?: number; oldest_at?: string; newest_at?: string | |
| } | |
| const SPECIAL = ['~saved', '~discover', '~clean'] | |
| export default function Sources(props: { channel: string; tab: string }) { | |
| return <VaultGate><SourcesInner {...props} /></VaultGate> | |
| } | |
| function SourcesInner({ channel, tab }: { channel: string; tab: string }) { | |
| const chs = useAsync(() => get<{ items: Channel[] }>('/api/channels'), []) | |
| const acct = useAsync(() => get<any>('/api/tgauth/status'), []) | |
| const [filter, setFilter] = useState('') | |
| const [addOpen, setAddOpen] = useState(false) | |
| const [acctOpen, setAcctOpen] = useState(false) | |
| const list = chs.data?.items || [] | |
| const anyBackfill = list.some(c => c.backfilling) | |
| useEffect(() => { | |
| if (!anyBackfill) return | |
| const t = setInterval(() => chs.reload(), 8000) | |
| return () => clearInterval(t) | |
| }, [anyBackfill]) | |
| const shown = list.filter(c => !filter || c.channel.toLowerCase().includes(filter.toLowerCase()) || (c.title || '').includes(filter)) | |
| const current = list.find(c => c.channel === channel) | |
| const totalPosts = list.reduce((a, c) => a + (c.posts || 0), 0) | |
| let main: React.ReactNode | |
| if (channel === '~saved') main = <SavedView /> | |
| else if (channel === '~discover') main = <DiscoverView onAdded={() => chs.reload()} connected={!!acct.data?.connected} onAccount={() => setAcctOpen(true)} /> | |
| else if (channel === '~clean') main = <CleanView /> | |
| else if (channel && current) main = <ChannelView key={channel} ch={current} tab={tab} onChanged={() => chs.reload()} /> | |
| else if (channel && chs.data) main = <div className="page"><Empty title="没有这个频道">它可能已被移除。</Empty></div> | |
| else if (!chs.data) main = chs.error ? <div className="page"><ErrorNote error={chs.error} onRetry={chs.reload} /></div> : <Loading /> | |
| else main = <Overview list={list} totalPosts={totalPosts} acct={acct.data} onAdd={() => setAddOpen(true)} onAccount={() => setAcctOpen(true)} /> | |
| return ( | |
| <div className="sources"> | |
| <aside className="src-side"> | |
| <div className="src-side-head"> | |
| <button className="src-home" onClick={() => go('sources')}><Radio size={15} />素材采集</button> | |
| <button className="icon-btn sm" onClick={() => setAddOpen(true)} title="添加频道"><Plus size={16} /></button> | |
| </div> | |
| <nav className="src-special"> | |
| <button className={cx('src-link', channel === '~saved' && 'on')} onClick={() => go('sources/~saved')}><Bookmark size={15} />收藏的灵感</button> | |
| <button className={cx('src-link', channel === '~discover' && 'on')} onClick={() => go('sources/~discover')}><Compass size={15} />发现新频道</button> | |
| <button className={cx('src-link', channel === '~clean' && 'on')} onClick={() => go('sources/~clean')}><Gauge size={15} />清洗进度</button> | |
| <button className="src-link" onClick={() => setAcctOpen(true)}><UserCircle2 size={15} />Telegram 账号<span className={cx('dot push', acct.data?.connected ? 'ok' : 'warn')} /></button> | |
| <VaultTools /> | |
| </nav> | |
| <label className="search-row slim"><Search size={14} /><input className="input bare" value={filter} onChange={e => setFilter(e.target.value)} placeholder={`在 ${list.length} 个频道中查找`} /></label> | |
| <div className="src-list"> | |
| {shown.map(c => ( | |
| <button key={c.channel} className={cx('src-item', c.channel === channel && 'on')} onClick={() => go(`sources/${c.channel}`)}> | |
| <Avatar c={c} /> | |
| <span className="si-text"><b>{c.title || c.channel}</b><span>@{c.channel} · {fmtNum(c.posts || 0)} 帖</span></span> | |
| {c.backfilling ? <Spinner size={12} /> : (c.annotated || 0) > 0 ? <Lightbulb size={13} className="si-flag" /> : null} | |
| </button> | |
| ))} | |
| </div> | |
| </aside> | |
| <section className="src-main">{main}</section> | |
| <AddChannel open={addOpen} onClose={() => setAddOpen(false)} onAdded={ch => { chs.reload(); go(`sources/${ch}`) }} onAccount={() => { setAddOpen(false); setAcctOpen(true) }} /> | |
| <AccountModal open={acctOpen} onClose={() => { setAcctOpen(false); acct.reload() }} status={acct.data} reload={acct.reload} /> | |
| </div> | |
| ) | |
| } | |
| function Avatar({ c, size = 30 }: { c: { avatar?: string; title?: string; channel: string }; size?: number }) { | |
| const [bad, setBad] = useState(false) | |
| if (c.avatar && !bad) return <img className="avatar" src={c.avatar} alt="" width={size} height={size} onError={() => setBad(true)} loading="lazy" /> | |
| return <span className="avatar ph" style={{ width: size, height: size }}>{(c.title || c.channel).slice(0, 1)}</span> | |
| } | |
| function Overview({ list, totalPosts, acct, onAdd, onAccount }: { list: Channel[]; totalPosts: number; acct: any; onAdd: () => void; onAccount: () => void }) { | |
| const recent = [...list].sort((a, b) => String(b.last_synced_at).localeCompare(String(a.last_synced_at))).slice(0, 8) | |
| const annotated = list.filter(c => (c.annotated || 0) > 0) | |
| return ( | |
| <div className="page"> | |
| <div className="eyebrow"><Radio size={14} />素材采集</div> | |
| <h1 className="page-title serif">从 Telegram 频道收集真实故事</h1> | |
| <p className="page-sub">添加频道后会自动抓取全部历史帖子并定期更新。打过分的频道可以在「灵感」里按质量挑选。</p> | |
| <div className="stat-row"> | |
| <div className="stat"><b>{list.length}</b><span>个频道</span></div> | |
| <div className="stat"><b>{fmtNum(totalPosts)}</b><span>条帖子</span></div> | |
| <div className="stat"><b>{annotated.length}</b><span>个频道已标注灵感</span></div> | |
| <button className="stat clickable" onClick={onAccount}><b className={acct?.connected ? 'ok-text' : 'warn-text'}>{acct?.connected ? '已连接' : '未连接'}</b><span>Telegram 账号</span></button> | |
| </div> | |
| {acct?.error && <div className="banner warn"><span>账号状态:{acct.error}</span><button className="link-btn" onClick={onAccount}>查看</button></div>} | |
| <div className="row gap"><button className="btn primary" onClick={onAdd}><Plus size={15} />添加频道</button><button className="btn ghost" onClick={() => go('sources/~discover')}><Compass size={15} />发现新频道</button></div> | |
| {annotated.length > 0 && <section className="sheet"> | |
| <h2 className="sheet-title">可以挑灵感的频道</h2> | |
| <div className="ch-cards">{annotated.map(c => <ChCard key={c.channel} c={c} to={`sources/${c.channel}/inspo`} />)}</div> | |
| </section>} | |
| <section className="sheet"> | |
| <h2 className="sheet-title">最近更新</h2> | |
| <div className="ch-cards">{recent.map(c => <ChCard key={c.channel} c={c} to={`sources/${c.channel}`} />)}</div> | |
| </section> | |
| </div> | |
| ) | |
| } | |
| function ChCard({ c, to }: { c: Channel; to: string }) { | |
| return ( | |
| <button className="ch-card" onClick={() => go(to)}> | |
| <Avatar c={c} size={36} /> | |
| <span className="cc-text"><b>{c.title || c.channel}</b><span>{fmtNum(c.posts || 0)} 帖{c.annotated ? ` · ${fmtNum(c.annotated)} 条已标注` : ''} · {fmtAgo(c.last_synced_at)}更新</span></span> | |
| </button> | |
| ) | |
| } | |
| /* ================= 频道 ================= */ | |
| type CTab = 'inspo' | 'posts' | 'stats' | |
| function ChannelView({ ch, tab, onChanged }: { ch: Channel; tab: string; onChanged: () => void }) { | |
| const toast = useToast() | |
| const confirm = useConfirm() | |
| const hasInspo = (ch.annotated || 0) > 0 | |
| const t = (['inspo', 'posts', 'stats'].includes(tab) ? tab : hasInspo ? 'inspo' : 'posts') as CTab | |
| const [busy, setBusy] = useState('') | |
| const [bump, setBump] = useState(0) | |
| const [descOpen, setDescOpen] = useState(false) | |
| const sync = async () => { | |
| setBusy('sync') | |
| try { const r = await post<any>('/api/posts/sync', { channel: ch.channel, pages: 5 }); toast(r.note || `已更新,新增 ${r.added ?? r.fetched ?? 0} 条`, 'ok'); onChanged(); setBump(b => b + 1) } | |
| catch (e: any) { toast(e.message, 'err') } finally { setBusy('') } | |
| } | |
| const backfill = async () => { | |
| setBusy('bf') | |
| try { const r = await post<any>(`/api/channels/${ch.channel}/backfill`, {}); toast(r.started ? '已开始在后台收集全部历史帖子' : '历史已收集完,或正在收集中'); onChanged() } | |
| catch (e: any) { toast(e.message, 'err') } finally { setBusy('') } | |
| } | |
| const remove = async () => { | |
| const ok = await confirm({ title: `移除频道 @${ch.channel}?`, body: '会删除这个频道已抓取的全部帖子和收藏,无法恢复。素材库里已经清洗好的素材不受影响。', ok: '永久移除', danger: true, typeToConfirm: ch.channel }) | |
| if (!ok) return | |
| setBusy('del') | |
| try { await del(`/api/channels/${ch.channel}`); toast('频道已移除'); onChanged(); go('sources') } | |
| catch (e: any) { toast(e.message, 'err') } finally { setBusy('') } | |
| } | |
| return ( | |
| <div className="page wide"> | |
| <header className="ch-head"> | |
| <Avatar c={ch} size={52} /> | |
| <div className="ch-head-text"> | |
| <h1 className="page-title serif">{ch.title || ch.channel}</h1> | |
| <div className="muted"> | |
| <a href={`https://t.me/${ch.channel}`} target="_blank" rel="noreferrer">@{ch.channel} <ExternalLink size={11} /></a> | |
| {' · '}{fmtNum(ch.posts || 0)} 条帖子 · {fmtAgo(ch.last_synced_at)}更新 | |
| {' · '}{ch.backfilling ? <span className="accent-text">正在收集历史…</span> : ch.backfill_status === 'done' ? '历史已收全' : '历史未收全'} | |
| </div> | |
| {ch.description && <div className={cx('ch-desc', descOpen && 'open')} onClick={() => setDescOpen(o => !o)}>{ch.description}</div>} | |
| </div> | |
| <div className="ch-actions"> | |
| <button className="btn small ghost" onClick={sync} disabled={!!busy}>{busy === 'sync' ? <Spinner size={13} /> : <RefreshCw size={14} />}同步最新</button> | |
| {ch.backfill_status !== 'done' && !ch.backfilling && <button className="btn small ghost" onClick={backfill} disabled={!!busy}><History size={14} />收集全部历史</button>} | |
| <button className="icon-btn danger" onClick={remove} disabled={!!busy} title="移除频道"><Trash2 size={15} /></button> | |
| </div> | |
| </header> | |
| <Tabs<CTab> value={t} onChange={v => go(`sources/${ch.channel}/${v}`)} className="room-tabs" items={[ | |
| { id: 'inspo', label: <><Lightbulb size={14} />灵感</>, count: ch.annotated || undefined }, | |
| { id: 'posts', label: <><List size={14} />全部帖子</>, count: ch.posts || undefined }, | |
| { id: 'stats', label: <><BarChart3 size={14} />统计</> }, | |
| ]} /> | |
| {t === 'posts' && <PostsTab ch={ch.channel} bump={bump} />} | |
| {t === 'inspo' && (hasInspo ? <InspoTab ch={ch.channel} /> : <Empty icon={<Lightbulb size={22} />} title="这个频道还没有灵感标注">标注完成后,这里会按素材价值给帖子打分、归类,方便挑选。现在可以先在「全部帖子」里浏览。</Empty>)} | |
| {t === 'stats' && <StatsTab ch={ch.channel} />} | |
| </div> | |
| ) | |
| } | |
| const SORT_POSTS = [{ id: 'latest', label: '最新' }, { id: 'views', label: '最多浏览' }, { id: 'reactions', label: '最多互动' }, { id: 'long', label: '最长' }] | |
| function PostsTab({ ch, bump }: { ch: string; bump: number }) { | |
| const [cat, setCat] = useState('') | |
| const [q, setQ] = useState('') | |
| const [sort, setSort] = useState('latest') | |
| const [hidePromo, setHidePromo] = useState(true) | |
| const [items, setItems] = useState<any[]>([]) | |
| const [total, setTotal] = useState(0) | |
| const [loading, setLoading] = useState(true) | |
| const [err, setErr] = useState('') | |
| const dq = useDebounced(q, 400) | |
| const stats = useAsync(() => get<any>(`/api/posts/stats${qs({ channel: ch })}`), [ch, bump]) | |
| const load = async (offset: number) => { | |
| setLoading(true); setErr('') | |
| try { | |
| const r = await get<any>(`/api/posts${qs({ channel: ch, category: cat, q: dq, sort, hidePromo: hidePromo ? 1 : '', limit: 30, offset })}`) | |
| setItems(prev => offset ? [...prev, ...r.items] : r.items); setTotal(r.total) | |
| } catch (e: any) { setErr(e.message) } finally { setLoading(false) } | |
| } | |
| useEffect(() => { load(0) }, [ch, cat, dq, sort, hidePromo, bump]) | |
| const cats: any[] = stats.data?.categories || [] | |
| return ( | |
| <div className="posts"> | |
| <div className="toolbar"> | |
| <label className="search-row grow"><Search size={15} /><input className="input bare" value={q} onChange={e => setQ(e.target.value)} placeholder="搜索帖子内容" /></label> | |
| <select className="input auto" value={sort} onChange={e => setSort(e.target.value)}>{SORT_POSTS.map(s => <option key={s.id} value={s.id}>{s.label}</option>)}</select> | |
| <label className="check"><input type="checkbox" checked={hidePromo} onChange={e => setHidePromo(e.target.checked)} />隐藏推广</label> | |
| </div> | |
| <div className="chips-row"> | |
| <button className={cx('chip', !cat && 'on')} onClick={() => setCat('')}>全部</button> | |
| {cats.map(c => <button key={c.category} className={cx('chip', cat === c.category && 'on')} onClick={() => setCat(cat === c.category ? '' : c.category)}>{c.category}<em>{c.n}</em></button>)} | |
| </div> | |
| {err && <ErrorNote error={err} onRetry={() => load(0)} />} | |
| <div className="muted small-note">共 {fmtNum(total)} 条</div> | |
| <div className="post-list">{items.map(p => <PostCard key={p.post_id} p={p} ch={ch} />)}</div> | |
| {loading ? <Loading /> : items.length < total && <button className="btn ghost block" onClick={() => load(items.length)}>再加载 30 条</button>} | |
| {!loading && !items.length && !err && <Empty title="没有符合条件的帖子" />} | |
| </div> | |
| ) | |
| } | |
| function PostCard({ p, ch, children, head }: { p: any; ch: string; children?: React.ReactNode; head?: React.ReactNode }) { | |
| const [open, setOpen] = useState(false) | |
| const toast = useToast() | |
| const long = (p.text || '').length > 260 | |
| return ( | |
| <article className="post"> | |
| <div className="post-meta"> | |
| {head} | |
| {p.category && <Tag>{p.category}</Tag>} | |
| <span className="muted">{fmtDate(p.posted_at)}</span> | |
| <span className="muted"><Eye size={12} /> {fmtNum(p.views)}</span> | |
| {p.reaction_total ? <span className="muted"><Heart size={12} /> {fmtNum(p.reaction_total)}</span> : null} | |
| <span className="muted">{p.char_count} 字</span> | |
| {p.photos?.length ? <span className="muted"><ImageIcon size={12} /> {p.photos.length}</span> : null} | |
| <span className="post-tools"> | |
| <button className="icon-btn sm" title="复制正文" onClick={async () => { await copyText(p.text); toast('已复制', 'ok') }}>⧉</button> | |
| <a className="icon-btn sm" title="在 Telegram 打开" href={`https://t.me/${ch}/${p.post_id}`} target="_blank" rel="noreferrer"><ExternalLink size={13} /></a> | |
| </span> | |
| </div> | |
| <div className={cx('post-text', !open && long && 'clamp')}>{p.text}</div> | |
| {long && <button className="link-btn" onClick={() => setOpen(o => !o)}>{open ? <><ChevronUp size={13} />收起</> : <><ChevronDown size={13} />展开全文</>}</button>} | |
| {p.reactions?.length ? <div className="reactions">{p.reactions.slice(0, 6).map((r: any, i: number) => <span key={i}>{r.emoji} {r.count}</span>)}</div> : null} | |
| {children} | |
| </article> | |
| ) | |
| } | |
| /* ---------- 灵感 ---------- */ | |
| const PRESETS: Record<string, { label: string; d: string; p: Record<string, any> }> = { | |
| best: { label: '精选', d: '完整故事 · 4 分以上 · 同类只留最佳', p: { kinds: '故事', minScore: 4, minChars: '', dedupe: '' } }, | |
| wide: { label: '宽松', d: '故事和片段 · 3 分以上 · 100 字以上', p: { kinds: '故事,片段', minScore: 3, minChars: 100, dedupe: '' } }, | |
| all: { label: '全部', d: '60 字以上 · 不去重', p: { kinds: '', minScore: '', minChars: 60, dedupe: '0' } }, | |
| } | |
| const KINDS = ['故事', '片段', '倾诉', '求助'] | |
| function InspoTab({ ch }: { ch: string }) { | |
| const [preset, setPreset] = useState('best') | |
| const [kinds, setKinds] = useState<string[]>(['故事']) | |
| const [minScore, setMinScore] = useState<number | ''>(4) | |
| const [minChars, setMinChars] = useState<number | ''>('') | |
| const [dedupe, setDedupe] = useState(true) | |
| const [motif, setMotif] = useState('') | |
| const [tag, setTag] = useState('') | |
| const [q, setQ] = useState('') | |
| const [saved, setSaved] = useState(false) | |
| const [sort, setSort] = useState('score') | |
| const [page, setPage] = useState(1) | |
| const [group, setGroup] = useState<string>('') | |
| const dq = useDebounced(q, 400) | |
| const applyPreset = (id: string) => { | |
| const p = PRESETS[id].p | |
| setPreset(id); setKinds(p.kinds ? String(p.kinds).split(',') : []); setMinScore(p.minScore || ''); setMinChars(p.minChars || ''); setDedupe(p.dedupe !== '0') | |
| } | |
| const params = { channel: ch, kinds: kinds.join(','), minScore, minChars, dedupe: dedupe ? '' : '0', motif, tag, q: dq, saved: saved ? 1 : '' } | |
| const key = JSON.stringify(params) | |
| useEffect(() => setPage(1), [key, sort]) | |
| const size = 20 | |
| const funnel = useAsync(() => get<any>(`/api/inspo/funnel${qs(params)}`), [key]) | |
| const list = useAsync(() => get<any>(`/api/inspo${qs({ ...params, sort, limit: size, offset: (page - 1) * size })}`), [key, sort, page]) | |
| const f = funnel.data | |
| const toggleKind = (k: string) => { setPreset(''); setKinds(ks => ks.includes(k) ? ks.filter(x => x !== k) : [...ks, k]) } | |
| const updateItem = (post_id: number, patch: any) => list.setData((d: any) => d ? { ...d, items: d.items.map((x: any) => x.post_id === post_id ? { ...x, ...patch } : x) } : d) | |
| return ( | |
| <div className="inspo"> | |
| <div className="presets"> | |
| {Object.entries(PRESETS).map(([id, p]) => ( | |
| <button key={id} className={cx('preset', preset === id && 'on')} onClick={() => applyPreset(id)}><b>{p.label}</b><span>{p.d}</span></button> | |
| ))} | |
| </div> | |
| <div className="inspo-filters"> | |
| <div className="fline"><span className="flabel">类型</span>{KINDS.map(k => <button key={k} className={cx('chip', kinds.includes(k) && 'on')} onClick={() => toggleKind(k)}>{k}</button>)}</div> | |
| <div className="fline"><span className="flabel">素材分</span> | |
| {['', 1, 2, 3, 4, 5].map(s => <button key={String(s)} className={cx('chip', minScore === s && 'on')} onClick={() => { setPreset(''); setMinScore(s as any) }}>{s ? `${s}+` : '不限'}</button>)} | |
| {f?.scoreDist?.length > 0 && <span className="score-dist">{f.scoreDist.map((x: any) => <i key={x.score} title={`${x.score} 分:${x.n} 条`} style={{ height: `${Math.max(8, (x.n / Math.max(...f.scoreDist.map((y: any) => y.n))) * 100)}%` }} />)}</span>} | |
| </div> | |
| <div className="fline"><span className="flabel">字数</span> | |
| {['', 60, 100, 300, 800].map(n => <button key={String(n)} className={cx('chip', minChars === n && 'on')} onClick={() => { setPreset(''); setMinChars(n as any) }}>{n ? `${n}+` : '不限'}</button>)} | |
| <label className="check push"><input type="checkbox" checked={dedupe} onChange={e => { setPreset(''); setDedupe(e.target.checked) }} />同类事件只留最佳</label> | |
| <label className="check"><input type="checkbox" checked={saved} onChange={e => setSaved(e.target.checked)} />只看收藏</label> | |
| </div> | |
| {f?.motifs?.length > 0 && <div className="fline wrap"><span className="flabel">母题</span> | |
| {motif && <button className="chip on" onClick={() => setMotif('')}>{motif} <X size={11} /></button>} | |
| {f.motifs.filter((m: any) => m.motif !== motif).slice(0, 24).map((m: any) => <button key={m.motif} className="chip" onClick={() => setMotif(m.motif)}>{m.motif}<em>{m.n}</em></button>)} | |
| </div>} | |
| {f?.tags?.length > 0 && <div className="fline wrap"><span className="flabel">元素</span> | |
| {tag && <button className="chip on" onClick={() => setTag('')}>{tag} <X size={11} /></button>} | |
| {f.tags.filter((t: any) => t.tag !== tag).slice(0, 20).map((t: any) => <button key={t.tag} className="chip" onClick={() => setTag(t.tag)}>{t.tag}<em>{t.n}</em></button>)} | |
| </div>} | |
| </div> | |
| {f?.steps && ( | |
| <div className="funnel"> | |
| {f.steps.map((s: any, i: number) => <div key={i} className="funnel-step"><b>{fmtNum(s.n)}</b><span>{s.label}</span></div>)} | |
| </div> | |
| )} | |
| <div className="toolbar"> | |
| <label className="search-row grow"><Search size={15} /><input className="input bare" value={q} onChange={e => setQ(e.target.value)} placeholder="在原文和一句话梗概里搜索" /></label> | |
| <Segmented value={sort} onChange={setSort} items={[{ id: 'score', label: '按分数' }, { id: 'random', label: '随机' }, { id: 'latest', label: '最新' }, { id: 'reactions', label: '互动' }, { id: 'long', label: '最长' }]} /> | |
| </div> | |
| {list.error ? <ErrorNote error={list.error} onRetry={list.reload} /> : !list.data ? <Loading /> : list.data.items.length === 0 ? <Empty title="没有符合条件的灵感">放宽筛选条件试试。</Empty> : <> | |
| <div className={cx('post-list', list.loading && 'dim')}> | |
| {list.data.items.map((p: any) => <InspoCard key={p.post_id} p={p} ch={ch} onGroup={() => setGroup(p.plot_group)} onUpdate={patch => updateItem(p.post_id, patch)} />)} | |
| </div> | |
| <Pager page={page} total={list.data.total} size={size} onChange={setPage} /> | |
| </>} | |
| <GroupModal ch={ch} gkey={group} onClose={() => setGroup('')} /> | |
| </div> | |
| ) | |
| } | |
| function InspoCard({ p, ch, onGroup, onUpdate }: { p: any; ch: string; onGroup?: () => void; onUpdate: (patch: any) => void }) { | |
| const toast = useToast() | |
| const [noteOpen, setNoteOpen] = useState(false) | |
| const [note, setNote] = useState(p.saved_note || p.note || '') | |
| const [busy, setBusy] = useState(false) | |
| const save = async (withNote?: string) => { | |
| setBusy(true) | |
| try { await post('/api/inspo/saves', { channel: p.channel || ch, post_id: p.post_id, note: withNote ?? (note || null) }); onUpdate({ saved: true, saved_note: withNote ?? note }); toast('已收藏', 'ok'); setNoteOpen(false) } | |
| catch (e: any) { toast(e.message, 'err') } finally { setBusy(false) } | |
| } | |
| const unsave = async () => { | |
| setBusy(true) | |
| try { await del(`/api/inspo/saves/${p.post_id}${qs({ channel: p.channel || ch })}`); onUpdate({ saved: false, saved_note: null }); toast('已取消收藏') } | |
| catch (e: any) { toast(e.message, 'err') } finally { setBusy(false) } | |
| } | |
| return ( | |
| <PostCard p={p} ch={p.channel || ch} head={<> | |
| {p.score != null && <span className={cx('score', `s${p.score}`)}>{p.score}</span>} | |
| {p.kind && <Tag tone="accent">{p.kind}</Tag>} | |
| {p.motif && <Tag>{p.motif}</Tag>} | |
| </>}> | |
| {p.logline && <div className="logline serif">{p.logline}</div>} | |
| {p.detail && <div className="detail-quote">「{p.detail}」</div>} | |
| <div className="inspo-foot"> | |
| {p.tags?.map((t: string) => <span key={t} className="mini-tag">#{t}</span>)} | |
| {p.group_size > 1 && onGroup && <button className="link-btn" onClick={onGroup}>同类事件 {p.group_size} 条</button>} | |
| <span className="push" /> | |
| {p.saved ? <> | |
| <button className="link-btn" onClick={() => setNoteOpen(o => !o)}>{p.saved_note ? '改笔记' : '加笔记'}</button> | |
| <button className="btn small ghost on" onClick={unsave} disabled={busy}><Star size={13} className="filled" />已收藏</button> | |
| </> : <button className="btn small ghost" onClick={() => save()} disabled={busy}><Star size={13} />收藏</button>} | |
| </div> | |
| {p.saved && p.saved_note && !noteOpen && <div className="saved-note">笔记:{p.saved_note}</div>} | |
| {noteOpen && ( | |
| <div className="note-edit"> | |
| <input className="input" value={note} onChange={e => setNote(e.target.value)} placeholder="为什么收藏它?可以怎么用?" autoFocus onKeyDown={e => { if (e.key === 'Enter') save(note) }} /> | |
| <button className="btn small primary" onClick={() => save(note)} disabled={busy}>保存</button> | |
| </div> | |
| )} | |
| </PostCard> | |
| ) | |
| } | |
| function GroupModal({ ch, gkey, onClose }: { ch: string; gkey: string; onClose: () => void }) { | |
| const [items, setItems] = useState<any[] | null>(null) | |
| useEffect(() => { if (!gkey) return; setItems(null); get<any>(`/api/inspo/group${qs({ channel: ch, key: gkey })}`).then(r => setItems(r.items), () => setItems([])) }, [ch, gkey]) | |
| return ( | |
| <Modal open={!!gkey} onClose={onClose} width={760} title={`同类事件:${gkey}`}> | |
| {!items ? <Loading /> : <div className="post-list">{items.map(p => <PostCard key={p.post_id} p={p} ch={ch} head={p.score != null ? <span className={cx('score', `s${p.score}`)}>{p.score}</span> : null}>{p.logline && <div className="logline serif">{p.logline}</div>}</PostCard>)}</div>} | |
| </Modal> | |
| ) | |
| } | |
| /* ---------- 统计 ---------- */ | |
| function StatsTab({ ch }: { ch: string }) { | |
| const s = useAsync(() => get<any>(`/api/posts/stats${qs({ channel: ch })}`), [ch]) | |
| if (s.error) return <ErrorNote error={s.error} onRetry={s.reload} /> | |
| if (!s.data) return <Loading /> | |
| const d = s.data, sum = d.summary || {} | |
| const cats: any[] = d.categories || [] | |
| const maxCat = Math.max(1, ...cats.map(c => c.n)) | |
| const daily: any[] = (d.daily || []).slice(-120) | |
| const maxDay = Math.max(1, ...daily.map(x => x.n)) | |
| return ( | |
| <div className="stats"> | |
| <div className="stat-row"> | |
| <div className="stat"><b>{fmtNum(sum.total)}</b><span>条帖子</span></div> | |
| <div className="stat"><b>{fmtNum(sum.avg_views)}</b><span>平均浏览</span></div> | |
| <div className="stat"><b>{fmtNum(sum.avg_chars)}</b><span>平均字数</span></div> | |
| <div className="stat"><b>{fmtNum(sum.total_reactions)}</b><span>总互动</span></div> | |
| </div> | |
| <p className="muted small-note">时间跨度:{fmtDate(sum.oldest_at, false)} — {fmtDate(sum.newest_at, false)}</p> | |
| <section className="sheet"> | |
| <h2 className="sheet-title">话题分布</h2> | |
| <div className="bars"> | |
| {cats.map(c => <div key={c.category} className="bar-row"><span className="bar-label">{c.category}</span><span className="bar"><i style={{ width: `${(c.n / maxCat) * 100}%` }} /></span><span className="bar-n">{c.n}</span><span className="bar-sub muted">均浏览 {fmtNum(c.avg_views)}</span></div>)} | |
| </div> | |
| </section> | |
| {daily.length > 0 && <section className="sheet"> | |
| <h2 className="sheet-title">发帖节奏 <span className="muted small-note">最近 {daily.length} 个有帖的日子</span></h2> | |
| <div className="spark-bars">{daily.map(x => <i key={x.day} title={`${x.day}:${x.n} 条`} style={{ height: `${(x.n / maxDay) * 100}%` }} />)}</div> | |
| </section>} | |
| {d.emojis?.length > 0 && <section className="sheet"> | |
| <h2 className="sheet-title">读者反应</h2> | |
| <div className="emojis">{d.emojis.map((e: any) => <span key={e.emoji}><b>{e.emoji}</b>{fmtNum(e.n)}</span>)}</div> | |
| </section>} | |
| </div> | |
| ) | |
| } | |
| /* ================= 收藏 ================= */ | |
| function SavedView() { | |
| const s = useAsync(() => get<any>('/api/inspo/saves?channel=*'), []) | |
| const items: any[] = s.data?.items || [] | |
| return ( | |
| <div className="page wide"> | |
| <div className="eyebrow"><Bookmark size={14} />收藏的灵感</div> | |
| <h1 className="page-title serif">随手存下的好故事</h1> | |
| {s.error ? <ErrorNote error={s.error} onRetry={s.reload} /> : !s.data ? <Loading /> : items.length === 0 ? <Empty icon={<Star size={22} />} title="还没有收藏">在频道的「灵感」里点「收藏」,就会出现在这里。</Empty> : ( | |
| <div className="post-list"> | |
| {items.map(p => <InspoCard key={`${p.channel}-${p.post_id}`} p={{ ...p, saved: true, saved_note: p.note }} ch={p.channel} | |
| onUpdate={patch => s.setData((d: any) => ({ ...d, items: patch.saved === false ? d.items.filter((x: any) => !(x.channel === p.channel && x.post_id === p.post_id)) : d.items.map((x: any) => x.channel === p.channel && x.post_id === p.post_id ? { ...x, note: patch.saved_note } : x) }))} />)} | |
| </div> | |
| )} | |
| </div> | |
| ) | |
| } | |
| /* ================= 发现 ================= */ | |
| function DiscoverView({ onAdded, connected, onAccount }: { onAdded: () => void; connected: boolean; onAccount: () => void }) { | |
| const toast = useToast() | |
| const confirm = useConfirm() | |
| const d = useAsync(() => get<any>('/api/discover'), []) | |
| const [kw, setKw] = useState('') | |
| const [show, setShow] = useState<'good' | 'all' | 'ignored'>('good') | |
| const [busy, setBusy] = useState('') | |
| const [open, setOpen] = useState('') | |
| const running = !!d.data?.running | |
| useEffect(() => { if (d.data && !kw) setKw((d.data.keywords || []).join('、')) }, [d.data]) | |
| useEffect(() => { | |
| if (!running) return | |
| const t = setInterval(() => d.reload(), 4000) | |
| return () => clearInterval(t) | |
| }, [running]) | |
| const act = async (name: string, fn: () => Promise<any>, msg?: string) => { | |
| setBusy(name) | |
| try { await fn(); if (msg) toast(msg, 'ok'); await d.reload() } catch (e: any) { toast(e.message, 'err') } finally { setBusy('') } | |
| } | |
| const items: any[] = d.data?.items || [] | |
| const filtered = items.filter(x => show === 'ignored' ? x.ignored : !x.ignored && (show === 'all' || x.suitable)).sort((a, b) => (b.score || 0) - (a.score || 0)) | |
| return ( | |
| <div className="page wide"> | |
| <div className="eyebrow"><Compass size={14} />发现新频道</div> | |
| <h1 className="page-title serif">用关键词找更多故事频道</h1> | |
| <p className="page-sub">输入几个关键词,系统会搜索相关频道,读取最新内容,判断是否适合当素材来源。</p> | |
| {!connected && <div className="banner warn"><span>需要先连接 Telegram 账号才能搜索。</span><button className="link-btn" onClick={onAccount}>去连接</button></div>} | |
| <div className="sheet"> | |
| <Field label="关键词" hint="用顿号或空格隔开,最多 20 个"><input className="input" value={kw} onChange={e => setKw(e.target.value)} placeholder="树洞、情感、真实经历" /></Field> | |
| <div className="row gap"> | |
| {running ? <button className="btn danger" onClick={() => act('stop', () => post('/api/discover/stop'), '已停止')} disabled={!!busy}><Square size={14} />停止</button> | |
| : <button className="btn primary" onClick={() => act('run', () => post('/api/discover/run', { keywords: kw.split(/[,,、\s]+/).filter(Boolean) }), '已开始搜索')} disabled={!!busy || !connected}><Play size={14} />开始搜索</button>} | |
| {items.length > 0 && !running && <button className="btn ghost" onClick={async () => { if (await confirm({ title: '清空搜索结果?', body: '只清空这里的候选列表,已添加的频道不受影响。', ok: '清空', danger: true })) act('clear', () => post('/api/discover/clear'), '已清空') }} disabled={!!busy}>清空结果</button>} | |
| {d.data?.phase && <span className="muted">{running && <Spinner size={13} />} {d.data.phase}</span>} | |
| </div> | |
| </div> | |
| {d.error ? <ErrorNote error={d.error} onRetry={d.reload} /> : !d.data ? <Loading /> : <> | |
| <Segmented value={show} onChange={setShow} items={[ | |
| { id: 'good', label: `合适的 ${items.filter(x => !x.ignored && x.suitable).length}` }, | |
| { id: 'all', label: `全部 ${items.filter(x => !x.ignored).length}` }, | |
| { id: 'ignored', label: `已忽略 ${items.filter(x => x.ignored).length}` }, | |
| ]} /> | |
| <div className="disc-list"> | |
| {filtered.map(x => ( | |
| <div key={x.username} className={cx('disc-item', x.ignored && 'ignored')}> | |
| <div className="disc-head"> | |
| <span className={cx('score-badge', x.suitable ? 'good' : 'bad')}>{x.score ?? '—'}</span> | |
| <div className="disc-title"><b>{x.title || x.username}</b><a className="muted" href={`https://t.me/${x.username}`} target="_blank" rel="noreferrer">@{x.username}</a></div> | |
| <div className="disc-tags"> | |
| {x.verdict && <Tag tone={x.suitable ? 'accent' : undefined}>{x.verdict}</Tag>} | |
| {x.adult && <Tag tone="warn">含成人内容</Tag>} | |
| {x.ad && <Tag>广告多</Tag>} | |
| {x.status !== 'checked' && <Tag>{x.status === 'pending' ? '待检查' : x.status}</Tag>} | |
| </div> | |
| <div className="disc-actions"> | |
| <button className="btn small primary" disabled={!!busy} onClick={() => act(`add-${x.username}`, async () => { await post('/api/channels', { channel: x.username }); onAdded() }, `已添加 @${x.username},正在收集历史`)}><Plus size={13} />添加</button> | |
| <button className="icon-btn sm" title={x.ignored ? '取消忽略' : '忽略'} disabled={!!busy} onClick={() => act(`ig-${x.username}`, () => post('/api/discover/update', { username: x.username, ignored: !x.ignored }))}>{x.ignored ? <Eye size={14} /> : <EyeOff size={14} />}</button> | |
| <button className="icon-btn sm" title="重新检查" disabled={!!busy} onClick={() => act(`re-${x.username}`, () => post('/api/discover/update', { username: x.username, recheck: true }), '已加入检查队列')}><RotateCw size={14} /></button> | |
| </div> | |
| </div> | |
| {x.stats && <div className="disc-stats muted">最近 {x.stats.n} 条 · 中位 {x.stats.median} 字 · 长文 {Math.round((x.stats.long || 0) * 100)}% · 故事 {Math.round((x.stats.story || 0) * 100)}% · 推广 {Math.round((x.stats.promo || 0) * 100)}%{x.last_post_at ? ` · 最近发帖 ${fmtAgo(x.last_post_at)}` : ''}{x.keywords?.length ? ` · 来自「${x.keywords.join('、')}」` : ''}</div>} | |
| {x.samples?.length > 0 && <> | |
| <button className="link-btn" onClick={() => setOpen(open === x.username ? '' : x.username)}>{open === x.username ? '收起样本' : `看 ${x.samples.length} 条样本`}</button> | |
| {open === x.username && <div className="samples">{x.samples.map((s: any, i: number) => <div key={i} className="sample">{String(s.text || '').slice(0, 400)}</div>)}</div>} | |
| </>} | |
| </div> | |
| ))} | |
| {!filtered.length && <Empty title="这里还没有结果" />} | |
| </div> | |
| </>} | |
| </div> | |
| ) | |
| } | |
| /* ================= 清洗进度 ================= */ | |
| function CleanView() { | |
| const p = useAsync(() => get<any>('/api/clean/progress'), []) | |
| const [page, setPage] = useState(0) | |
| const [showMat, setShowMat] = useState(false) | |
| const m = useAsync(() => showMat ? get<any>(`/api/clean/materials${qs({ page: page || '0' })}`) : Promise.resolve(null), [page, showMat]) | |
| if (p.error) return <div className="page"><ErrorNote error={p.error} onRetry={p.reload} /></div> | |
| if (!p.data) return <Loading /> | |
| const s = p.data.stats || {} | |
| const batches: any[] = [...(p.data.batches || [])].reverse() | |
| return ( | |
| <div className="page wide"> | |
| <div className="eyebrow"><Gauge size={14} />清洗进度</div> | |
| <h1 className="page-title serif">原帖 → 可用素材</h1> | |
| <p className="page-sub">逐批读取原帖,去掉不适合的内容,必要时改写。更新于 {fmtDate(p.data.updated_at)}。</p> | |
| <div className="progress-big"><i style={{ width: `${Math.min(100, s.percent || 0)}%` }} /><span>{s.percent ?? 0}%</span></div> | |
| <div className="stat-row"> | |
| <div className="stat"><b>{fmtNum(s.read)}</b><span>已读 / {fmtNum(s.total)}</span></div> | |
| <div className="stat"><b>{fmtNum(s.kept)}</b><span>原样保留</span></div> | |
| <div className="stat"><b>{fmtNum(s.rewritten)}</b><span>改写后保留</span></div> | |
| <div className="stat"><b>{fmtNum(s.dropped)}</b><span>丢弃</span></div> | |
| <div className="stat"><b>{fmtNum(s.materials)}</b><span>条素材 · {fmtNum(s.chars_out)} 字</span></div> | |
| </div> | |
| <div className="row gap"><button className="btn ghost small" onClick={() => setShowMat(v => !v)}>{showMat ? '收起素材' : '浏览清洗出的素材'}</button></div> | |
| {showMat && (m.loading && !m.data ? <Loading /> : m.error ? <ErrorNote error={m.error} /> : m.data && <section className="sheet"> | |
| <div className="post-list">{m.data.items.map((x: any) => <PostCard key={x.key} ch={x.channel} p={{ ...x, char_count: x.chars, reaction_total: x.reactions, reactions: [] }} head={<Tag tone={x.verdict === 'keep' ? 'accent' : undefined}>{x.verdict === 'keep' ? '保留' : '改写'}</Tag>}>{x.note && <div className="muted small-note">{x.note}</div>}</PostCard>)}</div> | |
| <Pager page={page + 1} total={m.data.total} size={Math.max(1, Math.ceil(m.data.total / Math.max(1, m.data.pages)))} onChange={pg => setPage(pg - 1)} /> | |
| </section>)} | |
| <section className="sheet"> | |
| <h2 className="sheet-title">最近处理的批次</h2> | |
| <div className="batch-table"> | |
| {batches.slice(0, 40).map(b => ( | |
| <div key={b.no} className="batch-row"> | |
| <span className="br-n">第 {b.no} 批</span> | |
| <span className="muted">{(b.channels || []).join('、')}</span> | |
| <span className="br-range">保留 {b.kept} · 改写 {b.rewritten} · 丢弃 {b.dropped}</span> | |
| <span className="muted push">{fmtAgo(b.finished_at)}</span> | |
| </div> | |
| ))} | |
| </div> | |
| </section> | |
| </div> | |
| ) | |
| } | |
| /* ================= 添加频道 ================= */ | |
| function AddChannel({ open, onClose, onAdded, onAccount }: { open: boolean; onClose: () => void; onAdded: (ch: string) => void; onAccount: () => void }) { | |
| const toast = useToast() | |
| const [v, setV] = useState('') | |
| const [backfill, setBackfill] = useState(true) | |
| const [busy, setBusy] = useState(false) | |
| const [err, setErr] = useState<{ msg: string; needAccount?: boolean } | null>(null) | |
| useEffect(() => { if (open) { setV(''); setErr(null) } }, [open]) | |
| const submit = async (e: React.FormEvent) => { | |
| e.preventDefault() | |
| if (!v.trim()) return | |
| setBusy(true); setErr(null) | |
| try { const r = await post<any>('/api/channels', { channel: v.trim(), backfill }); toast(`已添加 @${r.channel}`, 'ok'); onClose(); onAdded(r.channel) } | |
| catch (e: any) { setErr({ msg: e.message, needAccount: e.data?.needAccount }) } finally { setBusy(false) } | |
| } | |
| return ( | |
| <Modal open={open} onClose={onClose} title="添加 Telegram 频道" width={480}> | |
| <form onSubmit={submit} className="panel-stack"> | |
| <Field label="频道地址" hint="例如 https://t.me/chxpd 或 @chxpd"><input className="input" value={v} onChange={e => setV(e.target.value)} autoFocus placeholder="@频道用户名" /></Field> | |
| <label className="check"><input type="checkbox" checked={backfill} onChange={e => setBackfill(e.target.checked)} />添加后在后台收集全部历史帖子</label> | |
| {err && <div className="error-note"><span>{err.msg}</span>{err.needAccount && <button type="button" className="btn small ghost" onClick={onAccount}>连接账号</button>}</div>} | |
| <div className="row gap end"><button type="button" className="btn ghost" onClick={onClose}>取消</button><button className="btn primary" disabled={busy || !v.trim()}>{busy ? '正在读取频道…' : '添加'}</button></div> | |
| </form> | |
| </Modal> | |
| ) | |
| } | |
| /* ================= Telegram 账号 ================= */ | |
| function AccountModal({ open, onClose, status, reload }: { open: boolean; onClose: () => void; status: any; reload: () => void }) { | |
| const toast = useToast() | |
| const confirm = useConfirm() | |
| const [step, setStep] = useState<'idle' | 'start' | 'code' | 'password'>('idle') | |
| const [f, setF] = useState({ apiId: '', apiHash: '', phone: '', code: '', password: '' }) | |
| const [hint, setHint] = useState('') | |
| const [busy, setBusy] = useState(false) | |
| useEffect(() => { if (open) { setStep(status?.step === 'code' ? 'code' : status?.step === 'password' ? 'password' : 'idle'); setHint(status?.hint || '') } }, [open]) | |
| const set = (k: string, v: string) => setF(s => ({ ...s, [k]: v })) | |
| const call = async (url: string, body: any) => { | |
| setBusy(true) | |
| try { | |
| const r = await post<any>(url, body) | |
| if (r.done) { toast('Telegram 账号已连接', 'ok'); setStep('idle'); reload() } | |
| else if (r.step === 'code') { setStep('code'); toast(r.viaApp ? '验证码已发到你的 Telegram App' : '验证码已发送') } | |
| else if (r.step === 'password') { setStep('password'); setHint(r.hint || '') } | |
| } catch (e: any) { toast(e.message, 'err') } finally { setBusy(false) } | |
| } | |
| const logout = async () => { | |
| if (!(await confirm({ title: '退出 Telegram 账号?', body: '退出后,关闭了网页预览的频道将无法继续抓取。', ok: '退出', danger: true }))) return | |
| setBusy(true) | |
| try { await post('/api/tgauth/logout'); toast('已退出'); reload() } catch (e: any) { toast(e.message, 'err') } finally { setBusy(false) } | |
| } | |
| return ( | |
| <Modal open={open} onClose={onClose} title="Telegram 账号" width={500}> | |
| <div className="panel-stack"> | |
| <div className={cx('acct-status', status?.connected ? 'ok' : 'off')}> | |
| <UserCircle2 size={28} /> | |
| <div>{status?.connected ? <><b>{status.name}</b><div className="muted">{status.username ? `@${status.username} · ` : ''}{status.phone}</div></> : <><b>未连接</b><div className="muted">大部分公开频道无需登录;关闭网页预览的频道和「发现新频道」需要登录。</div></>}</div> | |
| {status?.connected && <button className="btn small ghost push" onClick={logout} disabled={busy}>退出</button>} | |
| </div> | |
| {status?.error && <div className="banner warn"><span>{status.error}</span></div>} | |
| {step === 'idle' && <button className="btn ghost" onClick={() => setStep('start')}>{status?.connected ? '换一个账号登录' : '登录 Telegram 账号'}</button>} | |
| {step === 'start' && <form className="panel-stack" onSubmit={e => { e.preventDefault(); call('/api/tgauth/start', { apiId: f.apiId, apiHash: f.apiHash, phone: f.phone }) }}> | |
| <p className="muted small-note">到 <a href="https://my.telegram.org" target="_blank" rel="noreferrer">my.telegram.org</a> 的 API development tools 创建应用,复制 API ID 和 API Hash。</p> | |
| <div className="form-grid tight"> | |
| <Field label="API ID"><input className="input" value={f.apiId} onChange={e => set('apiId', e.target.value)} inputMode="numeric" /></Field> | |
| <Field label="手机号"><input className="input" value={f.phone} onChange={e => set('phone', e.target.value)} placeholder="+8613800000000" /></Field> | |
| <Field label="API Hash" className="span2"><input className="input" value={f.apiHash} onChange={e => set('apiHash', e.target.value)} /></Field> | |
| </div> | |
| <div className="row gap end"><button type="button" className="btn ghost" onClick={() => setStep('idle')}>取消</button><button className="btn primary" disabled={busy}>{busy ? '发送中…' : '发送验证码'}</button></div> | |
| </form>} | |
| {step === 'code' && <form className="panel-stack" onSubmit={e => { e.preventDefault(); call('/api/tgauth/code', { code: f.code }) }}> | |
| <Field label="验证码" hint="在 Telegram App 或短信里查看"><input className="input" value={f.code} onChange={e => set('code', e.target.value)} autoFocus inputMode="numeric" /></Field> | |
| <div className="row gap end"><button type="button" className="btn ghost" onClick={() => setStep('start')}>重新发送</button><button className="btn primary" disabled={busy}>{busy ? '验证中…' : '确认'}</button></div> | |
| </form>} | |
| {step === 'password' && <form className="panel-stack" onSubmit={e => { e.preventDefault(); call('/api/tgauth/password', { password: f.password }) }}> | |
| <Field label="两步验证密码" hint={hint ? `提示:${hint}` : undefined}><input className="input" type="password" value={f.password} onChange={e => set('password', e.target.value)} autoFocus /></Field> | |
| <div className="row gap end"><button className="btn primary" disabled={busy}>{busy ? '登录中…' : '登录'}</button></div> | |
| </form>} | |
| </div> | |
| </Modal> | |
| ) | |
| } | |