feat(inspection): prepare STL for direct archive and confirm delivery

This commit is contained in:
Codex 2026-11-26 16:12:35 +08:00
parent e3fb31479e
commit e228a0ac82
2 changed files with 132 additions and 18 deletions

View File

@ -511,7 +511,18 @@
:disabled="!canArchive"
@click="archiveResults"
>{{ archived ? '已归档' : '归档' }}</el-button
><el-button
v-if="archived"
v-hasPermi="['lab:document:publish']"
type="primary"
:loading="busy"
:disabled="!canConfirmDelivery"
@click="confirmDelivery"
>{{ delivered ? '已确认交付' : '确认交付' }}</el-button
></div
><div v-if="archiving" class="archive-progress" role="status"
><el-progress :percentage="Math.max(0, Math.min(100, archiveProgress.progress || 0))" />
<span>{{ archiveProgress.message || '正在准备处理后STL并归档成果,请稍候' }}</span></div
><el-empty
v-if="!hasReport"
:description="
@ -622,6 +633,8 @@
</template>
<script setup lang="ts">
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<any>({}),
delivery = ref<any>(),
deliveryRevision = ref<number>()
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;

View File

@ -1,9 +1,7 @@
export async function downloadProcessedStl(
export async function prepareProcessedStl(
api: {
state: () => Promise<any>
start: (revision: number) => Promise<any>
file: () => Promise<Blob>
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<any>
start: (revision: number) => Promise<any>
file: () => Promise<Blob>
save: (file: Blob) => void
},
onProgress: (value: any) => void,
active: () => boolean = () => true,
wait?: () => Promise<void>,
now?: () => number
): Promise<boolean> {
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
}