shuishen
21 hours ago 8f75db57f3055b2a3575c86ee3e6acf1dd56ce47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
import { ReloadOutlined } from "@ant-design/icons-vue";
import { loadPointCloudTasks, type PointCloudTask } from "@/api/artifacts";
 
const tasks = ref<PointCloudTask[]>([]);
const loading = ref(false);
const error = ref("");
let timer: ReturnType<typeof setTimeout> | undefined;
 
const labels: Record<string, string> = { annotation_source: "标注源处理", training: "模型训练", model_inference: "模型分类", automatic_annotation: "自动标注" };
const active = computed(() => tasks.value.some((task) => ["queued", "running"].includes(task.status)));
const color = (status: PointCloudTask["status"]) => ({ complete: "success", failed: "error", interrupted: "warning", running: "processing", queued: "default" }[status]);
async function refresh() {
  loading.value = true;
  try { tasks.value = await loadPointCloudTasks(); error.value = ""; }
  catch (caught) { error.value = caught instanceof Error ? caught.message : "无法读取任务中心。"; }
  finally { loading.value = false; if (active.value) timer = setTimeout(() => { void refresh(); }, 3_000); }
}
onMounted(() => { void refresh(); });
onBeforeUnmount(() => { if (timer) clearTimeout(timer); });
</script>
 
<template>
  <section class="pointcloud-task-list">
    <div class="task-heading"><div><h3>任务中心</h3><p>任务状态会保存在本机;服务重启中的任务会标为“已中断”,不会伪装为已完成。</p></div><a-tooltip title="刷新任务状态"><a-button type="text" :loading="loading" aria-label="刷新任务状态" @click="refresh"><ReloadOutlined /></a-button></a-tooltip></div>
    <a-alert v-if="error" type="error" show-icon :message="error" />
    <a-list v-else size="small" :data-source="tasks" class="task-rows"><template #renderItem="{ item }"><a-list-item><a-space direction="vertical" :size="2"><a-space wrap><strong>{{ labels[item.kind] }}</strong><a-tag :color="color(item.status)">{{ item.status }}</a-tag><span>{{ item.runId }}</span></a-space><span class="task-stage">{{ item.error || `阶段:${item.stage}` }}</span></a-space></a-list-item></template><template #empty><a-empty description="暂无本机点云任务" /></template></a-list>
  </section>
</template>
 
<style scoped>
.pointcloud-task-list { display: grid; gap: 10px; } .task-heading { display: flex; justify-content: space-between; gap: 12px; align-items: start; } .task-heading h3 { margin: 0; font-size: 15px; } .task-heading p { margin: 4px 0 0; color: #6a7885; font-size: 13px; } .task-rows { max-height: 260px; overflow: auto; } .task-stage { color: #6a7885; font-size: 12px; overflow-wrap: anywhere; }
</style>