dev_forum
杨树林 5 years ago
parent cbf9b33600
commit 19a85a054a

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

Loading…
Cancel
Save