From da679e135e2edc5a00a638fbf2a7d0b376116f5a Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Sun, 1 Nov 2026 16:57:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=AF=BC=E5=87=BA=E4=B8=8E?= =?UTF-8?q?=E6=88=90=E6=9C=AC=E9=A1=B5=E7=AD=BE=EF=BC=9BGrid=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20CSS=20=E5=8F=98=E9=87=8F=E5=88=97=E5=AE=BD=E3=80=81?= =?UTF-8?q?=E8=A1=A5=E5=85=85=20MONO/TabStack=20=E5=8E=9F=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/ui/Page.tsx | 9 +- frontend/src/components/ui/Panel.tsx | 24 +- frontend/src/pages/project/Delivery.tsx | 407 +++++++++++++++++++++++- 3 files changed, 431 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/ui/Page.tsx b/frontend/src/components/ui/Page.tsx index e06771e..3a9a73a 100644 --- a/frontend/src/components/ui/Page.tsx +++ b/frontend/src/components/ui/Page.tsx @@ -10,8 +10,10 @@ import { cn } from '../../lib/cn' /** 次要说明文字(.muted):11px + 最淡的一级灰,表格单元格的第二行、附注都用它 */ export const MUTED = 'text-faint text-caption' +/** 等宽小字(.mono):路径 / id / 枚举码 / 数值列 */ +export const MONO = 'font-mono text-[10.5px] tracking-[-.2px]' /** 弱化 + 等宽(.muted.mono):id、路径、枚举码 */ -export const MUTED_MONO = 'text-faint text-[10.5px] font-mono tracking-[-.2px]' +export const MUTED_MONO = `${'text-faint'} ${MONO}` /** 站内文字链配色(.link): 没有组件形态,用这个类名常量保持一致 */ export const LINK_CLS = 'text-success text-caption no-underline hover:underline' @@ -65,6 +67,11 @@ export function Sub({ children, className }: { children?: ReactNode; className?: return
{children}
} +/** 页签正文(.tabstack):面板之间固定 16px 呼吸,页面不要再自己写 mb-* */ +export function TabStack({ children, className }: { children?: ReactNode; className?: string }) { + return
{children}
+} + /** * 两栏正文(.layout):主栏吃掉剩余宽度,侧栏最窄 300px。 * ≤1100 收成单列——断点写在组件里,页面不许再为自己写 @media。 diff --git a/frontend/src/components/ui/Panel.tsx b/frontend/src/components/ui/Panel.tsx index 93c4857..3b87d05 100644 --- a/frontend/src/components/ui/Panel.tsx +++ b/frontend/src/components/ui/Panel.tsx @@ -178,13 +178,27 @@ export function Actions({ children, className }: { children: ReactNode; classNam return
{children}
} -/** 通用栅格:.grid(4) .grid2 .grid3 .grid4 —— 1fr 轨道配 min-w-0,防止内容把列顶宽 */ -export function Grid({ children, cols = 4, gap = 12, className, min = 0 }: { - children: ReactNode; cols?: number | string; gap?: number; className?: string; min?: number +/** 窄屏折成一列的档位(字面量类名,Tailwind 只认源码里出现过的字符串) */ +const ONE_CLS: Record = { + mid: 'max-mid:grid-cols-1', mid2: 'max-mid2:grid-cols-1', nav: 'max-nav:grid-cols-1', + short: 'max-short:grid-cols-1', tiny: 'max-tiny:grid-cols-1', narrow: 'max-narrow:grid-cols-1' +} +export type GridCollapse = 'mid' | 'mid2' | 'nav' | 'short' | 'tiny' | 'narrow' + +/** + * 通用栅格(.grid / .grid2 / .grid3 / .grid4)。 + * + * 列数走 --cols/--min 两个 CSS 变量 + 字面量工具类,而不是内联 grid-template-columns: + * 内联样式会盖掉所有断点类,「窄屏折成一列」就再也写不上去 + * (旧站 .grid2 在 ≤560 就是单列,用内联 style 之后这一档静默失效)。 + */ +export function Grid({ children, cols = 4, gap = 12, min = 0, oneAt, className }: { + children?: ReactNode; cols?: number; gap?: number; min?: number; oneAt?: GridCollapse; className?: string }) { return ( -
*]:min-w-0', className)} - style={{ gridTemplateColumns: `repeat(${cols},minmax(${min}px,1fr))`, gap }}> +
*]:min-w-0 gap-[var(--gap)] grid-cols-[repeat(var(--cols),minmax(var(--min),1fr))]', + oneAt && ONE_CLS[oneAt], className)} + style={{ ['--cols' as string]: cols, ['--min' as string]: `${min}px`, ['--gap' as string]: `${gap}px` }}> {children}
) diff --git a/frontend/src/pages/project/Delivery.tsx b/frontend/src/pages/project/Delivery.tsx index adb7cb6..f889cb1 100644 --- a/frontend/src/pages/project/Delivery.tsx +++ b/frontend/src/pages/project/Delivery.tsx @@ -1,4 +1,405 @@ -/** 待迁移:导出与成本(占位,见 .local/vue-ref/src/views/tabs/Delivery.vue) */ -export default function Delivery() { - return
导出与成本 迁移中…
+/** + * 导出与成本(图2 节点 ⑫ compose → export) + * 出片走任务队列:合成失败可重试,成片留档 + 成本台账 + 生成记录(可复现提示词) + */ +import { useCallback, useEffect, useMemo, useState } from 'react' +import { Link } from 'react-router-dom' +import * as api from '../../api/client' +import { fmtAgo, fmtBytes, fmtMs, fmtMoney, fmtSeconds, fmtTime, statusLabel } from '../../lib/format' +import { fromExport } from '../../lib/media' +import { useAutoRefresh } from '../../hooks' +import { Select } from '../../components/forms' +import { MediaThumb } from '../../components/media/MediaThumb' +import { + Actions, Button, Chip, ChipBar, ErrorText, Field, Grid, LINK_CLS, LineHint, MONO, MUTED, MUTED_MONO, + Panel, PanelHead, Row, Spinner, Stat, StatGrid, Status, TabStack, Table, TableBox, Tag, cellCenter, cellRight +} from '../../components/ui' +import { refresh, useProjectStore } from '../../stores/project' +import { presetLabel, presets as FALLBACK_PRESETS, useSystemStore } from '../../stores/system' +import { notify } from '../../stores/notice' +import { openTogether } from '../../stores/preview' + +const PRESET_HINTS: Record = { + draft_720p: '1280×720 · CRF28 · veryfast(试片最快)', + vertical_720p: '720×1280 · CRF24 · medium(9:16 竖屏试片)', + web_1080p: '1920×1080 · CRF21 · medium(平台投放默认)', + vertical_1080p: '1080×1920 · CRF21 · medium(9:16 竖屏投放)', + hq_1080p: '1920×1080 · CRF18 · slow(高质量)', + uhd_4k: '3840×2160 · CRF18 · slow(超清,耗时最长)' +} + +const SUBTITLE_MODES = [ + { value: '', label: '跟随时间线设置(默认内嵌软字幕轨)' }, + { value: 'embed', label: '内嵌软字幕轨(可开关)' }, + { value: 'burn', label: '烧录进画面(硬字幕)' }, + { value: 'both', label: '烧录 + 内嵌' }, + { value: 'sidecar', label: '只出外挂 SRT' }, + { value: 'off', label: '不输出字幕' } +] + +const EMPTY_CELL = 'text-center py-[22px] leading-[1.7]' + +export default function Delivery() { + const projectId = useProjectStore((s) => s.id) + const meta = useSystemStore((s) => s.meta) + const health = useSystemStore((s) => s.health) + const [error, setError] = useState('') + const [busy, setBusy] = useState('') + const [exportList, setExportList] = useState([]) + const [costs, setCosts] = useState(null) + const [costItems, setCostItems] = useState([]) + const [generations, setGenerations] = useState([]) + const [report, setReport] = useState(null) + const [timelines, setTimelines] = useState([]) + const [showAllCost, setShowAllCost] = useState(false) + const [form, setForm] = useState({ presets: ['web_1080p'] as string[], name: '', subtitle_mode: '', timeline_id: '', priority: 2 }) + + const currency = costs?.currency || 'CNY' + const busyExports = exportList.filter((e) => ['queued', 'running', 'pending'].includes(e.status)) + const succeeded = exportList.filter((e) => e.status === 'succeeded') + const presetList: string[] = meta?.presets?.length ? meta.presets : FALLBACK_PRESETS + const shownCostItems = showAllCost ? costItems : costItems.slice(0, 12) + const blockingIssues = report && !report.ready + ? (report.issues || []).filter((y: any) => y.level === 'error') : [] + + const load = useCallback(async (silent = true) => { + if (!projectId) return + if (!silent) setBusy('读取交付数据') + try { + const [ex, cs, gen, rep, tl] = await Promise.all([ + api.get(`/api/projects/${projectId}/exports`), + api.get(`/api/projects/${projectId}/costs`), + api.get(`/api/projects/${projectId}/generations`), + api.get(`/api/projects/${projectId}/timeline/report`).catch(() => null), + api.get(`/api/projects/${projectId}/timelines`).catch(() => ({ timelines: [] })) + ]) + setExportList(ex.exports || []) + setCosts(cs.cost) + // /costs 把计费明细放在顶层 items,不在 cost 里;之前取 cs.cost.items 永远是空的 + setCostItems(cs.items || []) + setGenerations(gen.generations || []) + setReport(rep?.report || null) + setTimelines(tl.timelines || []) + setError('') + } catch (exc: any) { setError(exc?.message || String(exc)) } + finally { setBusy('') } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [projectId]) + + useEffect(() => { void load(false) }, [load]) + /* 有合成在跑就 4 秒看一次,空闲时回到 15 秒 */ + useAutoRefresh(() => void load(), busyExports.length ? 4000 : 15000, !!busy, !!busy) + + async function run(label: string, fn: () => Promise, message?: (res: any) => string) { + setBusy(label); setError('') + try { + const res = await fn() + const text = message ? message(res) : '' + if (text) notify(text) + await Promise.all([load(), refresh()]) + return res + } catch (exc: any) { setError(exc?.message || String(exc)); return null } + finally { setBusy('') } + } + + /** 出片:多选预设时依次入队(同一时间线复用,避免逐个点击等页面刷新) */ + async function compose() { + if (!projectId) return + const chosen = form.presets.length ? form.presets : ['web_1080p'] + setBusy(chosen.length > 1 ? `依次合成 ${chosen.length} 个预设` : '合成导出中') + setError('') + const done: string[] = [] + const queued: number[] = [] + const bad: string[] = [] + try { + for (const preset of chosen) { + try { + const r = await api.post(`/api/projects/${projectId}/compose`, { + preset, + name: chosen.length === 1 ? form.name.trim() : '', + subtitle_mode: form.subtitle_mode || null, + timeline_id: form.timeline_id ? Number(form.timeline_id) : null, + priority: form.priority + }) + const list = r?.exports || [] + const ok = list.filter((e: any) => e.status === 'succeeded') + if (ok.length) done.push(`${presetLabel[preset] || preset}:${ok[0].name}(${fmtMs(ok[0].duration_ms)} · ${fmtBytes(ok[0].size_bytes)})`) + else if (!list.length) queued.push(r?.task_id) + else bad.push(`${presetLabel[preset] || preset}:${list[0]?.error_message || statusLabel(list[0]?.status)}`) + } catch (exc: any) { bad.push(`${presetLabel[preset] || preset}:${exc?.message || exc}`) } + } + await Promise.all([load(), refresh()]) + const parts: string[] = [] + if (done.length) parts.push(done.join(';')) + if (queued.length) parts.push(`${queued.length} 个合成任务已入队(#${queued.join('、#')}),等待 worker 执行`) + if (bad.length) parts.push(`未完成 ${bad.length} 个:${bad.join(';')}`) + if (parts.length) notify(parts.join('。')) + } finally { setBusy('') } + } + + /** 导出成片 → 统一预览队列(点任意一行都能 ←/→ 翻所有成片) */ + const exportItems = useMemo(() => exportList.map((rec) => fromExport(rec)).filter(Boolean), [exportList]) + const indexOfExport = useCallback( + (rec: any) => exportItems.findIndex((m: any) => m.raw?.id === rec.id), + [exportItems] + ) + const retryExport = (rec: any) => + run('重试导出', () => api.post(`/api/tasks/${rec.task_id}/retry`, {}), () => `合成任务 #${rec.task_id} 已重新入队`) + + function togglePreset(p: string) { + setForm((f) => ({ ...f, presets: f.presets.includes(p) ? f.presets.filter((x) => x !== p) : [...f.presets, p] })) + } + + const burnBlocked = health?.ffmpeg_capabilities && !health.ffmpeg_capabilities.subtitle_burn + + return ( + +
+ + 成片 {succeeded.length} / {exportList.length} + 累计成本 {fmtMoney(costs?.total_cost, currency)} + 生成 {costs?.generations?.count ?? 0} 次 / {(costs?.generations?.seconds ?? 0).toFixed(1)}s + 待结算预估 {fmtMoney(costs?.estimated_pending, currency)} + {report && {report.ready ? '时间线可导出' : '时间线有阻塞'}} + + {busy && <> {busy}…} +
+ + {error} + {blockingIssues.length > 0 && ( + + 时间线尚未就绪,导出会被拒绝(409): + {blockingIssues.map((x: any, i: number) => {x.message} )} + 前往时间线修复 ↗ + + )} + + {/* ===== 出片 ===== */} + + + + + {presetList.map((p) => ( + togglePreset(p)}> + {presetLabel[p] || p} + + ))} + + + + setForm((f) => ({ ...f, subtitle_mode: v }))} options={SUBTITLE_MODES} /> + + + setForm((f) => ({ ...f, priority: Number(e.target.value) }))} /> + + + setForm((f) => ({ ...f, name: e.target.value }))} /> + + + + + 先检查时间线 ↗ + + {burnBlocked && ( + + ⚠ 本机 ffmpeg 缺 libass(无 subtitles/ass 滤镜),烧录模式会自动降级为内嵌软字幕轨; + 装好完整版后设 FFMPEG_BIN 指向它即可。当前使用:{health.ffmpeg_capabilities.ffmpeg_path || '未探测'}。 + + )} + + + + {costs?.records ?? 0} 条计费记录} /> + + + + + + + + + {(costs?.by_kind || []).map((row: any) => ( + + + + + ))} + {(costs?.by_provider || []).map((row: any) => ( + + + + + ))} + {(costs?.by_model || []).map((row: any) => ( + + + + + ))} + {!costs?.by_model?.length && ( + + )} + +
维度取值金额记录数
任务类型{statusLabel(row.key)}{fmtMoney(row.cost, currency)}{row.count}
Provider{row.key}{fmtMoney(row.cost, currency)}{row.count}
模型{row.key}{fmtMoney(row.cost, currency)}{row.count}
+ 暂无计费明细:本项目使用自建模型,但未在模型管理中心配置单价,服务端因此不会写入计费记录; + 「待生成预估」只统计排队中 / 执行中 / 已规划的任务,全部跑完后自然归零。
+ 可量化的投入见下方生成记录({costs?.generations?.count ?? 0} 次调用 / {(costs?.generations?.seconds ?? 0).toFixed(1)} 秒)。{' '} + 去配置模型单价 ↗ +
+
+
+
+ + {/* ===== 成片列表 ===== */} + + 成片记录} + right={媒体由后端 /media 直出,下载走 /api/exports/:id/download} /> + + + + + + + + + + + {exportList.map((rec) => { + const at = indexOfExport(rec) + return ( + + + + + + + + + + + + ) + })} + {!exportList.length && ( + + )} + +
#名称 / 预设状态规格时长大小耗时校验和操作
{rec.id} +
+ +
+ {rec.name} +
{rec.preset} · timeline#{rec.timeline_id} · task#{rec.task_id || '—'}
+ {rec.error_message && {rec.error_message}} +
+
+
+ + {rec.subtitle_burned &&
已烧字幕
} +
{rec.width || '?'}×{rec.height || '?'}{rec.fps ? ` @${rec.fps}` : ''}{fmtMs(rec.duration_ms)}{fmtBytes(rec.size_bytes)}{rec.elapsed_ms ? (rec.elapsed_ms / 1000).toFixed(1) + 's' : '—'} + {(rec.checksum || '').slice(0, 10) || '—'} + +
+ {rec.status === 'succeeded' && ( + <> + + 下载 ↗ + + )} + {rec.status !== 'succeeded' && rec.task_id && ['failed', 'cancelled'].includes(rec.status) && ( + + )} + {rec.status !== 'succeeded' && !(rec.task_id && ['failed', 'cancelled'].includes(rec.status)) && ( + — + )} +
+
还没有成片。先在时间线页通过交付预检,再回到这里出片。
+
+
+ + {/* ===== 生成记录 ===== */} + + + {generations.length} 条 + + } /> + + + + + + + + + + {generations.map((g) => ( + + + + + + + + + + + ))} + {!generations.length && ( + + )} + +
#镜头 / 类型Provider / 模型提示词时长成本尝试时间
{g.id}shot#{g.shot_id || '—'}
{statusLabel(g.kind)}
{g.provider}/{g.model} + {(g.prompt || '').slice(0, 130)}{(g.prompt || '').length > 130 ? '…' : ''} + {g.params && Object.keys(g.params).length > 0 &&
{JSON.stringify(g.params).slice(0, 120)}
} + {g.asset_paths?.length ?
参考素材 {g.asset_paths.length} 个 · job {g.provider_job_id || '—'}
: null} +
{fmtSeconds(g.duration_seconds)}{fmtMoney(g.cost, g.currency || currency)}{g.attempts}{fmtAgo(g.created_at)}
暂无生成记录。
+
+ {showAllCost && costItems.length > 0 && ( + + + + + + + + + + {shownCostItems.map((it) => ( + + + + + + + + + + ))} + +
#类型Provider / 模型数量单价金额时间
{it.id}{statusLabel(it.kind)}{it.provider}/{it.model}{it.quantity} {it.unit}{fmtMoney(it.unit_price, it.currency || currency)}{fmtMoney(it.cost, it.currency || currency)}{fmtTime(it.created_at)}
+
+ )} +
+
+ ) +} + +/** 面板里的短字段栅格(.frow):一行四列,窄列自动降列 */ +function FormGrid({ children }: { children: React.ReactNode }) { + return
{children}
}