151 lines
3.2 KiB
Svelte
151 lines
3.2 KiB
Svelte
<script lang="ts">
|
|
import { assetUrl } from '$lib/api';
|
|
import type { Job } from '$lib/comfy/types';
|
|
import { jobStatusInfo } from '$lib/jobStatus';
|
|
import { parseDbTs } from '$lib/dbtime';
|
|
import { missingOutputsOf, markOutputMissing } from '$lib/missingOutputs.svelte';
|
|
let {
|
|
jobs,
|
|
selectedId,
|
|
onSelect,
|
|
onHistory,
|
|
nameOf,
|
|
}: {
|
|
jobs: Job[];
|
|
selectedId: number | null;
|
|
onSelect: (job: Job) => void;
|
|
onHistory: () => void;
|
|
nameOf: (job: Job) => string;
|
|
} = $props();
|
|
const sorted = $derived(
|
|
[...jobs].sort((a, b) => parseDbTs(b.created_at) - parseDbTs(a.created_at)),
|
|
);
|
|
</script>
|
|
|
|
<section class="result-rail" aria-label="生成结果记录">
|
|
<header>
|
|
<strong>生成记录 <small>{jobs.length}</small></strong><button
|
|
class="a-btn ghost sm"
|
|
onclick={onHistory}>全部记录与任务 ↗</button
|
|
>
|
|
</header>
|
|
<div class="rail-items">
|
|
{#each sorted as job (job.id)}
|
|
{@const path = job.output_paths.find((p) => !missingOutputsOf(job).includes(p))}
|
|
{@const status = jobStatusInfo(job)}
|
|
<button
|
|
class="result-item"
|
|
class:selected={job.id === selectedId}
|
|
aria-pressed={job.id === selectedId}
|
|
aria-label="查看第 {job.id} 次生成,{status.label}"
|
|
title="{nameOf(job)} · {job.created_at} · {status.label}"
|
|
onclick={() => onSelect(job)}
|
|
>
|
|
<span class="thumb"
|
|
>{#if path && job.kind === 'image'}<img
|
|
src={assetUrl(path)}
|
|
alt=""
|
|
loading="lazy"
|
|
onerror={() => markOutputMissing(path)}
|
|
/>{:else}<span>{job.kind === 'video' ? '▶' : '✳'}</span>{/if}</span
|
|
>
|
|
<span class="record-label">{nameOf(job)}</span>
|
|
<span class="record-label"
|
|
>第 {job.id} 次 · {path
|
|
? status.label
|
|
: job.status === 'done'
|
|
? '文件缺失'
|
|
: status.label}</span
|
|
>
|
|
</button>
|
|
{:else}<p>生成后,结果会保存在这里。</p>{/each}
|
|
</div>
|
|
</section>
|
|
|
|
<style>
|
|
.result-rail {
|
|
border-top: 1px solid var(--line);
|
|
padding-top: 8px;
|
|
min-width: 0;
|
|
flex-shrink: 0;
|
|
}
|
|
header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
margin-bottom: 6px;
|
|
gap: 10px;
|
|
}
|
|
strong {
|
|
font-size: 12px;
|
|
}
|
|
small {
|
|
color: var(--text-3);
|
|
margin-left: 5px;
|
|
font-weight: 400;
|
|
}
|
|
.rail-items {
|
|
display: flex;
|
|
gap: 8px;
|
|
overflow-x: auto;
|
|
overscroll-behavior: contain;
|
|
padding-bottom: 5px;
|
|
}
|
|
.result-item {
|
|
width: 122px;
|
|
flex-shrink: 0;
|
|
border: 1px solid var(--line);
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
padding: 3px;
|
|
background: var(--surface);
|
|
cursor: pointer;
|
|
color: var(--text);
|
|
}
|
|
.result-item.selected {
|
|
border: 2px solid var(--accent);
|
|
padding: 2px;
|
|
background: var(--accent-soft);
|
|
}
|
|
.thumb {
|
|
display: grid;
|
|
place-items: center;
|
|
height: 48px;
|
|
background: var(--bg);
|
|
border-radius: 5px;
|
|
color: var(--accent);
|
|
font-size: 20px;
|
|
}
|
|
img {
|
|
width: 100%;
|
|
height: 48px;
|
|
object-fit: cover;
|
|
border-radius: 5px;
|
|
}
|
|
.record-label {
|
|
display: block;
|
|
font-size: 10px;
|
|
padding: 5px 3px;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
}
|
|
p {
|
|
font-size: 12px;
|
|
color: var(--text-3);
|
|
margin: 4px 0;
|
|
}
|
|
@media (max-height: 650px) {
|
|
.rail-items {
|
|
display: none;
|
|
}
|
|
.thumb,
|
|
img {
|
|
height: 32px;
|
|
}
|
|
.result-item {
|
|
width: 110px;
|
|
}
|
|
}
|
|
</style>
|