diff --git a/public/react/src/modules/courses/Resource/Fileslistitem.js b/public/react/src/modules/courses/Resource/Fileslistitem.js index c0a55ee80..3e1e21810 100644 --- a/public/react/src/modules/courses/Resource/Fileslistitem.js +++ b/public/react/src/modules/courses/Resource/Fileslistitem.js @@ -35,27 +35,27 @@ class Fileslistitem extends Component{ params:{ course_id:coursesId }, - }).then((result)=>{ + }).then((response)=>{ if(result.data.attachment_histories.length===0){ - let link = document.createElement('a'); - // link.href = window.URL.createObjectURL(new Blob([result.data.url])); - link.href = result.data.url; - link.download = result.data.title; - //兼容火狐浏览器 - console.log(link) - document.body.appendChild(link); - let evt = document.createEvent("MouseEvents"); - evt.initEvent("click", false, false); - link.dispatchEvent(evt); - document.body.removeChild(link); - }else{ + response.blob().then(blob => { + const aLink = document.createElement('a'); + document.body.appendChild(aLink); + aLink.style.display='none'; + const objectUrl = window.URL.createObjectURL(blob.data.url); + aLink.href = objectUrl; + aLink.download =blob.data.title; + aLink.click(); + document.body.removeChild(aLink); + }); + + }else{ this.setState({ Showoldfiles:true, allfiles:result.data }) } - // console.log(result) + }).catch((error)=>{ console.log(error) })