WEB/src/components/AsyncExportProgressDialog.vue
2026-09-03 18:36:28 +08:00

96 lines
2.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<el-dialog
:model-value="visible"
:title="title"
width="min(520px, 92vw)"
append-to-body
align-center
:show-close="!loading || Boolean(taskId)"
:close-on-click-modal="false"
:close-on-press-escape="!loading || Boolean(taskId)"
@update:model-value="emit('update:visible', $event)"
>
<div class="export-progress-panel">
<div class="export-progress-panel__header">
<span class="export-progress-panel__meta">任务ID:{{ taskId || '—' }}</span>
</div>
<el-progress :percentage="progressPercent" :status="progressStatus" :stroke-width="16" />
<div class="export-progress-panel__info">
<span>状态:{{ statusLabel }}</span>
<span>进度:{{ progressPercent }}%</span>
<span v-if="updateTime">更新时间:{{ formatDateTime(updateTime) }}</span>
</div>
<div v-if="message || error" class="export-progress-panel__message">
{{ error || message }}
</div>
<div v-if="loading && taskId" class="export-progress-panel__tip">
导出任务在后台执行中,关闭本窗口可停止自动刷新;重新进入本页面或再次点击导出可恢复查看结果。
</div>
</div>
</el-dialog>
</template>
<script setup lang="ts">
defineProps<{
visible: boolean
title?: string
loading: boolean
progressPercent: number
progressStatus?: '' | 'success' | 'exception' | 'warning'
statusLabel: string
taskId: string
message: string
error: string
updateTime?: number | string
}>()
const emit = defineEmits<{
(e: 'update:visible', value: boolean): void
}>()
function formatDateTime(value: string | number | null | undefined) {
if (!value) return '—'
let normalizedValue: string | number = value
if (typeof value === 'string' && /^\d+$/.test(value.trim())) {
normalizedValue = Number(value)
}
const date = typeof normalizedValue === 'number'
? new Date(normalizedValue < 1000000000000 ? normalizedValue * 1000 : normalizedValue)
: new Date(String(normalizedValue))
if (Number.isNaN(date.getTime())) return String(value)
const pad = (n: number) => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
}
</script>
<style scoped lang="scss">
.export-progress-panel {
display: flex;
flex-direction: column;
gap: 12px;
}
.export-progress-panel__header,
.export-progress-panel__info {
display: flex;
flex-wrap: wrap;
gap: 12px;
color: #606266;
font-size: 13px;
}
.export-progress-panel__message {
color: #909399;
font-size: 13px;
line-height: 1.5;
word-break: break-all;
}
.export-progress-panel__tip {
margin-top: 4px;
color: #b1b3b8;
font-size: 12px;
line-height: 1.5;
}
</style>