Files
aigc-home/calliope-web/src/routes/tasks/+page.svelte
T
总工andmultica-agent d882fd62d8 feat(ui): F批——其余页面融合收口与整站规范统一 (HEL-656)
- 移除 Calliope 旧壳死代码:/project/[id] 旧四段编辑器页面与 9 个遗留组件
  (NavRail/StoryStage/AssetsStage/ScriptStage/QueueStage/ActivityPanel/
  JobRow/AssetThumb/ProjectCard),/projects 死页面(308→/ 已有)
- 素材库 /library 迁入 AppShell 新壳:a-chip 筛选、ui/Modal、ConfirmDialog
  实心红两级删除、窄屏单列;移除 A 时期 308→/ 重定向;导航轨/更多菜单新增入口
- 智能体子系统去杂色:agentPalette 默认紫→中性、回退色板收敛为 avatar 五色族;
  AgentChat 气泡按 §3.2/3.6(用户 bg-3/Agent bg-2+line)、进行中指示改青、
  紫色空态图标清除;AgentComposer 天蓝/金芯片收敛
- 首页/工作台/五面板/StageStepper/PromptBlock/JobChip 类名收敛到全局 a-btn/
  a-input/a-tag/field;Stepper 补金色当前下划+已确认✓;镜头序号按规范用
  accent-lo+mono;分页/工作台选择页金色越界改中性或青
- 金色纪律修正:次级文字操作(重试/测试/链接)与必填星标、任务「测试」标签
  去金色;「默认」金标签按 §3.9 保留
- 断点收敛:1023/1279/900/780/700/640 → 1180/760(1440 增强保留)
- canvas/build-scene 可用级 ≤760 纵向堆叠适配 + 硬编码色/旧 fallback 清理;
  AppHeader 去 Calliope 品牌与死链
- favicon 收口:static/favicon.png 金色品牌图标,移除 204 stub 与构建豁免
- i18n 七语种 +3 key(shell.navLibrary/library.loadError/library.subtitle)全对齐
- 新增 e2e/fpages.mjs:F 页面三档走查/重定向/五段导入编辑/规范色断言 38 项

Co-authored-by: multica-agent <github@multica.ai>
2026-09-30 16:29:47 +08:00

605 lines
16 KiB
Svelte

<script lang="ts">
import { createQuery, useQueryClient } from '@tanstack/svelte-query';
import AppShell from '$lib/components/shell/AppShell.svelte';
import Icon from '$lib/components/ui/Icon.svelte';
import {
apiErrorMessage,
assetUrl,
jobsApi,
playgroundApi,
projects,
workflows,
type Job,
} from '$lib/api';
import { connectEvents } from '$lib/events';
import { parseDbTs } from '$lib/dbtime';
import { handleJobEvent, progressFor } from '$lib/jobProgress';
import { jobStatusInfo } from '$lib/jobStatus';
import { isFileMissing, markOutputMissing } from '$lib/missingOutputs.svelte';
import { toast } from '$lib/toast';
import { t } from '$lib/i18n.svelte';
import { isStandaloneJob, isWorkflowTestJob, jobSourceLabel } from '$lib/jobLabels';
import { createTakeDeleteQueue } from '$lib/components/generate/takeDelete.svelte';
/**
* 生成任务页 (spec-v2 §3.5, HEL-612/654 D 批): one table summing both
* task classes — image and video — from standalone windows, the
* creation flow, and Playground. Filter chips + search; running rows
* carry a 2px progress bar; 重试 is a ghost text op (spec v2 §1.2);
* deleting one task is record-level: 200ms collapse + 5s undo Toast,
* no dialog. The real DELETE only fires after the undo window.
*/
const client = useQueryClient();
const jobsQuery = createQuery({
queryKey: ['jobs'],
queryFn: () => jobsApi.list(),
refetchInterval: 5_000,
});
const workflowsQuery = createQuery({ queryKey: ['workflows'], queryFn: workflows.list });
const projectsQuery = createQuery({ queryKey: ['projects'], queryFn: projects.list });
$effect(() => {
const off = connectEvents((ev) => {
handleJobEvent(ev);
if (ev.type.startsWith('job.') || ev.type === 'events.resync') {
void client.invalidateQueries({ queryKey: ['jobs'] });
void client.invalidateQueries({ queryKey: ['playground-jobs'] });
}
});
return off;
});
type Filter = 'all' | 'image' | 'video' | 'failed' | 'active';
let filter = $state<Filter>('all');
let search = $state('');
const deleteQueue = createTakeDeleteQueue(client);
const pendingIds = deleteQueue.pending;
$effect(() => deleteQueue.destroy);
const genJobs = $derived(($jobsQuery.data ?? []).filter((j) => j.kind === 'image' || j.kind === 'video'));
const shown = $derived.by(() => {
const q = search.trim().toLowerCase();
return genJobs.filter((j) => {
if (pendingIds.has(j.id)) return false;
if (filter === 'image' || filter === 'video') {
if (j.kind !== filter) return false;
} else if (filter === 'failed' && jobStatusInfo(j).tone !== 'fail') return false;
else if (filter === 'active' && j.status !== 'pending' && j.status !== 'running') return false;
if (!q) return true;
return `${wfName(j)} ${jobSourceLabel(j)} ${j.error ?? ''} ${j.id}`.toLowerCase().includes(q);
});
});
const activeCount = $derived(genJobs.filter((j) => j.status === 'pending' || j.status === 'running').length);
function wfName(job: Job): string {
return (
($workflowsQuery.data ?? []).find((w) => w.id === job.workflow_id)?.name ??
t('studio.jobName', { id: job.id })
);
}
function projectOf(job: Job): string {
if (isStandaloneJob(job)) return '';
const title = ($projectsQuery.data ?? []).find((p) => p.id === job.project_id)?.title;
return title ? `《${title}》` : '';
}
function timeOf(job: Job): string {
const ts = parseDbTs(job.created_at);
if (!Number.isFinite(ts)) return '—';
const d = new Date(ts);
const p = (n: number) => String(n).padStart(2, '0');
return `${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
}
/** 2px 进度条贴行底 — real progress from the SSE store only. */
function rowProgress(job: Job): number {
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;
}
function toneOf(job: Job, base: string): string {
if (base === 'ok' && isFileMissing(job)) return 'warn';
if (base === 'queue') return '';
if (base === 'fail') return 'err';
return base;
}
function labelOf(job: Job, base: { tone: string; label: string }): string {
return base.tone === 'ok' && isFileMissing(job) ? t('jobst.missing') : base.label;
}
function requestDelete(job: Job) {
if (job.status === 'pending' || job.status === 'running') return;
deleteQueue.request(job, {
message: () =>
(job.output_paths?.length ?? 0) > 0
? t('studio.deletedTakeToast', { name: wfName(job) })
: t('studio.deletedTakeNoFilesToast', { name: wfName(job) }),
});
}
let busyId = $state<number | null>(null);
async function retry(job: Job) {
if (busyId != null) return;
busyId = job.id;
try {
await jobsApi.retry(job.id);
toast.success(t('studio.retryQueuedToast'));
await client.invalidateQueries({ queryKey: ['jobs'] });
} catch (err) {
toast.error(t('studio.retryFailedToast', { detail: apiErrorMessage(err) }));
} finally {
busyId = null;
}
}
async function cancel(job: Job) {
if (busyId != null) return;
busyId = job.id;
try {
await jobsApi.cancel(job.id);
toast.info(t('studio.cancelToast'));
await client.invalidateQueries({ queryKey: ['jobs'] });
} catch (err) {
toast.error(apiErrorMessage(err));
} finally {
busyId = null;
}
}
</script>
<AppShell active="tasks" title={t('tasks.title')} subtitle={t('tasks.subtitle')}>
{#snippet actions()}
<span class="status-chip">{t('tasks.count', { n: genJobs.length, m: activeCount })}</span>
{/snippet}
<div class="tasks-page">
<div class="toolbar">
<div class="chips" role="group" aria-label={t('tasks.title')}>
{#each [['all', t('tasks.filterAll')], ['image', t('tasks.filterImage')], ['video', t('tasks.filterVideo')], ['failed', t('tasks.filterFailed')], ['active', t('tasks.filterActive')]] as [value, label] (value)}
<button
type="button"
class="a-chip fchip"
class:sel={filter === value}
aria-pressed={filter === value}
onclick={() => (filter = value as Filter)}
>
{label}
</button>
{/each}
</div>
<label class="search">
<Icon name="search" size={13} />
<input type="search" bind:value={search} placeholder={t('tasks.searchPh')} aria-label={t('tasks.searchPh')} />
</label>
</div>
{#if !shown.length}
<div class="empty-card">
<Icon name="queue" size={22} />
<p>{search || filter !== 'all' ? t('tasks.emptyFiltered') : t('tasks.empty')}</p>
<a class="a-btn primary" href="/image">{t('tasks.goGenerate')}</a>
</div>
{:else}
<div class="task-table" role="table" aria-label={t('tasks.title')}>
{#each shown as job (job.id)}
{@const st = jobStatusInfo(job)}
{@const progress = rowProgress(job)}
<div class="trow" class:failed={st.tone === 'fail'} class:running={st.tone === 'run'}>
<span class="tkind {job.kind}">
<Icon name={job.kind === 'image' ? 'image' : 'film'} size={14} />
</span>
<div class="tthumb">
{#if job.output_paths?.[0]}
{#if job.kind === 'image'}
<img
src={assetUrl(job.output_paths[0])}
alt={wfName(job)}
loading="lazy"
onerror={() => job.output_paths[0] && markOutputMissing(job.output_paths[0])}
/>
{:else}
<video src={assetUrl(job.output_paths[0])} preload="metadata" muted></video>
{/if}
{/if}
</div>
<div class="tmain">
<div class="tname" title={wfName(job)}>
{#if isWorkflowTestJob(job)}<span class="tag-test">{t('tasks.testBadge')}</span>{/if}
{wfName(job)}
{#if job.workflow_id == null}<span class="a-tag wf-gone">{t('studio.wfDeletedTag')}</span>{/if}
</div>
<div class="tmeta mono">
{#if projectOf(job)}{projectOf(job)} · {/if}{jobSourceLabel(job)} · {timeOf(job)}
{#if (job.output_paths?.length ?? 0) > 0}
· {t('tasks.outputs', { n: job.output_paths.length })}
{/if}
</div>
{#if job.status === 'failed' && job.error}
<div class="terror">{job.error}</div>
{:else if st.tone === 'fail' || (job.status === 'done' && job.phase === 'dry_run')}
<div class="terror">{st.detail}</div>
{:else if st.tone === 'ok' && isFileMissing(job)}
<div class="twarn">{t('jobst.missingDetail')}</div>
{/if}
</div>
<div class="tout">
{#if job.output_paths?.length}
<div class="tout-thumbs">
{#each job.output_paths.slice(0, 4) as p (p)}
<a
href={assetUrl(p)}
download
target="_blank"
rel="noreferrer"
title={t('tasks.download')}
>
{#if job.kind === 'image'}
<img src={assetUrl(p)} alt="" loading="lazy" />
{:else}
<video src={assetUrl(p)} preload="metadata" muted></video>
{/if}
</a>
{/each}
</div>
{/if}
</div>
<span class="a-tag tst {toneOf(job, st.tone)}" title={st.detail}>{labelOf(job, st)}</span>
<span class="tactions">
{#if (st.tone === 'fail' || (st.tone === 'ok' && isFileMissing(job))) && job.error !== 'cancelled'}
<button type="button" class="link-ghost" disabled={busyId === job.id} onclick={() => retry(job)}>
{t('tasks.retry')}
</button>
{/if}
{#if job.status === 'pending' || job.status === 'running'}
<button type="button" class="link-ghost" disabled={busyId === job.id} onclick={() => cancel(job)}>
{t('tasks.cancel')}
</button>
{/if}
{#if job.output_paths?.length}
<a class="link-ghost" href={assetUrl(job.output_paths[0])} download>
{t('tasks.download')}
</a>
{/if}
{#if isStandaloneJob(job) && job.status !== 'pending' && job.status !== 'running'}
<button
type="button"
class="link-danger"
title={t('tasks.delete')}
onclick={() => requestDelete(job)}
>
<Icon name="trash" size={13} />
</button>
{/if}
</span>
{#if progress > 0}
<div class="rowbar" style:--p={progress / 100}><i></i></div>
{/if}
</div>
{/each}
</div>
{/if}
</div>
</AppShell>
<style>
.tasks-page {
padding: 20px 28px 40px;
max-width: 1560px;
width: 100%;
box-sizing: border-box;
margin: 0 auto;
display: flex;
flex-direction: column;
gap: 16px;
}
/* §3.5: 筛选芯片组(选中 = 金色文字 + accent-soft 底)+ 右侧搜索框 */
.toolbar {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.chips {
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.fchip {
height: 28px;
}
.search {
display: inline-flex;
align-items: center;
gap: 6px;
margin-left: auto;
min-width: 0;
height: 30px;
padding: 0 10px;
border: 1px solid var(--line);
border-radius: var(--r-pill);
background: var(--bg-2);
color: var(--text-3);
}
.search:focus-within {
border-color: var(--accent);
}
.search input {
min-width: 0;
width: 180px;
border: 0;
outline: 0;
background: transparent;
color: var(--text);
font: inherit;
font-size: 12px;
}
.search input::placeholder {
color: var(--text-3);
}
.empty-card {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
padding: 56px 24px;
border: 1.5px dashed var(--line-2);
border-radius: var(--r-lg);
color: var(--text-3);
}
.empty-card p {
margin: 0;
font-size: 13px;
line-height: 1.7;
}
/* 表格行:行底 --bg-2,悬停 --bg-3,进行中行底贴 2px 青进度条 */
.task-table {
display: flex;
flex-direction: column;
gap: 4px;
}
.trow {
position: relative;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 14px 10px 12px;
border: 1px solid var(--line);
border-radius: var(--r-md);
background: var(--bg-2);
min-height: 56px;
}
@media (hover: hover) and (pointer: fine) {
.trow:hover {
background: var(--bg-3);
}
}
.trow.failed {
border-color: color-mix(in srgb, var(--err) 35%, transparent);
}
.rowbar {
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 2px;
overflow: hidden;
border-radius: 0 0 var(--r-md) var(--r-md);
}
.rowbar i {
display: block;
height: 100%;
width: 100%;
transform-origin: left;
transform: scaleX(var(--p));
background: var(--run-grad);
transition: transform var(--d-progress) linear;
}
.tkind {
width: 28px;
height: 28px;
border-radius: 7px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
color: var(--text-2);
background: var(--bg-4);
}
.tthumb {
width: 48px;
height: 32px;
border-radius: 6px;
overflow: hidden;
border: 1px solid var(--line);
background: var(--bg-3);
flex-shrink: 0;
}
.tthumb img,
.tthumb video {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.tmain {
flex: 1;
min-width: 0;
}
.tname {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
font-size: 13px;
font-weight: 600;
color: var(--text);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.tname .wf-gone {
flex-shrink: 0;
}
.tmeta {
font-size: 10.5px;
color: var(--text-3);
margin-top: 1px;
}
.terror {
margin-top: 3px;
font-size: 11px;
color: var(--err);
line-height: 1.5;
}
.twarn {
margin-top: 3px;
font-size: 11px;
color: var(--warn);
line-height: 1.5;
}
.tout {
flex-shrink: 0;
}
.tout-thumbs {
display: flex;
gap: 4px;
}
.tout-thumbs a {
width: 32px;
height: 32px;
border-radius: 5px;
overflow: hidden;
border: 1px solid var(--line);
display: block;
}
.tout-thumbs img,
.tout-thumbs video {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.tst {
width: 64px;
text-align: center;
flex-shrink: 0;
}
/* §1.2 ghost:次级文字操作(重试/取消/下载)文字 --text-2,悬停 --text */
.tactions {
display: inline-flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
.link-ghost {
background: none;
border: none;
padding: 4px 6px;
font-family: inherit;
font-size: 12px;
color: var(--text-2);
cursor: pointer;
border-radius: 6px;
text-decoration: none;
display: inline-flex;
align-items: center;
}
@media (hover: hover) and (pointer: fine) {
.link-ghost:hover:not(:disabled) {
color: var(--text);
}
}
.link-ghost:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.link-ghost:disabled {
opacity: 0.5;
cursor: default;
}
.link-danger {
background: none;
border: none;
padding: 4px 6px;
font-family: inherit;
font-size: 12px;
color: var(--err);
cursor: pointer;
border-radius: 6px;
opacity: 0.85;
display: inline-flex;
align-items: center;
}
@media (hover: hover) and (pointer: fine) {
.link-danger:hover:not(:disabled) {
opacity: 1;
background: var(--err-soft);
}
}
.link-danger:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.link-danger:disabled {
opacity: 0.35;
cursor: default;
}
.tag-test {
flex-shrink: 0;
background: var(--bg-4);
color: var(--text-2);
font-size: 10px;
font-weight: 600;
padding: 1px 7px;
border-radius: 999px;
}
/* 窄屏:表格转卡片堆叠 */
@media (max-width: 1023px) {
.tasks-page {
padding: 14px 16px 32px;
}
.trow {
flex-wrap: wrap;
row-gap: 8px;
}
.tout {
order: 5;
width: 100%;
}
.tactions {
order: 6;
margin-left: auto;
}
.tst {
order: 4;
width: auto;
margin-left: auto;
}
.search {
margin-left: 0;
width: 100%;
}
.search input {
width: 100%;
flex: 1;
}
}
</style>