Browse Source

修改pdf预览慢

master
lzp 3 days ago
parent
commit
fb3b4fc780
  1. 2
      大唐会议前台1/node_modules/vuedraggable/src/vuedraggable.js
  2. 81
      大唐会议前台1/pages/index/pdf.vue

2
大唐会议前台1/node_modules/vuedraggable/src/vuedraggable.js

@ -28,7 +28,7 @@ function computeIndexes(slots, children, isTransition, footerOffset) {
}
function emit(evtName, evtData) {
this.$nextTick(() => this.$emit(evtName.toLowerCase(), {...evtData}));
this.$nextTick(() => this.$emit(evtName.toLowerCase(), evtData));
}
function delegateAndEmit(evtName) {

81
大唐会议前台1/pages/index/pdf.vue

@ -1,12 +1,11 @@
<template>
<view class="box" style="position: relative">
<!-- <image class="back" src='../../imgs/back.png' mode="widthFix" @click="handleBack"></image> -->
<image class="logo" src="../../imgs/logo.png" mode="widthFix"></image>
<view class="box-cent">
<view class="box-cent1">
<view class="view-pdf">
<pdf
v-for="i in numPages"
v-for="i in loadedPages"
:key="i"
:src="filePdfUrl"
:page="i"
@ -22,23 +21,9 @@
@confirm="handleOut"
></u-modal>
</view>
<!-- 底部背景图 -->
<view class="view-backimg">
<view class="view-backimg-top"></view>
<!-- <view class="view-backimg-bottom"></view> -->
</view>
<!-- <div class="tools">
<view style="width:50vw;display: flex;margin: auto;">
<button :theme="'default'" type="submit" @click.stop="prePage" class="mr10">
上一页
</button>
<div class="page">{{pageNum}}/{{pageTotalNum}}</div>
<button :theme="'default'" type="submit" @click.stop="nextPage" class="mr10">
下一页
</button>
</view>
</div> -->
<!-- 头像 - 头像 -->
<view class="avatarobx">
<view class="name">{{ userName }}</view>
<image
@ -58,88 +43,102 @@
</template>
<script>
import pdf from 'vue-pdf';
import pdf from "vue-pdf";
export default {
name: 'MeetingList',
props: ['infos'],
name: "MeetingList",
props: ["infos"],
components: {
pdf,
},
data() {
return {
filePdfUrl: '',
userName: uni.getStorageSync('userName'),
detailsId: '',
numPages: '',
filePdfUrl: "",
userName: uni.getStorageSync("userName"),
detailsId: "",
numPages: 0,
show: false,
loadedPages: [],
currentPage: 1,
loadInterval: null,
loadCount: 5, // 5
};
},
created() {
let routes = getCurrentPages(); //
let curParam = routes[routes.length - 1].options; //
let routes = getCurrentPages();
let curParam = routes[routes.length - 1].options;
this.detailsId = curParam.detailsId;
this.filePdfUrl = curParam.filePdfUrl;
this.getNumPages(this.filePdfUrl);
},
beforeDestroy() {
if (this.loadInterval) {
clearInterval(this.loadInterval);
}
},
methods: {
getNumPages(url) {
this.pdfSrc = url;
this.pdfSrc = pdf.createLoadingTask(this.pdfSrc);
this.pdfSrc.promise.then((pdf) => {
this.numPages = pdf.numPages;
console.log('this.numPages', this.numPages);
this.startLoadingPages();
});
},
// logo
startLoadingPages() {
this.loadInterval = setInterval(() => {
if (this.currentPage <= this.numPages) {
// loadCount
const endPage = Math.min(
this.currentPage + this.loadCount - 1,
this.numPages
);
for (let i = this.currentPage; i <= endPage; i++) {
this.loadedPages.push(i);
}
this.currentPage = endPage + 1;
} else {
clearInterval(this.loadInterval);
}
}, 500);
},
handleBack() {
uni.navigateTo({
url: `/pages/index/details?id=${this.detailsId}`,
});
// uni.navigateBack({
// delta: 1
// });
},
// 退
handleOut() {
uni.clearStorage();
uni.reLaunch({
url: '/pages/user/login',
url: "/pages/user/login",
});
},
// logo
handleLogo() {
uni.navigateTo({
url: `/pages/index/index`,
});
},
//
handleClose() {
this.pdfId = '';
this.pdfId = "";
this.show = false;
},
//
prePage() {
var page = this.pageNum;
page = page > 1 ? page - 1 : this.pageTotalNum;
this.pageNum = page;
},
//
nextPage() {
var page = this.pageNum;
page = page < this.pageTotalNum ? page + 1 : 1;
this.pageNum = page;
},
// e
pageLoaded(e) {
this.curPageNum = e;
},
//
pdfError(error) {
console.error(error);
},
},
//
onLoad() {},
};
</script>

Loading…
Cancel
Save