mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-25 19:52:48 +00:00
fix(EntityRow&FileRow): force file download using anchor tag download attribute
This commit is contained in:
parent
01a29b64e3
commit
448b5404ec
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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(() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue