feat(purchase-transaction): 重构handleFileSuccess方法实现异步导入优化

- 增强响应数据验证,确保taskId存在
- 清理旧的轮询定时器,避免内存泄漏
- 保存导入任务初始状态到localStorage
- 使用$notify通知替代弹窗提示
- 重置失败按钮和任务ID状态
- 调用startImportStatusPolling开始轮询

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
wkc
2026-02-08 14:00:10 +08:00
parent 8699559436
commit c620dc8b6d

View File

@@ -905,25 +905,54 @@ export default {
handleFileUploadProgress(event, file, fileList) { handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true; this.upload.isUploading = true;
}, },
// 文件上传成功处理 - 使用异步导入 // 文件上传成功处理
handleFileSuccess(response, file, fileList) { handleFileSuccess(response, file, fileList) {
// 检查是否返回了taskId异步导入
if (response.code === 200 && response.data && response.data.taskId) {
const taskId = response.data.taskId;
this.upload.isUploading = false; this.upload.isUploading = false;
this.upload.open = false; this.upload.open = false;
this.$refs.upload.clearFiles();
// 开始轮询导入状态 if (response.code === 200) {
this.startImportPolling(taskId); // 验证响应数据完整性
} else { if (!response.data || !response.data.taskId) {
// 同步导入结果(如果后端改为同步) this.$modal.msgError('导入任务创建失败:缺少任务ID');
this.upload.isUploading = false; this.upload.isUploading = false;
this.upload.open = false; this.upload.open = true;
this.getList(); return;
this.importResultContent = response.msg || response; }
this.importResultVisible = true;
this.$refs.upload.clearFiles(); const taskId = response.data.taskId;
// 清除旧的轮询定时器
if (this.importPollingTimer) {
clearInterval(this.importPollingTimer);
this.importPollingTimer = null;
}
this.clearImportTaskFromStorage();
// 保存新任务的初始状态
this.saveImportTaskToStorage({
taskId: taskId,
status: 'PROCESSING',
timestamp: Date.now(),
hasFailures: false
});
// 重置状态
this.showFailureButton = false;
this.currentTaskId = taskId;
// 显示后台处理提示(不是弹窗,是通知)
this.$notify({
title: '导入任务已提交',
message: '正在后台处理中,处理完成后将通知您',
type: 'info',
duration: 3000
});
// 开始轮询检查状态
this.startImportStatusPolling(taskId);
} else {
this.$modal.msgError(response.msg);
} }
}, },
// 开始轮询导入状态 // 开始轮询导入状态