From b262d98873d4b4d10dca80fef0c3554e6214f716 Mon Sep 17 00:00:00 2001 From: SylorHuang <sylor_huang@126.com> Date: Sat, 17 Aug 2019 11:25:47 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E9=99=84=E4=BB=B6=E4=B8=BApdf=E7=9A=84?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A4=E6=96=AD=EF=BC=8C=E5=B9=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_attachment_history.json.jbuilder | 3 ++- app/views/attachments/_attachment.json.jbuilder | 3 ++- app/views/attachments/_attachment_simple.json.jbuilder | 4 +++- app/views/attachments/_attachment_small.json.jbuilder | 4 ++-- app/views/files/histories.json.jbuilder | 8 +------- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 285aced42..6a02b569b 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -6,6 +6,7 @@ json.publish_time attachment.publish_time json.quotes attachment.quotes_count json.downloads_count attachment.downloads_count json.created_on attachment.created_on -json.url attachment_path(attachment, type: 'history').gsub("/api","") +# json.url attachment_path(attachment, type: 'history').gsub("/api","") json.is_pdf attachment.is_history_pdf? +json.url attachment.is_history_pdf? ? attachment_path(attachment, type: 'history').gsub("/api","") : attachment_path(attachment, type: 'history') json.attachment_id attachment.attachment_id diff --git a/app/views/attachments/_attachment.json.jbuilder b/app/views/attachments/_attachment.json.jbuilder index b87154157..76b9f2df0 100644 --- a/app/views/attachments/_attachment.json.jbuilder +++ b/app/views/attachments/_attachment.json.jbuilder @@ -11,6 +11,7 @@ json.quotes attachment.quotes_count json.description attachment.description json.downloads_count attachment.downloads_count json.created_on attachment.created_on -json.url download_url(attachment) +json.is_pdf attachment.is_pdf? +json.url attachment.is_pdf? ? download_url(attachment).gsub("/api","") : download_url(attachment) # json.url download_url(attachment) unless attachment.locked?(@is_member) diff --git a/app/views/attachments/_attachment_simple.json.jbuilder b/app/views/attachments/_attachment_simple.json.jbuilder index ad98fadb5..4bf6bd3e9 100644 --- a/app/views/attachments/_attachment_simple.json.jbuilder +++ b/app/views/attachments/_attachment_simple.json.jbuilder @@ -2,5 +2,7 @@ json.id attachment.id json.title attachment.title json.filesize number_to_human_size attachment.filesize json.description attachment.description -json.url download_url(attachment) +json.is_pdf attachment.is_pdf? +json.url attachment.is_pdf? ? download_url(attachment).gsub("/api","") : download_url(attachment) +# json.url download_url(attachment) json.set! :delete, delete.nil? ? true : delete if defined? delete \ No newline at end of file diff --git a/app/views/attachments/_attachment_small.json.jbuilder b/app/views/attachments/_attachment_small.json.jbuilder index 97cbee120..5a1faae3a 100644 --- a/app/views/attachments/_attachment_small.json.jbuilder +++ b/app/views/attachments/_attachment_small.json.jbuilder @@ -1,6 +1,6 @@ json.id attachment.id json.title attachment.title json.filesize number_to_human_size(attachment.filesize) -json.url download_url(attachment) +json.is_pdf attachment.is_pdf? +json.url attachment.is_pdf? ? download_url(attachment).gsub("/api","") : download_url(attachment) json.created_on attachment.created_on -json.is_pdf attachment.is_pdf? \ No newline at end of file diff --git a/app/views/files/histories.json.jbuilder b/app/views/files/histories.json.jbuilder index ed322bb17..7039752e7 100644 --- a/app/views/files/histories.json.jbuilder +++ b/app/views/files/histories.json.jbuilder @@ -1,9 +1,3 @@ -# json.partial! 'attachments/attachment_small', attachment: @file -json.id @file.id -json.title @file.title -json.filesize number_to_human_size(@file.filesize) -json.url download_url(@file).gsub("/api","") -json.created_on @file.created_on -json.is_pdf @file.is_pdf? +json.partial! 'attachments/attachment_small', attachment: @file json.partial! "attachment_histories/list", attachment_histories: @attachment_histories From b9de46e875b1cba52d559aacc3af18a5d0053818 Mon Sep 17 00:00:00 2001 From: SylorHuang <sylor_huang@126.com> Date: Sat, 17 Aug 2019 12:34:12 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E9=99=84=E4=BB=B6=E7=9A=84pdf=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E6=B7=BB=E5=8A=A0inline=E8=AF=B7=E6=B1=82=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 4 +++- app/helpers/application_helper.rb | 4 ++-- .../attachment_histories/_attachment_history.json.jbuilder | 2 +- app/views/attachments/_attachment.json.jbuilder | 2 +- app/views/attachments/_attachment_simple.json.jbuilder | 2 +- app/views/attachments/_attachment_small.json.jbuilder | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index a85937315..6202bf86d 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -15,7 +15,9 @@ class AttachmentsController < ApplicationController update_downloads(@file) redirect_to @file.cloud_url and return end - send_file(absolute_path(local_path(@file)), filename: @file.filename, type: @file.content_type.presence || 'application/octet-stream') + + pdf_attachment = params[:disposition] || "attachment" + send_file(absolute_path(local_path(@file)), filename: @file.filename,disposition: pdf_attachment, type: @file.content_type.presence || 'application/octet-stream') update_downloads(@file) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 099d45406..a5f291c7b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -257,8 +257,8 @@ module ApplicationHelper end end - def download_url attachment - attachment_path(attachment) + def download_url attachment,options={} + attachment_path(attachment,options) end # 耗时:天、小时、分、秒 diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 6a02b569b..a2369888f 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -8,5 +8,5 @@ json.downloads_count attachment.downloads_count json.created_on attachment.created_on # json.url attachment_path(attachment, type: 'history').gsub("/api","") json.is_pdf attachment.is_history_pdf? -json.url attachment.is_history_pdf? ? attachment_path(attachment, type: 'history').gsub("/api","") : attachment_path(attachment, type: 'history') +json.url attachment.is_history_pdf? ? attachment_path(attachment, type: 'history',disposition:"inline") : attachment_path(attachment, type: 'history') json.attachment_id attachment.attachment_id diff --git a/app/views/attachments/_attachment.json.jbuilder b/app/views/attachments/_attachment.json.jbuilder index 76b9f2df0..25d7aecd0 100644 --- a/app/views/attachments/_attachment.json.jbuilder +++ b/app/views/attachments/_attachment.json.jbuilder @@ -12,6 +12,6 @@ json.description attachment.description json.downloads_count attachment.downloads_count json.created_on attachment.created_on json.is_pdf attachment.is_pdf? -json.url attachment.is_pdf? ? download_url(attachment).gsub("/api","") : download_url(attachment) +json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) # json.url download_url(attachment) unless attachment.locked?(@is_member) diff --git a/app/views/attachments/_attachment_simple.json.jbuilder b/app/views/attachments/_attachment_simple.json.jbuilder index 4bf6bd3e9..6737838d1 100644 --- a/app/views/attachments/_attachment_simple.json.jbuilder +++ b/app/views/attachments/_attachment_simple.json.jbuilder @@ -3,6 +3,6 @@ json.title attachment.title json.filesize number_to_human_size attachment.filesize json.description attachment.description json.is_pdf attachment.is_pdf? -json.url attachment.is_pdf? ? download_url(attachment).gsub("/api","") : download_url(attachment) +json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) # json.url download_url(attachment) json.set! :delete, delete.nil? ? true : delete if defined? delete \ No newline at end of file diff --git a/app/views/attachments/_attachment_small.json.jbuilder b/app/views/attachments/_attachment_small.json.jbuilder index 5a1faae3a..853c14b40 100644 --- a/app/views/attachments/_attachment_small.json.jbuilder +++ b/app/views/attachments/_attachment_small.json.jbuilder @@ -2,5 +2,5 @@ json.id attachment.id json.title attachment.title json.filesize number_to_human_size(attachment.filesize) json.is_pdf attachment.is_pdf? -json.url attachment.is_pdf? ? download_url(attachment).gsub("/api","") : download_url(attachment) +json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) json.created_on attachment.created_on From 8af97d5655de723f1a2992e8bf7e75ebec49c17b Mon Sep 17 00:00:00 2001 From: SylorHuang <sylor_huang@126.com> Date: Sat, 17 Aug 2019 13:43:10 +0800 Subject: [PATCH 3/5] =?UTF-8?q?pdf=E7=9A=84=E9=A2=84=E8=A7=88=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0disposition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 6202bf86d..dde7828c5 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -17,8 +17,11 @@ class AttachmentsController < ApplicationController end pdf_attachment = params[:disposition] || "attachment" - send_file(absolute_path(local_path(@file)), filename: @file.filename,disposition: pdf_attachment, type: @file.content_type.presence || 'application/octet-stream') - + if pdf_attachment == "inline" + render pdf: absolute_path(local_path(@file)), filename: @file.filename, disposition: 'inline', type: @file.content_type.presence || 'application/octet-stream' + else + send_file(absolute_path(local_path(@file)), filename: @file.filename,stream:false, type: @file.content_type.presence || 'application/octet-stream') + end update_downloads(@file) end 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 4/5] =?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( <div className="graduateTopicList boardsList"> 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{ <div className="clearfix edu-txt-center lineh-40 bor-bottom-greyE" id={allfiles.id}> <li className="fl fontlefts"> - {allfiles.is_pdf===false? - <a className={"isabox"} href={allfiles.url} >{allfiles.title}</a>: - <a className={"isabox"} onClick={()=>this.showfiless(allfiles.url)} >{allfiles.title}</a> - } + <a className={"isabox"} href={allfiles.url} >{allfiles.title}</a> + {/*{allfiles.is_pdf===false?*/} + {/*<a className={"isabox"} href={allfiles.url} >{allfiles.title}</a>:*/} + {/*<a className={"isabox"} onClick={()=>this.showfiless(allfiles.url)} >{allfiles.title}</a>*/} + {/*}*/} <span className={"newcolor-orange fl"}>当前版本</span> </li> @@ -207,11 +198,11 @@ class Showoldfiles extends Component{ <div className="clearfix edu-txt-center lineh-40 bor-bottom-greyE" id={item.id} key={key}> <li className="fl fontlefts"> - - {item.is_pdf===false? - <a className={"isabox"} href={item.url}>{item.title}</a>: - <a className={"isabox"} onClick={()=>this.showfiless(item.url)} >{item.title}</a> - } + <a className={"isabox"} href={item.url}>{item.title}</a> + {/*{item.is_pdf===false?*/} + {/*<a className={"isabox"} href={item.url}>{item.title}</a>:*/} + {/*<a className={"isabox"} onClick={()=>this.showfiless(item.url)} >{item.title}</a>*/} + {/*}*/} </li> <li className="fl filesves "> 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 ( <div> From b094010ad11c5424eebee3395c238a129d947685 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:51:10 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/courses/Resource/Fileslistitem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/react/src/modules/courses/Resource/Fileslistitem.js b/public/react/src/modules/courses/Resource/Fileslistitem.js index 5f7c0fa83..d3405ebf5 100644 --- a/public/react/src/modules/courses/Resource/Fileslistitem.js +++ b/public/react/src/modules/courses/Resource/Fileslistitem.js @@ -129,7 +129,7 @@ class Fileslistitem extends Component{ const { checkBox, discussMessage, } = this.props; - + return( <div className="graduateTopicList boardsList">