am-freescan/am-web/src/views/lab/scan-task/ScanExecutionMonitor.vue
lixiaolong 6f8a40644c feat(scanner): 完善补扫、执行监控及资源释放
完善扫描流式预览、成果归档与PLY/STL查看、补扫历史、执行步骤及日志展示,支持局域网访问和改名节点的原始组件识别。修复试运行终止后的占用释放及未采集时重复暂停SDK的问题,增加终止中交互与回归验证。

验证:后端1114项通过、18项既有跳过;前端109项通过,类型检查及构建通过;Python脚本54项通过;模拟扫描设备7组试运行/终止接口回归通过。
2026-10-26 11:04:07 +08:00

413 lines
12 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="execution-monitor" :aria-busy="loading">
<header class="execution-overview">
<div class="overview-main"
><strong>{{ statusLabel(execution?.status || 'PENDING') }}</strong
><span class="monitor-caption">{{ execution?.executionNo || '尚未开始' }}</span></div
>
<div class="monitor-actions">
<el-popover trigger="click" :width="360" placement="bottom-start"
><template #reference><el-button text size="small">执行信息</el-button></template>
<div class="case-reference"
>扫描方案:{{ identity.caseName }} ·
{{ identity.versionNo != null ? `V${identity.versionNo}` : '版本待确认' }}</div
>
<div class="case-reference"
>方法号 / 测试用例 ID:<code>{{ identity.testCaseId || '-' }}</code></div
>
<p class="case-reference">执行编号:{{ execution?.executionNo || '尚未开始' }}</p>
<p v-if="execution?.executionType === 'SUPPLEMENT'" class="case-reference"
>补扫来源:{{
execution.runParams?.supplementSourceExecutionNo || execution.parentExecutionId
}}。原成果可从执行记录切换查看。</p
>
<p v-if="!identity.matchesPreparation" class="case-reference"
>历史记录的方案与版本,以本次执行时保存的信息为准。</p
>
</el-popover>
<el-button v-if="binding?.cmvrInstId" link type="primary" @click="openFlow"
>流程运行图</el-button
>
<el-button
text
size="small"
:loading="loading"
:disabled="!execution?.id"
@click="load(true)"
>刷新日志</el-button
>
</div>
</header>
<div
v-if="execution?.id"
class="progress-overview"
:data-status="execution.status"
aria-label="本次执行进度"
>
<div class="progress-heading"
><strong>{{ stepPlan.heading }}</strong
><span class="elapsed">总耗时 {{ stepPlan.duration }}</span></div
>
<div class="progress-line">
<el-progress
class="execution-progress"
:percentage="stepPlan.percent"
:status="progressStatus"
:stroke-width="6"
:show-text="false"
/>
<span class="progress-number">{{ stepPlan.percent }}%</span>
<span class="step-count">{{
stepPlan.hasPlan
? `已完成 ${stepPlan.completed} / ${stepPlan.total} 步`
: `已收到 ${stepPlan.total} 步记录`
}}</span>
<el-tooltip :content="stepPlan.hint" placement="top"
><button class="progress-help" type="button" aria-label="步骤进度说明"
>?</button
></el-tooltip
>
</div>
<p v-if="stepPlan.unrecorded" class="progress-note"
>{{
stepPlan.unrecorded
}}
步未收到执行记录,未计入已完成步骤;可结合流程分支和详细日志核对。</p
>
</div>
<el-alert
v-if="execution?.failureReason"
class="mb-12px"
type="error"
:closable="false"
:title="execution.failureReason"
/>
<el-alert v-if="error" class="mb-12px" type="warning" :closable="false" :title="error" />
<div v-if="execution?.id" class="monitor-layout">
<div class="monitor-visual"
><ScannerExecutionViews
:key="String(execution.id)"
:execution-id="execution.id"
:execution-no="execution.executionNo"
:status="execution.status"
:active="active"
/></div>
<ScanExecutionLog
:key="String(execution.id)"
:logs="logs"
:status="execution.status"
:loading="loading"
:active="active"
:height="height"
:steps="stepPlan.steps"
:focus-id="stepPlan.focusId"
:has-plan="stepPlan.hasPlan"
/>
</div>
<p v-else class="monitor-caption">确认本件装夹并开始后,可查看扫描画面和执行记录。</p>
</section>
</template>
<script setup lang="ts">
import * as ScanApi from '@/api/lab/scan-task'
import type { LabExecutionVO } from '@/api/lab/execution'
import { getInst } from '@/cmvr/common/api/test/log'
import ScanExecutionLog from './ScanExecutionLog.vue'
import ScannerExecutionViews from './ScannerExecutionViews.vue'
import { executionIdentity, readableLogs } from './executionPresentation.mjs'
import { executionStepPlan } from './executionSteps.mjs'
import { statusLabel } from './scanForm.mjs'
import { scannerLogCursor, mergeScannerLogs } from './scannerLogs.mjs'
const props = withDefaults(
defineProps<{
execution?: Partial<LabExecutionVO>
caseName?: string
testCaseId: string
versionNo?: number
flowData?: any
active?: boolean
height?: number
}>(),
{ active: true, height: 420 }
)
const binding = ref<any>()
const terminal = computed(() =>
['SUCCEEDED', 'FAILED', 'CANCELLED'].includes(props.execution?.status || '')
)
const nativeLogs = ref<any[]>([])
const loading = ref(false)
const error = ref('')
const now = ref(Date.now())
const identity = computed(() =>
executionIdentity(props.execution, binding.value, {
testCaseId: props.testCaseId,
caseName: props.caseName,
versionNo: props.versionNo,
flowData: props.flowData
})
)
const logs = computed(() => readableLogs(nativeLogs.value, identity.value.flowData))
const stepPlan = computed(() =>
executionStepPlan(props.execution, logs.value, identity.value.flowData, now.value)
)
const progressStatus = computed(() =>
props.execution?.status === 'SUCCEEDED'
? 'success'
: ['FAILED', 'CANCELLED'].includes(props.execution?.status || '')
? 'exception'
: props.execution?.status === 'PAUSED'
? 'warning'
: undefined
)
let generation = 0
let pending: { id: string; token: number } | undefined
let controller: AbortController | undefined
let suspended = false
async function load(force = false) {
const id = props.execution?.id
if (!id || (!force && pending?.id === String(id))) return
const token = ++generation
controller?.abort()
controller = new AbortController()
const signal = controller.signal
pending = { id: String(id), token }
loading.value = true
error.value = ''
try {
const result =
!force && binding.value?.cmvrInstId ? binding.value : await ScanApi.getCmvrBinding(id, signal)
if (token !== generation) return
binding.value = result
if (!result?.cmvrInstId) {
error.value = '执行已提交,正在等待原生流程实例。'
return
}
const found: any[] = []
const afterId = force ? undefined : scannerLogCursor(nativeLogs.value)
let pageNum = 1
while (true) {
const response: any = await getInst(
{ instId: result.cmvrInstId, afterId, pageNum, pageSize: 100 },
signal
)
if (token !== generation) return
const rows = response.rows || []
found.push(...rows)
if (!rows.length || found.length >= (response.total ?? found.length)) break
pageNum++
}
nativeLogs.value = force ? found : mergeScannerLogs(nativeLogs.value, found)
} catch (failure: any) {
if (token === generation && !signal.aborted)
error.value = failure.message || '日志加载失败,请刷新重试。'
} finally {
if (token === generation) loading.value = false
if (pending?.token === token) pending = undefined
}
}
function openFlow() {
if (!binding.value?.cmvrInstId) return
const query = new URLSearchParams({
itemId: binding.value.detectionItemId,
instId: binding.value.cmvrInstId,
taskId: binding.value.cmvrTaskId || '',
isLog: 'true',
name: identity.value.caseName || '扫描流程'
})
window.open(`/flow?${query}`, '_blank', 'noopener,noreferrer')
}
watch(
() => props.execution?.id,
() => {
generation++
controller?.abort()
pending = undefined
binding.value = undefined
nativeLogs.value = []
loading.value = false
error.value = ''
if (props.active && !suspended) load(true)
},
{ immediate: true }
)
watch([() => props.active, () => props.execution?.status], () => {
if (props.active && !suspended) load(true)
else {
generation++
controller?.abort()
pending = undefined
loading.value = false
}
})
const timer = setInterval(() => {
if (
props.active &&
!suspended &&
!document.hidden &&
['RUNNING', 'QUEUED', 'PREPARING', 'PAUSED'].includes(props.execution?.status || '')
)
load()
}, 2000)
const clock = setInterval(() => {
if (props.active && !suspended && !document.hidden && !terminal.value) now.value = Date.now()
}, 1000)
onActivated(() => {
suspended = false
if (props.active) load(true)
})
onDeactivated(() => {
suspended = true
generation++
controller?.abort()
pending = undefined
loading.value = false
})
onBeforeUnmount(() => {
generation++
controller?.abort()
clearInterval(timer)
clearInterval(clock)
})
</script>
<style scoped>
.execution-monitor {
container-type: inline-size;
}
.execution-overview,
.overview-main {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 10px;
}
.execution-overview {
justify-content: space-between;
padding: 0 0 12px;
border-bottom: 1px solid var(--el-border-color-lighter);
margin-bottom: 12px;
}
.overview-main {
min-width: 0;
font-size: 13px;
}
.overview-main strong {
font-weight: 500;
}
.current-step {
color: var(--el-text-color-regular);
font-size: 12px;
overflow-wrap: anywhere;
}
.execution-progress {
flex: 1;
min-width: 60px;
}
.progress-overview {
margin-bottom: 14px;
}
.progress-heading {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 9px;
}
.progress-heading strong {
font-size: 14px;
font-weight: 600;
overflow-wrap: anywhere;
}
.elapsed,
.step-count,
.progress-note {
color: var(--el-text-color-secondary);
font-size: 12px;
}
.elapsed {
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
.progress-line {
display: flex;
align-items: center;
gap: 10px;
}
.progress-number {
font-size: 13px;
color: var(--el-color-primary);
font-variant-numeric: tabular-nums;
}
.step-count {
white-space: nowrap;
}
.progress-help {
width: 17px;
height: 17px;
flex-shrink: 0;
border: 1px solid var(--el-border-color);
border-radius: 50%;
background: none;
padding: 0;
font-size: 11px;
color: var(--el-text-color-secondary);
cursor: help;
}
.progress-note {
margin: 7px 0 0;
line-height: 1.6;
}
[data-status='SUCCEEDED'] .progress-number {
color: var(--el-color-success);
}
[data-status='FAILED'] .progress-number {
color: var(--el-color-danger);
}
[data-status='PAUSED'] .progress-number {
color: var(--el-color-warning);
}
.monitor-layout {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
}
.monitor-visual {
min-width: 0;
}
.monitor-layout > .scan-log {
order: -1;
padding-bottom: 12px;
border-bottom: 1px solid var(--el-border-color-lighter);
--execution-step-list-height: 220px;
}
@container (min-width: 900px) {
.monitor-layout {
grid-template-columns: minmax(0, 1.6fr) minmax(330px, 1fr);
align-items: start;
}
.monitor-layout > .scan-log {
order: 0;
border-bottom: 0;
border-left: 1px solid var(--el-border-color-lighter);
padding: 12px 0 0 16px;
--execution-step-list-height: 1000px;
}
}
.case-reference {
color: var(--el-text-color-regular);
font-size: 12px;
overflow-wrap: anywhere;
}
.monitor-actions {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.monitor-caption {
color: var(--el-text-color-secondary);
font-size: 13px;
}
</style>