|
@@ -1,23 +0,0 @@
|
|
|
-export const downloadFile = (url: string | Blob, fileName: string) => {
|
|
|
|
|
- const download = (blob: Blob, fileName: string) => {
|
|
|
|
|
- const a = document.createElement('a')
|
|
|
|
|
- document.body.appendChild(a)
|
|
|
|
|
- a.style.display = 'none'
|
|
|
|
|
- // 使用获取到的blob对象创建的url
|
|
|
|
|
- const url = window.URL.createObjectURL(blob)
|
|
|
|
|
- a.href = url
|
|
|
|
|
- // 指定下载的文件名
|
|
|
|
|
- a.download = fileName
|
|
|
|
|
- a.click()
|
|
|
|
|
- document.body.removeChild(a)
|
|
|
|
|
- // 移除blob对象的url
|
|
|
|
|
- window.URL.revokeObjectURL(url)
|
|
|
|
|
- }
|
|
|
|
|
- let newUrl: any = ''
|
|
|
|
|
- if (url instanceof Blob) {
|
|
|
|
|
- newUrl = URL.createObjectURL(newUrl) // 创建blob地址
|
|
|
|
|
- download(newUrl, fileName)
|
|
|
|
|
- } else {
|
|
|
|
|
- fetch(newUrl).then((res) => res.blob()).then((blob) => download(blob, fileName))
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|