2026-10-22 16:18:37 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<section class="execution-monitor" :aria-busy="loading">
|
|
|
|
|
|
<div class="executed-case">
|
|
|
|
|
|
<span class="monitor-caption">{{ execution?.id ? '本次执行测试用例' : '准备执行测试用例' }}</span>
|
|
|
|
|
|
<strong>{{ identity.caseName }}</strong>
|
|
|
|
|
|
<span>方法号 / 测试用例 ID:<code>{{ identity.testCaseId || '-' }}</code></span>
|
|
|
|
|
|
<span>发布版本:{{ identity.versionNo != null ? `V${identity.versionNo}` : '尚未选择' }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-alert v-if="!identity.matchesPreparation" type="warning" :closable="false" class="mb-12px"
|
|
|
|
|
|
title="当前查看的是历史执行记录,以下用例和版本以本次执行时的冻结记录为准。" />
|
|
|
|
|
|
<div class="monitor-heading">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<h3>本次执行进度</h3>
|
|
|
|
|
|
<span class="monitor-caption">{{ execution?.executionNo || '尚未开始执行' }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="monitor-actions">
|
|
|
|
|
|
<el-tag v-if="binding">V{{ binding.versionNo }}</el-tag>
|
|
|
|
|
|
<el-button v-if="binding?.cmvrInstId" link type="primary" @click="openFlow"
|
|
|
|
|
|
>流程运行图</el-button
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-button :loading="loading" :disabled="!execution?.id" @click="load(true)"
|
|
|
|
|
|
>刷新日志</el-button
|
|
|
|
|
|
>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-progress :percentage="percentage" :status="progressStatus" :stroke-width="10" />
|
|
|
|
|
|
<div class="node-summary">
|
|
|
|
|
|
<span>状态:{{ statusLabel(execution?.status || 'PENDING') }}</span>
|
|
|
|
|
|
<span v-if="currentNode">当前节点:{{ currentNode }}</span>
|
|
|
|
|
|
</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" />
|
2026-10-23 09:03:27 +08:00
|
|
|
|
<ScannerExecutionViews v-if="execution?.id" :key="String(execution.id)" :execution-id="execution.id"
|
|
|
|
|
|
:execution-no="execution.executionNo" :status="execution.status" :active="active" />
|
2026-10-22 16:18:37 +08:00
|
|
|
|
<h3 class="log-heading">执行日志</h3>
|
|
|
|
|
|
<NativeTaskLog
|
|
|
|
|
|
v-if="execution?.id"
|
|
|
|
|
|
:key="String(execution.id)"
|
|
|
|
|
|
:items="items"
|
|
|
|
|
|
:list="logs"
|
|
|
|
|
|
:task-status="nativeStatus"
|
|
|
|
|
|
:height="height"
|
|
|
|
|
|
item-label="测试用例"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<el-empty v-else description="确认本件装夹并开始后,这里将显示执行进度和节点日志。" />
|
|
|
|
|
|
</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 NativeTaskLog from '@/cmvr/aima/views/intelligenceTest/runningTask/task-log.vue'
|
2026-10-23 09:03:27 +08:00
|
|
|
|
import ScannerExecutionViews from './ScannerExecutionViews.vue'
|
2026-10-22 16:18:37 +08:00
|
|
|
|
import { executionIdentity, executionProgress, readableLogs } from './executionPresentation.mjs'
|
|
|
|
|
|
import { statusLabel } from './scanForm.mjs'
|
2026-10-23 09:03:27 +08:00
|
|
|
|
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 nativeLogs = ref<any[]>([])
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const error = ref('')
|
|
|
|
|
|
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 percentage = computed(() => executionProgress(props.execution, logs.value, identity.value.flowData))
|
|
|
|
|
|
const progressStatus = computed(() =>
|
|
|
|
|
|
props.execution?.status === 'SUCCEEDED'
|
|
|
|
|
|
? 'success'
|
|
|
|
|
|
: ['FAILED', 'CANCELLED'].includes(props.execution?.status || '')
|
|
|
|
|
|
? 'exception'
|
|
|
|
|
|
: props.execution?.status === 'PAUSED'
|
|
|
|
|
|
? 'warning'
|
|
|
|
|
|
: undefined
|
|
|
|
|
|
)
|
|
|
|
|
|
const nativeStatusCodes: Record<string, number> = {
|
|
|
|
|
|
SUCCEEDED: 0,
|
|
|
|
|
|
RUNNING: 1,
|
|
|
|
|
|
FAILED: 2,
|
|
|
|
|
|
PAUSED: 3,
|
|
|
|
|
|
CANCELLED: 4
|
|
|
|
|
|
}
|
|
|
|
|
|
const nativeStatus = computed(() => nativeStatusCodes[props.execution?.status || ''] ?? 1)
|
|
|
|
|
|
const items = computed(() => [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: binding.value?.detectionItemId || identity.value.testCaseId,
|
|
|
|
|
|
detectItemId: binding.value?.detectionItemId,
|
|
|
|
|
|
testCaseId: identity.value.testCaseId,
|
|
|
|
|
|
caseName: identity.value.caseName
|
|
|
|
|
|
}
|
|
|
|
|
|
])
|
|
|
|
|
|
const currentNode = computed(() => {
|
|
|
|
|
|
const running = logs.value.filter((log: any) => ['RUNNING', '1'].includes(String(log.status)))
|
|
|
|
|
|
const last = running.at(-1) || logs.value.at(-1)
|
|
|
|
|
|
return last?.nodeName || ''
|
|
|
|
|
|
})
|
|
|
|
|
|
let generation = 0
|
|
|
|
|
|
let pending: { id: string; token: number } | undefined
|
2026-10-23 09:03:27 +08:00
|
|
|
|
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
|
2026-10-23 09:03:27 +08:00
|
|
|
|
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 {
|
2026-10-23 09:03:27 +08:00
|
|
|
|
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[] = []
|
2026-10-23 09:03:27 +08:00
|
|
|
|
const afterId = force ? undefined : scannerLogCursor(nativeLogs.value)
|
2026-10-22 16:18:37 +08:00
|
|
|
|
let pageNum = 1
|
|
|
|
|
|
while (true) {
|
2026-10-23 09:03:27 +08:00
|
|
|
|
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++
|
|
|
|
|
|
}
|
2026-10-23 09:03:27 +08:00
|
|
|
|
nativeLogs.value = force ? found : mergeScannerLogs(nativeLogs.value, found)
|
2026-10-22 16:18:37 +08:00
|
|
|
|
} catch (failure: any) {
|
2026-10-23 09:03:27 +08:00
|
|
|
|
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++
|
|
|
|
|
|
binding.value = undefined
|
|
|
|
|
|
nativeLogs.value = []
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
error.value = ''
|
2026-10-23 09:03:27 +08:00
|
|
|
|
if (props.active && !suspended) load(true)
|
2026-10-22 16:18:37 +08:00
|
|
|
|
},
|
|
|
|
|
|
{ immediate: true }
|
|
|
|
|
|
)
|
|
|
|
|
|
watch(
|
2026-10-23 09:03:27 +08:00
|
|
|
|
[() => props.active, () => props.execution?.status],
|
2026-10-22 16:18:37 +08:00
|
|
|
|
() => {
|
2026-10-23 09:03:27 +08:00
|
|
|
|
if (props.active && !suspended) load(true)
|
|
|
|
|
|
else { generation++; controller?.abort(); pending = undefined; loading.value = false }
|
2026-10-22 16:18:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
const timer = setInterval(() => {
|
|
|
|
|
|
if (
|
|
|
|
|
|
props.active &&
|
2026-10-23 09:03:27 +08:00
|
|
|
|
!suspended &&
|
2026-10-22 16:18:37 +08:00
|
|
|
|
!document.hidden &&
|
|
|
|
|
|
['RUNNING', 'QUEUED', 'PREPARING', 'PAUSED'].includes(props.execution?.status || '')
|
|
|
|
|
|
)
|
|
|
|
|
|
load()
|
|
|
|
|
|
}, 2000)
|
2026-10-23 09:03:27 +08:00
|
|
|
|
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++
|
2026-10-23 09:03:27 +08:00
|
|
|
|
controller?.abort()
|
2026-10-22 16:18:37 +08:00
|
|
|
|
clearInterval(timer)
|
|
|
|
|
|
})
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.executed-case {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
padding: 12px 16px;
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
background: var(--el-fill-color-light);
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
overflow-wrap: anywhere;
|
|
|
|
|
|
}
|
|
|
|
|
|
.monitor-heading,
|
|
|
|
|
|
.monitor-actions,
|
|
|
|
|
|
.node-summary {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
.monitor-heading {
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
h3 {
|
|
|
|
|
|
margin: 0 0 6px;
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.monitor-caption,
|
|
|
|
|
|
.node-summary {
|
|
|
|
|
|
color: var(--el-text-color-secondary);
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.node-summary {
|
|
|
|
|
|
margin: 10px 0 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.log-heading {
|
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|