Files
one-pipe-system/src/views/asset-management/task-management/phone-asset-unbind-import-tasks/detail.vue
luo 085a83d4e4
Some checks failed
构建并部署前端到测试环境 / build-and-deploy (push) Has been cancelled
fix: some
2026-09-20 10:10:50 +08:00

279 lines
8.6 KiB
Vue

<template>
<ArtTableFullScreen>
<div class="unbind-import-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>
<div v-if="loading && !taskDetail" class="detail-loading">
<ElIcon class="is-loading" :size="36">
<Loading />
</ElIcon>
<div>加载中...</div>
</div>
<template v-else-if="taskDetail">
<DetailPage :sections="detailSections" :data="taskDetail" />
<div class="row-table-title">逐行结果</div>
<ElTable :data="taskDetail.items || []" border stripe size="default" max-height="460">
<ElTableColumn prop="line" label="行号" width="80" />
<ElTableColumn
prop="asset_identifier"
label="资产标识(原文)"
min-width="180"
show-overflow-tooltip
/>
<ElTableColumn prop="asset_type" label="资产类型" width="110">
<template #default="{ row }">
{{ row.asset_type ? (row.asset_type === 'iot_card' ? '物联网卡' : '设备') : '-' }}
</template>
</ElTableColumn>
<ElTableColumn prop="asset_id" label="资产ID" width="100">
<template #default="{ row }">
{{ row.asset_id ? row.asset_id : '-' }}
</template>
</ElTableColumn>
<ElTableColumn prop="status" label="行状态" width="90">
<template #default="{ row }">
<ElTag :type="row.status === 3 ? 'success' : 'danger'" size="small">
{{ row.status_name || (row.status === 3 ? '成功' : '失败') }}
</ElTag>
</template>
</ElTableColumn>
<ElTableColumn
prop="associated_phones"
label="解绑时关联手机号"
min-width="200"
show-overflow-tooltip
>
<template #default="{ row }">
{{ (row.associated_phones || []).join('、') || '-' }}
</template>
</ElTableColumn>
<ElTableColumn prop="unbound_count" label="解除关系数" width="100" />
<ElTableColumn prop="reason" label="失败原因" min-width="200" show-overflow-tooltip>
<template #default="{ row }">
{{ row.reason || '-' }}
</template>
</ElTableColumn>
</ElTable>
</template>
<ElEmpty v-else description="暂无详情" />
</ElCard>
</div>
</ArtTableFullScreen>
</template>
<script setup lang="ts">
import { computed, h, onBeforeUnmount, onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElButton, ElCard, ElEmpty, ElIcon, ElMessage, 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 { PhoneAssetAssociationService } from '@/api/modules'
import { useAuth } from '@/composables/useAuth'
import { formatDateTime } from '@/utils/business/format'
import { normalizeApiError } from '@/utils/business/apiError'
import { RoutesAlias } from '@/router/routesAlias'
import { AUGUST_PERMISSIONS } from '@/config/constants'
import type {
PhoneAssetUnbindImportTaskDetail,
PhoneAssetUnbindImportTaskStatus
} from '@/types/api'
defineOptions({ name: 'PhoneAssetUnbindImportTaskDetail' })
const route = useRoute()
const router = useRouter()
const { hasAuth } = useAuth()
const taskId = computed(() => Number(route.query.id || route.params.id || 0))
const loading = ref(false)
const taskDetail = ref<PhoneAssetUnbindImportTaskDetail | null>(null)
let pollTimer: ReturnType<typeof setInterval> | null = null
const getStatusTagType = (status?: PhoneAssetUnbindImportTaskStatus) => {
const map: Record<number, 'info' | 'warning' | 'success' | 'danger'> = {
1: 'info',
2: 'warning',
3: 'success',
4: 'danger'
}
return status ? map[status] || 'info' : 'info'
}
const fetchDetail = async () => {
if (!taskId.value) {
ElMessage.error('缺少任务ID')
return
}
loading.value = true
try {
const res = await PhoneAssetAssociationService.getUnbindImportTaskDetail(taskId.value)
if (res.code === 403) {
ElMessage.error(res.msg || '无权限查看该任务详情')
return
}
if (res.code !== 0 || !res.data) {
ElMessage.error(res.msg || '获取解绑导入任务详情失败')
return
}
taskDetail.value = res.data
startPollingIfNeeded()
} catch (error) {
console.error('获取解绑导入任务详情失败:', error)
ElMessage.error(normalizeApiError(error).message || '获取解绑导入任务详情失败')
} finally {
loading.value = false
}
}
const startPollingIfNeeded = () => {
const status = taskDetail.value?.status
if (status === 1 || status === 2) {
if (!pollTimer) {
pollTimer = setInterval(fetchDetail, 5000)
}
} else {
stopPolling()
}
}
const stopPolling = () => {
if (pollTimer) {
clearInterval(pollTimer)
pollTimer = null
}
}
const detailSections = computed((): DetailSection[] => {
const data = taskDetail.value
if (!data) return []
return [
{
title: '任务基本信息',
fields: [
{ label: '任务编号', prop: 'task_no', formatter: (value: string) => value || '-' },
{ label: '文件名', prop: 'file_name', formatter: (value: string) => value || '-' },
{
label: '任务状态',
render: (task: PhoneAssetUnbindImportTaskDetail) =>
h(ElTag, { type: getStatusTagType(task.status) }, () => task.status_name || '-')
},
{
label: '任务级解绑原因',
prop: 'unbind_reason',
fullWidth: true,
formatter: (value: string) => value || '-'
},
{
label: '创建人',
prop: 'creator_name',
formatter: (value: string) => value || '-'
},
{
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: 'total_count',
formatter: (value: number) => String(value ?? 0)
},
{
label: '成功行数',
prop: 'success_count',
formatter: (value: number) => String(value ?? 0)
},
{
label: '失败行数',
prop: 'fail_count',
formatter: (value: number) => String(value ?? 0)
}
]
}
]
})
const goBack = () => {
router.push(RoutesAlias.PhoneAssetUnbindImportTasks)
}
onMounted(() => {
if (!hasAuth(AUGUST_PERMISSIONS.phoneAssetAssociation.unbindImportDetail)) {
ElMessage.warning('您没有查看解绑导入任务详情的权限')
goBack()
return
}
fetchDetail()
})
onBeforeUnmount(() => {
stopPolling()
})
</script>
<style scoped lang="scss">
.unbind-import-task-detail-page {
height: 100%;
}
.detail-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 16px;
.detail-title {
margin: 0;
font-size: 18px;
font-weight: 600;
}
}
.detail-loading {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
padding: 60px 0;
color: var(--el-text-color-secondary);
}
.row-table-title {
margin: 20px 0 12px;
font-size: 15px;
font-weight: 600;
}
</style>