|
@@ -128,15 +128,15 @@ export async function downloadBlob(fetchFunc, fileName) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-function toDataURL(url) {
|
|
|
|
- return fetch(url)
|
|
|
|
- .then(response => {
|
|
|
|
- return response.blob();
|
|
|
|
- })
|
|
|
|
- .then(blob => {
|
|
|
|
- return URL.createObjectURL(blob);
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
|
|
+// function toDataURL(url) {
|
|
|
|
+// return fetch(url)
|
|
|
|
+// .then(response => {
|
|
|
|
+// return response.blob();
|
|
|
|
+// })
|
|
|
|
+// .then(blob => {
|
|
|
|
+// return URL.createObjectURL(blob);
|
|
|
|
+// });
|
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
@@ -154,14 +154,15 @@ export async function downloadFileURL(url, name) {
|
|
.split("?")[0];
|
|
.split("?")[0];
|
|
link.setAttribute("download", fileName);
|
|
link.setAttribute("download", fileName);
|
|
|
|
|
|
- // txt 文件会直接在浏览器里面打开,这时候只能修改服务器设置,加上 Content-Disposition: attachment
|
|
|
|
- if ([".txt"].some(v => fileName.endsWith(v))) {
|
|
|
|
- // const urlObj = new URL(url);
|
|
|
|
- // link.href = await toDataURL(url.replace(urlObj.origin));
|
|
|
|
- link.href = await toDataURL(url);
|
|
|
|
- } else {
|
|
|
|
- link.href = url;
|
|
|
|
- }
|
|
|
|
|
|
+ // txt文件会直接在浏览器里面打开。
|
|
|
|
+ // 方案一:修改服务器设置,加上 Content-Disposition: attachment
|
|
|
|
+ // 方案二:同源文件a标签添加download属性
|
|
|
|
+ // if ([".txt"].some(v => fileName.endsWith(v))) {
|
|
|
|
+ // link.href = await toDataURL(url);
|
|
|
|
+ // } else {
|
|
|
|
+ // link.href = url;
|
|
|
|
+ // }
|
|
|
|
+ link.href = url;
|
|
document.body.appendChild(link);
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
document.body.removeChild(link);
|