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

1409 lines
46 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>
<div class="inspection-workspace" v-loading="initialLoading">
<el-alert v-if="error" :title="error" type="error" show-icon @close="error = ''" />
<section class="inspect-panel task-overview">
<div class="task-heading"
><div
><div class="inspect-sub">检测任务 / {{ recordId }}</div
><h2>{{ current.title || '读取检测任务…' }}</h2></div
><el-tag :type="statusType">{{ statusLabel }}</el-tag
><el-button :disabled="busy" @click="reload">刷新状态</el-button></div
>
<el-progress v-if="processing" :percentage="current.progress || 0" />
<el-alert
v-if="current.engine_unavailable"
title="计算服务暂不可用,当前显示已保存的记录和报告;三维交互需计算服务恢复。"
type="warning"
:closable="false"
/>
<el-alert
v-else-if="current.message && !ready"
:title="current.message"
:type="current.status === 'error' ? 'error' : 'info'"
:closable="false"
/>
<el-alert
v-if="current.auto_measure_error"
:title="current.auto_measure_error"
type="error"
:closable="false"
/>
<el-alert
v-if="current.summary?.validity?.status === 'review_required'"
:title="current.summary.validity.verdict || '计算结果需要人工复核,尚不代表零件检测合格。'"
type="warning"
show-icon
:closable="false"
/>
<div class="task-files"
><span><Icon icon="ep:aim" />扫描:{{ inputs.source?.name || '—' }}</span
><span><Icon icon="ep:box" />数模:{{ inputs.target?.name || '—' }}</span
><span><Icon icon="ep:document" />图纸:{{ inputs.drawing?.name || '未上传' }}</span></div
>
<div class="workspace-nav" role="tablist" aria-label="检测工作区"
><button
v-for="item in panels"
:key="item.id"
type="button"
role="tab"
:aria-selected="panel === item.id"
:class="{ active: panel === item.id }"
@click="switchPanel(item.id)"
><Icon :icon="item.icon" :size="20" /><span
><strong>{{ item.title }}</strong
><small>{{ item.text }}</small></span
></button
></div
>
</section>
<InspectionCleanup
v-if="cleanupOpened && (current.preview_available || ready || current.status === 'review')"
v-show="panel === 'cleanup' && !processing"
:key="current.revision"
:record-id="recordId"
:blocked="dirty"
@dirty="cleanupDirty = $event"
@applied="cleaned"
/>
<el-alert
v-if="panel === 'cleanup' && processing"
title="正在读取文件或重新计算,完成后可继续处理点云。"
type="info"
:closable="false"
/>
<section
v-show="panel !== 'results' && panel !== 'cleanup'"
class="inspect-panel workspace-visual"
>
<div class="workspace-section-heading"
><div
><h3>{{ panel === 'plan' ? '测量位置与几何调整' : '数模与点云对比' }}</h3
><p>{{
panel === 'plan'
? '先选择检测项,在三维视图核对位置;可切换推荐几何或重新选点。'
: '设计数模与扫描点云共用设计坐标系,切换图层检查清理和对齐效果。'
}}</p></div
><div class="workspace-actions"
><el-button v-if="ready" @click="switchPanel('cleanup')">配置点云处理</el-button
><el-button :loading="cloudLoading" :disabled="processing" @click="loadVisual(true)"
>重新加载三维</el-button
></div
></div
>
<div v-if="visualError" class="visual-error"><Icon icon="ep:warning" />{{ visualError }}</div>
<div v-if="panel === 'plan' && dirty" class="workspace-dirty"
>有未保存的计划或绑定修改。保存后可重新测量;原有报告版本仍保留。</div
>
<div v-if="panel === 'plan' && ready && selectedRow" class="binding-quickbar">
<strong>{{ selectedIndex + 1 }}. {{ selectedRow.name }}</strong>
<el-button v-if="isCircle" size="small" :disabled="!aligned" @click="beginPick('circle')"
>三点指定圆截面</el-button
>
<el-button
v-if="selectedRow.table === 'feature'"
size="small"
:disabled="!aligned"
@click="beginPick('center')"
>点选近似位置</el-button
>
<el-button
v-if="selectedRow.table === 'gauge'"
size="small"
:disabled="!aligned"
@click="beginPick('pair')"
>点间距 A / B</el-button
>
<el-button size="small" :disabled="!undoStack.length" @click="undoBinding"
>撤销调整</el-button
>
<span>Esc 取消选点 / 撤销调整</span>
</div>
<div class="binding-layout" :class="{ 'is-plan': panel === 'plan' }">
<aside v-if="panel === 'plan'" class="binding-list"
><el-input v-model="itemFilter" placeholder="搜索检测项" clearable /><div
class="binding-count"
>{{ rows.length }} 项 · {{ measuredCount }} 项有测量值</div
><div class="binding-scroll"
><button
v-for="entry in filteredRows"
:key="entry.index"
type="button"
:class="['binding-list-item', { selected: selectedIndex === entry.index }]"
@click="select(entry.index)"
><strong>{{ entry.index + 1 }}. {{ entry.row.name }}</strong
><small>{{ entry.row.control }} · 名义 {{ entry.row.nominal_mm ?? '—' }} mm</small
><span
>{{ entry.row.measured_mm ?? entry.row.trial_measured_mm ?? '—' }}
<i v-if="entry.row.measured_mm != null || entry.row.trial_measured_mm != null">mm</i
><em>{{
entry.row.inspection_result || entry.row.measurement_status || '待测'
}}</em></span
></button
></div
></aside
>
<div class="binding-view"
><InspectionViewer
ref="viewer"
:points="visual.points || []"
:reference="visual.reference || []"
:mesh="visual.mesh"
:thermal="visual.thermal"
:total="visual.total || 0"
:frame="visual.coordinate_frame || 'source_mm'"
:loading="cloudLoading"
:hint="panel === 'plan' ? selectedRow?.geometry_hint : undefined"
:seeds="pickSession?.points || []"
:pick="pickLabel"
:empty-message="processing ? '正在处理,三维预览将在数据就绪后加载' : visualError"
@point="pickPoint"
@cancel="cancelPick"
/><div class="inspect-sub viewer-sampling"
>三维窗口使用轻量显示数据,正式测量使用完整保留点云和原始设计网格。</div
></div
>
</div>
<div v-if="panel === 'model'" class="model-summary"
><div
><span>点云清理</span
><strong
>{{
current.summary?.cleanup?.retained_count?.toLocaleString() ||
current.kept?.toLocaleString() ||
'—'
}}
/
{{
current.summary?.cleanup?.original_count?.toLocaleString() ||
current.total?.toLocaleString() ||
'—'
}}</strong
><small>保留点 / 原始点</small></div
><div
><span>表面 RMS</span
><strong>{{ number(current.summary?.statistics?.rms_mm) }} <small>mm</small></strong
><small>点到设计表面的偏差</small></div
><div
><span>检测计划</span><strong>{{ rows.length }} <small>项</small></strong
><small>{{ current.automatic_setup?.template?.label || '当前任务计划' }}</small></div
><div
><span>下一步</span
><el-button type="primary" :disabled="!ready" @click="switchPanel('plan')"
>核对计划与选点 <Icon icon="ep:right" class="ml-6px" /></el-button
><small>可修正几何位置与公差</small></div
></div
>
<template v-if="panel === 'plan'">
<div v-if="!ready" class="workspace-empty"
><el-empty description="请先完成点云清理与配准,再调整测量计划" /><el-button
v-if="current.status === 'review'"
type="primary"
:loading="busy"
@click="compare"
>确认保留点云并开始比对</el-button
></div
>
<div v-else-if="selectedRow" class="binding-editor">
<div class="workspace-section-heading"
><div
><h3>{{ selectedIndex + 1 }}. {{ selectedRow.name }}</h3
><p>{{ selectedRow.control }} · {{ bindingLabel }} · 设计坐标系 / mm</p></div
><div class="workspace-actions"
><el-button :disabled="selectedIndex <= 0" @click="select(selectedIndex - 1)"
>上一项</el-button
><el-button
:disabled="selectedIndex >= rows.length - 1"
@click="select(selectedIndex + 1)"
>下一项</el-button
><el-button :disabled="!undoStack.length" @click="undoBinding"
>撤销调整</el-button
></div
></div
>
<div class="binding-editor-grid"
><div
><div class="binding-method"
><strong>设计几何推荐</strong
><el-button
link
type="primary"
:loading="proposalsLoading"
:disabled="busy || !!current.engine_unavailable"
@click="recommend"
>提取 / 刷新推荐</el-button
></div
><el-select
v-model="candidateChoice"
placeholder="选择候选,三维中立即定位"
class="w-full"
@change="chooseCandidate"
><el-option
v-for="(c, i) in candidates[selectedIndex] || []"
:key="c.id"
:value="i"
:label="c.label" /></el-select
><div class="binding-help"
>优先使用 CAD
圆或平面拟合。推荐仅辅助定位,可根据三维位置换选,生成报告时自动确认并计算。</div
>
<div class="workspace-actions"
><el-button
v-if="selectedRow.table === 'feature'"
:disabled="!aligned"
@click="beginPick('center')"
>点选近似位置</el-button
><el-button v-if="isCircle" :disabled="!aligned" @click="beginPick('circle')"
>三点指定圆截面</el-button
><el-button
v-if="selectedRow.table === 'gauge'"
:disabled="!aligned"
@click="beginPick('pair')"
>改用扫描点间距 A / B</el-button
><el-button @click="clearBinding">清除绑定</el-button></div
>
<div class="binding-help">{{
selectedRow.table === 'gauge'
? '点间距使用两个真实扫描点,会将本项控制方式改为点间距。孔心距、面距请选对应 CAD 几何推荐。'
: '近似位置用于查找附近 CAD 圆;三点指定需在同一截面选择分散圆周点,测量时再用附近扫描点拟合。'
}}</div
><el-alert
v-if="selectedRow.measurement_reason"
:title="selectedRow.measurement_reason"
type="info"
:closable="false"
/></div>
<div class="binding-fields"
><el-form label-position="top" size="small"
><el-row :gutter="12"
><el-col :span="12"
><el-form-item label="名义值 / mm"
><el-input
v-model="selectedRow.nominal_mm"
@change="invalidateSelected" /></el-form-item></el-col
><el-col :span="12"
><el-form-item label="公差"
><el-input
v-model="selectedRow.tol_text"
placeholder="如 ±0.1"
@change="invalidateSelected" /></el-form-item></el-col></el-row></el-form
><div class="binding-values"
><span
>测量值<strong
>{{
number(selectedRow.measured_mm ?? selectedRow.trial_measured_mm)
}}
mm</strong
></span
><span
>判定<strong>{{ selectedRow.inspection_result || '待重测' }}</strong></span
></div
><div class="binding-coordinates"
><span>中心 / A</span
><code>{{
pointText(
selectedRow.geometry_hint?.approx_center_mm ||
selectedRow.geometry_hint?.point_a
)
}}</code
><span>B</span><code>{{ pointText(selectedRow.geometry_hint?.point_b) }}</code></div
></div
></div
> </div
><div v-else class="workspace-empty"
>当前任务暂无检测项,可导入 CSV / JSON 或载入检测模板。</div
>
</template>
<div v-if="current.status === 'review' && panel === 'model'" class="workspace-bottom"
><span>当前为原始扫描坐标,确认保留点云后执行配准。</span
><el-button type="primary" :loading="busy" @click="compare"
>确认点云并开始比对</el-button
></div
>
</section>
<section v-if="panel === 'plan' && ready" class="inspect-panel plan-table-panel"
><div class="workspace-section-heading"
><div
><h3>完整检测计划</h3
><p>点击一行即可在上方定位并调整;修改不会直接覆盖已归档报告。</p></div
><div class="workspace-actions"
><el-select v-model="selectedTemplate" placeholder="选择检测模板" style="width: 240px"
><el-option
v-for="t in catalog.filter((t) => t.automatic)"
:key="t.id"
:value="t.id"
:label="`${t.label} · V${t.version}`" /></el-select
><el-button :disabled="!selectedTemplate || busy" @click="applyTemplate"
>载入模板</el-button
><el-button :disabled="busy" @click="importInput?.click()">导入计划</el-button
><el-button @click="router.push('/lab/dimension/inspection-templates')"
>模板维护</el-button
><input
ref="importInput"
type="file"
accept=".csv,.json"
hidden
@change="importPlan" /></div
></div>
<el-table
:data="rows"
border
max-height="450"
highlight-current-row
:row-class-name="
({ rowIndex }: any) => (rowIndex === selectedIndex ? 'is-selected-row' : '')
"
@row-click="(row: any) => select(rows.indexOf(row), true)"
><el-table-column type="index" width="55" /><el-table-column
prop="name"
label="检测项"
min-width="180"
/><el-table-column prop="control" label="控制" width="100" /><el-table-column
label="名义 / mm"
width="115"
><template #default="s"
><el-input
v-model="s.row.nominal_mm"
size="small"
@change="invalidate(s.row)" /></template></el-table-column
><el-table-column label="公差" width="130"
><template #default="s"
><el-input
v-model="s.row.tol_text"
size="small"
@change="invalidate(s.row)" /></template></el-table-column
><el-table-column label="测量 / mm" width="115"
><template #default="s">{{
number(s.row.measured_mm ?? s.row.trial_measured_mm)
}}</template></el-table-column
><el-table-column prop="inspection_result" label="判定" width="100" /><el-table-column
label="几何绑定"
width="100"
><template #default="s">{{
s.row.geometry_hint?.binding_status === 'bound' ? '已绑定' : '待核对'
}}</template></el-table-column
><el-table-column label="操作" width="100" fixed="right"
><template #default="s"
><el-button link type="primary" @click.stop="select(rows.indexOf(s.row), true)"
>定位 / 调整</el-button
></template
></el-table-column
></el-table
>
</section>
<section v-if="panel === 'results'" class="inspect-panel results-panel"
><el-alert
v-if="dirty"
title="当前计划有未重测的修改;此处报告和色谱对应上一次计算。请保存并重新测量后查看新版报告。"
type="warning"
:closable="false"
/>
<div class="workspace-section-heading"
><div
><h3>检测结果与报告</h3
><p>测量结果、表面色谱和报告下载集中展示,历史成果版本返回任务查看。</p></div
><div class="workspace-actions"
><el-button @click="switchPanel('plan')">调整计划与选点</el-button
><el-button @click="emit('history')">历史成果</el-button></div
></div
><div class="result-metrics"
><div
><span>参与统计点数</span
><strong>{{ current.summary?.statistics?.count?.toLocaleString() ?? '—' }}</strong></div
><div
><span>均方根偏差 / mm</span
><strong>{{ number(current.summary?.statistics?.rms_mm) }}</strong></div
><div
><span>有测量值</span><strong>{{ measuredCount }} / {{ rows.length }}</strong></div
><div
><span>通过 / 超差</span
><strong
>{{ rows.filter((r) => r.inspection_result === '通过').length }} /
{{ rows.filter((r) => r.inspection_result === '失败').length }}</strong
></div
></div
>
<div v-if="hasReport" class="workspace-actions"
><el-button type="primary" :loading="busy" @click="previewReport">预览报告</el-button
><el-button :loading="busy" @click="download('report_signed_chromatogram.pdf')"
>下载 PDF</el-button
><el-button :loading="busy" @click="download('result.zip')">下载结果包</el-button
><el-button :loading="busy" @click="download('aligned_colored.ply')"
>下载处理后点云</el-button
><el-button :loading="busy" @click="download('worker.log')">处理日志</el-button></div
><el-empty
v-else
:description="
processing ? '正在测量与生成报告,请稍候' : '报告尚未生成,可在计划核对后点击生成报告'
"
/><img
v-if="chromatogram"
:src="chromatogram"
class="workspace-spectrum"
alt="零件表面偏差色谱"
/>
<el-table v-if="rows.length" :data="rows" border
><el-table-column prop="name" label="检测项" min-width="200" /><el-table-column
prop="control"
label="控制"
/><el-table-column prop="nominal_mm" label="名义 / mm" /><el-table-column label="测量 / mm"
><template #default="s">{{
number(s.row.measured_mm ?? s.row.trial_measured_mm)
}}</template></el-table-column
><el-table-column prop="tol_text" label="公差" /><el-table-column
prop="inspection_result"
label="判定"
/><el-table-column label="操作" width="100"
><template #default="s"
><el-button link type="primary" @click="reviewRow(s.row)">定位复核</el-button></template
></el-table-column
></el-table
>
</section>
<div v-if="ready" class="workspace-savebar"
><div
><strong>{{ dirty ? '有修改待保存' : '计划已同步' }}</strong
><span
>{{ rows.length }} 个检测项 ·
{{ panel === 'plan' ? '选择左侧检测项进行调整' : '可进入计划与选点核对测量位置' }}</span
></div
><div class="workspace-actions"
><el-button v-if="panel !== 'plan'" @click="switchPanel('plan')">计划与选点</el-button
><el-button
v-hasPermi="['lab:result:confirm']"
:disabled="!dirty || busy || !!pickSession"
@click="savePlan"
>保存计划</el-button
><el-button
v-hasPermi="['lab:result:confirm']"
type="primary"
:loading="busy"
:disabled="!!pickSession"
@click="generate"
>{{ dirty ? '保存并重新测量' : '重新测量 / 生成报告' }}</el-button
></div
></div
>
<el-dialog v-model="reportDialog" title="三维检测报告" width="90%" destroy-on-close
><iframe
v-if="reportHtml"
:srcdoc="reportHtml"
sandbox=""
referrerpolicy="no-referrer"
title="三维检测报告预览"
class="inspect-report-frame"
/><iframe
v-else-if="reportPdfUrl"
:src="reportPdfUrl"
title="归档PDF报告预览"
class="inspect-report-frame"
/><template #footer
><el-button @click="download('report_signed_chromatogram.pdf')"
>下载 PDF</el-button
></template
></el-dialog
>
</div>
</template>
<script setup lang="ts">
import * as Api from '@/api/lab/inspection'
import { ElMessage, ElMessageBox } from 'element-plus'
import InspectionViewer from './InspectionViewer.vue'
import InspectionCleanup from './InspectionCleanup.vue'
import { clone, applyHint, circleThrough, xyz, distance, type Vec3 } from './geometry'
import { statusText } from './display'
const props = defineProps<{ recordId: string }>(),
router = useRouter()
const emit = defineEmits<{ changed: []; history: [] }>()
const current = ref<any>({}),
inputs = ref<any>({}),
rows = ref<any[]>([]),
catalog = ref<any[]>([]),
visual = shallowRef<any>({}),
error = ref(''),
visualError = ref(''),
initialLoading = ref(true),
cloudLoading = ref(false),
busy = ref(false),
proposalsLoading = ref(false)
const panel = ref('model'),
selectedIndex = ref(0),
itemFilter = ref(''),
selectedTemplate = ref(''),
candidates = ref<any[][]>([]),
candidateChoice = ref<number>(),
reportDialog = ref(false),
reportHtml = ref(''),
reportPdfUrl = ref(''),
chromatogram = ref(''),
cleanupOpened = ref(panel.value === 'cleanup'),
cleanupDirty = ref(false)
const viewer = ref<InstanceType<typeof InspectionViewer>>(),
importInput = ref<HTMLInputElement>(),
undoStack = ref<{ index: number; row: any }[]>([]),
pickSession = ref<{ mode: string; index: number; points: Vec3[] } | null>(null)
const baseline = ref('[]'),
dirty = computed(() => JSON.stringify(rows.value) !== baseline.value),
selectedRow = computed(() => rows.value[selectedIndex.value]),
ready = computed(() => current.value.status === 'done'),
processing = computed(() => current.value.status === 'processing'),
aligned = computed(() => visual.value.coordinate_frame === 'target_mm' && ready.value),
isCircle = computed(
() =>
selectedRow.value?.table === 'feature' &&
['circle', 'hole', 'cylinder'].includes(selectedRow.value?.type || 'circle')
)
const measuredCount = computed(
() => rows.value.filter((r) => r.measured_mm != null || r.trial_measured_mm != null).length
),
filteredRows = computed(() =>
rows.value
.map((row, index) => ({ row, index }))
.filter((v) => !itemFilter.value || v.row.name?.includes(itemFilter.value))
),
hasReport = computed(
() => current.value.report_ready !== false && ['done', 'blocked'].includes(current.value.status)
),
statusType = computed(() =>
current.value.summary?.validity?.status === 'review_required'
? 'warning'
: ready.value
? 'success'
: ['error', 'blocked'].includes(current.value.status)
? 'danger'
: 'info'
),
statusLabel = computed(() =>
processing.value
? '计算中'
: current.value.summary?.validity?.status === 'review_required'
? '计算完成 · 待复核'
: ready.value && current.value.report_ready === false
? '计划已计算 · 待生成报告'
: statusText(current.value.status)
)
const bindingLabel = computed(
() =>
({
bound: '已绑定',
candidate: '设计候选',
incomplete: '绑定未完整',
needs_rebind: '需要重新绑定'
})[selectedRow.value?.geometry_hint?.binding_status] || '未绑定'
)
const pickLabel = computed(() =>
!pickSession.value
? ''
: pickSession.value.mode === 'circle'
? `选取同一截面圆周点 ${pickSession.value.points.length + 1} / 3`
: pickSession.value.mode === 'pair'
? `选择扫描端点 ${pickSession.value.points.length ? 'B' : 'A'}(点间距)`
: '选择近似位置'
)
const panels = [
{ id: 'cleanup', icon: 'ep:filter', title: '点云处理', text: '去噪 / 裁剪 / 主体' },
{ id: 'model', icon: 'ep:box', title: '三维查看', text: '数模 / 点云 / 对齐' },
{ id: 'plan', icon: 'ep:aim', title: '计划与选点', text: '定位 / 调整 / 重测' },
{ id: 'results', icon: 'ep:document-checked', title: '结果与报告', text: '色谱 / 测量 / 下载' }
]
let active = true,
timer: ReturnType<typeof setTimeout> | undefined,
visualRequest = 0,
proposalRequest = 0,
lastPlanRevision = '',
lastVisualRevision = '',
expectReport = false
const number = (v: any) =>
v == null || v === '' ? '—' : Number.isFinite(Number(v)) ? Number(v).toFixed(3) : '—'
const pointText = (v: any) => (xyz(v) ? v.map((n) => n.toFixed(3)).join(' , ') : '—')
async function guard(fn: () => Promise<void>) {
if (busy.value) return
busy.value = true
error.value = ''
try {
await fn()
} catch (e: any) {
if (e !== 'cancel' && e !== 'close') {
error.value = e?.message || String(e)
ElMessage.error(error.value)
}
} finally {
busy.value = false
}
}
function acceptRows(value: any[]) {
rows.value = value
baseline.value = JSON.stringify(value)
selectedIndex.value = Math.min(selectedIndex.value, Math.max(0, value.length - 1))
undoStack.value = []
candidates.value = []
pickSession.value = null
candidateChoice.value = undefined
}
async function refresh() {
clearTimeout(timer)
try {
const result = await Api.state(props.recordId)
if (!active) return
current.value = result
if (result.engine_unavailable) {
timer = setTimeout(refresh, 5000)
return
}
if (result.status === 'review' && panel.value === 'model') switchPanel('cleanup')
if (result.inputs) inputs.value = result.inputs
if (processing.value && !result.engine_unavailable) {
timer = setTimeout(refresh, 1800)
return
}
const rev = String(result.report_revision || result.revision || 'initial')
if (ready.value && (lastPlanRevision !== rev || !rows.value.length) && !dirty.value) {
const data = await Api.get(props.recordId, 'plan')
if (!active) return
acceptRows(data.rows || [])
lastPlanRevision = rev
}
if (
(ready.value || result.preview_available || result.status === 'review') &&
!result.engine_unavailable &&
lastVisualRevision !== `${result.status}:${rev}`
) {
await loadVisual()
lastVisualRevision = `${result.status}:${rev}`
}
if (hasReport.value && !chromatogram.value) {
try {
const image = await Api.artifact(props.recordId, 'chromatogram_signed.png')
if (active) chromatogram.value = URL.createObjectURL(image)
} catch {
/* A diagnostic report may not have a chromatogram. */
}
}
if (expectReport && !processing.value) {
expectReport = false
switchPanel('results')
if (!hasReport.value) error.value = result.auto_measure_error || '报告未生成,请查看处理日志'
}
} catch (e: any) {
if (active) error.value = e?.message || '读取检测状态失败'
} finally {
initialLoading.value = false
}
}
async function reload() {
if (dirty.value) {
await guard(async () => {
await ElMessageBox.confirm('刷新计划将放弃未保存的修改,是否继续?', '刷新检测任务')
const data = await Api.get(props.recordId, 'plan')
acceptRows(data.rows || [])
lastPlanRevision = ''
lastVisualRevision = ''
await refresh()
})
} else {
lastPlanRevision = ''
lastVisualRevision = ''
await refresh()
}
}
async function loadVisual(force = false) {
if (cloudLoading.value && !force) return
const owner = ++visualRequest
cloudLoading.value = true
visualError.value = ''
try {
const data = await Api.get(props.recordId, ready.value ? 'plan-preview' : 'preview')
if (!active || owner !== visualRequest) return
visual.value = ready.value
? data
: {
points: data.points.filter((_: any, i: number) => data.retained[i]),
total: data.kept,
coordinate_frame: 'source_mm'
}
if (data.mesh_warning) visualError.value = '显示网格未加载,当前展示设计表面采样点。'
} catch (e: any) {
if (owner === visualRequest)
visualError.value = e?.message || '三维数据暂不可用,请稍后重新加载'
} finally {
if (owner === visualRequest) cloudLoading.value = false
}
}
function switchPanel(value: string) {
cancelPick()
panel.value = value
if (value === 'cleanup') cleanupOpened.value = true
if (value === 'plan' && !candidates.value.length && ready.value && !proposalsLoading.value)
void recommend()
nextTick(() => viewer.value?.fit())
}
function select(index: number, scroll = false) {
cancelPick()
selectedIndex.value = index
candidateChoice.value = undefined
if (scroll)
document
.querySelector('.workspace-visual')
?.scrollIntoView({ block: 'start', behavior: 'smooth' })
nextTick(() => viewer.value?.fit(true))
}
function reviewRow(row: any) {
switchPanel('plan')
select(rows.value.indexOf(row), true)
}
function remember() {
undoStack.value.push({ index: selectedIndex.value, row: clone(selectedRow.value) })
}
function undoBinding() {
if (pickSession.value) {
cancelPick()
return
}
const old = undoStack.value.pop()
if (old) {
rows.value[old.index] = old.row
selectedIndex.value = old.index
candidateChoice.value = undefined
ElMessage.success('已撤销绑定调整')
}
}
function invalidate(row: any) {
for (const key of ['measured_mm', 'trial_measured_mm', 'inspection_result']) row[key] = null
row.measurement_status = '待重测'
row.measurement_reason = '计划已修改,请保存并重新测量'
}
function invalidateSelected() {
invalidate(selectedRow.value)
candidates.value[selectedIndex.value] = []
}
function clearBinding() {
remember()
applyHint(selectedRow.value, {})
candidateChoice.value = undefined
}
async function recommend() {
if (!ready.value || proposalsLoading.value) return
const request = ++proposalRequest,
signature = JSON.stringify(rows.value)
proposalsLoading.value = true
try {
const data = await Api.post(props.recordId, 'binding-proposals', { rows: clone(rows.value) })
if (!active || request !== proposalRequest || signature !== JSON.stringify(rows.value)) return
candidates.value = data.candidates || []
} catch (e: any) {
ElMessage.warning(e?.message || '推荐暂不可用,可使用扫描点选修正')
} finally {
if (request === proposalRequest) proposalsLoading.value = false
}
}
function chooseCandidate(index: number) {
const c = candidates.value[selectedIndex.value]?.[index]
if (!c) return
remember()
selectedRow.value.type = c.kind
if (selectedRow.value.table === 'gauge' && selectedRow.value.control === '点间距')
selectedRow.value.control = c.kind === 'hole_distance' ? '孔距' : '3D距离'
applyHint(selectedRow.value, {
...c.geometry_hint,
source: 'confirmed_cad',
binding_status: 'bound'
})
nextTick(() => viewer.value?.fit(true))
}
function beginPick(mode: string) {
if (!aligned.value) {
ElMessage.warning('请先加载已对齐点云')
return
}
pickSession.value = { mode, index: selectedIndex.value, points: [] }
}
function cancelPick() {
pickSession.value = null
}
function pickPoint(p: Vec3) {
const s = pickSession.value
if (!s || s.index !== selectedIndex.value) return
if (s.points.some((a) => distance(a, p) < 0.01)) {
ElMessage.warning('请选取不同且分散的扫描点')
return
}
const points = [...s.points, clone(p)]
if ((s.mode === 'circle' && points.length < 3) || (s.mode === 'pair' && points.length < 2)) {
s.points = points
return
}
try {
let hint: any = { source: 'pick_bind', coordinate_frame: 'target_mm', binding_status: 'bound' }
if (s.mode === 'circle') {
const c = circleThrough(points)
Object.assign(hint, {
measurement_kind: 'manual_circle_section',
approx_center_mm: c.center,
normal: c.normal,
radius_mm: c.radius,
seed_points: points
})
} else if (s.mode === 'pair')
Object.assign(hint, {
measurement_kind: 'point_distance',
point_a: points[0],
point_b: points[1]
})
else Object.assign(hint, { approx_center_mm: p })
remember()
if (s.mode === 'pair') {
selectedRow.value.type = 'point_distance'
selectedRow.value.control = '点间距'
}
applyHint(selectedRow.value, hint)
candidateChoice.value = undefined
cancelPick()
ElMessage.success('已更新绑定,可保存并重新测量;Esc 撤销本次修改')
} catch (e: any) {
ElMessage.warning(e.message)
}
}
const savePlan = () =>
guard(async () => {
const result = await Api.post(props.recordId, 'plan', { rows: rows.value })
acceptRows(result.rows || [])
ElMessage.success('计划已保存')
})
const generate = () =>
guard(async () => {
current.value = await Api.post(props.recordId, 'generate-report', { rows: rows.value })
baseline.value = JSON.stringify(rows.value)
undoStack.value = []
release()
expectReport = true
lastPlanRevision = ''
lastVisualRevision = ''
await refresh()
})
const applyTemplate = () =>
guard(async () => {
await ElMessageBox.confirm('载入模板会替换当前检测计划,已归档报告仍保留。', '更换计划')
const result = await Api.post(props.recordId, 'plan/template', {
template_id: selectedTemplate.value
})
acceptRows(result.rows || [])
void recommend()
})
async function importPlan(e: Event) {
const input = e.target as HTMLInputElement,
file = input.files?.[0]
if (!file) return
await guard(async () => {
const result = await Api.post(props.recordId, 'plan/import', {
text: await file.text(),
filename: file.name,
save: true
})
acceptRows(result.rows || [])
void recommend()
})
input.value = ''
}
const compare = () =>
guard(async () => {
if (cleanupDirty.value) {
switchPanel('cleanup')
throw new Error('点云处理规则尚未应用,请先预览并确认当前规则')
}
current.value = await Api.post(props.recordId, 'compare', { revision: current.value.revision })
lastPlanRevision = ''
lastVisualRevision = ''
await refresh()
})
const cleaned = (result: any) =>
guard(async () => {
current.value = result
acceptRows([])
cleanupDirty.value = false
lastPlanRevision = ''
lastVisualRevision = ''
visual.value = {}
release()
current.value = await Api.post(props.recordId, 'compare', { revision: result.revision })
switchPanel('model')
await refresh()
})
function release() {
if (chromatogram.value) URL.revokeObjectURL(chromatogram.value)
chromatogram.value = ''
reportHtml.value = ''
if (reportPdfUrl.value) URL.revokeObjectURL(reportPdfUrl.value)
reportPdfUrl.value = ''
}
const previewReport = () =>
guard(async () => {
if (reportPdfUrl.value) URL.revokeObjectURL(reportPdfUrl.value)
reportPdfUrl.value = ''
reportHtml.value = ''
try {
const blob = await Api.artifact(props.recordId, 'report_signed_chromatogram.html')
reportHtml.value = (await blob.text()).replace(/<nav[\s\S]*?<\/nav>/gi, '')
} catch {
const blob = await Api.artifact(props.recordId, 'report_signed_chromatogram.pdf')
reportPdfUrl.value = URL.createObjectURL(blob)
}
reportDialog.value = true
})
const download = (name: string) =>
guard(async () => Api.saveBlob(await Api.artifact(props.recordId, name), name))
function escape(e: KeyboardEvent) {
if (e.key !== 'Escape' || reportDialog.value || panel.value === 'cleanup') return
if (pickSession.value) {
cancelPick()
e.preventDefault()
} else if (!(e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement)) {
undoBinding()
}
}
function beforeUnload(e: BeforeUnloadEvent) {
if (dirty.value || cleanupDirty.value) {
e.preventDefault()
e.returnValue = ''
}
}
async function confirmLeave() {
if (!dirty.value && !cleanupDirty.value && !pickSession.value) return true
try {
await ElMessageBox.confirm('当前计划有未保存修改,离开将丢失这些修改。', '离开检测工作区', {
confirmButtonText: '放弃修改并离开',
cancelButtonText: '继续编辑'
})
return true
} catch {
return false
}
}
defineExpose({ confirmLeave })
watch(
() => [current.value.status, current.value.report_revision],
() => emit('changed')
)
onMounted(async () => {
if (!panels.some((p) => p.id === panel.value)) panel.value = 'model'
window.addEventListener('keydown', escape)
window.addEventListener('beforeunload', beforeUnload)
try {
const [record, templates] = await Promise.all([
Api.record(props.recordId),
Api.templates().catch(() => ({ templates: [] }))
])
inputs.value = record.inputs || {}
current.value = record
catalog.value = templates.templates || []
await refresh()
if (panel.value === 'plan' && ready.value) void recommend()
} catch (e: any) {
error.value = e?.message || '读取任务失败'
initialLoading.value = false
}
})
onBeforeUnmount(() => {
active = false
clearTimeout(timer)
visualRequest++
proposalRequest++
release()
window.removeEventListener('keydown', escape)
window.removeEventListener('beforeunload', beforeUnload)
})
</script>
<style scoped>
.inspection-workspace {
padding-bottom: 84px;
}
.binding-quickbar {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
margin-bottom: 14px;
padding: 10px 14px;
border-radius: 8px;
background: var(--el-color-primary-light-9);
}
.binding-quickbar strong {
font-size: 13px;
margin-right: auto;
}
.binding-quickbar span {
font-size: 11px;
color: var(--el-text-color-secondary);
}
.inspection-workspace .el-alert {
margin: 12px 0;
}
.task-heading {
display: flex;
align-items: center;
gap: 14px;
}
.task-heading > div {
flex: 1;
min-width: 0;
}
.task-heading h2 {
margin: 8px 0;
font-size: 20px;
}
.task-files {
display: flex;
gap: 24px;
flex-wrap: wrap;
margin: 20px 0;
color: var(--el-text-color-secondary);
font-size: 12px;
}
.task-files > span {
display: flex;
align-items: center;
gap: 7px;
min-width: 0;
overflow-wrap: anywhere;
}
.workspace-nav {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 14px;
margin-top: 24px;
}
.workspace-nav button {
display: flex;
align-items: center;
gap: 13px;
border: 1px solid var(--el-border-color-light);
border-radius: 10px;
padding: 17px;
background: var(--el-fill-color-lighter);
color: var(--el-text-color-secondary);
cursor: pointer;
text-align: left;
}
.workspace-nav button.active {
border-color: var(--el-color-primary);
background: var(--el-color-primary-light-9);
color: var(--el-color-primary);
}
.workspace-nav strong,
.workspace-nav small {
display: block;
}
.workspace-nav strong {
font-size: 14px;
margin-bottom: 5px;
}
.workspace-nav small {
font-size: 11px;
font-weight: 400;
}
.workspace-section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
margin-bottom: 18px;
}
.workspace-section-heading h3 {
margin: 0 0 7px;
font-size: 16px;
}
.workspace-section-heading p {
margin: 0;
font-size: 12px;
color: var(--el-text-color-secondary);
line-height: 1.7;
}
.workspace-actions {
display: flex;
align-items: center;
gap: 9px;
flex-wrap: wrap;
}
.workspace-actions .el-button + .el-button {
margin-left: 0;
}
.binding-layout {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
}
.binding-layout.is-plan {
grid-template-columns: 235px minmax(0, 1fr);
}
.binding-list {
border: 1px solid var(--el-border-color-lighter);
border-radius: 10px;
padding: 12px;
min-width: 0;
}
.binding-count {
font-size: 11px;
color: var(--el-text-color-secondary);
padding: 12px 0;
}
.binding-scroll {
overflow-y: auto;
max-height: 500px;
}
.binding-list-item {
display: block;
width: 100%;
text-align: left;
padding: 12px 10px;
margin-bottom: 7px;
background: var(--el-bg-color);
border: 1px solid var(--el-border-color-lighter);
border-radius: 7px;
cursor: pointer;
color: var(--el-text-color-primary);
}
.binding-list-item.selected {
border-color: var(--el-color-primary);
background: var(--el-color-primary-light-9);
}
.binding-list-item strong {
font-size: 12px;
display: block;
line-height: 1.6;
}
.binding-list-item small {
display: block;
font-size: 11px;
color: var(--el-text-color-secondary);
margin: 5px 0 10px;
}
.binding-list-item span {
display: block;
font-size: 13px;
}
.binding-list-item i {
font-style: normal;
font-size: 11px;
}
.binding-list-item em {
float: right;
font-style: normal;
font-size: 11px;
color: var(--el-text-color-secondary);
}
.binding-view {
min-width: 0;
}
.viewer-sampling {
margin-top: 9px;
font-size: 11px;
}
.model-summary,
.result-metrics {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 16px;
margin-top: 24px;
}
.model-summary > div,
.result-metrics > div {
padding: 17px 20px;
background: var(--el-fill-color-lighter);
border-radius: 9px;
}
.model-summary span,
.result-metrics span {
font-size: 12px;
color: var(--el-text-color-secondary);
display: block;
margin-bottom: 12px;
}
.model-summary strong,
.result-metrics strong {
font-size: 21px;
display: block;
font-weight: 600;
}
.model-summary small {
font-size: 11px;
color: var(--el-text-color-secondary);
display: block;
margin-top: 9px;
}
.model-summary strong small {
display: inline;
font-size: 12px;
font-weight: 400;
}
.binding-editor {
border-top: 1px solid var(--el-border-color-lighter);
margin-top: 24px;
padding-top: 22px;
}
.binding-editor-grid {
display: grid;
grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
gap: 30px;
}
.binding-method {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 13px;
margin-bottom: 10px;
}
.binding-help {
font-size: 12px;
color: var(--el-text-color-secondary);
line-height: 1.8;
margin: 10px 0;
}
.binding-values {
display: flex;
gap: 35px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
.binding-values strong {
display: block;
color: var(--el-text-color-primary);
margin: 8px 0 16px;
font-size: 17px;
}
.binding-coordinates {
display: grid;
grid-template-columns: 70px 1fr;
gap: 9px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
.binding-coordinates code {
overflow-wrap: anywhere;
font-size: 11px;
}
.binding-editor .workspace-actions {
margin: 15px 0;
}
.workspace-savebar {
position: sticky;
bottom: 12px;
z-index: 8;
display: flex;
justify-content: space-between;
gap: 16px;
align-items: center;
background: var(--el-bg-color);
border: 1px solid var(--el-border-color-light);
border-radius: 10px;
padding: 15px 22px;
box-shadow: 0 5px 28px #132d4314;
}
.workspace-savebar strong {
display: block;
font-size: 13px;
margin-bottom: 6px;
}
.workspace-savebar span {
font-size: 12px;
color: var(--el-text-color-secondary);
}
.workspace-spectrum {
display: block;
max-width: 100%;
max-height: 650px;
margin: 24px auto;
object-fit: contain;
}
.results-panel > .workspace-actions {
margin: 22px 0;
}
.workspace-empty {
text-align: center;
padding: 25px;
color: var(--el-text-color-secondary);
}
.workspace-dirty,
.visual-error {
padding: 10px 14px;
margin-bottom: 15px;
border-radius: 6px;
background: var(--el-color-warning-light-9);
color: var(--el-color-warning-dark-2);
font-size: 12px;
line-height: 1.7;
}
.workspace-bottom {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 20px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
.cleanup-box {
padding-top: 15px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
.cleanup-box > div {
display: flex;
align-items: center;
gap: 10px;
margin: 12px 0;
}
.cleanup-box .el-input-number {
width: 190px;
}
.plan-table-panel :deep(.is-selected-row td) {
background: var(--el-color-primary-light-9);
}
@media (max-width: 1050px) {
.binding-layout.is-plan {
grid-template-columns: 190px minmax(0, 1fr);
}
.workspace-section-heading {
align-items: flex-start;
flex-wrap: wrap;
}
.binding-editor-grid {
gap: 18px;
}
.model-summary,
.result-metrics {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 720px) {
.binding-layout.is-plan,
.binding-editor-grid {
grid-template-columns: minmax(0, 1fr);
}
.binding-scroll {
max-height: 210px;
}
.workspace-nav {
gap: 6px;
}
.workspace-nav button {
padding: 12px 8px;
gap: 6px;
}
.workspace-nav small {
display: none;
}
.workspace-savebar {
flex-wrap: wrap;
}
.task-heading {
flex-wrap: wrap;
}
.model-summary {
gap: 8px;
}
.model-summary > div {
padding: 12px;
}
.task-overview {
padding: 16px;
}
}
</style>