am-freescan/am-web/src/views/lab/scan-task/ScanExecutionMonitor.vue

413 lines
12 KiB
Vue
Raw Normal View History

2026-10-22 16:18:37 +08:00
<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
>
2026-10-22 16:18:37 +08:00
<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>
2026-10-22 16:18:37 +08:00
<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)"
2026-10-22 16:18:37 +08:00
>刷新日志</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
>
2026-10-22 16:18:37 +08:00
</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>
2026-10-22 16:18:37 +08:00
</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'
2026-10-22 16:18:37 +08:00
import { statusLabel } from './scanForm.mjs'
import { scannerLogCursor, mergeScannerLogs } from './scannerLogs.mjs'
2026-10-22 16:18:37 +08:00
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 || '')
)
2026-10-22 16:18:37 +08:00
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
})
)
2026-10-22 16:18:37 +08:00
const logs = computed(() => readableLogs(nativeLogs.value, identity.value.flowData))
const stepPlan = computed(() =>
executionStepPlan(props.execution, logs.value, identity.value.flowData, now.value)
)
2026-10-22 16:18:37 +08:00
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
2026-10-22 16:18:37 +08:00
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
2026-10-22 16:18:37 +08:00
pending = { id: String(id), token }
loading.value = true
error.value = ''
try {
const result =
!force && binding.value?.cmvrInstId ? binding.value : await ScanApi.getCmvrBinding(id, signal)
2026-10-22 16:18:37 +08:00
if (token !== generation) return
binding.value = result
if (!result?.cmvrInstId) {
error.value = '执行已提交,正在等待原生流程实例。'
return
}
const found: any[] = []
const afterId = force ? undefined : scannerLogCursor(nativeLogs.value)
2026-10-22 16:18:37 +08:00
let pageNum = 1
while (true) {
const response: any = await getInst(
{ instId: result.cmvrInstId, afterId, pageNum, pageSize: 100 },
signal
)
2026-10-22 16:18:37 +08:00
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)
2026-10-22 16:18:37 +08:00
} catch (failure: any) {
if (token === generation && !signal.aborted)
error.value = failure.message || '日志加载失败,请刷新重试。'
2026-10-22 16:18:37 +08:00
} 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
2026-10-22 16:18:37 +08:00
binding.value = undefined
nativeLogs.value = []
loading.value = false
error.value = ''
if (props.active && !suspended) load(true)
2026-10-22 16:18:37 +08:00
},
{ immediate: true }
)
watch([() => props.active, () => props.execution?.status], () => {
if (props.active && !suspended) load(true)
else {
generation++
controller?.abort()
pending = undefined
loading.value = false
2026-10-22 16:18:37 +08:00
}
})
2026-10-22 16:18:37 +08:00
const timer = setInterval(() => {
if (
props.active &&
!suspended &&
2026-10-22 16:18:37 +08:00
!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
})
2026-10-22 16:18:37 +08:00
onBeforeUnmount(() => {
generation++
controller?.abort()
2026-10-22 16:18:37 +08:00
clearInterval(timer)
clearInterval(clock)
2026-10-22 16:18:37 +08:00
})
</script>
<style scoped>
.execution-monitor {
container-type: inline-size;
2026-10-22 16:18:37 +08:00
}
.execution-overview,
.overview-main {
2026-10-22 16:18:37 +08:00
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;
2026-10-22 16:18:37 +08:00
}
.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;
2026-10-22 16:18:37 +08:00
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 9px;
2026-10-22 16:18:37 +08:00
}
.progress-heading strong {
font-size: 14px;
font-weight: 600;
overflow-wrap: anywhere;
2026-10-22 16:18:37 +08:00
}
.elapsed,
.step-count,
.progress-note {
2026-10-22 16:18:37 +08:00
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 {
2026-10-22 16:18:37 +08:00
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);
2026-10-22 16:18:37 +08:00
}
[data-status='FAILED'] .progress-number {
color: var(--el-color-danger);
2026-10-22 16:18:37 +08:00
}
[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;
2026-10-22 16:18:37 +08:00
}
</style>