|
@@ -1,6 +1,6 @@
|
|
<template>
|
|
<template>
|
|
- <div class="vue-pdf" >
|
|
|
|
- <vue-pdf-embed :source="testpdf1" ref="vuePdfRef" :style="scaleFun" class="vue-pdf-cs" @scroll="onScroll" @loaded="onPdfLoaded" :renderPageNumber="true" />
|
|
|
|
|
|
+ <div class="vue-pdf" @scroll="onScroll" ref="myDiv">
|
|
|
|
+ <vue-pdf-embed :source="testpdf1" ref="vuePdfRef" :style="scaleFun" class="vue-pdf-cs" @loaded="onPdfLoaded" :renderPageNumber="true" />
|
|
</div>
|
|
</div>
|
|
<div class="page-tool">
|
|
<div class="page-tool">
|
|
<div class="page-tool-item" @click="lastPage">上一页</div>
|
|
<div class="page-tool-item" @click="lastPage">上一页</div>
|
|
@@ -24,8 +24,7 @@ const scaleFun = computed(() => {
|
|
return {
|
|
return {
|
|
transform: `scale(${scaleData.scale})`,
|
|
transform: `scale(${scaleData.scale})`,
|
|
transition: 'all 0.3s',
|
|
transition: 'all 0.3s',
|
|
- transformOrigin: 'top',
|
|
|
|
- height: '135vh'
|
|
|
|
|
|
+ transformOrigin: 'top'
|
|
};
|
|
};
|
|
});
|
|
});
|
|
|
|
|
|
@@ -35,14 +34,13 @@ const scaleData = reactive({
|
|
scaleMax: 100, // 最大缩放比例
|
|
scaleMax: 100, // 最大缩放比例
|
|
scaleMin: 0.1, // 最小缩放比例
|
|
scaleMin: 0.1, // 最小缩放比例
|
|
scaleBtn: 0.4, // 缩放按钮缩放比例
|
|
scaleBtn: 0.4, // 缩放按钮缩放比例
|
|
- rotate: 0, // 旋转角度
|
|
|
|
pageNum: 1, // 当前页面
|
|
pageNum: 1, // 当前页面
|
|
url: 'http://www.fao.fudan.edu.cn/_upload/article/files/f5/53/8b40af524563b9b60049899b2dd3/c9a205b4-4188-4af3-863e-bc4e56872e33.pdf',
|
|
url: 'http://www.fao.fudan.edu.cn/_upload/article/files/f5/53/8b40af524563b9b60049899b2dd3/c9a205b4-4188-4af3-863e-bc4e56872e33.pdf',
|
|
numPages: 0
|
|
numPages: 0
|
|
});
|
|
});
|
|
|
|
|
|
const vuePdfRef = ref<InstanceType<typeof VuePdfEmbed> | null>(null);
|
|
const vuePdfRef = ref<InstanceType<typeof VuePdfEmbed> | null>(null);
|
|
-
|
|
|
|
|
|
+const myDiv = ref(null);
|
|
const lastPage = () => {
|
|
const lastPage = () => {
|
|
if (scaleData.pageNum > 1) {
|
|
if (scaleData.pageNum > 1) {
|
|
scaleData.pageNum--
|
|
scaleData.pageNum--
|
|
@@ -88,7 +86,7 @@ const onPdfLoaded = (data: { numPages: number }) => {
|
|
};
|
|
};
|
|
|
|
|
|
const scrollToPage = () => {
|
|
const scrollToPage = () => {
|
|
- const pdfContainer = vuePdfRef.value.$el;
|
|
|
|
|
|
+ const pdfContainer = myDiv.value;
|
|
const pageHeight = pdfContainer.scrollHeight / scaleData.numPages;
|
|
const pageHeight = pdfContainer.scrollHeight / scaleData.numPages;
|
|
const targetScrollPosition = (scaleData.pageNum-1) * pageHeight;
|
|
const targetScrollPosition = (scaleData.pageNum-1) * pageHeight;
|
|
|
|
|
|
@@ -98,7 +96,7 @@ const scrollToPage = () => {
|
|
});
|
|
});
|
|
};
|
|
};
|
|
const onScroll = () => {
|
|
const onScroll = () => {
|
|
- const pdfContainer = vuePdfRef.value.$el;
|
|
|
|
|
|
+ const pdfContainer = myDiv.value;
|
|
const scrollTop = pdfContainer.scrollTop+100;
|
|
const scrollTop = pdfContainer.scrollTop+100;
|
|
const pageHeight = pdfContainer.scrollHeight / scaleData.numPages;
|
|
const pageHeight = pdfContainer.scrollHeight / scaleData.numPages;
|
|
const currentPage = Math.floor(scrollTop / pageHeight) + 1;
|
|
const currentPage = Math.floor(scrollTop / pageHeight) + 1;
|
|
@@ -146,18 +144,16 @@ const onScroll = () => {
|
|
margin: 0px auto;
|
|
margin: 0px auto;
|
|
width: 100%;
|
|
width: 100%;
|
|
position: relative;
|
|
position: relative;
|
|
- height: calc(100vh - 180px);
|
|
|
|
|
|
+ overflow: auto;
|
|
background: #e3e2e2;
|
|
background: #e3e2e2;
|
|
}
|
|
}
|
|
|
|
|
|
.vue-pdf-cs{
|
|
.vue-pdf-cs{
|
|
width: 100%;
|
|
width: 100%;
|
|
height: 100%;
|
|
height: 100%;
|
|
- overflow: auto;
|
|
|
|
text-align: center;
|
|
text-align: center;
|
|
display: flex;
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex-direction: column;
|
|
gap: 20px;
|
|
gap: 20px;
|
|
-
|
|
|
|
}
|
|
}
|
|
</style>
|
|
</style>
|