am-freescan/am-web/src/views/lab/inspection/ProcessedStlDownload.vue

60 lines
1.7 KiB
Vue

<template>
<div class="stl-download">
<el-button :loading="loading" :disabled="disabled" @click="download">下载处理后 STL</el-button>
<div v-if="loading" class="stl-progress">
<el-progress :percentage="Math.min(100, progress.progress || 0)" :stroke-width="5" />
<span>{{ progress.message || '正在准备 STL' }}</span>
</div>
</div>
</template>
<script setup lang="ts">
import * as Api from '@/api/lab/inspection'
import { ElMessage } from 'element-plus'
import { userMessage } from './display'
import { downloadProcessedStl } from './stlDownload'
const props = defineProps<{ recordId: string; disabled?: boolean }>()
const loading = ref(false),
progress = ref<any>({})
let active = true
onBeforeUnmount(() => {
active = false
})
async function download() {
if (loading.value || props.disabled) return
const recordId = props.recordId
loading.value = true
try {
await downloadProcessedStl(
{
state: () => Api.state(recordId),
start: (revision) => Api.post(recordId, 'cleanup', { operation: 'export_stl', revision }),
file: () => Api.processedStl(recordId),
save: (blob) => Api.saveBlob(blob, '处理后点云.stl')
},
(value) => {
progress.value = value
},
() => active && props.recordId === recordId
)
} catch (error) {
if (active && props.recordId === recordId)
ElMessage.error(userMessage(error, 'STL 下载失败,请重试'))
} finally {
if (active) loading.value = false
}
}
</script>
<style scoped>
.stl-download {
display: inline-flex;
align-items: center;
gap: 12px;
}
.stl-progress {
min-width: 220px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
</style>