Files
aigc-home/calliope-web/src/lib/components/generate/TakeCard.svelte
T
总工andmultica-agent 949cd2ecad HEL-654: D 批——记录流状态语义、金框结果切换、撤销删除与任务页重皮
- 点选金框滑动 + 检视区 150ms 交叉淡变;↑↓/J/K 即时切换、空格播放、
  Delete 删除、] 检视区、浮层让位;新记录入场/完成金光/失败抖动,减动效只余短淡变
- 单条删除 5 秒撤销(Toast 金色动作钮),窗口过后才提交 DELETE,离页 flush;
  任务页同队列同步;工作流删除保留旧记录并标识「工作流已删除」
- 红/琥珀界线:失败红 + 中文结论展开;done 但文件取不到 → 琥珀「文件缺失」
  + 用相同参数重做/移除记录
- 参数页提交自动切结果页;工作流选择器 ↑↓ 真高亮 + Enter 使用(ShellPop arrowRoving 开关)
- 记录流 80 条分页(220 条专项:50 次轮询 490ms);任务页 §3.5 芯片+搜索+
  行内进度条+ghost 重试;i18n 七语种 +17 键

Co-authored-by: multica-agent <github@multica.ai>
2026-09-30 13:02:51 +08:00

569 lines
14 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts">
import Icon from '$lib/components/ui/Icon.svelte';
import { assetUrl } from '$lib/api';
import type { Job, Workflow } from '$lib/comfy/types';
import { progressFor } from '$lib/jobProgress';
import { jobStatusInfo } from '$lib/jobStatus';
import { parseDbTs } from '$lib/dbtime';
import { clearOutputMissing, markOutputMissing, missingOutputsOf } from '$lib/missingOutputs.svelte';
import { t } from '$lib/i18n.svelte';
import { usageLabel } from './schema';
import { elapsedSec, fmtClock, fmtDur, inputsOf, isVideoOutput, promptOf } from './takes';
/**
* 一条记录 (spec-v2 §3.3 记录卡): workflow · usage · time, the prompt, the
* inputs it used, its real state (phase / progress / time / error) and
* the first output. The whole card selects; actions sit above it.
* D 批 (HEL-654): the gold sel-mark frame slides between cards on
* pointer selection (driven by the feed), new takes enter with a
* 220ms rise, completion flashes once, failure shakes once, a done
* take whose files no longer load turns amber (文件缺失) with
* 用相同参数重做 / 移除记录, and takes on a deleted workflow are
* marked as such instead of pretending nothing changed.
*/
interface Props {
job: Job;
wf: Workflow | undefined;
selected: boolean;
nowMs: number;
busy?: boolean;
/** Play the 220ms entrance rise (new take / undo restore). */
enter?: boolean;
/** One-shot 900ms gold flash on completion. */
flash?: boolean;
/** One-shot failure shake. */
shake?: boolean;
onSelect: () => void;
onReuse: () => void;
onRetry: () => void;
onCancel: () => void;
onDelete: () => void;
}
let {
job,
wf,
selected,
nowMs,
busy = false,
enter = false,
flash = false,
shake = false,
onSelect,
onReuse,
onRetry,
onCancel,
onDelete,
}: Props = $props();
const st = $derived(jobStatusInfo(job));
// §3.4 红/琥珀界线: red follows the backend task status only. Amber is
// reserved for a SUCCEEDED take whose product files no longer load.
const gonePaths = $derived(missingOutputsOf(job));
const fileGone = $derived(gonePaths.length > 0);
const tone = $derived(fileGone ? 'warn' : st.tone === 'queue' ? '' : st.tone === 'fail' ? 'err' : st.tone);
const label = $derived(fileGone ? t('jobst.missing') : st.label);
const wfDeleted = $derived(job.workflow_id == null);
const prompt = $derived(promptOf(job, wf));
const inputs = $derived(inputsOf(job, wf).filter((i) => i.kind === 'image'));
const output = $derived(
fileGone
? (job.output_paths.find((p) => !gonePaths.includes(p)) ?? null)
: (job.output_paths[0] ?? null),
);
const progress = $derived.by(() => {
if (job.status !== 'running') return 0;
const live = progressFor(job.id);
const phase = live?.phase ?? job.phase;
if (phase !== 'comfy_running' && phase !== 'saving') return 0;
return live?.progress ?? 3;
});
const active = $derived(job.status === 'pending' || job.status === 'running');
const name = $derived(wf?.name ?? t('studio.jobName', { id: job.id }));
let portrait = $state(false);
let clipSec = $state<number | null>(null);
let errOpen = $state(false);
function noteImage(e: Event) {
const img = e.currentTarget as HTMLImageElement;
portrait = img.naturalHeight > img.naturalWidth;
}
function noteVideo(e: Event) {
const v = e.currentTarget as HTMLVideoElement;
portrait = v.videoHeight > v.videoWidth;
if (Number.isFinite(v.duration)) clipSec = v.duration;
}
</script>
<article
class="take"
class:selected
class:enter
class:done-flash={flash}
class:shake
data-job={job.id}
>
<span class="sel-mark" aria-hidden="true"></span>
<button
type="button"
class="hit"
aria-pressed={selected}
aria-label={`${name} · ${label}`}
onclick={onSelect}
></button>
<div class="head">
<span class="name">{name}</span>
{#if wfDeleted}<span class="a-tag">{t('studio.wfDeletedTag')}</span>{/if}
{#if wf?.usage}<span class="a-tag">{usageLabel(wf.usage)}</span>{/if}
<span class="meta mono">{fmtClock(parseDbTs(job.created_at))}</span>
</div>
{#if prompt}<p class="prompt">{prompt}</p>{/if}
{#if inputs.length}
<div class="inputs" aria-label={t('desk.inputs')}>
{#each inputs.slice(0, 5) as inp (inp.path + inp.label)}
<img class="mini" src={assetUrl(inp.path)} alt={inp.label} title={inp.label} loading="lazy" />
{/each}
{#if inputs.length > 5}<span class="more">+{inputs.length - 5}</span>{/if}
</div>
{/if}
<div class="state">
<span class="a-tag {tone}">{label}</span>
{#if st.tone === 'run'}
{#if progress > 0}
<div class="a-progress bar" style:--p={progress / 100}><i></i></div>
{/if}
<span class="txt">{fmtDur(elapsedSec(job, nowMs))}</span>
{:else if st.tone === 'ok' && !fileGone}
<span class="txt">{t('desk.took', { d: fmtDur(elapsedSec(job, nowMs)) })}</span>
{:else if st.tone === 'fail'}
<button
type="button"
class="err-txt"
class:open={errOpen}
title={st.detail}
aria-expanded={errOpen}
onclick={() => (errOpen = !errOpen)}
>
{st.detail}
</button>
{:else if fileGone}
<span class="gone-txt">{t('jobst.missingDetail')}</span>
{:else}
<span class="txt">{st.detail}</span>
{/if}
<div class="actions">
{#if fileGone}
<button type="button" class="a-btn ghost xs" disabled={busy} onclick={onRetry}>
{t('desk.redo')}
</button>
<button type="button" class="a-btn danger xs" onclick={onDelete}>{t('desk.removeRecord')}</button>
{:else}
<button type="button" class="a-btn ghost xs" onclick={onReuse}>{t('desk.reuse')}</button>
{#if st.tone === 'fail' && job.error !== 'cancelled'}
<button type="button" class="a-btn ghost xs" disabled={busy} onclick={onRetry}>{t('common.retry')}</button>
{/if}
{#if active}
<button type="button" class="a-btn ghost xs" disabled={busy} onclick={onCancel}>{t('common.cancel')}</button>
{/if}
{#if output}
<a class="a-btn ghost xs" href={assetUrl(output)} download>{t('desk.download')}</a>
{/if}
{#if !active}
<button type="button" class="a-btn danger xs" onclick={onDelete}>{t('studio.deleteBtn')}</button>
{/if}
{/if}
</div>
</div>
<div class="out">
{#if output}
<div class="thumb" class:portrait>
{#if isVideoOutput(job, output)}
<video
src={assetUrl(output)}
preload="metadata"
muted
playsinline
onloadedmetadata={(e) => {
clearOutputMissing(output);
noteVideo(e);
}}
onerror={() => output && markOutputMissing(output)}
></video>
<span class="play" aria-hidden="true"><Icon name="play" size={10} /></span>
{#if clipSec != null}<span class="badge mono">{fmtDur(clipSec)}</span>{/if}
{:else}
<img
src={assetUrl(output)}
alt=""
loading="lazy"
onload={(e) => {
clearOutputMissing(output);
noteImage(e);
}}
onerror={() => output && markOutputMissing(output)}
/>
{/if}
{#if job.output_paths.length > 1}<span class="count mono">×{job.output_paths.length}</span>{/if}
</div>
{:else if active}
<div class="thumb pending">{st.label}</div>
{:else if fileGone}
<div class="thumb gone">{t('jobst.missing')}</div>
{:else}
<div class="thumb missing">{t('desk.notGenerated')}</div>
{/if}
</div>
</article>
<style>
.take {
position: relative;
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: var(--sp-4) var(--sp-6);
margin-bottom: var(--sp-3);
padding: var(--sp-5) var(--sp-6);
border: 1px solid var(--line);
border-radius: var(--r-lg);
background: var(--bg-2);
transition:
border-color var(--d-state) ease,
background-color var(--d-state) ease,
box-shadow var(--d-state) ease;
}
/* 选中框:金色描边从上一条记录滑到新选中的记录(feed 驱动 WAAPI) */
.sel-mark {
position: absolute;
inset: -1px;
z-index: 3;
display: none;
border: 1px solid var(--accent-line);
border-radius: inherit;
pointer-events: none;
}
.take.selected {
border-color: transparent;
background: var(--accent-wash), var(--bg-3);
box-shadow: var(--sel-shadow);
}
.take.selected > .sel-mark {
display: block;
}
@media (hover: hover) and (pointer: fine) {
.take:hover:not(.selected) {
border-color: var(--line-2);
background: var(--bg-3);
}
}
/* 新记录 / 撤销恢复:220ms 上移 8px 入场(减动效只余淡变) */
.take.enter {
animation: take-in var(--d-enter) var(--ease-out);
}
@keyframes take-in {
from {
opacity: 0;
transform: translateY(8px);
}
}
/* 完成一次性金色光晕 900ms;失败原地轻抖一次 */
.take.done-flash {
animation: done-flash var(--d-flash) var(--ease-out);
}
@keyframes done-flash {
from {
box-shadow: var(--accent-glow), 0 0 0 1px var(--accent-line);
}
}
.take.shake {
animation: take-shake 320ms var(--ease-out);
}
@keyframes take-shake {
20% {
transform: translateX(-4px);
}
45% {
transform: translateX(4px);
}
70% {
transform: translateX(-2px);
}
}
:global(:root[data-reduce='1']) .take.enter {
animation: take-fade var(--d-state) ease;
}
:global(:root[data-reduce='1']) .take.done-flash,
:global(:root[data-reduce='1']) .take.shake {
animation: none;
}
@keyframes take-fade {
from {
opacity: 0;
}
}
.hit {
position: absolute;
inset: 0;
z-index: 0;
padding: 0;
border: 0;
border-radius: inherit;
background: transparent;
cursor: pointer;
}
.hit:focus-visible {
outline-offset: -2px;
border-radius: var(--r-lg);
}
.head,
.prompt,
.inputs,
.state {
grid-column: 1;
position: relative;
pointer-events: none;
}
.head {
display: flex;
align-items: center;
gap: var(--sp-3);
min-width: 0;
}
.name {
font-weight: 600;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.meta {
color: var(--text-3);
font-size: var(--fs-aux);
white-space: nowrap;
}
.prompt {
margin: 0;
color: var(--text-2);
font-size: var(--fs-body-sm);
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.inputs {
display: flex;
align-items: center;
gap: var(--sp-1);
}
.mini {
width: 26px;
height: 26px;
border-radius: 5px;
object-fit: cover;
border: 1px solid var(--line-2);
}
.more {
padding-left: 2px;
font-size: var(--fs-mini);
color: var(--text-3);
}
.state {
display: flex;
align-items: center;
gap: var(--sp-3);
min-height: 22px;
font-size: var(--fs-aux);
}
.bar {
flex: 0 0 140px;
}
.txt {
color: var(--text-2);
white-space: nowrap;
}
.gone-txt {
min-width: 0;
color: var(--warn);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* 失败:一行中文结论自动展开,点开看完整详情 */
.err-txt {
min-width: 0;
max-width: 100%;
padding: 0;
border: 0;
background: transparent;
color: var(--err);
font: inherit;
font-size: var(--fs-aux);
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
pointer-events: auto;
cursor: pointer;
}
.err-txt.open {
white-space: normal;
word-break: break-word;
}
.err-txt:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
border-radius: var(--r-sm);
}
.actions {
display: flex;
gap: var(--sp-1);
margin-left: auto;
pointer-events: auto;
opacity: 0;
transition: opacity var(--d-state) ease;
}
.take:focus-within .actions,
.take.selected .actions {
opacity: 1;
}
@media (hover: hover) and (pointer: fine) {
.take:hover .actions {
opacity: 1;
}
}
@media (hover: none) {
.actions {
opacity: 1;
}
}
.out {
grid-column: 2;
grid-row: 1 / span 4;
align-self: start;
position: relative;
pointer-events: none;
}
.thumb {
position: relative;
width: 150px;
aspect-ratio: 16 / 9;
overflow: hidden;
border-radius: var(--r-md);
background: var(--bg-4);
box-shadow: inset 0 0 0 1px var(--on-media-line);
}
.thumb.portrait {
width: 96px;
aspect-ratio: 3 / 4;
}
.thumb img,
.thumb video {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.badge,
.count {
position: absolute;
bottom: var(--sp-2);
padding: 1px 5px;
border-radius: 4px;
background: var(--media-scrim);
color: var(--on-media);
font-size: var(--fs-mini);
}
.badge {
right: var(--sp-2);
}
.count {
right: var(--sp-2);
top: var(--sp-2);
bottom: auto;
}
.play {
position: absolute;
left: var(--sp-2);
bottom: var(--sp-2);
display: grid;
place-items: center;
width: 22px;
height: 22px;
border-radius: 50%;
background: var(--media-scrim);
color: var(--on-media);
}
.thumb.pending,
.thumb.missing,
.thumb.gone {
display: grid;
place-items: center;
padding: var(--sp-2);
box-sizing: border-box;
text-align: center;
font-size: var(--fs-mini);
color: var(--text-3);
border: 1px dashed var(--line-2);
background: var(--bg-2);
box-shadow: none;
}
.thumb.pending {
border-style: solid;
color: var(--run);
}
.thumb.gone {
color: var(--warn);
border-color: var(--warn);
}
.thumb.pending::after {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(100deg, transparent 30%, var(--run-soft) 50%, transparent 70%);
animation: take-sheen 1.4s linear infinite;
}
@keyframes take-sheen {
from {
transform: translateX(-100%);
}
to {
transform: translateX(100%);
}
}
:global(:root[data-reduce='1']) .thumb.pending::after {
animation: none;
}
@media (max-width: 760px) {
.take {
padding: var(--sp-4);
}
.head {
flex-wrap: wrap;
row-gap: 2px;
}
.out {
grid-row: 1 / span 2;
}
.state {
grid-column: 1 / -1;
flex-wrap: wrap;
}
.thumb {
width: 108px;
}
.thumb.portrait {
width: 72px;
}
.bar {
flex-basis: 80px;
}
}
</style>