diff --git a/am-web/src/views/lab/inspection/InspectionWorkbench.vue b/am-web/src/views/lab/inspection/InspectionWorkbench.vue index bd29b59..2063ccd 100644 --- a/am-web/src/views/lab/inspection/InspectionWorkbench.vue +++ b/am-web/src/views/lab/inspection/InspectionWorkbench.vue @@ -511,7 +511,18 @@ :disabled="!canArchive" @click="archiveResults" >{{ archived ? '已归档' : '归档' }}{{ delivered ? '已确认交付' : '确认交付' }}
+ {{ archiveProgress.message || '正在准备处理后STL并归档成果,请稍候' }}
import * as Api from '@/api/lab/inspection' +import * as DimensionApi from '@/api/lab/dimension' +import { prepareProcessedStl } from './stlDownload' import { snapshotResultRows, type ResultLoadState, @@ -669,6 +682,10 @@ const panel = ref('model'), cleanupOpened = ref(panel.value === 'cleanup'), cleanupDirty = ref(false) const featureDirty = ref(false) +const archiving = ref(false), + archiveProgress = ref({}), + delivery = ref(), + deliveryRevision = ref() const featureFocus = ref('') const resultNote = (row: any) => getResultNote(row, userMessage) function focusResult(row: any) { @@ -819,7 +836,8 @@ const measuredCount = computed( : inspectionCompletionLabel(current.value) || statusText(current.value.status) ) const archived = computed( - () => current.value.platform_job?.status === 'ARCHIVED' && !!current.value.platform_job?.delivery_id + () => + current.value.platform_job?.status === 'ARCHIVED' && !!current.value.platform_job?.delivery_id ) const canArchive = computed( () => @@ -832,6 +850,28 @@ const canArchive = computed( !featureDirty.value && !current.value.engine_unavailable ) +const delivered = computed(() => delivery.value?.status === 'DELIVERED') +const canConfirmDelivery = computed( + () => + archived.value && + !!delivery.value?.current && + deliveryRevision.value != null && + !delivered.value && + !busy.value && + !dirty.value && + !cleanupDirty.value && + !featureDirty.value +) +async function loadDelivery() { + const job = current.value.platform_job + delivery.value = undefined + deliveryRevision.value = undefined + if (!archived.value || !job.task_id || !job.unit_id) return + const data = await DimensionApi.detail(job.task_id, job.unit_id) + if (!active || current.value.platform_job?.delivery_id !== job.delivery_id) return + delivery.value = data.deliveries.find((row: any) => String(row.id) === String(job.delivery_id)) + deliveryRevision.value = data.case.revision +} const bindingLabel = computed( () => ({ @@ -907,6 +947,7 @@ async function refresh() { const result = await Api.state(props.recordId) if (!active) return current.value = result + await loadDelivery() if (surfaceOnly.value && !availablePanels.value.some((item) => item.id === panel.value)) switchPanel(surfaceReady.value ? 'results' : 'model') if (!surfaceReady.value && surfaceOnly.value) { @@ -1285,12 +1326,32 @@ function archiveResults() { if (!canArchive.value) return const recordId = props.recordId return guard(async () => { - const result = await Api.sync(recordId) + archiving.value = true + archiveProgress.value = {} + let result + try { + const prepared = await prepareProcessedStl( + { + state: () => Api.state(recordId), + start: (revision) => Api.post(recordId, 'cleanup', { operation: 'export_stl', revision }) + }, + (progress) => { + archiveProgress.value = progress + }, + () => active && props.recordId === recordId + ) + if (!prepared || !active || props.recordId !== recordId) return + archiveProgress.value = { progress: 100, message: 'STL已准备完成,正在成套归档STL与PDF' } + result = await Api.sync(recordId) + } finally { + archiving.value = false + } if (!active || props.recordId !== recordId) return current.value = result emit('changed') if (archived.value) { - ElMessage.success('STL与PDF已成套归档,可在任务成果中查看') + await loadDelivery() + ElMessage.success('STL与PDF已成套归档,可点击“确认交付”') } else { error.value = result.platform_job?.last_error || @@ -1299,6 +1360,29 @@ function archiveResults() { } }) } +function confirmDelivery() { + if (!canConfirmDelivery.value) return + const recordId = props.recordId + return guard(async () => { + await loadDelivery() + if (!active || props.recordId !== recordId) return + if (!delivery.value?.current || deliveryRevision.value == null) + throw Error('成果或输入版本已变化,请刷新后核对当前成果') + if (delivered.value) return + const deliveryId = delivery.value.id, + revision = deliveryRevision.value + await ElMessageBox.confirm( + '已核对当前样件、输入版本、比对STL和PDF报告一致,确认交付此成果版本?', + '确认交付' + ) + if (!active || props.recordId !== recordId) return + await DimensionApi.confirm({ deliveryId, revision, filesConfirmed: true }) + if (!active || props.recordId !== recordId) return + emit('changed') + await loadDelivery() + ElMessage.success('已确认交付') + }) +} function escape(e: KeyboardEvent) { if (e.key !== 'Escape' || reportDialog.value || panel.value === 'cleanup') return if (pickSession.value) { @@ -1732,6 +1816,11 @@ onBeforeUnmount(() => { .results-panel > .workspace-actions { margin: 22px 0; } +.archive-progress { + max-width: 560px; + margin: 16px 0; + color: var(--el-text-color-secondary); +} .workspace-empty { padding: 25px; diff --git a/am-web/src/views/lab/inspection/stlDownload.ts b/am-web/src/views/lab/inspection/stlDownload.ts index 6f31248..299443d 100644 --- a/am-web/src/views/lab/inspection/stlDownload.ts +++ b/am-web/src/views/lab/inspection/stlDownload.ts @@ -1,9 +1,7 @@ -export async function downloadProcessedStl( +export async function prepareProcessedStl( api: { state: () => Promise start: (revision: number) => Promise - file: () => Promise - save: (file: Blob) => void }, onProgress: (value: any) => void, active: () => boolean = () => true, @@ -13,27 +11,28 @@ export async function downloadProcessedStl( const started = now() let state = await api.state() if (!active()) return false + const revision = state.revision let progress = state.stl_export || {} + const sameInput = () => { + const input = progress.input_revision + // Some engine versions return an opaque input fingerprint; the archive API verifies it. + return !/^\d{1,10}$/.test(String(input)) || String(input) === String(revision) + } + if (progress.status === 'processing' && !sameInput()) + throw Error('STL正在处理其他输入版本,请等待结束后重试') + if (progress.status === 'done' && !sameInput()) progress = {} if (!['processing', 'done'].includes(progress.status)) - progress = (await api.start(state.revision)).stl_export || {} + progress = (await api.start(revision)).stl_export || {} while (active()) { + if (String(state.revision) !== String(revision) || !sameInput()) + throw Error('输入版本已变化,请刷新后重试') onProgress(progress) if (progress.status === 'done') { - const file = await api.file() - const header = await file.slice(0, 84).arrayBuffer() - if ( - header.byteLength !== 84 || - new DataView(header).getUint32(80, true) < 1 || - file.size !== 84 + 50 * new DataView(header).getUint32(80, true) - ) - throw Error('STL 文件无效,请重新生成') - if (!active()) return false - api.save(file) return true } if (progress.status === 'error' || progress.status === 'stale') throw Error(progress.message || 'STL 生成失败,请重新生成') - if (now() - started > 660000) throw Error('STL 生成时间较长,请稍后重新下载') + if (now() - started > 660000) throw Error('STL 生成时间较长,请稍后重试') await wait() if (!active()) return false state = await api.state() @@ -41,3 +40,29 @@ export async function downloadProcessedStl( } return false } + +export async function downloadProcessedStl( + api: { + state: () => Promise + start: (revision: number) => Promise + file: () => Promise + save: (file: Blob) => void + }, + onProgress: (value: any) => void, + active: () => boolean = () => true, + wait?: () => Promise, + now?: () => number +): Promise { + if (!(await prepareProcessedStl(api, onProgress, active, wait, now)) || !active()) return false + const file = await api.file() + const header = await file.slice(0, 84).arrayBuffer() + if ( + header.byteLength !== 84 || + new DataView(header).getUint32(80, true) < 1 || + file.size !== 84 + 50 * new DataView(header).getUint32(80, true) + ) + throw Error('STL 文件无效,请重新生成') + if (!active()) return false + api.save(file) + return true +}