295 lines
14 KiB
Vue
295 lines
14 KiB
Vue
<template>
|
||
<ContentWrap>
|
||
<el-page-header @back="push({ name: 'LabExecution' })" :content="detail.executionNo || '执行工作台'" />
|
||
<div class="mt-12px flex flex-wrap items-center gap-8px">
|
||
<dict-tag :type="DICT_TYPE.LAB_EXECUTION_STATUS" :value="detail.status" />
|
||
<dict-tag :type="DICT_TYPE.LAB_EXECUTION_TYPE" :value="detail.executionType" />
|
||
<span>编号 {{ detail.executionNo }}</span>
|
||
<span>任务 {{ detail.taskNo }}</span>
|
||
<span>进度 {{ detail.progress ?? 0 }}%</span>
|
||
<span>扫描阶段 {{ scanStageLabel(detail.scanStage) }}</span>
|
||
<span>当前步骤 {{ detail.currentStepId || '-' }}</span>
|
||
<span>检测项版本 {{ detail.methodVersion || '-' }}</span>
|
||
<span>零件类型 {{ detail.partTypeCode || '-' }}</span>
|
||
<span>成果交付 {{ deliveryLabel(detail.resultDeliveryStatus) }}</span>
|
||
<span>阶段更新 {{ formatDate(detail.scanStageUpdatedAt) || '-' }}</span>
|
||
<span>接入方 {{ detail.providerName || '-' }}</span>
|
||
<span>外部任务 {{ detail.externalJobId || '-' }}</span>
|
||
<span>接入状态 {{ claimLabel(detail.dispatchSyncStatus) }}</span>
|
||
<span>技术状态 {{ detail.status || '-' }}</span>
|
||
<el-button v-if="!isScanAttempt && canPrecheck" v-hasPermi="['lab:execution:precheck']" @click="doPrecheck">预检</el-button>
|
||
<el-button v-if="!isScanAttempt && !isTerminal" type="primary" v-hasPermi="['lab:execution:dispatch']" @click="doDispatch">发布执行</el-button>
|
||
<el-button v-if="!isScanAttempt && !isLocalDetection" v-hasPermi="['lab:execution:control']" @click="doPause">暂停</el-button>
|
||
<el-button v-if="!isScanAttempt && !isLocalDetection" v-hasPermi="['lab:execution:control']" @click="doResume">恢复</el-button>
|
||
<el-button v-if="!isScanAttempt && !isTerminal" type="danger" plain v-hasPermi="['lab:execution:cancel']" @click="doCancel">取消</el-button>
|
||
<el-button @click="doSync">同步状态</el-button>
|
||
<el-button v-if="!isScanAttempt" v-hasPermi="['lab:execution:followup']" @click="followVisible = true">补扫/复测</el-button>
|
||
<el-button v-else type="primary" @click="push({ name: 'LabScanTaskWorkbench', params: { id: String(detail.taskId) } })">返回扫描任务</el-button>
|
||
</div>
|
||
<el-steps v-if="!isLocalDetection" class="mt-16px" :active="scanStepIndex" finish-status="success" align-center>
|
||
<el-step v-for="item in scanStages" :key="item.key" :title="item.label" />
|
||
</el-steps>
|
||
<el-alert
|
||
v-if="detail.dispatchSyncStatus === 'REJECTED'"
|
||
class="mt-12px"
|
||
type="warning"
|
||
:closable="false"
|
||
:title="'设备接入方拒绝执行:' + (detail.rejectMessage || detail.rejectReasonCode || '未说明原因')"
|
||
description="执行未失败。请重新检查资源后再次发布。"
|
||
/>
|
||
</ContentWrap>
|
||
<ContentWrap><el-collapse><el-collapse-item title="本次运行参数快照" name="runParams"><pre class="text-12px overflow-auto">{{ JSON.stringify(detail.runParams || {}, null, 2) }}</pre></el-collapse-item></el-collapse></ContentWrap>
|
||
<ContentWrap v-if="isLocalDetection"><div class="font-bold mb-12px">检测流程运行日志</div><RunResult :run="detectionRun || undefined" empty-text="发布执行后在这里查看真实节点状态与日志" /></ContentWrap>
|
||
<ContentWrap v-loading="loading">
|
||
<el-row :gutter="16">
|
||
<el-col :span="14">
|
||
<div class="mb-8px font-bold">步骤</div>
|
||
<el-table :data="detail.steps || []">
|
||
<el-table-column label="步骤" prop="stepName" />
|
||
<el-table-column label="状态" prop="status" width="120" />
|
||
<el-table-column label="开始" prop="startedAt" width="170">
|
||
<template #default="scope">{{ formatDate(scope.row.startedAt) }}</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div class="mb-8px mt-16px font-bold">控制指令(与执行状态分开)</div>
|
||
<el-table :data="detail.commands || []">
|
||
<el-table-column label="指令" prop="commandType" width="100" />
|
||
<el-table-column label="指令状态" width="110">
|
||
<template #default="scope">{{ commandLabel(scope.row.status) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="原因" prop="reason" />
|
||
</el-table>
|
||
<div class="mb-8px mt-16px font-bold">事件</div>
|
||
<el-table :data="events">
|
||
<el-table-column label="序号" prop="sequence" width="80" />
|
||
<el-table-column label="类型" prop="eventType" />
|
||
<el-table-column label="时间" width="170">
|
||
<template #default="scope">{{ formatDate(scope.row.eventAt) }}</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</el-col>
|
||
<el-col :span="10">
|
||
<div class="mb-8px font-bold">最近异常</div>
|
||
<div class="mb-12px text-13px">{{ detail.latestException || '无' }}</div>
|
||
<div class="mb-8px font-bold">设备状态(只读回传)</div>
|
||
<el-card v-for="(dev, idx) in detail.deviceStates || []" :key="idx" shadow="never" class="mb-8px">
|
||
<div>{{ dev.deviceType }} / {{ dev.mode }}</div>
|
||
<div class="text-13px text-[var(--el-text-color-secondary)]">{{ dev.summary }}</div>
|
||
</el-card>
|
||
<el-empty v-if="!(detail.deviceStates || []).length" description="暂无设备回传" :image-size="60" />
|
||
<div class="mb-8px mt-16px font-bold">资源快照</div>
|
||
<el-table :data="detail.resources || []" size="small">
|
||
<el-table-column label="类型" prop="resourceType" width="90" />
|
||
<el-table-column label="名称" min-width="140">
|
||
<template #default="scope">{{ scope.row.resourceCode }} {{ scope.row.resourceName }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="外部编号" prop="externalId" />
|
||
<el-table-column label="设备类型" prop="deviceType" width="100" />
|
||
</el-table>
|
||
<div class="mb-8px mt-16px font-bold">扫描成果</div>
|
||
<el-table :data="artifacts" size="small">
|
||
<el-table-column label="成果" min-width="100">
|
||
<template #default="scope">{{ artifactLabel(scope.row.artifactType) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="文件" prop="fileName" min-width="140" />
|
||
<el-table-column label="状态" width="90">
|
||
<template #default="scope">{{ scope.row.fileStatus === 'AVAILABLE' ? '可用' : scope.row.fileStatus }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="80">
|
||
<template #default="scope">
|
||
<el-button v-if="scope.row.fileStatus === 'AVAILABLE'" link type="primary" @click="downloadArtifact(scope.row)">下载</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div v-if="precheck" class="mt-16px">
|
||
<div class="mb-8px font-bold">最近预检 {{ precheck.passed ? '通过' : '阻断 ' + precheck.blockingCount }}</div>
|
||
<el-table :data="precheck.items || []" size="small">
|
||
<el-table-column label="项" prop="itemCode" />
|
||
<el-table-column label="结果" prop="result" width="80" />
|
||
<el-table-column label="说明" prop="message" />
|
||
</el-table>
|
||
</div>
|
||
</el-col>
|
||
</el-row>
|
||
</ContentWrap>
|
||
<Dialog v-model="followVisible" title="补扫/复测" width="480">
|
||
<el-form label-width="90px">
|
||
<el-form-item label="类型" required>
|
||
<el-select v-model="follow.executionType" class="!w-full">
|
||
<el-option v-for="dict in getStrDictOptions(DICT_TYPE.LAB_EXECUTION_TYPE)" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="原因" required>
|
||
<el-input v-model="follow.reason" type="textarea" />
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button type="primary" @click="submitFollow">创建</el-button>
|
||
<el-button @click="followVisible = false">取消</el-button>
|
||
</template>
|
||
</Dialog>
|
||
</template>
|
||
<script lang="ts" setup>
|
||
import { ElMessageBox } from 'element-plus'
|
||
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
|
||
import { formatDate } from '@/utils/formatTime'
|
||
import * as ExecutionApi from '@/api/lab/execution'
|
||
import * as DataApi from '@/api/lab/data'
|
||
import * as DetectionApi from '@/api/lab/detection-item'
|
||
import RunResult from '@/views/lab/detection-item/components/RunResult.vue'
|
||
import { downloadArtifactFile } from '@/utils/labArtifactDownload'
|
||
|
||
defineOptions({ name: 'LabExecutionWorkbench' })
|
||
const route = useRoute()
|
||
const { push } = useRouter()
|
||
const message = useMessage()
|
||
const loading = ref(false)
|
||
const detail = ref<ExecutionApi.LabExecutionVO>({} as ExecutionApi.LabExecutionVO)
|
||
const isScanAttempt = computed(() => !!detail.value.sampleUnitId)
|
||
const detectionRun = ref<DetectionApi.DetectionRun | null>(null)
|
||
const isLocalDetection = computed(() => !!detectionRun.value || detail.value.methodExternalId?.startsWith('LOCAL:'))
|
||
const isTerminal = computed(() => ['SUCCEEDED', 'FAILED', 'CANCELLED'].includes(detail.value.status))
|
||
const canPrecheck = computed(() => !detail.value.publishedAt && !detail.value.dispatchedAt && ['QUEUED', 'PREPARING', 'READY'].includes(detail.value.status))
|
||
const events = ref<ExecutionApi.LabExecutionEventVO[]>([])
|
||
const artifacts = ref<DataApi.LabArtifactVO[]>([])
|
||
const precheck = ref<ExecutionApi.LabExecutionPrecheckVO>()
|
||
const followVisible = ref(false)
|
||
const follow = reactive({ executionType: 'RESCAN', reason: '' })
|
||
|
||
const load = async (spin = true) => {
|
||
if (spin) loading.value = true
|
||
try {
|
||
const id = String(route.params.id)
|
||
detail.value = await ExecutionApi.getExecution(id)
|
||
detectionRun.value = detail.value.methodExternalId?.startsWith('LOCAL:') ? await DetectionApi.getDetectionRunByExecution(id) : null
|
||
const eventPage = await ExecutionApi.getExecutionEventPage({ pageNo: 1, pageSize: 50, executionId: id })
|
||
events.value = eventPage.list
|
||
const files = await DataApi.getArtifactPage({ pageNo: 1, pageSize: 50, executionId: id })
|
||
artifacts.value = files.list || []
|
||
} finally {
|
||
if (spin) loading.value = false
|
||
}
|
||
}
|
||
const doPrecheck = async () => {
|
||
const checked: ExecutionApi.LabExecutionPrecheckVO = await ExecutionApi.precheckExecution(detail.value.id!)
|
||
precheck.value = checked
|
||
message.success(checked.passed ? '预检通过' : '存在阻断项')
|
||
await load()
|
||
}
|
||
const scanStages = [
|
||
{ key: 'WAITING', label: '待扫描' },
|
||
{ key: 'PREPARING', label: '扫描准备中' },
|
||
{ key: 'SCANNING', label: '扫描中' },
|
||
{ key: 'DATA_PROCESSING', label: '数据整合中' },
|
||
{ key: 'ANALYZING', label: '分析中' },
|
||
{ key: 'GENERATING_RESULT', label: '结果生成中' },
|
||
{ key: 'UPLOADING', label: '成果上传中' },
|
||
{ key: 'COMPLETED', label: '扫描完成' }
|
||
]
|
||
const scanStepIndex = computed(() => {
|
||
const index = scanStages.findIndex((item) => item.key === detail.value.scanStage)
|
||
return index < 0 ? 0 : index
|
||
})
|
||
const scanStageLabel = (stage?: string) =>
|
||
({
|
||
WAITING: '待扫描',
|
||
PREPARING: '扫描准备中',
|
||
SCANNING: '扫描中',
|
||
DATA_PROCESSING: '数据整合中',
|
||
ANALYZING: '分析中',
|
||
GENERATING_RESULT: '结果生成中',
|
||
UPLOADING: '成果上传中',
|
||
COMPLETED: '扫描完成',
|
||
PAUSED: '已暂停',
|
||
FAILED: '扫描失败',
|
||
CANCELLED: '已取消'
|
||
}[stage || ''] || stage || '-')
|
||
const deliveryLabel = (status?: string) =>
|
||
({
|
||
NOT_READY: '成果未生成',
|
||
READY: '成果已生成',
|
||
UPLOADING: '成果上传中',
|
||
PARTIAL: '部分成果已上传',
|
||
AVAILABLE: '必需成果全部可用',
|
||
FAILED: '成果交付失败'
|
||
}[status || ''] || status || '-')
|
||
const artifactLabel = (type?: string) =>
|
||
({
|
||
PDF_REPORT: 'PDF报告',
|
||
REPORT_FILE: 'PDF报告',
|
||
POINT_CLOUD: '点云',
|
||
MESH: '3D网格',
|
||
SCAN_PROJECT: '扫描工程',
|
||
IMAGE: '图像',
|
||
MEASUREMENT_DATA: '测量数据',
|
||
MEASUREMENT_EXPORT: '测量数据',
|
||
DEVICE_LOG: '设备日志',
|
||
OTHER: '其他'
|
||
}[type || ''] || type || '-')
|
||
const downloadArtifact = downloadArtifactFile
|
||
const claimLabel = (status?: string) => {
|
||
if (status === 'ACCEPTED') return '已受理'
|
||
if (status === 'PENDING') return '待领取'
|
||
if (status === 'REJECTED') return '已拒绝'
|
||
return status || '-'
|
||
}
|
||
const commandLabel = (status?: string) =>
|
||
({ PENDING: '待接收', DELIVERED: '已拉取', ACKED: '已确认', REJECTED: '已拒绝' }[status || ''] || status || '-')
|
||
let pollTimer: number | undefined
|
||
const stopPoll = () => {
|
||
if (pollTimer) {
|
||
window.clearInterval(pollTimer)
|
||
pollTimer = undefined
|
||
}
|
||
}
|
||
const liveNow = () => !!detail.value.status && !['SUCCEEDED', 'FAILED', 'CANCELLED'].includes(detail.value.status)
|
||
const startPoll = () => {
|
||
stopPoll()
|
||
if (!liveNow()) return
|
||
pollTimer = window.setInterval(async () => {
|
||
await load(false)
|
||
if (!liveNow()) stopPoll()
|
||
}, 3000)
|
||
}
|
||
const doDispatch = async () => {
|
||
await ExecutionApi.dispatchExecution(detail.value.id!)
|
||
message.success('已提交执行,请查看运行状态与节点日志')
|
||
await load()
|
||
startPoll()
|
||
}
|
||
const doPause = async () => {
|
||
await ExecutionApi.pauseExecution(detail.value.id!)
|
||
message.success('暂停指令待接收')
|
||
await load()
|
||
}
|
||
const doResume = async () => {
|
||
await ExecutionApi.resumeExecution(detail.value.id!)
|
||
message.success('继续指令待接收')
|
||
await load()
|
||
}
|
||
const doCancel = async () => {
|
||
const { value } = await ElMessageBox.prompt('请输入取消原因', '取消执行', { inputPattern: /\S+/, inputErrorMessage: '原因不能为空' })
|
||
await ExecutionApi.cancelExecution(detail.value.id!, value)
|
||
message.success('已取消')
|
||
await load()
|
||
}
|
||
const doSync = async () => {
|
||
if (!isLocalDetection.value) await ExecutionApi.syncExecution(detail.value.id!)
|
||
await load()
|
||
}
|
||
const submitFollow = async () => {
|
||
const id = await ExecutionApi.createFollowup({
|
||
parentExecutionId: detail.value.id!,
|
||
executionType: follow.executionType,
|
||
reason: follow.reason
|
||
})
|
||
followVisible.value = false
|
||
push({ name: 'LabExecutionWorkbench', params: { id: String(id) } })
|
||
}
|
||
onMounted(async () => {
|
||
await load()
|
||
startPoll()
|
||
})
|
||
onUnmounted(stopPoll)
|
||
</script>
|