379 lines
12 KiB
Vue
379 lines
12 KiB
Vue
<template>
|
|
<ArtTableFullScreen>
|
|
<div class="task-detail-page" id="table-full-screen">
|
|
<ElCard shadow="never" class="art-table-card">
|
|
<div class="detail-header">
|
|
<ElButton @click="goBack">
|
|
<template #icon>
|
|
<ElIcon><ArrowLeft /></ElIcon>
|
|
</template>
|
|
返回
|
|
</ElButton>
|
|
<h2 class="detail-title">{{ taskTitle }}</h2>
|
|
</div>
|
|
|
|
<DetailPage v-if="taskDetail" :sections="detailSections" :data="taskDetail" />
|
|
|
|
<div v-if="taskDetail?.fail_count && taskDetail.fail_count > 0" class="result-section">
|
|
<ElDivider content-position="left">
|
|
<span class="section-title"
|
|
>{{ resultAction }}失败记录 ({{ taskDetail.fail_count }})</span
|
|
>
|
|
</ElDivider>
|
|
<ElTable :data="taskDetail.failed_items || []" border style="width: 100%">
|
|
<ElTableColumn prop="line" label="行号" width="100" />
|
|
<ElTableColumn v-if="taskType === 'card'" prop="iccid" label="ICCID" min-width="180" />
|
|
<ElTableColumn v-else label="设备标识" min-width="180" show-overflow-tooltip>
|
|
<template #default="scope">
|
|
{{ scope.row.device_identifier || scope.row.virtual_no || '-' }}
|
|
</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn prop="reason" :label="`${resultAction}失败原因`" min-width="300" />
|
|
</ElTable>
|
|
</div>
|
|
|
|
<div v-if="taskDetail?.skip_count && taskDetail.skip_count > 0" class="result-section">
|
|
<ElDivider content-position="left">
|
|
<span class="section-title"
|
|
>{{ resultAction }}跳过记录 ({{ taskDetail.skip_count }})</span
|
|
>
|
|
</ElDivider>
|
|
<ElTable :data="taskDetail.skipped_items || []" border style="width: 100%">
|
|
<ElTableColumn prop="line" label="行号" width="100" />
|
|
<ElTableColumn v-if="taskType === 'card'" prop="iccid" label="ICCID" min-width="180" />
|
|
<ElTableColumn v-else label="设备标识" min-width="180" show-overflow-tooltip>
|
|
<template #default="scope">
|
|
{{ scope.row.device_identifier || scope.row.virtual_no || '-' }}
|
|
</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn prop="reason" :label="`${resultAction}跳过原因`" min-width="300" />
|
|
</ElTable>
|
|
</div>
|
|
|
|
<div v-if="warningCount > 0" class="result-section">
|
|
<ElDivider content-position="left">
|
|
<span class="section-title">{{ resultAction }}警告记录 ({{ warningCount }})</span>
|
|
</ElDivider>
|
|
<ElTable :data="warningItems" border style="width: 100%">
|
|
<ElTableColumn prop="line" label="行号" width="100" />
|
|
<ElTableColumn label="设备标识" min-width="180" show-overflow-tooltip>
|
|
<template #default="scope">
|
|
{{ scope.row.device_identifier || scope.row.virtual_no || '-' }}
|
|
</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn prop="reason" label="警告原因" min-width="300" />
|
|
</ElTable>
|
|
</div>
|
|
</ElCard>
|
|
</div>
|
|
</ArtTableFullScreen>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, h, onMounted, ref } from 'vue'
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
import { CardService, DeviceService } from '@/api/modules'
|
|
import { ElDivider, ElIcon, ElMessage, ElTable, ElTableColumn, ElTag } from 'element-plus'
|
|
import type { TagProps } from 'element-plus'
|
|
import { ArrowLeft } from '@element-plus/icons-vue'
|
|
import { formatDateTime } from '@/utils/business/format'
|
|
import type { IotCardImportTaskDetail } from '@/types/api/card'
|
|
import type { DeviceImportTaskDetail, DeviceImportTaskOperationType } from '@/types/api/device'
|
|
import type { DetailSection } from '@/components/common/DetailPage.vue'
|
|
import DetailPage from '@/components/common/DetailPage.vue'
|
|
import { useUserStore } from '@/store/modules/user'
|
|
|
|
defineOptions({ name: 'TaskDetail' })
|
|
|
|
const router = useRouter()
|
|
const route = useRoute()
|
|
const userStore = useUserStore()
|
|
const isPlatformAccount = computed(() => [1, 2].includes(Number(userStore.info.user_type)))
|
|
|
|
type TaskType = 'card' | 'device'
|
|
type TaskDetail = IotCardImportTaskDetail | DeviceImportTaskDetail
|
|
|
|
const taskDetail = ref<TaskDetail | null>(null)
|
|
const taskType = ref<TaskType>('card')
|
|
const loading = ref(false)
|
|
const getOperationLabel = (operationType?: DeviceImportTaskOperationType) => {
|
|
switch (operationType) {
|
|
case 'assign_shop':
|
|
return '分配目标代理'
|
|
case 'assign_series':
|
|
return '设置套餐系列'
|
|
case 'recall':
|
|
return '批量回收设备'
|
|
case 'import':
|
|
return '导入设备'
|
|
default:
|
|
return '设备任务'
|
|
}
|
|
}
|
|
|
|
const deviceTask = computed(() =>
|
|
taskType.value === 'device' ? (taskDetail.value as DeviceImportTaskDetail | null) : null
|
|
)
|
|
const taskTitle = computed(() =>
|
|
taskType.value === 'device'
|
|
? `${getOperationLabel(deviceTask.value?.operation_type)}任务详情`
|
|
: 'ICCID导入任务详情'
|
|
)
|
|
const resultAction = computed(() => {
|
|
if (taskType.value !== 'device') return '导入'
|
|
switch (deviceTask.value?.operation_type) {
|
|
case 'assign_shop':
|
|
return '分配'
|
|
case 'assign_series':
|
|
return '设置套餐系列'
|
|
case 'recall':
|
|
return '回收'
|
|
default:
|
|
return '导入'
|
|
}
|
|
})
|
|
const warningCount = computed(() =>
|
|
taskType.value === 'device' ? deviceTask.value?.warning_count || 0 : 0
|
|
)
|
|
const warningItems = computed(() =>
|
|
taskType.value === 'device' ? deviceTask.value?.warning_items || [] : []
|
|
)
|
|
|
|
const getStatusType = (status?: number): TagProps['type'] => {
|
|
switch (status) {
|
|
case 1:
|
|
return 'info'
|
|
case 2:
|
|
return 'warning'
|
|
case 3:
|
|
return 'success'
|
|
case 4:
|
|
return 'danger'
|
|
default:
|
|
return 'info'
|
|
}
|
|
}
|
|
|
|
const detailSections = computed((): DetailSection[] => {
|
|
const deviceFields: DetailSection['fields'] =
|
|
taskType.value === 'device'
|
|
? [
|
|
{
|
|
label: '操作名称',
|
|
prop: 'operation_name',
|
|
formatter: (value: string) =>
|
|
value || getOperationLabel(deviceTask.value?.operation_type)
|
|
},
|
|
{
|
|
label: '目标名称',
|
|
prop: 'target_name',
|
|
formatter: (value: string | null | undefined) => value || '-'
|
|
}
|
|
]
|
|
: []
|
|
|
|
const cardFields: DetailSection['fields'] =
|
|
taskType.value === 'card'
|
|
? [
|
|
{
|
|
label: '运营商',
|
|
prop: 'carrier_name',
|
|
formatter: (value: string) => value || '-'
|
|
},
|
|
{
|
|
label: '卡业务类型',
|
|
render: (data: any) => {
|
|
if (!data.card_category) return h('span', '-')
|
|
return h(
|
|
ElTag,
|
|
{
|
|
type: data.card_category === 'industry' ? 'warning' : 'success',
|
|
size: 'small'
|
|
},
|
|
() =>
|
|
data.card_category === 'normal'
|
|
? '普通卡'
|
|
: data.card_category === 'industry'
|
|
? '行业卡'
|
|
: data.card_category
|
|
)
|
|
}
|
|
}
|
|
]
|
|
: []
|
|
|
|
return [
|
|
{
|
|
title: '任务基本信息',
|
|
fields: [
|
|
{ label: '任务编号', prop: 'task_no', formatter: (value: string) => value || '-' },
|
|
{
|
|
label: '任务类型',
|
|
render: () =>
|
|
h(
|
|
ElTag,
|
|
{ type: taskType.value === 'device' ? 'warning' : 'primary', size: 'small' },
|
|
() =>
|
|
taskType.value === 'device'
|
|
? getOperationLabel(deviceTask.value?.operation_type)
|
|
: 'ICCID导入'
|
|
)
|
|
},
|
|
...deviceFields,
|
|
{ label: '批次号', prop: 'batch_no', formatter: (value: string) => value || '-' },
|
|
{ label: '文件名', prop: 'file_name', formatter: (value: string) => value || '-' },
|
|
{ label: '操作人', prop: 'creator_name', formatter: (value: string) => value || '-' },
|
|
{
|
|
label: '任务状态',
|
|
render: (data: TaskDetail) =>
|
|
h(
|
|
ElTag,
|
|
{ type: getStatusType(data.status) },
|
|
() => (data as DeviceImportTaskDetail).status_name || data.status_text || '-'
|
|
)
|
|
},
|
|
...cardFields,
|
|
{
|
|
label: '创建时间',
|
|
prop: 'created_at',
|
|
formatter: (value: string) => (value ? formatDateTime(value) : '-')
|
|
},
|
|
{
|
|
label: '开始处理时间',
|
|
prop: 'started_at',
|
|
formatter: (value: string | null) => (value ? formatDateTime(value) : '-')
|
|
},
|
|
{
|
|
label: '完成时间',
|
|
prop: 'completed_at',
|
|
formatter: (value: string | null) => (value ? formatDateTime(value) : '-')
|
|
},
|
|
...(taskDetail.value?.error_message
|
|
? [
|
|
{
|
|
label: '错误信息',
|
|
prop: 'error_message',
|
|
fullWidth: true,
|
|
render: (data: TaskDetail) =>
|
|
h(
|
|
'span',
|
|
{ style: { color: 'var(--el-color-danger)' } },
|
|
data.error_message || ''
|
|
)
|
|
}
|
|
]
|
|
: [])
|
|
]
|
|
},
|
|
{
|
|
title: '统计信息',
|
|
columns: 2,
|
|
fields: [
|
|
{
|
|
label: '总数',
|
|
render: (data: TaskDetail) =>
|
|
h(
|
|
'span',
|
|
{
|
|
style: { fontSize: '16px', fontWeight: 'bold', color: 'var(--el-color-primary)' }
|
|
},
|
|
String(data.total_count || 0)
|
|
)
|
|
},
|
|
{
|
|
label: '成功数',
|
|
render: (data: TaskDetail) =>
|
|
h(ElTag, { type: 'success' }, () => String(data.success_count || 0))
|
|
},
|
|
{
|
|
label: '失败数',
|
|
render: (data: TaskDetail) =>
|
|
h(ElTag, { type: 'danger' }, () => String(data.fail_count || 0))
|
|
},
|
|
{
|
|
label: '跳过数',
|
|
render: (data: TaskDetail) =>
|
|
h(ElTag, { type: 'warning' }, () => String(data.skip_count || 0))
|
|
},
|
|
...(taskType.value === 'device'
|
|
? [
|
|
{
|
|
label: '警告数',
|
|
render: (data: TaskDetail) =>
|
|
h(ElTag, { type: 'info' }, () =>
|
|
String((data as DeviceImportTaskDetail).warning_count || 0)
|
|
)
|
|
}
|
|
]
|
|
: [])
|
|
]
|
|
}
|
|
]
|
|
})
|
|
|
|
const goBack = () => router.back()
|
|
|
|
const getTaskDetail = async () => {
|
|
const taskId = route.query.id
|
|
const queryTaskType = route.query.task_type as TaskType | undefined
|
|
if (!taskId) {
|
|
ElMessage.error('缺少任务 ID 参数')
|
|
goBack()
|
|
return
|
|
}
|
|
if (queryTaskType) taskType.value = queryTaskType
|
|
if (taskType.value === 'device' && !isPlatformAccount.value) {
|
|
ElMessage.error('当前账号无权查看设备任务详情')
|
|
goBack()
|
|
return
|
|
}
|
|
|
|
loading.value = true
|
|
try {
|
|
if (taskType.value === 'device') {
|
|
const res = await DeviceService.getImportTaskDetail(Number(taskId))
|
|
if (res.code === 0) taskDetail.value = res.data
|
|
} else {
|
|
const res = await CardService.getIotCardImportTaskDetail(Number(taskId))
|
|
if (res.code === 0) taskDetail.value = res.data
|
|
}
|
|
} catch (error) {
|
|
console.error('获取任务详情失败:', error)
|
|
ElMessage.error('获取任务详情失败')
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
void getTaskDetail()
|
|
})
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.task-detail-page {
|
|
.detail-header {
|
|
display: flex;
|
|
gap: 16px;
|
|
align-items: center;
|
|
padding-bottom: 16px;
|
|
|
|
.detail-title {
|
|
margin: 0;
|
|
font-size: 20px;
|
|
font-weight: 600;
|
|
color: var(--el-text-color-primary);
|
|
}
|
|
}
|
|
|
|
.result-section {
|
|
margin-top: 20px;
|
|
|
|
.section-title {
|
|
font-size: 16px;
|
|
font-weight: bold;
|
|
}
|
|
}
|
|
}
|
|
</style>
|