diff --git a/public/react/src/modules/courses/shixunHomework/Listofworks.js b/public/react/src/modules/courses/shixunHomework/Listofworks.js index d6950d43a..e58d2bb0e 100644 --- a/public/react/src/modules/courses/shixunHomework/Listofworks.js +++ b/public/react/src/modules/courses/shixunHomework/Listofworks.js @@ -1346,7 +1346,7 @@ class Listofworks extends Component { // } // let url = "/zip/shixun_report"; // let homeworkid = this.props.match.params.homeworkid; - axios.get((url),{headers:{'filename':'utf-8'}}).then((response) => { + axios.get((url),{headers:{'filename':'utf-8'},responseType: 'blob',}).then((response) => { console.log("1350"); console.log(response); if(response.data.status&&response.data.status===-1){ @@ -1355,20 +1355,20 @@ class Listofworks extends Component { }else if(response.data.status&&response.data.status===-2){ }else{ - window.location.href("/api"+url); - // response.blob().then(blob => { - // //关闭loading 按钮恢复正常 - // let blobUrl = window.URL.createObjectURL(blob); - // const filename = times.formatNowDate() + '.zip'; - // const aElement = document.createElement('a'); - // document.body.appendChild(aElement); - // aElement.style.display = 'none'; - // aElement.href = blobUrl; - // aElement.download = filename; - // aElement.click(); - // document.body.removeChild(aElement); - // }); - + // window.location.href("/api"+url); + console.log("开始下载zip文件") + const type='application/zip'//ZIP文件 + const blob = new Blob([response.data], { type: type }) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) + //后台再header中传文件名 + const name = decodeURI(response.headers['content-disposition'].split('=')[1]) + downloadElement.href = href + downloadElement.download = name + document.body.appendChild(downloadElement) + downloadElement.click() + document.body.removeChild(downloadElement) // 下载完成移除元素 + window.URL.revokeObjectURL(href) // 释放掉blob对象 } }).catch((error) => { console.log(error)