Merge branch 'fix/608-check-initVuePdfEmbed-before-IntersectionObserver' into 'dev'
PDF inline issue and improvement Closes #608 See merge request keanuapp/keanuapp-weblite!365
This commit is contained in:
commit
a214dad0a4
1 changed files with 11 additions and 7 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
v-if="pageVisibility[pageNum]"
|
v-if="pageVisibility[pageNum]"
|
||||||
:source="doc"
|
:source="doc"
|
||||||
:page="pageNum"
|
:page="pageNum"
|
||||||
|
:width="!util.isMobileOrTabletBrowser() ? 800 : undefined"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -52,6 +53,7 @@ import { Attachment } from "../../models/attachment";
|
||||||
import ImageWithProgress from "../ImageWithProgress.vue";
|
import ImageWithProgress from "../ImageWithProgress.vue";
|
||||||
import VuePdfEmbed, { useVuePdfEmbed } from 'vue-pdf-embed';
|
import VuePdfEmbed, { useVuePdfEmbed } from 'vue-pdf-embed';
|
||||||
import { Source } from 'vue-pdf-embed/types';
|
import { Source } from 'vue-pdf-embed/types';
|
||||||
|
import util from "@/plugins/utils";
|
||||||
|
|
||||||
function isEventAttachment(source: EventAttachment | Attachment | undefined): source is EventAttachment {
|
function isEventAttachment(source: EventAttachment | Attachment | undefined): source is EventAttachment {
|
||||||
return (source as EventAttachment)?.event !== undefined;
|
return (source as EventAttachment)?.event !== undefined;
|
||||||
|
|
@ -188,11 +190,14 @@ const { doc } = useVuePdfEmbed({
|
||||||
source: pdfSource,
|
source: pdfSource,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const initVuePdfEmbed = computed(()=> props.showInlinePDF && isPDF.value)
|
||||||
|
|
||||||
const pageNums = computed(() =>
|
const pageNums = computed(() =>
|
||||||
doc.value ? [...Array(doc.value.numPages + 1).keys()].slice(1) : []
|
doc.value ? [...Array(doc.value.numPages + 1).keys()].slice(1) : []
|
||||||
);
|
);
|
||||||
|
|
||||||
const resetPageIntersectionObserver = () => {
|
const resetPageIntersectionObserver = () => {
|
||||||
|
if(!initVuePdfEmbed.value) return
|
||||||
pageIntersectionObserver?.disconnect()
|
pageIntersectionObserver?.disconnect()
|
||||||
pageIntersectionObserver = new IntersectionObserver((entries) => {
|
pageIntersectionObserver = new IntersectionObserver((entries) => {
|
||||||
entries.forEach((entry) => {
|
entries.forEach((entry) => {
|
||||||
|
|
@ -212,17 +217,16 @@ const resetPageIntersectionObserver = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(pageNums, (newPageNums) => {
|
watch(pageNums, (newPageNums) => {
|
||||||
|
if(!initVuePdfEmbed.value) return
|
||||||
pageVisibility.value = { [newPageNums[0]]: true }
|
pageVisibility.value = { [newPageNums[0]]: true }
|
||||||
pageRefs.value = []
|
pageRefs.value = []
|
||||||
nextTick(resetPageIntersectionObserver)
|
nextTick(resetPageIntersectionObserver)
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(source, (newSource) => {
|
watch(source, (newSource) => {
|
||||||
if (isPDF.value) {
|
if(!initVuePdfEmbed.value) return
|
||||||
pdfSource.value = newSource;
|
pdfSource.value = isPDF.value ? newSource : null;
|
||||||
}
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const loadingProgress = computed(() => {
|
const loadingProgress = computed(() => {
|
||||||
if (isEventAttachment(item)) {
|
if (isEventAttachment(item)) {
|
||||||
|
|
@ -283,8 +287,8 @@ onBeforeUnmount(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
.pdf-container {
|
.pdf-container {
|
||||||
padding: 24px 16px;
|
margin-top: 100px;
|
||||||
margin-top: 200px;
|
height: 100vh;
|
||||||
|
|
||||||
& > * {
|
& > * {
|
||||||
margin: 30px auto 0 auto;
|
margin: 30px auto 0 auto;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue