This commit is contained in:
@@ -0,0 +1,295 @@
|
||||
<template>
|
||||
<ArtTableFullScreen>
|
||||
<div class="export-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">导出任务详情</h2>
|
||||
<div class="detail-actions" v-if="taskDetail">
|
||||
<ElButton
|
||||
v-if="
|
||||
taskDetail.status === ExportTaskStatus.COMPLETED && hasAuth('export_task:download')
|
||||
"
|
||||
type="primary"
|
||||
@click="downloadTask"
|
||||
>
|
||||
下载文件
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-if="canCancelTask && hasAuth('export_task:cancel')"
|
||||
type="danger"
|
||||
@click="cancelTask"
|
||||
>
|
||||
取消任务
|
||||
</ElButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="detail-loading">
|
||||
<ElIcon class="is-loading" :size="36">
|
||||
<Loading />
|
||||
</ElIcon>
|
||||
<div>加载中...</div>
|
||||
</div>
|
||||
<DetailPage v-else-if="taskDetail" :sections="detailSections" :data="taskDetail" />
|
||||
<ElEmpty v-else description="暂无详情" />
|
||||
</ElCard>
|
||||
</div>
|
||||
</ArtTableFullScreen>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElButton, ElCard, ElEmpty, ElIcon, ElMessage, ElMessageBox, ElTag } from 'element-plus'
|
||||
import { ArrowLeft, Loading } from '@element-plus/icons-vue'
|
||||
import DetailPage from '@/components/common/DetailPage.vue'
|
||||
import type { DetailSection } from '@/components/common/DetailPage.vue'
|
||||
import { ExportTaskService } from '@/api/modules'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { formatDateTime } from '@/utils/business/format'
|
||||
import type { ExportTaskDetail, ExportTaskScene } from '@/types/api'
|
||||
import { ExportTaskStatus } from '@/types/api'
|
||||
|
||||
defineOptions({ name: 'ExportTaskDetail' })
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { hasAuth } = useAuth()
|
||||
const loading = ref(false)
|
||||
const taskDetail = ref<ExportTaskDetail | null>(null)
|
||||
|
||||
const getSceneName = (scene?: ExportTaskScene) => {
|
||||
const sceneMap: Record<ExportTaskScene, string> = {
|
||||
device: '设备管理',
|
||||
iot_card: 'IoT卡管理'
|
||||
}
|
||||
|
||||
return scene ? sceneMap[scene] : '-'
|
||||
}
|
||||
|
||||
const getStatusTagType = (status?: ExportTaskStatus) => {
|
||||
const statusTypeMap: Record<
|
||||
ExportTaskStatus,
|
||||
'primary' | 'success' | 'warning' | 'danger' | 'info'
|
||||
> = {
|
||||
[ExportTaskStatus.PENDING]: 'info',
|
||||
[ExportTaskStatus.PROCESSING]: 'warning',
|
||||
[ExportTaskStatus.COMPLETED]: 'success',
|
||||
[ExportTaskStatus.FAILED]: 'danger',
|
||||
[ExportTaskStatus.CANCELED]: 'info'
|
||||
}
|
||||
|
||||
return status ? statusTypeMap[status] : 'info'
|
||||
}
|
||||
|
||||
const canCancelTask = computed(() =>
|
||||
[ExportTaskStatus.PENDING, ExportTaskStatus.PROCESSING].includes(
|
||||
taskDetail.value?.status as ExportTaskStatus
|
||||
)
|
||||
)
|
||||
|
||||
const detailSections = computed((): DetailSection[] => [
|
||||
{
|
||||
title: '任务基本信息',
|
||||
fields: [
|
||||
{ label: '任务编号', prop: 'task_no', formatter: (value: string) => value || '-' },
|
||||
{
|
||||
label: '导出场景',
|
||||
render: (data: ExportTaskDetail) => h(ElTag, {}, () => getSceneName(data.scene))
|
||||
},
|
||||
{
|
||||
label: '任务状态',
|
||||
render: (data: ExportTaskDetail) =>
|
||||
h(ElTag, { type: getStatusTagType(data.status) }, () => data.status_name || '-')
|
||||
},
|
||||
{ label: '导出格式', prop: 'format', formatter: (value: string) => value || '-' },
|
||||
{
|
||||
label: '取消请求',
|
||||
formatter: (_value: unknown, data: ExportTaskDetail) =>
|
||||
data.cancel_requested ? '是' : '否'
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
prop: 'created_at',
|
||||
formatter: (value: string) => formatDateTime(value) || '-'
|
||||
},
|
||||
{
|
||||
label: '开始时间',
|
||||
prop: 'started_at',
|
||||
formatter: (value: string) => formatDateTime(value) || '-'
|
||||
},
|
||||
{
|
||||
label: '完成时间',
|
||||
prop: 'completed_at',
|
||||
formatter: (value: string) => formatDateTime(value) || '-'
|
||||
},
|
||||
{
|
||||
label: '错误信息',
|
||||
prop: 'error_message',
|
||||
fullWidth: true,
|
||||
formatter: (value: string) => value || '-'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '处理进度',
|
||||
fields: [
|
||||
{ label: '进度', prop: 'progress', formatter: (value: number) => `${value ?? 0}%` },
|
||||
{ label: '总行数', prop: 'total_rows', formatter: (value: number) => String(value ?? 0) },
|
||||
{
|
||||
label: '已处理行数',
|
||||
prop: 'processed_rows',
|
||||
formatter: (value: number) => String(value ?? 0)
|
||||
},
|
||||
{
|
||||
label: '分片进度',
|
||||
formatter: (_value: unknown, data: ExportTaskDetail) =>
|
||||
`${data.success_shards ?? 0}/${data.total_shards ?? 0}`
|
||||
},
|
||||
{
|
||||
label: '失败分片',
|
||||
prop: 'failed_shards',
|
||||
formatter: (value: number) => String(value ?? 0)
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '文件信息',
|
||||
fields: [
|
||||
{
|
||||
label: '文件Key',
|
||||
prop: 'file_key',
|
||||
fullWidth: true,
|
||||
formatter: (value: string) => value || '-'
|
||||
},
|
||||
{
|
||||
label: '下载地址',
|
||||
fullWidth: true,
|
||||
render: (data: ExportTaskDetail) => {
|
||||
if (!data.download_url) return h('span', '-')
|
||||
return h(
|
||||
ElButton,
|
||||
{
|
||||
type: 'primary',
|
||||
link: true,
|
||||
onClick: () => window.open(data.download_url, '_blank')
|
||||
},
|
||||
() => '打开下载地址'
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '下载过期时间',
|
||||
prop: 'download_expires_at',
|
||||
formatter: (value: string) => formatDateTime(value) || '-'
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
const goBack = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
const getTaskId = () => Number(route.query.id)
|
||||
|
||||
const getTaskDetail = async () => {
|
||||
const taskId = getTaskId()
|
||||
if (!taskId) {
|
||||
ElMessage.error('缺少任务ID参数')
|
||||
goBack()
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await ExportTaskService.getExportTaskDetail(taskId)
|
||||
if (res.code === 0) {
|
||||
taskDetail.value = res.data
|
||||
} else {
|
||||
ElMessage.error(res.msg || '获取导出任务详情失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取导出任务详情失败:', error)
|
||||
ElMessage.error('获取导出任务详情失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const downloadTask = () => {
|
||||
if (!taskDetail.value?.download_url) {
|
||||
ElMessage.warning('当前任务暂无可用下载地址')
|
||||
return
|
||||
}
|
||||
|
||||
window.open(taskDetail.value.download_url, '_blank')
|
||||
}
|
||||
|
||||
const cancelTask = () => {
|
||||
if (!taskDetail.value) return
|
||||
|
||||
ElMessageBox.confirm(`确定取消导出任务 ${taskDetail.value.task_no} 吗?`, '取消确认', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
try {
|
||||
const res = await ExportTaskService.cancelExportTask(taskDetail.value!.id)
|
||||
if (res.code === 0) {
|
||||
ElMessage.success(res.data?.message || '任务取消成功')
|
||||
getTaskDetail()
|
||||
} else {
|
||||
ElMessage.error(res.msg || '取消导出任务失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('取消导出任务失败:', error)
|
||||
ElMessage.error('取消导出任务失败')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getTaskDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.export-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);
|
||||
}
|
||||
|
||||
.detail-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.detail-loading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 220px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user