Files
aigc-home/calliope-web/src/lib/components/workbench/JobChip.svelte
T

104 lines
2.2 KiB
Svelte

<script lang="ts">
import type { WorkbenchJobBrief } from '$lib/api';
import { progressFor } from '$lib/jobProgress';
import { t } from '$lib/i18n.svelte';
/**
* Inline workbench job state chip (spec §5 任务条目四态):
* 排队灰 / 进行中琥珀百分比 / 完成绿 / 失败红(附原因).
*/
interface Props {
job: WorkbenchJobBrief;
}
let { job }: Props = $props();
const live = $derived(progressFor(job.id));
const pct = $derived(live?.progress ?? null);
const state = $derived(
job.status === 'done'
? 'done'
: job.status === 'failed'
? 'failed'
: job.status === 'running'
? 'running'
: 'pending',
);
</script>
<span class="job-chip st-{state}" data-testid="wb-job-chip">
{#if state === 'running'}
<span class="breath" aria-hidden="true"></span>
{#if pct != null}{t('workbench.jobRunningPct', { n: Math.round(pct) })}{:else}{t('workbench.jobRunning')}{/if}
{:else if state === 'pending'}
{t('workbench.jobQueued')}
{:else if state === 'done'}
{t('workbench.jobDone')}
{:else}
{t('workbench.jobFailed')}
{/if}
</span>
{#if state === 'failed' && job.error}
<span class="job-error">{job.error}</span>
{/if}
<style>
.job-chip {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 1px 9px;
border-radius: 999px;
font-size: 10.5px;
font-weight: 600;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.st-pending {
color: var(--text-2);
background: var(--surface-3);
}
.st-running {
color: var(--run);
background: var(--run-soft);
}
.st-done {
color: var(--success);
background: var(--success-dim);
}
.st-failed {
color: var(--error);
background: var(--error-dim);
}
.job-error {
display: block;
font-size: 11px;
color: var(--error);
line-height: 1.5;
margin-top: 2px;
}
.breath {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--run);
animation: var(--decorative-loop-name, motion-jobchip-wb-chip-breath) 2s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}
@keyframes -global-motion-jobchip-wb-chip-breath {
0%,
100% {
opacity: 0.35;
}
50% {
opacity: 1;
}
}
@media (prefers-reduced-motion: reduce) {
.breath {
animation: none;
}
}
</style>