下载
export const download = async (record) => {
let key = 'update'
createMessage.info({
key: key,
content: '下载数据中,请稍后...',
duration: 0
});
try {
// let percent = 0;
const response = await defHttp.get(
{
url: `${Api.downloadFile}/?versionId=${record.versionId}`,
responseType: 'blob',
},
{ isReturnNativeResponse: true }
);
// 3. 创建下载链接
const blob = new Blob([response.data], {
type: response.headers['content-type'] || 'application/octet-stream',
});
const downloadUrl = URL.createObjectURL(blob);
// 4. 触发下载
const link = document.createElement('a');
link.href = downloadUrl;
link.download = record.name + '.zip';
document.body.appendChild(link);
link.click();
setTimeout(() => {
document.body.removeChild(link);
URL.revokeObjectURL(downloadUrl);
createMessage.success({
key: key,
content: '下载成功',
duration: 3
});
}, 100);
} catch (err) {
createMessage.error({
key: key,
content: '下载失败',
duration: 3
})
}
}

692

被折叠的 条评论
为什么被折叠?



