mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-11 11:56:44 +08:00
案例pdf滚动加载
This commit is contained in:
@@ -31,7 +31,7 @@
|
|||||||
<span v-if="loadedRatio !== 1" style="margin:0 10px;">0 / 0</span>
|
<span v-if="loadedRatio !== 1" style="margin:0 10px;">0 / 0</span>
|
||||||
<span v-else style="margin:0 10px;">{{ currentPage }} / {{ pageCount }}</span>
|
<span v-else style="margin:0 10px;">{{ currentPage }} / {{ pageCount }}</span>
|
||||||
<el-button @click="nextPage('footer')" :disabled="loadedRatio !== 1" icon="el-icon-arrow-right"></el-button> -->
|
<el-button @click="nextPage('footer')" :disabled="loadedRatio !== 1" icon="el-icon-arrow-right"></el-button> -->
|
||||||
<el-button type="primary" @click="clickMore()">加载更多</el-button>
|
<el-button type="primary" @click="clickMore()" v-if="moreState == 1">加载更多</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -63,6 +63,9 @@ export default {
|
|||||||
scale: 100, //放大系数
|
scale: 100, //放大系数
|
||||||
loadedRatio:0,// 加载进度
|
loadedRatio:0,// 加载进度
|
||||||
showProgress:true,
|
showProgress:true,
|
||||||
|
moreState:1,// 1 加载更多 2 加载中 3无数据
|
||||||
|
isscroll:false,
|
||||||
|
pdfpage:0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
@@ -70,6 +73,13 @@ export default {
|
|||||||
if(this.filePath){
|
if(this.filePath){
|
||||||
this.loadInitPdf(this.filePath);
|
this.loadInitPdf(this.filePath);
|
||||||
}
|
}
|
||||||
|
window.addEventListener(
|
||||||
|
"scroll",
|
||||||
|
this.handleScroll
|
||||||
|
);
|
||||||
|
},
|
||||||
|
beforeDestroy(){
|
||||||
|
window.removeEventListener("scroll",this.handleScroll);
|
||||||
},
|
},
|
||||||
watch:{
|
watch:{
|
||||||
filePath(newVal){
|
filePath(newVal){
|
||||||
@@ -89,36 +99,88 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadProgress(e){
|
loadProgress(e){
|
||||||
console.log(e,'loadProgress');
|
console.log(e,'loadProgress');
|
||||||
},
|
},
|
||||||
loadedPageHandle(e){
|
loadedPageHandle(e){
|
||||||
console.log(e,'loadedPageHandle');
|
console.log(e,'loadedPageHandle');
|
||||||
|
this.pdfpage = e;
|
||||||
|
|
||||||
},
|
},
|
||||||
loadPdfHandle(e){
|
loadPdfHandle(e){
|
||||||
console.log(e,'loadPdfHandle');
|
console.log(e,'loadPdfHandle');
|
||||||
},
|
},
|
||||||
clickMore(){
|
clickMore(){
|
||||||
if(this.totalPages>this.showPages){
|
if(this.totalPages>this.showPages){
|
||||||
this.showPages++;
|
this.showPages++;
|
||||||
}
|
}
|
||||||
},
|
this.isscroll = true;
|
||||||
|
|
||||||
|
},
|
||||||
//加载页面
|
//加载页面
|
||||||
loadInitPdf(url) {
|
loadInitPdf(url) {
|
||||||
|
|
||||||
if(url && url.indexOf('.pdf')>-1){
|
if(url && url.indexOf('.pdf')>-1){
|
||||||
let loadingTask = pdf.createLoadingTask(url);
|
let loadingTask = pdf.createLoadingTask(url);
|
||||||
this.src=loadingTask;
|
this.src=loadingTask;
|
||||||
|
|
||||||
loadingTask.promise.then((pdf) =>{
|
loadingTask.promise.then((pdf) =>{
|
||||||
|
console.log(pdf)
|
||||||
this.totalPages=pdf.numPages;
|
this.totalPages=pdf.numPages;
|
||||||
|
|
||||||
|
|
||||||
if(pdf.numPages>this.initNum){
|
if(pdf.numPages>this.initNum){
|
||||||
this.showPages = this.initNum;
|
this.showPages = this.initNum;
|
||||||
}else{
|
|
||||||
|
} else{
|
||||||
this.showPages =pdf.numPages;
|
this.showPages =pdf.numPages;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}).catch((err) =>{
|
}).catch((err) =>{
|
||||||
this.$message.error("加载内容失败,请联系管理员");
|
this.$message.error("加载内容失败,请联系管理员");
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleScroll() {
|
||||||
|
let el_anking = document.querySelector('#case-list-content');
|
||||||
|
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)
|
||||||
|
if(this.pdfpage >= this.totalPages){
|
||||||
|
this.isscroll = false
|
||||||
|
this.moreState = 3
|
||||||
|
// console.log('hcuewhf')
|
||||||
|
}
|
||||||
|
// if(scrollTop > 400) {
|
||||||
|
// document.querySelector('#articleAnking').style.cssText = "position: fixed;top: 0;width:242.5px";
|
||||||
|
// } else {
|
||||||
|
// document.querySelector('#articleAnking').style.cssText = "position: static";
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
debounce(func, wait) {// 非立即执行
|
||||||
|
let timeout;
|
||||||
|
return function () {
|
||||||
|
let context = this;
|
||||||
|
let args = arguments;
|
||||||
|
if (timeout) clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
func.apply(context, args)
|
||||||
|
}, wait);
|
||||||
|
}
|
||||||
|
},
|
||||||
prePage(type) {
|
prePage(type) {
|
||||||
if (this.currentPage > 1) {
|
if (this.currentPage > 1) {
|
||||||
this.currentPage--;
|
this.currentPage--;
|
||||||
|
|||||||
Reference in New Issue
Block a user