dev_forum
杨树明 6 years ago
parent cb18c95ef2
commit 6df310eda1

@ -28,16 +28,24 @@ class Fileslistitem extends Component{
this.props.Settingtypes(discussMessage.id) this.props.Settingtypes(discussMessage.id)
} }
downloadfiles=(url,name)=>{ downloadfiles=(url)=>{
const aLink = document.createElement('a'); axios.get((url),{responseType: 'blob'}).then((response) => {
aLink.style.display='none'; const blob = new Blob([response.data]);
console.log(name) const downloadElement = document.createElement('a');
aLink.setAttribute('download',name) const href = window.URL.createObjectURL(blob);
aLink.href = url; // const string = Base64.decode(response.headers['content-disposition'].split('=')[1]);
document.body.appendChild(aLink); const string = response.headers['content-disposition'].split('=')[1];
aLink.click(); downloadElement.href = href;
// document.body.removeChild(aLink); downloadElement.download = string;
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement) ;// 下载完成移除元素
window.URL.revokeObjectURL(href) // 释放掉blob对象
}).catch((error) => {
console.log(error)
});
} }
showfiles=(value)=>{ showfiles=(value)=>{
let {discussMessage,coursesId}=this.props let {discussMessage,coursesId}=this.props
let file_id=discussMessage.id let file_id=discussMessage.id
@ -47,16 +55,14 @@ class Fileslistitem extends Component{
course_id:coursesId course_id:coursesId
}, },
}).then((result)=>{ }).then((result)=>{
if(result.data.attachment_histories.length===0){ if(result.data.attachment_histories.length===0){
this.downloadfiles(result.data.url,result.data.title) this.downloadfiles(result.data.url)
}else{ }else{
this.setState({ this.setState({
Showoldfiles:true, Showoldfiles:true,
allfiles:result.data allfiles:result.data
}) })
} }
}).catch((error)=>{ }).catch((error)=>{
console.log(error) console.log(error)
}) })

Loading…
Cancel
Save