From be82ad85b69c846769166f572fc63d1effe381da Mon Sep 17 00:00:00 2001 From: daihh Date: Wed, 8 Jun 2022 09:28:27 +0800 Subject: [PATCH] =?UTF-8?q?pdf=E9=A2=84=E8=A7=88=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PdfPreview/view.vue | 29 +++++++++++++------------- src/views/portal/case/Detail.vue | 33 +++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/components/PdfPreview/view.vue b/src/components/PdfPreview/view.vue index 6f25b874..8953efec 100644 --- a/src/components/PdfPreview/view.vue +++ b/src/components/PdfPreview/view.vue @@ -114,33 +114,33 @@ export default { this.showPages++; } this.isscroll = true; - - }, + + }, //加载页面 loadInitPdf(url) { - + if(url && url.indexOf('.pdf')>-1){ let loadingTask = pdf.createLoadingTask(url); this.src=loadingTask; - + loadingTask.promise.then((pdf) =>{ console.log(pdf) this.totalPages=pdf.numPages; - + if(pdf.numPages>this.initNum){ this.showPages = this.initNum; - + } else{ this.showPages =pdf.numPages; - + } - - + + }).catch((err) =>{ this.$message.error("加载内容失败,请联系管理员"); }); - + } }, @@ -149,11 +149,11 @@ export default { let innerHeight = document.querySelector('#pdf-perView').clientHeight let outerHeight = document.documentElement.clientHeight let scrollTop = document.documentElement.scrollTop - + if(this.isscroll){ this.showPages++; this.debounce(this.loadInitPdf(),5000); - + } // console.log(this.pdfpage,'000') // console.log(this.totalPages,this.pdfpage) @@ -168,8 +168,8 @@ export default { // document.querySelector('#articleAnking').style.cssText = "position: static"; // } }, - - + + debounce(func, wait) {// 非立即执行 let timeout; return function () { @@ -229,6 +229,7 @@ export default { min-height: 300px; width: 100%; //border: 1px solid #dfdfdf; + background-color: #e9e9e9; overflow-y: hidden; overflow-x: hidden; >span{ diff --git a/src/views/portal/case/Detail.vue b/src/views/portal/case/Detail.vue index 74895453..b85993a0 100644 --- a/src/views/portal/case/Detail.vue +++ b/src/views/portal/case/Detail.vue @@ -20,7 +20,7 @@ {{ caseDetail.sysCreateTime.substring(0,10) }} - +
{{ caseDetail.summary }}
@@ -138,6 +138,8 @@ import apiUser from '@/api/system/user.js'; import author from '@/components/Portal/authorInfo.vue'; import apiMessage from '@/api/system/message.js'; import apiDict from "@/api/modules/dict.js" +import {encrypt} from '@/utils/jsencrypt.js'; +import cookies from 'vue-cookies' export default { name: 'atticle', components: { portalHeader, portalFooter, interactBar, author, comments,pdfPreview }, @@ -168,7 +170,7 @@ export default { this.getCaseData(); } this.getAnkingData(); - this.getPopularity(); + this.getPopularity(); this.getPositive(); window.addEventListener( "scroll", @@ -176,9 +178,20 @@ export default { ); }, methods: { - - - + createPlayUrl(u){ + let nowDate=new Date(); + let ctime=parseInt(nowDate.getTime()/1000); + let beforeUrl=parseInt(nowDate.getTime()/1000)+'/'+u; + let urlSign=encodeURIComponent(encrypt(beforeUrl)); + cookies.set('CASE_TIME', ctime);//写客户端的cookie保存 + //以下判断是为了区分本地环境和服务器环境 + if(process.env.NODE_ENV == 'development'){ + this.pdfPath=process.env.VUE_APP_FILE_BASE_URL+u; + }else{ + this.pdfPath=process.env.VUE_APP_BASE_API+'/xboe/m/course/cware/resource?sign='+urlSign; + } + //console.log(this.pdfPath,'this.blobUrl'); + }, handleScroll() { let innerHeight = document.querySelector('#case-list-content').clientHeight let outerHeight = document.documentElement.clientHeight @@ -226,11 +239,16 @@ export default { this.caseDetail = res.result; this.getCaseUserDetail(); if(this.caseDetail.filePath){ - this.pdfPath=this.basePath+this.caseDetail.filePath; + if(this.caseDetail.filePath){ + //this.pdfPath=this.basePath+this.caseDetail.filePath; + this.createPlayUrl(this.caseDetail.filePath); + }else{ + this.$message.error('无内容文件,请与管理员联系'); + } }else{ this.$message.error('内容文件不存在或已被删除,请与管理员联系'); } - + } } }); @@ -354,6 +372,7 @@ export default { .jianjie { margin: 15px 0; background-color: #fff; + min-height: 300px; padding: 0px 0px 10px 0px; .content { padding: 10px 0;