Skip to content

Commit

Permalink
add pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
rwv committed Nov 13, 2023
1 parent 6690458 commit cbd3e63
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/components/canvas-scan/preview/PreviewCompare.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
<template>
<SideBySidePreview>
<template #pdf>
<ImagePreview :image="image.blob" v-if="image" />
</template>
<template #scan>
<ImagePreview :image="scanImage.blob" v-if="scanImage" />
</template>
</SideBySidePreview>
<n-space vertical>
<SideBySidePreview>
<template #pdf>
<ImagePreview :image="image.blob" v-if="image" />
</template>
<template #scan>
<ImagePreview :image="scanImage.blob" v-if="scanImage" />
</template>
</SideBySidePreview>
<PreviewPagination
v-model:page="page"
:numPages="numPages"
v-if="numPages >= 2"
/>
</n-space>
</template>

<script lang="ts" setup>
import SideBySidePreview from "./SideBySidePreview.vue";
import ImagePreview from "./ImagePreview.vue";
import { ref } from "vue";
import { computedAsync } from "@vueuse/core";
import PreviewPagination from "./PreviewPagination.vue";
import { NSpace } from "naive-ui";
const page = ref(1);
Expand Down Expand Up @@ -86,4 +95,10 @@ const scanImage = computedAsync(async () => {
width,
};
});
const numPages = computedAsync(async () => {
page.value = 1;
if (!props.pdfRenderer) return 1;
return await props.pdfRenderer.getNumPages();
}, 1);
</script>
27 changes: 27 additions & 0 deletions src/components/canvas-scan/preview/PreviewPagination.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<n-space justify="center">
<n-pagination
v-model:page="page"
:page-count="numPages"
v-show="numPages >= 2"
:page-slot="5"
size="small"
/>
</n-space>
</template>

<script lang="ts" setup>
import { NPagination, NSpace } from "naive-ui";
import { useVModel } from "@vueuse/core";
const props = defineProps<{
page: number;
numPages: number;
}>();
const emit = defineEmits<{
(e: "update:page", page: number): void;
}>();
const page = useVModel(props, "page", emit);
</script>

0 comments on commit cbd3e63

Please sign in to comment.