fix: TikTok 页 UI 去重,引导/表单/操作栏不再堆叠显示

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
eric 2026-08-14 10:26:54 -05:00
parent e0524e5b8b
commit 19bb3ba134

View File

@ -3,8 +3,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import Link from "next/link";
import {
CheckCircle2,
Circle,
Clock3,
ExternalLink,
KeyRound,
@ -23,8 +21,6 @@ import { useToast } from "@/components/Toast";
import { PageLoader } from "@/components/ui";
import { fetchJson, fmtTs, todayBeijingISO } from "@/lib/api";
type SetupStep = { id: string; title: string; url?: string; done: boolean };
type Channel = {
id: string;
name: string;
@ -137,13 +133,24 @@ export default function TikTokPage() {
});
const setup = status?.setup;
const setupDone = setup?.steps?.every((s: SetupStep) => s.done);
const hasChannels = channels.length > 0;
const authorizedCount = channels.filter((c) => c.authorized).length;
const allReady = hasChannels && authorizedCount === channels.length;
const setupDone = allReady;
const board = status?.board || {};
const boardChannels: BoardChannel[] = board.channels || [];
const upcoming: Upcoming[] = board.upcoming || [];
const beijingWindow = board.beijing_window || "";
const cookiesDir = status?.setup?.cookies_dir || "";
const authMode = status?.auth_mode || "cookie";
const openAddForm = () => {
setEditId("");
setFormName("TikTok 账号");
setFormPrivacy("PUBLIC_TO_EVERYONE");
setFormTitle("{anchor} #fyp");
setFormDesc("{anchor}\n{url}");
setShowForm(true);
setShowSessionForm(false);
};
const togglePipeline = async () => {
const on = status?.enabled;
@ -183,7 +190,7 @@ export default function TikTokPage() {
};
const addChannel = async () => {
await fetchJson("/api/tiktok/channels", {
const r = await fetchJson("/api/tiktok/channels", {
method: "POST",
body: JSON.stringify({
name: formName,
@ -194,6 +201,10 @@ export default function TikTokPage() {
});
toast.push("账号已添加,请粘贴 Cookie", "ok");
setShowForm(false);
const ch = r?.channel as Channel | undefined;
if (ch?.id) {
openSessionForm(ch.id, ch);
}
void load();
};
@ -232,6 +243,7 @@ export default function TikTokPage() {
setSessionId("");
setSessionDcId("useast2a");
setSessionUsername(ch?.tiktok_username || "");
setShowForm(false);
setShowSessionForm(true);
};
@ -355,62 +367,35 @@ export default function TikTokPage() {
</div>
</div>
{/* Setup wizard */}
{!setupDone && (
{/* 首次使用:仅显示引导或表单,不堆叠 */}
{!hasChannels && !showForm && !showSessionForm && (
<section className="mb-6 rounded-2xl border border-pink-500/25 bg-gradient-to-br from-pink-500/10 to-transparent p-5">
<h2 className="mb-1 text-base font-medium text-slate-100">🚀 Cookie 会话配置(无需开发者 API)</h2>
<h2 className="mb-1 text-base font-medium text-slate-100">开始使用 TikTok 上传</h2>
<p className="mb-4 text-sm text-slate-400">
浏览器登录 tiktok.com 后导出 <code className="text-pink-300">sessionid</code>,粘贴到账号即可上传。
模式:{authMode}
无需 TikTok 开发者应用。浏览器登录 tiktok.com 后复制{" "}
<code className="text-pink-300">sessionid</code>,粘贴即可上传。
</p>
<ol className="mb-5 list-inside list-decimal space-y-2 text-sm text-slate-300">
<li>点击下方「添加账号」</li>
<li>保存后在弹窗中粘贴 Cookie</li>
<li>全部账号配置完成后,再点「启动自动上传」</li>
</ol>
<button
type="button"
onClick={openAddForm}
className="flex items-center gap-2 rounded-xl bg-pink-500 px-4 py-2.5 text-sm font-medium text-white hover:bg-pink-400"
>
<Plus className="h-4 w-4" />
添加 TikTok 账号
</button>
{setup?.note && <p className="mt-4 text-xs text-amber-300/90">⚠️ {setup.note}</p>}
</section>
)}
<div className="mb-5 space-y-3">
{(setup?.steps || []).map((step: SetupStep, i: number) => (
<div key={step.id} className="flex items-start gap-3 rounded-xl border border-white/10 bg-black/20 p-3">
{step.done ? (
<CheckCircle2 className="mt-0.5 h-5 w-5 shrink-0 text-teal-400" />
) : (
<Circle className="mt-0.5 h-5 w-5 shrink-0 text-slate-500" />
)}
<div className="min-w-0 flex-1">
<div className="text-sm text-slate-200">
{i + 1}. {step.title}
</div>
{step.url && !step.done && (
<a
href={step.url}
target="_blank"
rel="noreferrer"
className="mt-1 inline-flex items-center gap-1 text-xs text-pink-300 hover:underline"
>
打开官方文档 <ExternalLink className="h-3 w-3" />
</a>
)}
</div>
</div>
))}
</div>
{channels.length === 0 && (
<button
type="button"
onClick={() => {
setEditId("");
setShowForm(true);
}}
className="mt-2 flex items-center gap-2 rounded-xl bg-pink-500 px-4 py-2.5 text-sm font-medium text-white hover:bg-pink-400"
>
<Plus className="h-4 w-4" />
添加第一个 TikTok 账号
</button>
)}
{setup?.note && (
<p className="mt-4 text-xs text-amber-300/90">⚠️ {setup.note}</p>
)}
{cookiesDir ? (
<p className="mt-2 text-[11px] text-slate-500">Cookie 存储:{cookiesDir}</p>
) : null}
{/* 有账号但未全部配置 Cookie */}
{hasChannels && !allReady && !showForm && !showSessionForm && (
<section className="mb-6 rounded-xl border border-amber-500/25 bg-amber-500/5 px-4 py-3 text-sm text-amber-100/90">
还有 {channels.length - authorizedCount} 个账号未粘贴 Cookie,配置完成后才能启动自动上传。
</section>
)}
@ -442,28 +427,24 @@ export default function TikTokPage() {
</div>
)}
{/* Control bar */}
{channels.length >= 0 && (
{/* 有账号时:顶部操作栏 */}
{hasChannels && !showForm && !showSessionForm && (
<div className="mb-6 flex flex-wrap items-center gap-2">
<button
type="button"
onClick={() => {
setEditId("");
setFormName("TikTok 账号");
setShowForm(true);
}}
onClick={openAddForm}
className="flex items-center gap-1 rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-sm text-slate-200 hover:bg-white/10"
>
<Plus className="h-4 w-4" />
新增账号
</button>
<Link
href="https://github.com/makiisthenes/TiktokAutoUploader"
href="https://www.tiktok.com"
target="_blank"
className="flex items-center gap-1 rounded-xl border border-white/10 px-3 py-2 text-xs text-slate-400 hover:text-slate-200"
>
<ExternalLink className="h-3 w-3" />
TiktokAutoUploader
打开 TikTok 登录
</Link>
</div>
)}
@ -706,8 +687,8 @@ export default function TikTokPage() {
</div>
)}
{/* Jobs table */}
{setupDone && (
{/* Jobs table — 有账号即显示 */}
{hasChannels && (
<section className="rounded-2xl border border-white/10 bg-black/25 p-4">
<div className="mb-3 flex items-center justify-between">
<h3 className="text-sm font-medium text-slate-100">任务流水(今日 {jobTotal})</h3>
@ -788,19 +769,26 @@ export default function TikTokPage() {
</section>
)}
{/* Quick help */}
<section className="mt-6 rounded-2xl border border-white/5 bg-black/15 p-4 text-xs text-slate-500">
<div className="mb-2 flex items-center gap-2 font-medium text-slate-400">
<Zap className="h-4 w-4 text-pink-400" />
使用说明
</div>
<ol className="list-inside list-decimal space-y-1">
<li>浏览器登录 tiktok.com,F12 → Cookies 复制 <code className="text-pink-300">sessionid</code></li>
<li>添加 TikTok 账号 → 点击「粘贴 Cookie」保存会话</li>
<li>确认 <code className="text-pink-300">tiktok_enabled</code> 开启后再点「启动自动上传」</li>
<li>系统从抖音直播取样、录屏、错峰上传到 TikTok(独立模块,默认关闭)</li>
</ol>
</section>
{/* Quick help — 未完成配置时显示 */}
{!allReady && (
<section className="mt-6 rounded-2xl border border-white/5 bg-black/15 p-4 text-xs text-slate-500">
<div className="mb-2 flex items-center gap-2 font-medium text-slate-400">
<Zap className="h-4 w-4 text-pink-400" />
如何获取 Cookie
</div>
<ol className="list-inside list-decimal space-y-1">
<li>
浏览器打开{" "}
<a href="https://www.tiktok.com" target="_blank" rel="noreferrer" className="text-pink-300 hover:underline">
tiktok.com
</a>{" "}
并登录
</li>
<li>F12 → Application → Cookies → 复制 sessionid</li>
<li>在账号卡片上点「粘贴 Cookie」保存</li>
</ol>
</section>
)}
</div>
</Shell>
);