am-freescan/am-web/src/views/lab/dimension/ComparisonPanel.vue
lixiaolong c903364fa2 feat: integrate dimension comparison and optimize task workbench
Connect task CAD, PDF and PLY to the supplier workspace and preserve paired result provenance. Add fixture framework download/copy, reduce idle map and task polling, improve tab navigation, and update standalone schema migration.
2026-11-12 10:24:55 +08:00

145 lines
11 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<section class="comparison-panel">
<div class="comparison-heading">
<div><h3>尺寸比对</h3><span class="secondary">自动使用本任务选定的数模、PDF和扫描PLY。</span></div>
<div class="comparison-buttons">
<el-tag :type="health.available ? 'success' : 'info'">{{ health.available ? '计算服务就绪' : '计算服务未就绪' }}</el-tag>
<el-button :loading="loading" @click="refresh(true)">刷新状态</el-button>
<el-button v-hasPermi="['lab:result:query']" @click="router.push('/lab/dimension/inspection-templates')">维护检测计划</el-button>
</div>
</div>
<el-alert v-if="error" :title="error" type="error" :closable="false" />
<el-alert v-else-if="!health.available" :title="health.message || '请先启动本机检测EXE,再刷新状态。'" type="info" :closable="false" />
<el-form label-position="top" class="comparison-options" :disabled="busy">
<el-form-item label="检测计划">
<el-select v-model="options.planTemplateId" filterable class="plan-select">
<el-option label="按图纸及完整零件号自动匹配" value="auto" />
<el-option v-for="item in catalog" :key="item.id" :value="item.id" :label="`${item.label} · V${item.version}`" />
<el-option label="CAD几何检测(无图纸计划)" value="cad-geometry" />
</el-select>
</el-form-item>
<el-collapse><el-collapse-item title="单位与处理设置" name="options">
<div class="comparison-fields">
<el-form-item label="扫描数据单位"><el-select v-model="options.sourceScale"><el-option v-for="item in units" :key="item.value" :label="item.label" :value="item.value" /></el-select></el-form-item>
<el-form-item label="标准数模单位"><el-select v-model="options.targetScale"><el-option v-for="item in units" :key="item.value" :label="item.label" :value="item.value" /></el-select></el-form-item>
<el-form-item label="表面偏差阈值(mm)"><el-input-number v-model="options.tolerance" :min="0.001" :max="100" :precision="3" /></el-form-item>
</div>
<el-checkbox v-model="options.autoReport">计算后自动生成报告</el-checkbox>
<el-checkbox v-model="options.sourceClean">扫描数据已清理,仅含被测零件</el-checkbox>
<el-checkbox v-model="options.reviewCleanup" :disabled="options.sourceClean">对齐前先人工确认点云清理</el-checkbox>
</el-collapse-item></el-collapse>
</el-form>
<div class="comparison-buttons gap">
<el-button type="primary" :loading="busy" :disabled="!ready || dirty || sourceChanged || !health.available || pendingSameInput" v-hasPermi="['lab:data:upload']" @click="start">{{ busy ? '正在提交文件' : '开始尺寸比对' }}</el-button>
<el-button v-if="job.engine_id" type="primary" plain @click="expanded = true">打开比对工作区</el-button>
<el-button v-if="job.engine_id && ['ARCHIVE_ERROR', 'ARCHIVE_PENDING'].includes(job.status)" :loading="syncing" v-hasPermi="['lab:data:upload']" @click="sync">重试成果归档</el-button>
<span v-if="dirty" class="secondary">请先保存选用的资料版本。</span>
<span v-else-if="sourceChanged" class="secondary">扫描记录已更新,请先关联本次PLY。</span>
</div>
<div v-if="job.id" class="comparison-status">
<div class="comparison-heading"><strong>{{ labels[job.status] || job.status }}</strong><span class="secondary">{{ sameInput ? '对应当前输入' : '历史比对,输入版本已更新' }}</span></div>
<el-progress v-if="['SUBMITTING','PROCESSING'].includes(job.status)" :percentage="50" :indeterminate="true" :show-text="false" />
<p v-if="job.last_error" class="comparison-error">{{ job.last_error }}</p>
<p v-else-if="job.status === 'ARCHIVED'">STL与PDF已成套归档,可在下方核对、查看并确认交付。</p>
<p v-else-if="job.status === 'REVIEW'">打开工作区确认清理、测量项或生成新版报告。</p>
<p v-else-if="job.status === 'UNKNOWN'">提交回执未确认,请核对计算服务记录。系统不会自动重复提交。</p>
<p class="secondary">比对作业 {{ job.id }}<span v-if="job.source_execution_id"> · 来源扫描 {{ job.source_execution_id }}</span><span v-if="job.engine_revision"> · 成果版本 {{ job.engine_revision }}</span></p>
</div>
<el-dialog v-model="expanded" title="尺寸比对工作区" width="min(1600px, 97vw)" top="2vh" destroy-on-close append-to-body :before-close="closeWorkspace">
<InspectionWorkbench v-if="job.engine_id" ref="workspace" :key="job.engine_id" :record-id="job.engine_id" @changed="workspaceChanged" @history="closeWorkspace(() => expanded = false)" />
</el-dialog>
</section>
</template>
<script setup lang="ts">
import * as Api from '@/api/lab/inspection'
import { onBeforeUnmount, watch, ref, reactive, computed, defineAsyncComponent } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import '@/views/lab/inspection/inspection.scss'
import { comparisonPollInterval } from '@/views/lab/scan-task/workbenchPolling.mjs'
const InspectionWorkbench = defineAsyncComponent(() => import('@/views/lab/inspection/InspectionWorkbench.vue'))
const props = defineProps<{ taskId: string; unitId: string; revision: number; ready: boolean; dirty: boolean; sourceChanged: boolean; active: boolean; inputs: { modelId: any; drawingId: any; cloudId: any } }>()
const emit = defineEmits<{ changed: [] }>()
const router = useRouter(), job = ref<any>({}), health = ref<any>({}), catalog = ref<any[]>([]), error = ref(''), loading = ref(false), busy = ref(false), syncing = ref(false), expanded = ref(false), workspace = ref<any>()
const options = reactive({ planTemplateId: 'auto', sourceScale: 1, targetScale: 1, tolerance: 0.2, autoReport: true, sourceClean: false, reviewCleanup: false })
const units = [{value: 1,label:'毫米 mm'},{value:1000,label:'米 m'},{value:0.001,label:'微米 μm'}]
const labels: Record<string,string> = {SUBMITTING:'正在提交资料',UNKNOWN:'提交结果待核对',PROCESSING:'计算处理中',REVIEW:'待人工核对',ARCHIVE_PENDING:'计算完成,正在归档',ARCHIVE_ERROR:'计算完成,成果归档待处理',ARCHIVED:'成果已成套归档',FAILED:'比对失败'}
const sameInput = computed(() => {
// Historical snapshots stored Snowflake IDs as JSON integers; preserve them before parsing.
try { const frozen = JSON.parse((job.value.input_json || '{}').replace(/"id"\s*:\s*(\d{16,})(?=\s*[,}])/g, '"id":"$1"')); return String(frozen.model?.id || '') === String(props.inputs.modelId || '') && String(frozen.drawing?.id || '') === String(props.inputs.drawingId || '') && String(frozen.cloud?.id || '') === String(props.inputs.cloudId || '') }
catch { return false }
})
const pendingSameInput = computed(() => sameInput.value && ['SUBMITTING','UNKNOWN','PROCESSING','REVIEW','ARCHIVE_PENDING','ARCHIVE_ERROR'].includes(job.value.status))
let timer: ReturnType<typeof setTimeout> | undefined, generation = 0, abort: AbortController | undefined
let lastDelivery = ''
let suspended=false
function schedulePoll(token:number){clearTimeout(timer);const delay=comparisonPollInterval(job.value.status);if(delay&&token===generation&&props.active&&!suspended&&!document.hidden)timer=setTimeout(()=>refresh(),delay)}
async function refresh(withHealth = false) {
if (!props.active || !props.unitId || suspended || document.hidden || loading.value) return
const current = generation
loading.value = true
error.value = ''
try {
const [currentJob, state, plans] = await Promise.all([Api.comparison(props.taskId,props.unitId,abort?.signal),withHealth ? Api.health() : Promise.resolve(null),withHealth ? Api.templates() : Promise.resolve(null)])
if (current !== generation) return
job.value = currentJob || {}
if (state) health.value = state
if (plans) catalog.value = plans.templates || []
const delivery = String(job.value.delivery_id || '')
if (delivery && lastDelivery && delivery !== lastDelivery) emit('changed')
if (delivery && !lastDelivery) emit('changed')
lastDelivery = delivery
} catch (e: any) { if (current === generation && !abort?.signal.aborted) error.value = e?.message || '读取比对状态失败' }
finally { if(current === generation) { loading.value = false;schedulePoll(current) } }
}
watch(() => [props.taskId,props.unitId,props.active], async () => {
generation++; abort?.abort(); abort = new AbortController(); clearTimeout(timer); loading.value=false;job.value = {}; lastDelivery = ''
if (props.active && props.unitId && props.unitId !== '0') await refresh(true)
},{immediate:true})
async function start() {
if (busy.value) return
const token = generation
busy.value = true; error.value = ''
try {
const started = await Api.startComparison({taskId:props.taskId,unitId:props.unitId,revision:props.revision,...options})
if (token !== generation) return
job.value = started
schedulePoll(token)
emit('changed')
if (job.value.engine_id) expanded.value = true
} catch(e:any) { if(token === generation) { error.value = e?.message || '提交失败,请刷新状态后核对'; await refresh() } }
finally { busy.value = false }
}
async function sync() {
if (syncing.value || !job.value.engine_id) return
syncing.value = true
try { await Api.sync(job.value.engine_id); await refresh(); emit('changed'); ElMessage.success('已更新归档状态') }
catch(e:any) { error.value = e?.message || '归档尚未完成' }
finally { syncing.value = false }
}
async function workspaceChanged() { await refresh(); emit('changed') }
async function canLeave() { return !expanded.value || !workspace.value || await workspace.value.confirmLeave() }
async function closeWorkspace(done: () => void) { if(await canLeave()) { done(); await workspaceChanged() } }
defineExpose({ canLeave })
function visibilityChanged(){if(document.hidden)clearTimeout(timer);else if(props.active&&comparisonPollInterval(job.value.status))void refresh()}
onMounted(()=>document.addEventListener('visibilitychange',visibilityChanged))
onActivated(()=>{suspended=false;if(props.active)void refresh()})
onDeactivated(()=>{suspended=true;clearTimeout(timer);generation++;abort?.abort();abort=new AbortController();loading.value=false})
onBeforeUnmount(() => { generation++; clearTimeout(timer); abort?.abort();document.removeEventListener('visibilitychange',visibilityChanged) })
</script>
<style scoped>
.comparison-panel { margin: 16px 0 24px; }
.comparison-heading { display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap; }
.comparison-heading h3 { margin: 0 0 6px; }
.comparison-buttons { display:flex;align-items:center;gap:10px;flex-wrap:wrap; }
.comparison-options { margin-top:18px; }
.plan-select { max-width:620px; }
.comparison-fields { display:grid;grid-template-columns:repeat(3,minmax(140px,1fr));gap:16px; }
.comparison-status { padding:14px 0;border-top:1px solid var(--el-border-color-lighter); }
.comparison-status p { margin:10px 0; }
.comparison-error { color:var(--el-color-warning);white-space:pre-wrap; }
.secondary { color:var(--el-text-color-secondary);font-size:12px;overflow-wrap:anywhere; }
.gap { margin-top:16px; }
@media(max-width:700px) { .comparison-fields { grid-template-columns:1fr; } }
</style>