fix: 改进导入处理逻辑的健壮性
- 添加response验证,防止taskId缺失 - 添加轮询超时机制,防止无限轮询(5分钟) - 完善状态处理逻辑,成功时清除失败按钮 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -685,6 +685,14 @@ export default {
|
|||||||
this.upload.open = false;
|
this.upload.open = false;
|
||||||
|
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
|
// 验证响应数据完整性
|
||||||
|
if (!response.data || !response.data.taskId) {
|
||||||
|
this.$modal.msgError('导入任务创建失败:缺少任务ID');
|
||||||
|
this.upload.isUploading = false;
|
||||||
|
this.upload.open = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const taskId = response.data.taskId;
|
const taskId = response.data.taskId;
|
||||||
|
|
||||||
// 清除旧的导入记录(防止并发)
|
// 清除旧的导入记录(防止并发)
|
||||||
@@ -728,8 +736,20 @@ export default {
|
|||||||
},
|
},
|
||||||
/** 开始轮询导入状态 */
|
/** 开始轮询导入状态 */
|
||||||
startImportStatusPolling(taskId) {
|
startImportStatusPolling(taskId) {
|
||||||
|
let pollCount = 0;
|
||||||
|
const maxPolls = 150; // 最多轮询150次(5分钟)
|
||||||
|
|
||||||
this.pollingTimer = setInterval(async () => {
|
this.pollingTimer = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
|
pollCount++;
|
||||||
|
|
||||||
|
// 超时检查
|
||||||
|
if (pollCount > maxPolls) {
|
||||||
|
clearInterval(this.pollingTimer);
|
||||||
|
this.$modal.msgWarning('导入任务处理超时,请联系管理员');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await getImportStatus(taskId);
|
const response = await getImportStatus(taskId);
|
||||||
|
|
||||||
if (response.data && response.data.status !== 'PROCESSING') {
|
if (response.data && response.data.status !== 'PROCESSING') {
|
||||||
@@ -761,6 +781,7 @@ export default {
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
duration: 5000
|
duration: 5000
|
||||||
});
|
});
|
||||||
|
this.showFailureButton = false; // 成功时清除失败按钮显示
|
||||||
this.getList();
|
this.getList();
|
||||||
} else if (statusResult.failureCount > 0) {
|
} else if (statusResult.failureCount > 0) {
|
||||||
this.$notify({
|
this.$notify({
|
||||||
|
|||||||
Reference in New Issue
Block a user