From 8f453c4ebdc785e376e4a7f90a10cbcbaba5b329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Sat, 17 Aug 2019 13:48:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/courses/Resource/Fileslistitem.js | 35 +++++-------------- .../courses/coursesPublic/Showoldfiles.js | 29 ++++++--------- public/react/src/modules/tpm/TPMIndexHOC.js | 14 +++++++- 3 files changed, 31 insertions(+), 47 deletions(-) diff --git a/public/react/src/modules/courses/Resource/Fileslistitem.js b/public/react/src/modules/courses/Resource/Fileslistitem.js index 706622570..5f7c0fa83 100644 --- a/public/react/src/modules/courses/Resource/Fileslistitem.js +++ b/public/react/src/modules/courses/Resource/Fileslistitem.js @@ -38,30 +38,13 @@ class Fileslistitem extends Component{ }).then((result)=>{ if(result.data.attachment_histories.length===0){ - if(result.data.is_pdf===true){ - this.props.ShowOnlinePdf(result.data.url) - //预览pdf - // axios({ - // method:'get', - // url:result.data.url, - // responseType: 'arraybuffer', - // }).then((result)=>{ - // var binaryData = []; - // binaryData.push(result.data); - // this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); - // window.open(this.url); - // }) - }else{ - let link = document.createElement('a'); - document.body.appendChild(link); - link.href =result.data.url; - link.download = result.data.title; - //兼容火狐浏览器 - let evt = document.createEvent("MouseEvents"); - evt.initEvent("click", false, false); - link.dispatchEvent(evt); - document.body.removeChild(link); - } + // if(result.data.is_pdf===true){ + // this.props.ShowOnlinePdf(result.data.url) + // //预览pdf + // }else{ + // + // } + this.props.DownloadFileA(result.data.title,result.data.url) }else{ this.setState({ Showoldfiles:true, @@ -146,9 +129,7 @@ class Fileslistitem extends Component{ const { checkBox, discussMessage, } = this.props; - - - + return(
diff --git a/public/react/src/modules/courses/coursesPublic/Showoldfiles.js b/public/react/src/modules/courses/coursesPublic/Showoldfiles.js index 6b56702c3..693e3448b 100644 --- a/public/react/src/modules/courses/coursesPublic/Showoldfiles.js +++ b/public/react/src/modules/courses/coursesPublic/Showoldfiles.js @@ -43,16 +43,6 @@ class Showoldfiles extends Component{ } showfiless=(url)=>{ - // axios({ - // method:'get', - // url:url, - // responseType: 'arraybuffer', - // }).then((result)=>{ - // var binaryData = []; - // binaryData.push(result.data); - // this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); - // window.open(this.url); - // }) this.props.ShowOnlinePdf(url) } render(){ @@ -188,10 +178,11 @@ class Showoldfiles extends Component{
  • - {allfiles.is_pdf===false? - {allfiles.title}: - this.showfiless(allfiles.url)} >{allfiles.title} - } + {allfiles.title} + {/*{allfiles.is_pdf===false?*/} + {/*{allfiles.title}:*/} + {/*this.showfiless(allfiles.url)} >{allfiles.title}*/} + {/*}*/} 当前版本
  • @@ -207,11 +198,11 @@ class Showoldfiles extends Component{
  • - - {item.is_pdf===false? - {item.title}: - this.showfiless(item.url)} >{item.title} - } + {item.title} + {/*{item.is_pdf===false?*/} + {/*{item.title}:*/} + {/*this.showfiless(item.url)} >{item.title}*/} + {/*}*/}
  • diff --git a/public/react/src/modules/tpm/TPMIndexHOC.js b/public/react/src/modules/tpm/TPMIndexHOC.js index 690e8bc80..682e8f866 100644 --- a/public/react/src/modules/tpm/TPMIndexHOC.js +++ b/public/react/src/modules/tpm/TPMIndexHOC.js @@ -334,6 +334,17 @@ export function TPMIndexHOC(WrappedComponent) { window.open(this.url); }) } + DownloadFileA=(title,url)=>{ + let link = document.createElement('a'); + document.body.appendChild(link); + link.href =url; + link.download = title; + //兼容火狐浏览器 + let evt = document.createEvent("MouseEvents"); + evt.initEvent("click", false, false); + link.dispatchEvent(evt); + document.body.removeChild(link); + } render() { let{Headertop,Footerdown, isRender, AccountProfiletype}=this.state; const common = { @@ -351,7 +362,8 @@ export function TPMIndexHOC(WrappedComponent) { checkIfLogin: this.checkIfLogin, showProfileCompleteDialog: this.showProfileCompleteDialog, checkIfProfileCompleted: this.checkIfProfileCompleted, - ShowOnlinePdf:(url)=>this.ShowOnlinePdf(url) + ShowOnlinePdf:(url)=>this.ShowOnlinePdf(url), + DownloadFileA:(title,url)=>this.DownloadFileA(title,url), } return (