diff --git a/frontend/src/app/shorts/page.tsx b/frontend/src/app/shorts/page.tsx index 2a9811f..4094c74 100644 --- a/frontend/src/app/shorts/page.tsx +++ b/frontend/src/app/shorts/page.tsx @@ -17,6 +17,7 @@ import { } from "lucide-react"; import { DouyinLiveBadge } from "@/components/DouyinLiveBadge"; +import { EnableSwitch } from "@/components/EnableSwitch"; import { Shell } from "@/components/Shell"; import { useConfirm } from "@/components/ConfirmDialog"; import { useToast } from "@/components/Toast"; @@ -150,6 +151,7 @@ export default function ShortsPage() { const [form, setForm] = useState({ ...emptyForm }); const [editId, setEditId] = useState(""); const [busy, setBusy] = useState(false); + const [togglingId, setTogglingId] = useState(""); const [msg, setMsg] = useState(""); const [error, setError] = useState(""); const [jobFilter, setJobFilter] = useState(""); @@ -549,6 +551,16 @@ export default function ShortsPage() { async function toggleChannelEnabled(ch: Channel) { const turningOn = ch.enabled === false; + if (!turningOn) { + const ok = await confirm({ + title: `停用「${ch.name}」?`, + message: "关闭后将立即清除该频道全部任务与成片,并停止取样/录制/上传。可随时再开。", + confirmLabel: "停用并清任务", + destructive: true, + }); + if (!ok) return; + } + setTogglingId(ch.id); try { const r = await fetchJson(`/api/shorts/channels/${ch.id}`, { method: "PATCH", @@ -557,7 +569,7 @@ export default function ShortsPage() { const cleared = r.cleared as { jobs?: number; clips?: number } | undefined; if (!turningOn && cleared) { toast.push( - `已停用「${ch.name}」· 清除任务 ${cleared.jobs ?? 0} · 成片 ${cleared.clips ?? 0}`, + `已停用 · 清除任务 ${cleared.jobs ?? 0} · 成片 ${cleared.clips ?? 0}`, "ok", ); } else { @@ -566,6 +578,8 @@ export default function ShortsPage() { await load(); } catch (e) { toast.push((e as Error).message, "err"); + } finally { + setTogglingId(""); } } @@ -1203,8 +1217,14 @@ export default function ShortsPage() { return (
@@ -1218,18 +1238,13 @@ export default function ShortsPage() { />
{full ? ( - + void toggleChannelEnabled(full)} + /> ) : null}
diff --git a/frontend/src/app/tiktok/page.tsx b/frontend/src/app/tiktok/page.tsx index c8dbf53..32ca5d0 100644 --- a/frontend/src/app/tiktok/page.tsx +++ b/frontend/src/app/tiktok/page.tsx @@ -16,6 +16,7 @@ import { import { Shell } from "@/components/Shell"; import { useConfirm } from "@/components/ConfirmDialog"; import { useToast } from "@/components/Toast"; +import { EnableSwitch } from "@/components/EnableSwitch"; import { PageLoader } from "@/components/ui"; import { TikTokUpcomingUploadRow, @@ -130,6 +131,7 @@ export default function TikTokPage() { const rightPanelRef = useRef(null); const [loading, setLoading] = useState(true); + const [togglingId, setTogglingId] = useState(""); const [status, setStatus] = useState(null); const [channels, setChannels] = useState([]); const [socksProfiles, setSocksProfiles] = useState([]); @@ -421,6 +423,16 @@ export default function TikTokPage() { const toggleChannelEnabled = async (ch: Channel) => { const turningOn = ch.enabled === false; + if (!turningOn) { + const ok = await confirm({ + title: `停用「${ch.name}」?`, + message: "关闭后将立即清除该账号全部任务与成片,并停止取样/录制/上传。可随时再开。", + confirmLabel: "停用并清任务", + destructive: true, + }); + if (!ok) return; + } + setTogglingId(ch.id); try { const r = await fetchJson(`/api/tiktok/channels/${ch.id}`, { method: "PATCH", @@ -429,7 +441,7 @@ export default function TikTokPage() { const cleared = r.cleared as { jobs?: number; clips?: number } | undefined; if (!turningOn && cleared) { toast.push( - `已停用「${ch.name}」· 清除任务 ${cleared.jobs ?? 0} · 成片 ${cleared.clips ?? 0}`, + `已停用 · 清除任务 ${cleared.jobs ?? 0} · 成片 ${cleared.clips ?? 0}`, "ok", ); } else { @@ -438,6 +450,8 @@ export default function TikTokPage() { void load(); } catch (e: any) { toast.push(e?.message || "切换失败", "err"); + } finally { + setTogglingId(""); } }; @@ -1156,9 +1170,20 @@ export default function TikTokPage() {
- - {full?.authorized ? "Cookie 就绪" : "未配置"} - +
+ {full ? ( + void toggleChannelEnabled(full)} + /> + ) : null} + + {full?.authorized ? "Cookie 就绪" : "未配置"} + +
{(full?.follower_count || full?.video_count || full?.heart_count) ? (
@@ -1220,15 +1245,6 @@ export default function TikTokPage() { 刷新资料 ) : null} - {full && ( - - )} {full && ( + void toggleAccountEnabled(a)} + />
))} diff --git a/frontend/src/app/yt-long/page.tsx b/frontend/src/app/yt-long/page.tsx index cb806f9..0ecab71 100644 --- a/frontend/src/app/yt-long/page.tsx +++ b/frontend/src/app/yt-long/page.tsx @@ -17,6 +17,7 @@ import { import { Shell } from "@/components/Shell"; import { useConfirm } from "@/components/ConfirmDialog"; import { useToast } from "@/components/Toast"; +import { EnableSwitch } from "@/components/EnableSwitch"; import { OauthClientBadge, normalizeOauthProfileId } from "@/components/OauthClientBadge"; import { YtChannelProfileSnippet, type YtProfileSnippet } from "@/components/YtChannelProfileSnippet"; import { buildChannelMeta } from "@/lib/ytChannelMeta"; @@ -190,6 +191,7 @@ export default function YtLongPage() { const [form, setForm] = useState({ ...emptyForm }); const [editId, setEditId] = useState(""); const [busy, setBusy] = useState(false); + const [togglingId, setTogglingId] = useState(""); const [msg, setMsg] = useState(""); const [error, setError] = useState(""); const [jobFilter, setJobFilter] = useState(""); @@ -455,6 +457,16 @@ export default function YtLongPage() { async function toggleChannelEnabled(ch: Channel) { const turningOn = ch.enabled === false; + if (!turningOn) { + const ok = await confirm({ + title: `停用「${ch.name}」?`, + message: "关闭后将立即清除该频道全部长视频任务,并停止取样/录制/上传。可随时再开。", + confirmLabel: "停用并清任务", + destructive: true, + }); + if (!ok) return; + } + setTogglingId(ch.id); try { const r = await fetchJson(`/api/yt-long/channels/${ch.id}`, { method: "PATCH", @@ -462,13 +474,15 @@ export default function YtLongPage() { }); const cleared = r.cleared as { jobs?: number } | undefined; if (!turningOn && cleared) { - toast.push(`已停用「${ch.name}」· 清除任务 ${cleared.jobs ?? 0}`, "ok"); + toast.push(`已停用 · 清除任务 ${cleared.jobs ?? 0}`, "ok"); } else { toast.push(turningOn ? `已启用「${ch.name}」` : `已停用「${ch.name}」`, "ok"); } await load(); } catch (e) { toast.push((e as Error).message, "err"); + } finally { + setTogglingId(""); } } @@ -675,10 +689,12 @@ export default function YtLongPage() { return (
@@ -692,18 +708,13 @@ export default function YtLongPage() { />
{full ? ( - + void toggleChannelEnabled(full)} + /> ) : null}
diff --git a/frontend/src/components/EnableSwitch.tsx b/frontend/src/components/EnableSwitch.tsx new file mode 100644 index 0000000..f1da8bc --- /dev/null +++ b/frontend/src/components/EnableSwitch.tsx @@ -0,0 +1,90 @@ +"use client"; + +type Accent = "teal" | "pink" | "orange" | "amber"; + +const TRACK_ON: Record = { + teal: "bg-teal-400 shadow-[0_0_12px_rgba(45,212,191,0.35)]", + pink: "bg-pink-400 shadow-[0_0_12px_rgba(244,114,182,0.35)]", + orange: "bg-orange-400 shadow-[0_0_12px_rgba(251,146,60,0.35)]", + amber: "bg-amber-400 shadow-[0_0_12px_rgba(251,191,36,0.35)]", +}; + +type Props = { + checked: boolean; + onChange: (next: boolean) => void; + disabled?: boolean; + busy?: boolean; + label?: string; + accent?: Accent; + size?: "sm" | "md"; + className?: string; +}; + +/** Compact iOS-style enable switch for channel / account cards. */ +export function EnableSwitch({ + checked, + onChange, + disabled = false, + busy = false, + label, + accent = "teal", + size = "sm", + className = "", +}: Props) { + const locked = disabled || busy; + const trackW = size === "md" ? "h-6 w-11" : "h-5 w-9"; + const knob = size === "md" ? "h-5 w-5" : "h-4 w-4"; + const travel = size === "md" ? "translate-x-5" : "translate-x-4"; + + return ( +
e.stopPropagation()} + > + {label ? ( + + {label} + + ) : null} + +
+ ); +}