fix: TikTok 上传确认弹窗与任务流水显示素材时长
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
21f74cb85c
commit
9833891cf4
@ -113,6 +113,7 @@ def schedule_board(limit: int = 24) -> dict[str, Any]:
|
||||
"channel_name": ch.get("name") or "",
|
||||
"status": j.get("status"),
|
||||
"clip_ready": bool(clip) and Path(clip).is_file(),
|
||||
"clip_seconds": float(j.get("clip_seconds") or 0),
|
||||
"can_upload_now": (
|
||||
str(j.get("status") or "") in {"scheduled", "recorded", "uploading", "failed"}
|
||||
and bool(str(j.get("clip_path") or "").strip())
|
||||
|
||||
@ -6,12 +6,10 @@ import {
|
||||
Clock3,
|
||||
ExternalLink,
|
||||
KeyRound,
|
||||
Loader2,
|
||||
Music2,
|
||||
Plus,
|
||||
RefreshCw,
|
||||
Trash2,
|
||||
Upload,
|
||||
Zap,
|
||||
} from "lucide-react";
|
||||
|
||||
@ -19,7 +17,13 @@ import { Shell } from "@/components/Shell";
|
||||
import { useConfirm } from "@/components/ConfirmDialog";
|
||||
import { useToast } from "@/components/Toast";
|
||||
import { PageLoader } from "@/components/ui";
|
||||
import { fetchJson, fmtTs, todayBeijingISO } from "@/lib/api";
|
||||
import {
|
||||
TikTokUpcomingUploadRow,
|
||||
TikTokUploadConfirmModal,
|
||||
useTikTokUpload,
|
||||
type TikTokUploadTarget,
|
||||
} from "@/components/TikTokUploadUx";
|
||||
import { fetchJson, fmtDuration, fmtTs, todayBeijingISO } from "@/lib/api";
|
||||
|
||||
type Channel = {
|
||||
id: string;
|
||||
@ -59,22 +63,30 @@ type Upcoming = {
|
||||
id: string;
|
||||
anchor_name?: string;
|
||||
channel_name?: string;
|
||||
channel_pk?: string;
|
||||
upload_at?: number;
|
||||
status?: string;
|
||||
can_upload_now?: boolean;
|
||||
clip_ready?: boolean;
|
||||
clip_seconds?: number;
|
||||
room_id?: string;
|
||||
};
|
||||
|
||||
type Job = {
|
||||
id: string;
|
||||
anchor_name?: string;
|
||||
channel_name?: string;
|
||||
channel_pk?: string;
|
||||
status?: string;
|
||||
push_date?: string;
|
||||
error?: string;
|
||||
clip_ready?: boolean;
|
||||
clip_seconds?: number;
|
||||
tiktok_publish_id?: string;
|
||||
upload_at?: number;
|
||||
created_at?: number;
|
||||
finished_at?: number;
|
||||
room_id?: string;
|
||||
};
|
||||
|
||||
export default function TikTokPage() {
|
||||
@ -103,8 +115,6 @@ export default function TikTokPage() {
|
||||
const [savingSession, setSavingSession] = useState(false);
|
||||
const [showSessionForm, setShowSessionForm] = useState(false);
|
||||
|
||||
const [uploadingId, setUploadingId] = useState("");
|
||||
|
||||
const load = useCallback(async () => {
|
||||
const iso = todayBeijingISO();
|
||||
const [st, j] = await Promise.all([
|
||||
@ -118,6 +128,8 @@ export default function TikTokPage() {
|
||||
setLoading(false);
|
||||
}, []);
|
||||
|
||||
const uploadUx = useTikTokUpload(load);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
const t = setInterval(() => void load(), 12000);
|
||||
@ -312,17 +324,30 @@ export default function TikTokPage() {
|
||||
void load();
|
||||
};
|
||||
|
||||
const uploadNow = async (jobId: string) => {
|
||||
setUploadingId(jobId);
|
||||
try {
|
||||
await fetchJson(`/api/tiktok/jobs/${jobId}/upload-now`, { method: "POST" });
|
||||
toast.push("上传成功", "ok");
|
||||
void load();
|
||||
} catch (e: any) {
|
||||
toast.push(e?.message || "上传失败", "err");
|
||||
} finally {
|
||||
setUploadingId("");
|
||||
}
|
||||
const toUploadTarget = (u: {
|
||||
id: string;
|
||||
anchor_name?: string;
|
||||
room_id?: string;
|
||||
channel_name?: string;
|
||||
channel_pk?: string;
|
||||
upload_at?: number;
|
||||
clip_ready?: boolean;
|
||||
clip_seconds?: number;
|
||||
status?: string;
|
||||
}): TikTokUploadTarget => {
|
||||
const ch = channels.find((c) => c.id === (u.channel_pk || ""));
|
||||
return {
|
||||
id: u.id,
|
||||
anchor_name: u.anchor_name,
|
||||
room_id: u.room_id,
|
||||
channel_name: u.channel_name || ch?.name || "",
|
||||
channel_pk: u.channel_pk,
|
||||
upload_at: u.upload_at,
|
||||
clip_ready: u.clip_ready !== false,
|
||||
clip_seconds: Number(u.clip_seconds || 0) || undefined,
|
||||
status: u.status,
|
||||
title_template: ch?.title_template || "",
|
||||
};
|
||||
};
|
||||
|
||||
const retryJob = async (jobId: string) => {
|
||||
@ -417,6 +442,12 @@ export default function TikTokPage() {
|
||||
|
||||
return (
|
||||
<Shell>
|
||||
<TikTokUploadConfirmModal
|
||||
target={uploadUx.confirmTarget}
|
||||
onCancel={uploadUx.cancelConfirm}
|
||||
onConfirm={uploadUx.confirmUpload}
|
||||
busy={uploadUx.busy}
|
||||
/>
|
||||
<div className="mx-auto max-w-7xl px-4 py-6 sm:px-6">
|
||||
{/* Header */}
|
||||
<div className="mb-6 flex flex-wrap items-center justify-between gap-3">
|
||||
@ -824,34 +855,13 @@ export default function TikTokPage() {
|
||||
</div>
|
||||
) : (
|
||||
upcoming.map((u) => (
|
||||
<div
|
||||
<TikTokUpcomingUploadRow
|
||||
key={u.id}
|
||||
className="flex items-center justify-between gap-2 rounded-xl border border-white/10 bg-white/[0.03] p-3"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-sm text-slate-100">{u.anchor_name || "—"}</div>
|
||||
<div className="truncate text-[10px] text-slate-500">
|
||||
{u.channel_name} · {u.upload_at ? fmtTs(u.upload_at) : "—"}
|
||||
</div>
|
||||
</div>
|
||||
{u.can_upload_now && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={uploadingId === u.id}
|
||||
onClick={() => void uploadNow(u.id)}
|
||||
className="shrink-0 rounded-lg bg-teal-500/20 px-2 py-1 text-[11px] text-teal-200 hover:bg-teal-500/30 disabled:opacity-50"
|
||||
>
|
||||
{uploadingId === u.id ? (
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
) : (
|
||||
<>
|
||||
<Upload className="mr-1 inline h-3 w-3" />
|
||||
立即上传
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
item={toUploadTarget(u)}
|
||||
track={uploadUx.tracks[u.id]}
|
||||
onRequestUpload={uploadUx.openConfirm}
|
||||
onRetry={uploadUx.retryUpload}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
@ -871,6 +881,7 @@ export default function TikTokPage() {
|
||||
<tr className="border-b border-white/10 text-xs text-slate-500">
|
||||
<th className="py-2 pr-3">主播</th>
|
||||
<th className="py-2 pr-3">账号</th>
|
||||
<th className="py-2 pr-3">时长</th>
|
||||
<th className="py-2 pr-3">状态</th>
|
||||
<th className="py-2 pr-3">时间</th>
|
||||
<th className="py-2">操作</th>
|
||||
@ -879,7 +890,7 @@ export default function TikTokPage() {
|
||||
<tbody>
|
||||
{jobs.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={5} className="py-8 text-center text-slate-500">
|
||||
<td colSpan={6} className="py-8 text-center text-slate-500">
|
||||
暂无任务
|
||||
</td>
|
||||
</tr>
|
||||
@ -888,6 +899,17 @@ export default function TikTokPage() {
|
||||
<tr key={j.id} className="border-b border-white/5">
|
||||
<td className="py-2 pr-3 text-slate-200">{j.anchor_name || "—"}</td>
|
||||
<td className="py-2 pr-3 text-slate-400">{j.channel_name || "—"}</td>
|
||||
<td className="py-2 pr-3 tabular-nums text-xs text-slate-300">
|
||||
{Number(j.clip_seconds || 0) > 0 ? (
|
||||
fmtDuration(Number(j.clip_seconds))
|
||||
) : j.clip_ready ? (
|
||||
<span className="text-slate-500">成片就绪</span>
|
||||
) : j.status === "recording" || j.status === "pending" ? (
|
||||
<span className="text-amber-300/80">录制中</span>
|
||||
) : (
|
||||
"—"
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2 pr-3">
|
||||
<span
|
||||
className={
|
||||
@ -895,7 +917,9 @@ export default function TikTokPage() {
|
||||
? "text-teal-300"
|
||||
: j.status === "failed"
|
||||
? "text-rose-300"
|
||||
: "text-slate-400"
|
||||
: j.status === "uploading"
|
||||
? "text-pink-300"
|
||||
: "text-slate-400"
|
||||
}
|
||||
>
|
||||
{statusLabel[j.status as keyof typeof statusLabel] || j.status}
|
||||
@ -914,11 +938,15 @@ export default function TikTokPage() {
|
||||
{j.clip_ready && j.status !== "uploaded" && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={uploadingId === j.id}
|
||||
onClick={() => void uploadNow(j.id)}
|
||||
className="rounded bg-teal-500/15 px-2 py-0.5 text-[10px] text-teal-200"
|
||||
disabled={uploadUx.busy || uploadUx.tracks[j.id]?.phase === "uploading"}
|
||||
onClick={() => uploadUx.openConfirm(toUploadTarget(j))}
|
||||
className="rounded bg-pink-500/15 px-2 py-0.5 text-[10px] text-pink-200 hover:bg-pink-500/25 disabled:opacity-50"
|
||||
>
|
||||
{j.status === "uploading" ? "重试上传" : "上传"}
|
||||
{uploadUx.tracks[j.id]?.phase === "uploading"
|
||||
? "上传中…"
|
||||
: j.status === "uploading"
|
||||
? "重试上传"
|
||||
: "立即上传"}
|
||||
</button>
|
||||
)}
|
||||
{j.status === "failed" && (
|
||||
|
||||
360
frontend/src/components/TikTokUploadUx.tsx
Normal file
360
frontend/src/components/TikTokUploadUx.tsx
Normal file
@ -0,0 +1,360 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
Loader2,
|
||||
Upload,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
|
||||
import { Modal } from "@/components/Modal";
|
||||
import { useToast } from "@/components/Toast";
|
||||
import { fetchJson, fmtDuration, fmtTs } from "@/lib/api";
|
||||
|
||||
export type TikTokUploadTarget = {
|
||||
id: string;
|
||||
anchor_name?: string;
|
||||
room_id?: string;
|
||||
channel_name?: string;
|
||||
channel_pk?: string;
|
||||
upload_at?: number;
|
||||
clip_ready?: boolean;
|
||||
clip_seconds?: number;
|
||||
status?: string;
|
||||
title_template?: string;
|
||||
};
|
||||
|
||||
type UploadPhase = "idle" | "uploading" | "success" | "failed";
|
||||
|
||||
type UploadTrack = {
|
||||
phase: UploadPhase;
|
||||
startedAt: number;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise((r) => setTimeout(r, ms));
|
||||
}
|
||||
|
||||
function labelOf(t: TikTokUploadTarget) {
|
||||
return t.anchor_name || t.room_id || "素材";
|
||||
}
|
||||
|
||||
export function useTikTokUpload(onRefresh: () => Promise<void>) {
|
||||
const toast = useToast();
|
||||
const [confirmTarget, setConfirmTarget] = useState<TikTokUploadTarget | null>(null);
|
||||
const [tracks, setTracks] = useState<Record<string, UploadTrack>>({});
|
||||
const pollRef = useRef<AbortController | null>(null);
|
||||
|
||||
const patchTrack = useCallback((id: string, patch: Partial<UploadTrack>) => {
|
||||
setTracks((prev) => {
|
||||
const cur = prev[id] || { phase: "idle" as const, startedAt: Date.now() };
|
||||
return { ...prev, [id]: { ...cur, ...patch } };
|
||||
});
|
||||
}, []);
|
||||
|
||||
const finishSuccess = useCallback(
|
||||
async (jobId: string, label: string) => {
|
||||
patchTrack(jobId, { phase: "success" });
|
||||
toast.push(`「${label}」已上传到 TikTok`, "ok", { durationMs: 6000 });
|
||||
await onRefresh();
|
||||
window.setTimeout(() => {
|
||||
setTracks((prev) => {
|
||||
const next = { ...prev };
|
||||
delete next[jobId];
|
||||
return next;
|
||||
});
|
||||
}, 4000);
|
||||
},
|
||||
[onRefresh, patchTrack, toast],
|
||||
);
|
||||
|
||||
const pollJob = useCallback(
|
||||
async (jobId: string, label: string, signal: AbortSignal) => {
|
||||
for (let i = 0; i < 90; i++) {
|
||||
if (signal.aborted) return;
|
||||
try {
|
||||
const data = await fetchJson(`/api/tiktok/jobs/${jobId}`);
|
||||
const job = data.job || data;
|
||||
const st = String(job.status || "");
|
||||
if (st === "uploaded" || st === "done") {
|
||||
await finishSuccess(jobId, label);
|
||||
return;
|
||||
}
|
||||
if (st === "failed") {
|
||||
const err = String(job.error || "上传失败");
|
||||
patchTrack(jobId, { phase: "failed", error: err });
|
||||
toast.push(`「${label}」上传失败:${err}`, "err", { durationMs: 7000 });
|
||||
await onRefresh();
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
if (signal.aborted) return;
|
||||
if (i >= 2) {
|
||||
const err = (e as Error).message;
|
||||
patchTrack(jobId, { phase: "failed", error: err });
|
||||
toast.push(err, "err");
|
||||
return;
|
||||
}
|
||||
}
|
||||
await sleep(i < 15 ? 1500 : 2500);
|
||||
}
|
||||
patchTrack(jobId, { phase: "failed", error: "上传耗时较长,请稍后刷新查看" });
|
||||
toast.push(`「${label}」仍在处理,请稍后刷新`, "warn", { durationMs: 5000 });
|
||||
await onRefresh();
|
||||
},
|
||||
[finishSuccess, onRefresh, patchTrack, toast],
|
||||
);
|
||||
|
||||
const startUpload = useCallback(
|
||||
async (target: TikTokUploadTarget) => {
|
||||
const id = target.id;
|
||||
const label = labelOf(target);
|
||||
setConfirmTarget(null);
|
||||
patchTrack(id, { phase: "uploading", startedAt: Date.now(), error: "" });
|
||||
|
||||
pollRef.current?.abort();
|
||||
const ac = new AbortController();
|
||||
pollRef.current = ac;
|
||||
|
||||
try {
|
||||
const data = await fetchJson(`/api/tiktok/jobs/${id}/upload-now`, { method: "POST" });
|
||||
const job = data.job || data;
|
||||
const st = String(job.status || "");
|
||||
if (st === "uploaded" || st === "done") {
|
||||
await finishSuccess(id, label);
|
||||
return;
|
||||
}
|
||||
if (st === "failed") {
|
||||
const err = String(job.error || "上传失败");
|
||||
patchTrack(id, { phase: "failed", error: err });
|
||||
toast.push(`「${label}」上传失败:${err}`, "err");
|
||||
await onRefresh();
|
||||
return;
|
||||
}
|
||||
toast.push(`「${label}」上传中…`, "ok", { durationMs: 2000 });
|
||||
void pollJob(id, label, ac.signal);
|
||||
} catch (e) {
|
||||
const err = (e as Error).message;
|
||||
patchTrack(id, { phase: "failed", error: err });
|
||||
toast.push(err, "err");
|
||||
await onRefresh();
|
||||
}
|
||||
},
|
||||
[finishSuccess, onRefresh, patchTrack, pollJob, toast],
|
||||
);
|
||||
|
||||
useEffect(() => () => pollRef.current?.abort(), []);
|
||||
|
||||
return {
|
||||
confirmTarget,
|
||||
openConfirm: setConfirmTarget,
|
||||
cancelConfirm: () => setConfirmTarget(null),
|
||||
confirmUpload: () => confirmTarget && void startUpload(confirmTarget),
|
||||
tracks,
|
||||
retryUpload: (target: TikTokUploadTarget) => void startUpload(target),
|
||||
busy: Object.values(tracks).some((t) => t.phase === "uploading"),
|
||||
};
|
||||
}
|
||||
|
||||
export function TikTokUploadConfirmModal({
|
||||
target,
|
||||
onCancel,
|
||||
onConfirm,
|
||||
busy,
|
||||
}: {
|
||||
target: TikTokUploadTarget | null;
|
||||
onCancel: () => void;
|
||||
onConfirm: () => void;
|
||||
busy?: boolean;
|
||||
}) {
|
||||
if (!target) return null;
|
||||
const label = labelOf(target);
|
||||
const scheduled = target.upload_at ? fmtTs(Number(target.upload_at)) : "未排程";
|
||||
const duration =
|
||||
Number(target.clip_seconds || 0) > 0 ? fmtDuration(Number(target.clip_seconds)) : "未知";
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={Boolean(target)}
|
||||
onClose={onCancel}
|
||||
panelClassName="w-full max-w-md rounded-2xl border border-white/10 bg-[#0b1626] p-0 shadow-2xl"
|
||||
>
|
||||
<div className="border-b border-white/10 px-5 py-4">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<p className="text-xs uppercase tracking-wider text-pink-300/80">手动上传</p>
|
||||
<h3 className="mt-1 font-display text-lg font-semibold text-white">确认立即上传到 TikTok?</h3>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onCancel}
|
||||
className="rounded-lg p-1 text-slate-400 hover:bg-white/5 hover:text-white"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-3 px-5 py-4 text-sm">
|
||||
<div className="rounded-xl border border-white/10 bg-black/30 p-3">
|
||||
<div className="font-medium text-slate-100">{label}</div>
|
||||
<div className="mt-2 space-y-1 text-xs text-slate-400">
|
||||
<div>目标账号 · {target.channel_name || "—"}</div>
|
||||
<div>素材时长 · {duration}</div>
|
||||
<div>原错峰排程 · {scheduled}</div>
|
||||
<div>{target.clip_ready === false ? "成片状态 · 等待录制完成" : "成片状态 · 已就绪"}</div>
|
||||
{target.title_template ? <div>发布文案 · {target.title_template}</div> : null}
|
||||
</div>
|
||||
{target.clip_ready !== false && target.id ? (
|
||||
<video
|
||||
src={`/api/tiktok/jobs/${target.id}/clip`}
|
||||
controls
|
||||
playsInline
|
||||
preload="metadata"
|
||||
className="mt-3 aspect-[9/16] max-h-52 w-full rounded-lg bg-black object-contain"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
<p className="text-xs leading-relaxed text-amber-200/90">
|
||||
将跳过错峰等待,立即发到 TikTok。发得太快会被限流,请确认素材和文案无误后再点。
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2 border-t border-white/10 px-5 py-4">
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={onCancel}
|
||||
className="flex-1 rounded-xl border border-white/10 bg-white/5 px-4 py-2.5 text-sm text-slate-300 hover:bg-white/10"
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy || target.clip_ready === false}
|
||||
onClick={onConfirm}
|
||||
className="inline-flex flex-1 items-center justify-center gap-2 rounded-xl bg-pink-500 px-4 py-2.5 text-sm font-medium text-white hover:bg-pink-400 disabled:opacity-50"
|
||||
>
|
||||
{busy ? <Loader2 className="h-4 w-4 animate-spin" /> : <Upload className="h-4 w-4" />}
|
||||
确认上传
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function elapsedSec(startedAt: number) {
|
||||
return Math.max(0, Math.floor((Date.now() - startedAt) / 1000));
|
||||
}
|
||||
|
||||
export function TikTokUpcomingUploadRow({
|
||||
item,
|
||||
track,
|
||||
onRequestUpload,
|
||||
onRetry,
|
||||
}: {
|
||||
item: TikTokUploadTarget;
|
||||
track?: UploadTrack;
|
||||
onRequestUpload: (item: TikTokUploadTarget) => void;
|
||||
onRetry: (item: TikTokUploadTarget) => void;
|
||||
}) {
|
||||
const phase = track?.phase || "idle";
|
||||
const [, setTick] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (phase !== "uploading") return;
|
||||
const t = window.setInterval(() => setTick((n) => n + 1), 1000);
|
||||
return () => window.clearInterval(t);
|
||||
}, [phase]);
|
||||
|
||||
const label = labelOf(item);
|
||||
const clipReady = item.clip_ready !== false;
|
||||
const duration =
|
||||
Number(item.clip_seconds || 0) > 0 ? fmtDuration(Number(item.clip_seconds)) : null;
|
||||
const border =
|
||||
phase === "uploading"
|
||||
? "border-pink-500/40 bg-pink-500/[0.06]"
|
||||
: phase === "success"
|
||||
? "border-teal-500/40 bg-teal-500/[0.06]"
|
||||
: phase === "failed"
|
||||
? "border-rose-500/35 bg-rose-500/[0.05]"
|
||||
: "border-white/10 bg-white/[0.03]";
|
||||
|
||||
return (
|
||||
<div className={`rounded-xl border px-3 py-2.5 transition-colors ${border}`}>
|
||||
<div className="flex items-center gap-3">
|
||||
<div
|
||||
className={`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg ${
|
||||
phase === "success"
|
||||
? "bg-teal-500/20 text-teal-300"
|
||||
: phase === "failed"
|
||||
? "bg-rose-500/15 text-rose-300"
|
||||
: phase === "uploading"
|
||||
? "bg-pink-500/20 text-pink-300"
|
||||
: "bg-amber-500/15 text-amber-300"
|
||||
}`}
|
||||
>
|
||||
{phase === "uploading" ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
) : phase === "success" ? (
|
||||
<CheckCircle2 className="h-4 w-4" />
|
||||
) : phase === "failed" ? (
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
) : (
|
||||
<Upload className="h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm font-medium text-slate-100">{label}</div>
|
||||
<div className="mt-0.5 truncate text-[11px] text-slate-500">
|
||||
{item.channel_name || "账号"}
|
||||
{duration ? ` · ${duration}` : ""}
|
||||
{item.upload_at ? ` · 排程 ${fmtTs(Number(item.upload_at))}` : " · 待排程"}
|
||||
{!clipReady ? " · 等待成片" : phase === "idle" ? " · 成片就绪" : ""}
|
||||
</div>
|
||||
</div>
|
||||
{phase === "idle" && clipReady ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onRequestUpload(item)}
|
||||
className="inline-flex shrink-0 items-center gap-1.5 rounded-lg bg-pink-500 px-3 py-1.5 text-xs font-medium text-white shadow-sm hover:bg-pink-400"
|
||||
>
|
||||
<Upload className="h-3.5 w-3.5" />
|
||||
立即上传
|
||||
</button>
|
||||
) : null}
|
||||
{phase === "failed" ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onRetry(item)}
|
||||
className="inline-flex shrink-0 items-center gap-1 rounded-lg border border-rose-500/30 bg-rose-500/10 px-3 py-1.5 text-xs text-rose-100"
|
||||
>
|
||||
重试
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
{phase === "uploading" ? (
|
||||
<div className="mt-3">
|
||||
<div className="mb-1 flex items-center justify-between text-[11px] text-pink-200/90">
|
||||
<span>
|
||||
{elapsedSec(track?.startedAt || Date.now()) >= 60
|
||||
? "TikTok 仍在接收,请稍候…"
|
||||
: "正在上传到 TikTok…"}
|
||||
</span>
|
||||
<span>{elapsedSec(track?.startedAt || Date.now())}s</span>
|
||||
</div>
|
||||
<div className="h-1.5 overflow-hidden rounded-full bg-white/10">
|
||||
<div className="h-full w-full animate-pulse rounded-full bg-gradient-to-r from-pink-600/40 via-pink-400/80 to-pink-600/40" />
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
{phase === "failed" && track?.error ? (
|
||||
<p className="mt-2 text-[11px] leading-relaxed text-rose-300">{track.error}</p>
|
||||
) : null}
|
||||
{phase === "success" ? (
|
||||
<p className="mt-2 text-[11px] text-teal-300">上传完成</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user