import { ChangeDetectionStrategy, Component, input } from '@angular/core'; import { DatePipe } from '@angular/common'; import { TaskLifecycle } from '../../core/models/session.model'; export function durationText(value: number | null | undefined): string { if (value == null || !Number.isFinite(value)) return '未记录'; const seconds = Math.max(0, Math.floor(value)); return seconds < 60 ? `${seconds} 秒` : `${Math.floor(seconds / 60)} 分 ${seconds % 60} 秒`; } @Component({ selector: 'app-task-lifecycle', standalone: true, imports: [DatePipe], changeDetection: ChangeDetectionStrategy.OnPush, template: `@if (value(); as progress) {
任务进度 · {{ phase(progress.phase) }}
@for (item of items; track item.key) {
{{ item.label }}
{{ duration(progress.durations[item.key]) }}
}

{{ progress.note || '分项使用实际记录;缺失为未知。执行完成不等于验证通过。' }}

@if (progress.observed_at != null) { 记录更新于 {{ progress.observed_at * 1000 | date:'HH:mm:ss' }} }
}`, styles: [` :host { display: block; } .lifecycle { margin: 8px 0; padding: 10px 12px; border: 1px solid var(--app-border-control, #cbd5e1); border-radius: 8px; color: var(--app-text-control, #1e293b); background: var(--app-surface, #fff); font-size: 12px; } summary { cursor: pointer; font-weight: 600; } dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 12px 0; } dt, p, small { color: var(--app-text-muted, #64748b); } dd { margin: 4px 0 0; font-variant-numeric: tabular-nums; } p { margin: 8px 0; line-height: 1.6; overflow-wrap: anywhere; } `] }) export class TaskLifecycleComponent { value = input(null); duration = durationText; items = [ {key:'total', label:'总历时'}, {key:'queued', label:'后台排队'}, {key:'resource_wait', label:'等待设备/资源'}, {key:'paused', label:'暂停与示范'}, {key:'execution', label:'执行与整理'}, {key:'final_review', label:'最终验收'}, {key:'report_export', label:'报告导出'} ]; phase(value: string): string { return ({queued:'后台排队', waiting_resources:'等待设备/资源', running:'执行中', paused:'已暂停', demonstrating:'人工示范中', analyzing_demo:'正在分析示范', final_review:'正在最终验收', report_export:'正在导出报告', finished:'执行已结束', unknown:'状态未记录'} as Record)[value] || '状态待确认'; } }