1
This commit is contained in:
parent
7f4a4549b6
commit
e3f5c9ede5
@ -5,9 +5,9 @@
|
||||
width="min(520px, 92vw)"
|
||||
append-to-body
|
||||
align-center
|
||||
:show-close="!loading"
|
||||
:show-close="!loading || Boolean(taskId)"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!loading"
|
||||
:close-on-press-escape="!loading || Boolean(taskId)"
|
||||
@update:model-value="emit('update:visible', $event)"
|
||||
>
|
||||
<div class="export-progress-panel">
|
||||
@ -23,6 +23,9 @@
|
||||
<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>
|
||||
@ -82,4 +85,11 @@ function formatDateTime(value: string | number | null | undefined) {
|
||||
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>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { computed, onBeforeUnmount, reactive, ref } from 'vue'
|
||||
import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { ExportMode } from '@/utils/asyncExportHelpers'
|
||||
import {
|
||||
@ -34,7 +34,33 @@ export function useAsyncExportTask(options: {
|
||||
|
||||
let exportPollingTimer: number | null = null
|
||||
|
||||
/** 连续轮询失败次数(网络异常/接口非成功),达到上限后放弃,避免无限请求 */
|
||||
let pollFailCount = 0
|
||||
/** 任务仍处于 submitted/running 且状态无任何推进的连续轮询次数 */
|
||||
let stallPollCount = 0
|
||||
/** 总轮询次数兜底(防无限轮询) */
|
||||
let totalPollCount = 0
|
||||
/** 上一轮快照,用于判断任务是否停滞 */
|
||||
let lastPollSnapshot: { status: string; progress: number; updateTime: number } | null = null
|
||||
|
||||
/** 连续失败达到该次数即放弃(网络/接口异常,继续重试无意义) */
|
||||
const MAX_CONSECUTIVE_FAILURES = 6
|
||||
/** 运行中连续无进展轮询达到该次数(约 2 分钟)判定为停滞并放弃 */
|
||||
const STALL_CONFIRM_POLLS = 80
|
||||
/** 总轮询次数兜底(约 15 分钟) */
|
||||
const MAX_TOTAL_POLLS = 600
|
||||
/** 失败重试间隔 */
|
||||
const FAILURE_RETRY_DELAY = 2000
|
||||
|
||||
function resetPollGuards() {
|
||||
pollFailCount = 0
|
||||
stallPollCount = 0
|
||||
totalPollCount = 0
|
||||
lastPollSnapshot = null
|
||||
}
|
||||
|
||||
function resetExportProgress() {
|
||||
resetPollGuards()
|
||||
exportTaskProgress.taskId = ''
|
||||
exportTaskProgress.status = 'submitted'
|
||||
exportTaskProgress.progress = 0
|
||||
@ -76,6 +102,16 @@ export function useAsyncExportTask(options: {
|
||||
}
|
||||
}
|
||||
|
||||
/** 停止等待并清理(用于轮询失败/停滞/超时),避免无限请求与进度框无法关闭 */
|
||||
function giveUpExportWaiting(message: string) {
|
||||
stopExportPolling()
|
||||
exportLoading.value = false
|
||||
exportDialogVisible.value = false
|
||||
clearSavedExportTaskId()
|
||||
resetExportProgress()
|
||||
ElMessage.error(message)
|
||||
}
|
||||
|
||||
async function refreshExportTaskProgress() {
|
||||
if (!exportTaskProgress.taskId) return
|
||||
try {
|
||||
@ -84,9 +120,15 @@ export function useAsyncExportTask(options: {
|
||||
taskId: exportTaskProgress.taskId
|
||||
})
|
||||
if (!isSuccess(res)) {
|
||||
pollFailCount += 1
|
||||
if (pollFailCount >= MAX_CONSECUTIVE_FAILURES) {
|
||||
giveUpExportWaiting('导出进度查询异常次数过多,已停止自动等待,请稍后重新导出')
|
||||
return
|
||||
}
|
||||
scheduleExportPolling()
|
||||
return
|
||||
}
|
||||
pollFailCount = 0
|
||||
const payload = parseExportTaskPayload(res)
|
||||
exportTaskProgress.status = String(payload.status || exportTaskProgress.status)
|
||||
exportTaskProgress.progress = Number.isFinite(Number(payload.progress))
|
||||
@ -125,9 +167,42 @@ export function useAsyncExportTask(options: {
|
||||
return
|
||||
}
|
||||
|
||||
// 仍处于 submitted/running:继续轮询,但做停滞/总次数兜底,杜绝无限请求
|
||||
totalPollCount += 1
|
||||
const snapshot = {
|
||||
status: exportTaskProgress.status,
|
||||
progress: exportTaskProgress.progress,
|
||||
updateTime: exportTaskProgress.updateTime
|
||||
}
|
||||
if (
|
||||
lastPollSnapshot
|
||||
&& lastPollSnapshot.status === snapshot.status
|
||||
&& lastPollSnapshot.progress === snapshot.progress
|
||||
&& lastPollSnapshot.updateTime === snapshot.updateTime
|
||||
) {
|
||||
stallPollCount += 1
|
||||
} else {
|
||||
stallPollCount = 0
|
||||
}
|
||||
lastPollSnapshot = snapshot
|
||||
|
||||
if (stallPollCount >= STALL_CONFIRM_POLLS) {
|
||||
giveUpExportWaiting('导出任务长时间无进度更新,可能后台处理异常,已停止等待,请重新导出')
|
||||
return
|
||||
}
|
||||
if (totalPollCount >= MAX_TOTAL_POLLS) {
|
||||
giveUpExportWaiting('导出等待超时,已停止轮询,请稍后重新导出')
|
||||
return
|
||||
}
|
||||
|
||||
scheduleExportPolling()
|
||||
} catch {
|
||||
scheduleExportPolling(2000)
|
||||
pollFailCount += 1
|
||||
if (pollFailCount >= MAX_CONSECUTIVE_FAILURES) {
|
||||
giveUpExportWaiting('导出进度查询连续失败,已停止自动等待,请检查网络后重新导出')
|
||||
return
|
||||
}
|
||||
scheduleExportPolling(FAILURE_RETRY_DELAY)
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,6 +287,7 @@ export function useAsyncExportTask(options: {
|
||||
function resumeExportTaskFromStorage() {
|
||||
const savedTaskId = getSavedExportTaskId()
|
||||
if (!savedTaskId || exportLoading.value) return
|
||||
resetPollGuards()
|
||||
exportTaskProgress.taskId = savedTaskId
|
||||
exportTaskProgress.status = 'submitted'
|
||||
exportTaskProgress.progress = 0
|
||||
@ -228,6 +304,16 @@ export function useAsyncExportTask(options: {
|
||||
return Boolean(getSavedExportTaskId())
|
||||
}
|
||||
|
||||
// 用户在等待轮询期间主动关闭进度框:停止轮询并解除 loading,
|
||||
// 保留已保存的 taskId,便于之后再次进入页面时恢复查询/下载
|
||||
watch(exportDialogVisible, (visible) => {
|
||||
if (!visible && exportLoading.value && exportTaskProgress.taskId) {
|
||||
stopExportPolling()
|
||||
exportLoading.value = false
|
||||
resetPollGuards()
|
||||
}
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopExportPolling()
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user