feat: 批量下载失败-重新下载

This commit is contained in:
rd
2025-07-21 15:42:35 +08:00
parent e6798bf313
commit 4387037b2d
2 changed files with 50 additions and 15 deletions

View File

@ -11,7 +11,7 @@ import { useTableSelectionWithPagination } from '@/hooks/useTableSelectionWithPa
import { downloadByUrl } from '@/utils/tools';
import DeleteTaskModal from './delete-task-modal.vue';
import icon1 from '@/assets/img/media-account/icon-delete.png';
import { showExportNotification } from '@/utils/arcoD';
import { showExportNotification, showFailExportNotification } from '@/utils/arcoD';
export default {
setup(props, { emit, expose }) {
@ -102,12 +102,13 @@ export default {
}
};
const clearQueryTaskTimer = () => {
if (queryTaskTimer) {
clearInterval(queryTaskTimer);
queryTaskTimer = null;
// 批量下载
const handleBatchDownload = debounce(async () => {
const { code, data } = await postBatchDownload({ ids: selectedRowKeys.value });
if (code === 200) {
startBatchDownload(data.id);
}
};
}, 500);
const startBatchDownload = (id) => {
const randomId = genRandomId();
showExportNotification(
@ -122,17 +123,10 @@ export default {
randomId,
});
// getSyncTaskStatus(randomId);
if (!queryTaskTimer) {
queryTaskTimer = setInterval(() => getSyncTaskStatus(), 3000);
}
};
const handleBatchDownload = debounce(async () => {
const { code, data } = await postBatchDownload({ ids: selectedRowKeys.value });
if (code === 200) {
startBatchDownload(data.id);
}
}, 500);
const getSyncTaskStatus = async () => {
const { code, data } = await batchQueryTaskStatus({ ids: downloadTaskIds.value.map((v) => v.id) });
if (code === 200) {
@ -149,8 +143,17 @@ export default {
AMessage.success('批量下载已完成,正在下载文件...');
downloadByUrl(file);
} else if (status === 2) {
AMessage.error('批量下载失败,请重新尝试下载');
const onReDownload = () => {
startBatchDownload(id);
};
showFailExportNotification(
`${selectedRows.value[0]?.name}”等${selectedRows.value.length}个文件下载失败`,
{ onReDownload },
);
}
// 结束的任务过滤掉
downloadTaskIds.value = downloadTaskIds.value.filter((v) => v.id !== id);
}
});
@ -182,6 +185,13 @@ export default {
selectedRowKeys.value = [];
getData();
};
const clearQueryTaskTimer = () => {
if (queryTaskTimer) {
clearInterval(queryTaskTimer);
queryTaskTimer = null;
}
};
const unloadComp = () => {
clearQueryTaskTimer();
};