fix: TikTok 页 UI 去重,引导/表单/操作栏不再堆叠显示
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
e0524e5b8b
commit
19bb3ba134
@ -3,8 +3,6 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import {
|
||||||
CheckCircle2,
|
|
||||||
Circle,
|
|
||||||
Clock3,
|
Clock3,
|
||||||
ExternalLink,
|
ExternalLink,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
@ -23,8 +21,6 @@ import { useToast } from "@/components/Toast";
|
|||||||
import { PageLoader } from "@/components/ui";
|
import { PageLoader } from "@/components/ui";
|
||||||
import { fetchJson, fmtTs, todayBeijingISO } from "@/lib/api";
|
import { fetchJson, fmtTs, todayBeijingISO } from "@/lib/api";
|
||||||
|
|
||||||
type SetupStep = { id: string; title: string; url?: string; done: boolean };
|
|
||||||
|
|
||||||
type Channel = {
|
type Channel = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -137,13 +133,24 @@ export default function TikTokPage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const setup = status?.setup;
|
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 board = status?.board || {};
|
||||||
const boardChannels: BoardChannel[] = board.channels || [];
|
const boardChannels: BoardChannel[] = board.channels || [];
|
||||||
const upcoming: Upcoming[] = board.upcoming || [];
|
const upcoming: Upcoming[] = board.upcoming || [];
|
||||||
const beijingWindow = board.beijing_window || "";
|
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 togglePipeline = async () => {
|
||||||
const on = status?.enabled;
|
const on = status?.enabled;
|
||||||
@ -183,7 +190,7 @@ export default function TikTokPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const addChannel = async () => {
|
const addChannel = async () => {
|
||||||
await fetchJson("/api/tiktok/channels", {
|
const r = await fetchJson("/api/tiktok/channels", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: formName,
|
name: formName,
|
||||||
@ -194,6 +201,10 @@ export default function TikTokPage() {
|
|||||||
});
|
});
|
||||||
toast.push("账号已添加,请粘贴 Cookie", "ok");
|
toast.push("账号已添加,请粘贴 Cookie", "ok");
|
||||||
setShowForm(false);
|
setShowForm(false);
|
||||||
|
const ch = r?.channel as Channel | undefined;
|
||||||
|
if (ch?.id) {
|
||||||
|
openSessionForm(ch.id, ch);
|
||||||
|
}
|
||||||
void load();
|
void load();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -232,6 +243,7 @@ export default function TikTokPage() {
|
|||||||
setSessionId("");
|
setSessionId("");
|
||||||
setSessionDcId("useast2a");
|
setSessionDcId("useast2a");
|
||||||
setSessionUsername(ch?.tiktok_username || "");
|
setSessionUsername(ch?.tiktok_username || "");
|
||||||
|
setShowForm(false);
|
||||||
setShowSessionForm(true);
|
setShowSessionForm(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -355,62 +367,35 @@ export default function TikTokPage() {
|
|||||||
</div>
|
</div>
|
||||||
</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">
|
<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">
|
<p className="mb-4 text-sm text-slate-400">
|
||||||
浏览器登录 tiktok.com 后导出 <code className="text-pink-300">sessionid</code>,粘贴到账号即可上传。
|
无需 TikTok 开发者应用。浏览器登录 tiktok.com 后复制{" "}
|
||||||
模式:{authMode}
|
<code className="text-pink-300">sessionid</code>,粘贴即可上传。
|
||||||
</p>
|
</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">
|
{/* 有账号但未全部配置 Cookie */}
|
||||||
{(setup?.steps || []).map((step: SetupStep, i: number) => (
|
{hasChannels && !allReady && !showForm && !showSessionForm && (
|
||||||
<div key={step.id} className="flex items-start gap-3 rounded-xl border border-white/10 bg-black/20 p-3">
|
<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">
|
||||||
{step.done ? (
|
还有 {channels.length - authorizedCount} 个账号未粘贴 Cookie,配置完成后才能启动自动上传。
|
||||||
<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}
|
|
||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -442,28 +427,24 @@ export default function TikTokPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Control bar */}
|
{/* 有账号时:顶部操作栏 */}
|
||||||
{channels.length >= 0 && (
|
{hasChannels && !showForm && !showSessionForm && (
|
||||||
<div className="mb-6 flex flex-wrap items-center gap-2">
|
<div className="mb-6 flex flex-wrap items-center gap-2">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={openAddForm}
|
||||||
setEditId("");
|
|
||||||
setFormName("TikTok 账号");
|
|
||||||
setShowForm(true);
|
|
||||||
}}
|
|
||||||
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"
|
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" />
|
<Plus className="h-4 w-4" />
|
||||||
新增账号
|
新增账号
|
||||||
</button>
|
</button>
|
||||||
<Link
|
<Link
|
||||||
href="https://github.com/makiisthenes/TiktokAutoUploader"
|
href="https://www.tiktok.com"
|
||||||
target="_blank"
|
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"
|
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" />
|
<ExternalLink className="h-3 w-3" />
|
||||||
TiktokAutoUploader
|
打开 TikTok 登录
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -706,8 +687,8 @@ export default function TikTokPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Jobs table */}
|
{/* Jobs table — 有账号即显示 */}
|
||||||
{setupDone && (
|
{hasChannels && (
|
||||||
<section className="rounded-2xl border border-white/10 bg-black/25 p-4">
|
<section className="rounded-2xl border border-white/10 bg-black/25 p-4">
|
||||||
<div className="mb-3 flex items-center justify-between">
|
<div className="mb-3 flex items-center justify-between">
|
||||||
<h3 className="text-sm font-medium text-slate-100">任务流水(今日 {jobTotal})</h3>
|
<h3 className="text-sm font-medium text-slate-100">任务流水(今日 {jobTotal})</h3>
|
||||||
@ -788,19 +769,26 @@ export default function TikTokPage() {
|
|||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Quick help */}
|
{/* Quick help — 未完成配置时显示 */}
|
||||||
<section className="mt-6 rounded-2xl border border-white/5 bg-black/15 p-4 text-xs text-slate-500">
|
{!allReady && (
|
||||||
<div className="mb-2 flex items-center gap-2 font-medium text-slate-400">
|
<section className="mt-6 rounded-2xl border border-white/5 bg-black/15 p-4 text-xs text-slate-500">
|
||||||
<Zap className="h-4 w-4 text-pink-400" />
|
<div className="mb-2 flex items-center gap-2 font-medium text-slate-400">
|
||||||
使用说明
|
<Zap className="h-4 w-4 text-pink-400" />
|
||||||
</div>
|
如何获取 Cookie
|
||||||
<ol className="list-inside list-decimal space-y-1">
|
</div>
|
||||||
<li>浏览器登录 tiktok.com,F12 → Cookies 复制 <code className="text-pink-300">sessionid</code></li>
|
<ol className="list-inside list-decimal space-y-1">
|
||||||
<li>添加 TikTok 账号 → 点击「粘贴 Cookie」保存会话</li>
|
<li>
|
||||||
<li>确认 <code className="text-pink-300">tiktok_enabled</code> 开启后再点「启动自动上传」</li>
|
浏览器打开{" "}
|
||||||
<li>系统从抖音直播取样、录屏、错峰上传到 TikTok(独立模块,默认关闭)</li>
|
<a href="https://www.tiktok.com" target="_blank" rel="noreferrer" className="text-pink-300 hover:underline">
|
||||||
</ol>
|
tiktok.com
|
||||||
</section>
|
</a>{" "}
|
||||||
|
并登录
|
||||||
|
</li>
|
||||||
|
<li>F12 → Application → Cookies → 复制 sessionid</li>
|
||||||
|
<li>在账号卡片上点「粘贴 Cookie」保存</li>
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Shell>
|
</Shell>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user