shuishen
9 hours ago 385be2eca72eb3833efa4be0a0088b34e764788a
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<script setup lang="ts">
import { computed, ref } from "vue";
import { DeleteOutlined } from "@ant-design/icons-vue";
import { deletePointCloudSemanticModel, loadPointCloudSemanticModelDeletionPlan, type PointCloudSemanticModelDeletionPlan } from "@/api/artifacts";
 
const props = defineProps<{ modelId: string; label: string; disabled?: boolean }>();
const emit = defineEmits<{ removed: [] }>();
const visible = ref(false);
const loadingPlan = ref(false);
const deleting = ref(false);
const error = ref<string | null>(null);
const plan = ref<PointCloudSemanticModelDeletionPlan | null>(null);
const dependentCount = computed(() => (plan.value?.inferenceDirectories.length ?? 0) + (plan.value?.autoAnnotationDirectories.length ?? 0));
 
async function open() {
  if (props.disabled) return;
  visible.value = true; loadingPlan.value = true; error.value = null; plan.value = null;
  try { plan.value = await loadPointCloudSemanticModelDeletionPlan(props.modelId); }
  catch (reason) { error.value = reason instanceof Error ? reason.message : "无法读取模型删除范围。"; }
  finally { loadingPlan.value = false; }
}
async function confirm() {
  if (!plan.value?.removable) return;
  deleting.value = true; error.value = null;
  try { await deletePointCloudSemanticModel(props.modelId); visible.value = false; emit("removed"); }
  catch (reason) { error.value = reason instanceof Error ? reason.message : "删除模型失败。"; }
  finally { deleting.value = false; }
}
</script>
 
<template>
  <a-tooltip title="删除训练模型及其推理、自动标注产物">
    <a-button type="text" danger size="small" :disabled="disabled" aria-label="删除训练模型" @click="open"><DeleteOutlined /></a-button>
  </a-tooltip>
  <a-modal v-model:open="visible" :title="`移除训练模型:${label}`" :confirm-loading="deleting" :ok-button-props="{ danger: true, disabled: loadingPlan || !plan?.removable }" ok-text="移除模型及关联产物" cancel-text="取消" @ok="confirm">
    <a-spin :spinning="loadingPlan">
      <a-alert v-if="error" type="error" show-icon :message="error" />
      <template v-else-if="plan">
        <a-alert type="warning" show-icon message="此操作不可恢复" description="会删除模型、由它产生的推理和自动标注产物;不会删除人工标注版本、baseData 或外部输入。" />
        <a-descriptions size="small" :column="1" class="deletion-summary">
          <a-descriptions-item label="训练模型目录">{{ plan.trainingDirectories.length }}</a-descriptions-item>
          <a-descriptions-item label="模型推理结果">{{ plan.inferenceDirectories.length }}</a-descriptions-item>
          <a-descriptions-item label="自动标注结果">{{ plan.autoAnnotationDirectories.length }}</a-descriptions-item>
          <a-descriptions-item label="关联结果总数">{{ dependentCount }}</a-descriptions-item>
        </a-descriptions>
      </template>
    </a-spin>
  </a-modal>
</template>
 
<style scoped>
.deletion-summary { margin-top: 16px; }
</style>