import { type ReactNode, type Ref } from 'react' import { cn } from '../../lib/cn' /** * 流程节点条里的「一格」(全站唯一一份:WorkflowBar 与项目列表、概览共用)。 * * 节点状态口径来自 lib/pipeline.ts:done / active / failed / pending。 * 「当前节点」只有 openNode() 一个算法——以前五个地方各算各的,草稿项目会喊 * 「当前 · 导出完整视频」,流程全绿之后还在喊最后一个节点名(明明已经交付)。 */ export const STATE_LABEL: Record = { done: '完成', failed: '需处理', active: '进行中', pending: '待处理' } export function stepIcon(state: string, index: number): string { if (state === 'done') return '✓' if (state === 'failed') return '!' if (state === 'active') return '▶' return String(index + 1) } /** 后端没有计数的节点显示中文状态;有计数的节点显示 done/total 并夹住分母 */ export function nodeProgress(node: any): string { if (node?.done === null || node?.done === undefined) return STATE_LABEL[node?.state] || String(node?.state ?? '') return `${Math.min(node.done, node.total)}/${node.total}` } export function nodeHint(node: any): string { return [`${node.label}(${STATE_LABEL[node.state] || node.state})`, node.detail].filter(Boolean).join(' — ') } const NUM: Record = { done: 'bg-accent-fill text-on-accent', active: 'bg-accent-fill text-on-accent', failed: 'bg-danger text-danger-ink', pending: 'bg-active text-muted' } export function Step({ node, index, current, compact, onClick, className }: { node: any index: number current?: boolean compact?: boolean onClick?: (node: any) => void className?: string }) { const st = node.state === 'done' ? 'done' : node.state === 'failed' ? 'failed' : node.state === 'active' ? 'active' : 'pending' return (
onClick(node) : undefined} className={cn('flex-1 basis-[118px] min-w-[96px] bg-panel border rounded-tile p-[9px_10px] relative min-w-0 transition-colors', onClick && 'cursor-pointer', current && 'shadow-[0_0_0_1px_var(--c-accent-line)]', st === 'done' && 'border-success-line bg-raised', st === 'active' && 'border-success-line bg-accent-tint shadow-[inset_0_0_0_1px_var(--c-success-line)]', st === 'failed' && 'border-danger-line bg-panel', st === 'pending' && 'border-[--c-bg-active] opacity-70', className)}>
{stepIcon(node.state, index)} {nodeProgress(node)}
{node.label}
{!compact && (
{node.detail}
)}
) } export function Steps({ nodes, currentKey, compact, onStep, className, id, scrollSmooth, ref }: { nodes: any[] currentKey?: string compact?: boolean onStep?: (node: any, at: number) => void className?: string id?: string scrollSmooth?: boolean /** 横向滚动容器:WorkflowBar 需要量它、并把当前节点滚进视野 */ ref?: Ref }) { const list = nodes || [] return (
{(list.length ? list : [{ state: 'pending', label: '暂无流程数据' }]).map((n: any, at: number) => ( onStep(node, at) : undefined} /> ))}
) } /** 流程条底部那一行「已完成 x / y · 当前:xxx」;全绿时不再报最后一个节点名 */ export function FlowCaption({ nodes, current, allDone, className }: { nodes: any[]; current?: ReactNode; allDone?: boolean; className?: string }) { const done = (nodes || []).filter((s: any) => s.state === 'done').length return (
已完成 {done} / {nodes.length} 个节点 {current ? <> · 当前:{current} : allDone ? <> · 流程已全部完成 : null}
) }