306 lines
9.3 KiB
Vue
306 lines
9.3 KiB
Vue
<template>
|
|
<div class="execution-page">
|
|
<header class="execution-header">
|
|
<div class="execution-heading">
|
|
<h1>执行任务</h1><span class="task-total">{{ total }} 项</span>
|
|
</div>
|
|
<div class="header-actions">
|
|
<el-button :loading="loading" @click="load"
|
|
><Icon icon="ep:refresh" class="mr-6px" />刷新</el-button
|
|
>
|
|
<el-button type="primary" @click="push('/lab/task/import')"
|
|
><Icon icon="ep:upload" class="mr-6px" />导入任务</el-button
|
|
>
|
|
</div>
|
|
</header>
|
|
<ContentWrap class="execution-content" :body-style="{ padding: '0' }">
|
|
<el-form inline :model="query" class="execution-filters" @submit.prevent="search">
|
|
<el-form-item
|
|
><el-input
|
|
v-model="query.taskNo"
|
|
aria-label="任务编号"
|
|
placeholder="搜索任务编号"
|
|
clearable
|
|
@keyup.enter="search"
|
|
/></el-form-item>
|
|
<el-form-item
|
|
><el-select v-model="query.status" aria-label="状态" placeholder="全部状态" clearable class="!w-140px" @change="search"
|
|
><el-option
|
|
v-for="status in statuses"
|
|
:key="status"
|
|
:value="status"
|
|
:label="status === 'CLAIMED' ? '已领取' : statusLabel(status)" /></el-select
|
|
></el-form-item>
|
|
<el-form-item
|
|
><el-button @click="search"
|
|
><Icon icon="ep:search" class="mr-6px" />查询</el-button
|
|
><el-button text @click="resetFilters">重置</el-button></el-form-item
|
|
>
|
|
</el-form>
|
|
<el-table
|
|
v-loading="loading"
|
|
:data="rows"
|
|
row-key="id"
|
|
class="execution-table"
|
|
:row-style="{ height: '64px' }"
|
|
>
|
|
<el-table-column type="expand" width="40">
|
|
<template #default="{ row }"><div class="row-details"><span>外部编号:{{ row.externalTaskNo || '未填写' }}</span><span>负责人:{{ row.ownerName || row.ownerId || '未领取' }}</span></div></template>
|
|
</el-table-column>
|
|
<el-table-column label="任务" min-width="260">
|
|
<template #default="{ row }">
|
|
<div class="task-cell">
|
|
<strong :title="row.taskName">{{ row.taskName || '未命名任务' }}</strong>
|
|
<span class="task-number">{{ row.taskNo }}</span>
|
|
</div>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="扫描方案" min-width="180" show-overflow-tooltip
|
|
><template #default="{ row }"
|
|
><span :class="{ 'muted-text': !row.caseName && !row.testCaseId }">{{
|
|
row.caseName || row.testCaseId || '尚未关联方案'
|
|
}}</span></template
|
|
></el-table-column
|
|
>
|
|
<el-table-column label="样件进度" min-width="145"
|
|
><template #default="{ row }"
|
|
><div class="completion-cell"
|
|
><span
|
|
><strong>{{ row.completedCount || 0 }}</strong> / {{ row.quantity || 0 }} 件</span
|
|
>
|
|
<el-progress
|
|
:percentage="completion(row)"
|
|
:show-text="false"
|
|
:stroke-width="5"
|
|
:status="row.status === 'COMPLETED' ? 'success' : undefined" /></div></template
|
|
></el-table-column>
|
|
<el-table-column label="任务状态" width="120"
|
|
><template #default="{ row }"
|
|
><span class="task-state" :data-state="row.status"><i />{{ statusLabel(row.status) }}</span></template
|
|
></el-table-column
|
|
>
|
|
<el-table-column label="任务创建时间" prop="createTime" width="185" :formatter="dateFormatter" />
|
|
<el-table-column label="扫描完成时间" prop="completedAt" width="185" :formatter="dateFormatter" />
|
|
<el-table-column label="操作" width="110" fixed="right"
|
|
><template #default="{ row }"
|
|
><el-button
|
|
link
|
|
type="primary"
|
|
@click="push({ name: 'LabScanTaskWorkbench', params: { id: String(row.id) } })"
|
|
>{{
|
|
['COMPLETED', 'CANCELLED'].includes(row.status) ? '查看记录' : '进入工作台'
|
|
}}</el-button
|
|
></template
|
|
></el-table-column
|
|
>
|
|
<template #empty
|
|
><el-empty description="没有符合条件的任务,可调整筛选条件或导入任务" :image-size="88"
|
|
/></template>
|
|
</el-table>
|
|
<div class="execution-pagination">
|
|
<Pagination
|
|
:total="total"
|
|
v-model:page="query.pageNo"
|
|
v-model:limit="query.pageSize"
|
|
@pagination="load"
|
|
/>
|
|
</div>
|
|
</ContentWrap>
|
|
</div>
|
|
</template>
|
|
<script setup lang="ts">
|
|
import { dateFormatter } from '@/utils/formatTime'
|
|
import * as ScanApi from '@/api/lab/scan-task'
|
|
import { statusLabel } from '@/views/lab/scan-task/scanForm.mjs'
|
|
defineOptions({ name: 'LabExecution' })
|
|
const { push } = useRouter()
|
|
const route = useRoute()
|
|
const loading = ref(false)
|
|
const rows = ref<ScanApi.ScanTaskRow[]>([])
|
|
const total = ref(0)
|
|
const query = reactive({
|
|
pageNo: 1,
|
|
pageSize: 10,
|
|
taskNo: String(route.query.taskNo || ''),
|
|
status: (route.query.status === 'RUNNING'
|
|
? 'EXECUTING'
|
|
: route.query.status
|
|
? String(route.query.status)
|
|
: undefined) as string | undefined
|
|
})
|
|
const statuses = [
|
|
'PENDING_CONFIRM',
|
|
'CONFIRMED',
|
|
'CLAIMED',
|
|
'PREPARING',
|
|
'READY',
|
|
'EXECUTING',
|
|
'BLOCKED',
|
|
'STOP_PENDING',
|
|
'COMPLETED',
|
|
'CANCELLED'
|
|
]
|
|
let requestVersion = 0
|
|
const load = async () => {
|
|
const request = ++requestVersion
|
|
loading.value = true
|
|
try {
|
|
const result = await ScanApi.getPage(query)
|
|
if (request !== requestVersion) return
|
|
rows.value = result.list || []
|
|
total.value = result.total
|
|
} finally {
|
|
if (request === requestVersion) loading.value = false
|
|
}
|
|
}
|
|
const search = () => {
|
|
query.pageNo = 1
|
|
load()
|
|
}
|
|
const resetFilters = () => {
|
|
query.taskNo = ''
|
|
query.status = undefined
|
|
search()
|
|
}
|
|
const completion = (row: ScanApi.ScanTaskRow) =>
|
|
row.quantity > 0
|
|
? Math.min(100, Math.max(0, Math.round(((row.completedCount || 0) / row.quantity) * 100)))
|
|
: 0
|
|
let timer: ReturnType<typeof setInterval> | undefined
|
|
const startPolling = () => {
|
|
if (timer) return
|
|
load().catch(() => {})
|
|
timer = setInterval(() => {
|
|
if (!loading.value && !document.hidden) load().catch(() => {})
|
|
}, 10000)
|
|
}
|
|
const stopPolling = () => {
|
|
requestVersion++
|
|
clearInterval(timer)
|
|
timer = undefined
|
|
loading.value = false
|
|
}
|
|
onMounted(startPolling)
|
|
watch(
|
|
() => [route.query.taskNo, route.query.status],
|
|
() => {
|
|
query.taskNo = String(route.query.taskNo || '')
|
|
query.status =
|
|
route.query.status === 'RUNNING'
|
|
? 'EXECUTING'
|
|
: route.query.status
|
|
? String(route.query.status)
|
|
: undefined
|
|
search()
|
|
}
|
|
)
|
|
onActivated(startPolling)
|
|
onDeactivated(stopPolling)
|
|
onUnmounted(stopPolling)
|
|
</script>
|
|
<style scoped>
|
|
.execution-page {
|
|
color: var(--el-text-color-primary);
|
|
}
|
|
.execution-header,
|
|
.execution-heading,
|
|
.header-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 14px;
|
|
}
|
|
.execution-header {
|
|
justify-content: space-between;
|
|
flex-wrap: wrap;
|
|
margin: 0 0 14px;
|
|
}
|
|
.execution-heading {
|
|
min-width: 0;
|
|
gap: 10px;
|
|
}
|
|
h1 {
|
|
margin: 0;
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
}
|
|
.task-total {
|
|
color: var(--el-text-color-secondary);
|
|
font-size: 13px;
|
|
}
|
|
.header-actions {
|
|
gap: 10px;
|
|
}
|
|
.header-actions .el-button + .el-button {
|
|
margin-left: 0;
|
|
}
|
|
.execution-content {
|
|
border-radius: 6px;
|
|
}
|
|
.execution-filters {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 8px 12px;
|
|
align-items: center;
|
|
padding: 12px 16px;
|
|
border-bottom: 1px solid var(--el-border-color-lighter);
|
|
}
|
|
.execution-filters :deep(.el-form-item) {
|
|
margin: 0;
|
|
}
|
|
.execution-filters :deep(.el-input) {
|
|
width: 210px;
|
|
}
|
|
.muted-text {
|
|
color: var(--el-text-color-secondary);
|
|
font-size: 12px;
|
|
}
|
|
.execution-table :deep(th.el-table__cell) {
|
|
background: var(--el-fill-color-lighter);
|
|
color: var(--el-text-color-secondary);
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
}
|
|
.execution-table :deep(.cell) {
|
|
padding-left: 14px;
|
|
padding-right: 14px;
|
|
}
|
|
.task-cell {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 3px;
|
|
min-width: 0;
|
|
}
|
|
.task-cell strong {
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
.task-number {
|
|
font-size: 12px;
|
|
color: var(--el-text-color-regular);
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
.completion-cell {
|
|
display: grid;
|
|
gap: 6px;
|
|
padding-right: 12px;
|
|
color: var(--el-text-color-secondary);
|
|
font-size: 12px;
|
|
}
|
|
.completion-cell strong {
|
|
color: var(--el-text-color-primary);
|
|
font-weight: 500;
|
|
}
|
|
.execution-pagination {
|
|
padding: 4px 16px 12px;
|
|
}
|
|
.row-details { display: flex; flex-wrap: wrap; gap: 8px 28px; padding: 12px 54px; background: var(--el-fill-color-lighter); font-size: 12px; color: var(--el-text-color-regular); overflow-wrap: anywhere; }
|
|
.task-state { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; white-space: nowrap; }
|
|
.task-state i { width: 6px; height: 6px; border-radius: 50%; background: var(--el-text-color-placeholder); }
|
|
.task-state[data-state='COMPLETED'] i { background: var(--el-color-success); }
|
|
.task-state[data-state='EXECUTING'] i { background: var(--el-color-primary); }
|
|
.task-state[data-state='BLOCKED'] i, .task-state[data-state='STOP_PENDING'] i, .task-state[data-state='FAILED'] i { background: var(--el-color-danger); }
|
|
</style>
|