Files
short-drama-agent-front/src/features/workflows/HistoryPanel.vue
T

97 lines
3.6 KiB
Vue
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 setup lang="ts">
import { computed, ref } from 'vue'
import { NButton, NScrollbar, NEmpty, NTimeline, NTimelineItem } from 'naive-ui'
import { Clock3 } from '@lucide/vue'
import { formatDate, nodeLabel } from '../../lib/format'
import { workflowCheckpoints } from './selectors'
import type { Checkpoint } from './types'
import WorkflowDiagnosticsDialog from './WorkflowDiagnosticsDialog.vue'
/** 时间线只说明 checkpoint 已保存,不把每条记录误标为工作流成功。 */
const props = defineProps<{ checkpoints: Checkpoint[]; workflow: string; projectId?: string }>()
const emit = defineEmits<{
/** 关闭覆盖层中的执行记录 */
close: []
}>()
const diagnosticsOpen = ref(false)
const history = computed(() => workflowCheckpoints(props.checkpoints, props.workflow).slice(-18).toReversed())
</script>
<template>
<aside class="history-panel">
<NScrollbar class="panel-scroll" content-class="history-content">
<div class="history-heading">
<h3 class="mb-1 flex items-center gap-2 text-sm font-semibold"><Clock3 :size="15" />执行记录</h3>
<NButton class="history-close" text size="small" @click="emit('close')">关闭</NButton>
</div>
<p class="mb-6 text-xs leading-5 text-muted">最近 18 条保存记录 · 自动更新</p>
<NButton v-if="projectId" text size="small" class="mb-4" @click="diagnosticsOpen = true"
>查看完整运行诊断</NButton
>
<NEmpty v-if="!history.length" size="small" description="工作流尚未保存执行记录。" />
<NTimeline v-else>
<NTimelineItem
v-for="item in history"
:key="item.checkpointId"
:type="item.state.workflowExecution?.status === 'failed' ? 'error' : 'default'"
>
<p class="text-xs font-medium">{{ nodeLabel(item.metadata?.nodeName) }}</p>
<p class="mt-1 text-[11px] text-muted">
{{ formatDate(item.createdAt)
}}<span v-if="item.metadata?.nodeDurationMs">
· {{ (item.metadata.nodeDurationMs / 1000).toFixed(1) }}s</span
>
</p>
<span
v-if="item.state.workflowExecution?.status === 'failed'"
class="mt-1 block text-xs text-danger"
>运行失败</span
>
</NTimelineItem>
</NTimeline>
<p class="mt-5 pt-4 text-[11px] leading-5 text-muted">
记录在节点或批次结束后更新,长时间无新记录不一定意味着任务失败。
</p>
</NScrollbar>
<WorkflowDiagnosticsDialog
v-if="projectId"
v-model:open="diagnosticsOpen"
:project-id="projectId"
:checkpoints="checkpoints"
/>
</aside>
</template>
<style>
/* 本组件专属布局与 Naive 内部结构覆盖。 */
@reference "../../styles/styles.css";
.history-panel {
@apply py-[23px] px-[21px] bg-(--app-subtle);
}
@media (max-width: 1200px) {
.history-panel {
border-left: 0;
}
}
.history-panel {
@apply p-0;
}
.history-content {
@apply py-[23px] px-[21px];
}
.history-heading {
@apply flex items-start justify-between gap-3;
}
.history-close {
@apply hidden;
}
@media (max-width: 800px) {
.history-panel {
@apply overflow-hidden min-h-0 bg-(--app-subtle);
}
.history-close {
@apply inline-flex shrink-0;
}
}
</style>