import pdf from "vue-pdf"; import CMapReaderFactory from "vue-pdf/src/CMapReaderFactory.js"; export default { components: { pdf, }, props: { pdfURL: { type: String, default: "", }, }, data() { return { muluShowFlag: false, thumbnails: null, currentPage: 0, pageCount: 0, pageNumber: 1, scale: 1, imgUrl: null, numPages: null, muluLoading: false, }; }, mounted() { this.$nextTick(() => { this.getNumPages(this.pdfURL); }); }, methods: { onChangePdfPageFn(itemPage) { this.currentPage = itemPage; this.pageNumber = itemPage; }, getNumPages(url) { this.muluLoading = true; this.imgUrl = pdf.createLoadingTask({ url, CMapReaderFactory }); this.imgUrl.promise .then((pdf) => { this.numPages = pdf.numPages; this.muluLoading = false; }) .catch((err) => { console.error("pdf加载失败"); }); }, onPushMuluFlagFn() { let flag = this.muluShowFlag; this.muluShowFlag = !flag; }, loadPdfHandler() { this.currentPage = 1; this.pageNumber = 1; }, scaleD() { this.scale += 0.1; this.$refs.pdfWrapper.$el.style.transform = "scale(" + this.scale + ")"; this.$refs.pdfWrapper.$el.style.transformOrigin = "top center"; }, scaleX() { if (this.scale === 1) { return; } this.scale += -0.1; this.$refs.pdfWrapper.$el.style.transform = "scale(" + this.scale + ")"; }, changePdfPage(val) { if (val === 0 && this.currentPage > 1) { this.currentPage--; this.pageNumber = this.currentPage; } if (val === 1 && this.currentPage < this.pageCount) { this.currentPage++; this.pageNumber = this.currentPage; } }, pageChange() { if ( Number(this.pageNumber) > 0 && Number(this.pageNumber) <= this.pageCount ) { this.currentPage = Number(this.pageNumber); } else { this.currentPage = 1; this.pageNumber = 1; } }, }, };
|