fix(EntityRow&FileRow): force file download using anchor tag download attribute

This commit is contained in:
WittF 2025-06-22 23:27:19 +08:00
parent 01a29b64e3
commit 448b5404ec
2 changed files with 18 additions and 4 deletions

View File

@ -50,8 +50,15 @@ const EntityRow = ({
dispatch(getEntityUrl(entity?.id ?? 0))
.then((url) => {
// 直接下载文件
window.location.assign(url);
// 直接下载文件使用a标签的download属性强制下载
const link = document.createElement('a');
link.href = url;
link.download = `entity-${entity?.id}`;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})
.finally(() => {
setOpenLoading(false);

View File

@ -89,8 +89,15 @@ const FileRow = ({
// 可预览文件:新窗口打开预览,窗口保持显示预览内容
window.open(url, "_blank");
} else {
// 下载文件:当前窗口下载(不跳转页面,直接下载链接)
window.location.assign(url);
// 下载文件使用a标签的download属性强制下载
const link = document.createElement('a');
link.href = url;
link.download = file?.name || `file-${file?.id}`;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
})
.finally(() => {