|
|
@@ -5,9 +5,10 @@
|
|
|
<script>
|
|
|
import pdfjs from '@/utils/pdf'
|
|
|
import downloadFile from '@/utils/download-base64'
|
|
|
+import { mapState } from 'vuex'
|
|
|
+import { SET_TOTAL_PAGES, USE_SCREEN_SHOT } from '@/store/types/pdf-types'
|
|
|
|
|
|
export default {
|
|
|
- props: ['src', 'page'],
|
|
|
mounted () {
|
|
|
this._canvas = document.getElementById('pdf-canvas')
|
|
|
this._context = this._canvas.getContext('2d')
|
|
|
@@ -19,17 +20,31 @@ export default {
|
|
|
const loadingTask = pdfjs.getDocument(this.src)
|
|
|
loadingTask.promise.then(pdf => {
|
|
|
this._pdf = pdf
|
|
|
+ this.$store.commit(SET_TOTAL_PAGES, { totalPages: pdf.numPages })
|
|
|
this.showPage()
|
|
|
})
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ ...mapState({
|
|
|
+ src: state => state.pdf.src,
|
|
|
+ currentPage: state => state.pdf.currentPage,
|
|
|
+ screenShot: state => state.pdf.screenShot
|
|
|
+ })
|
|
|
+ },
|
|
|
watch: {
|
|
|
- page (newPage) {
|
|
|
+ currentPage () {
|
|
|
this.showPage()
|
|
|
+ },
|
|
|
+ screenShot () {
|
|
|
+ if (this.screenShot) {
|
|
|
+ this.getScreenShot()
|
|
|
+ this.$store.commit(USE_SCREEN_SHOT)
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- showPage() {
|
|
|
- this._pdf.getPage(this.page ? this.page : 1).then(page => {
|
|
|
+ showPage () {
|
|
|
+ this._pdf && this._pdf.getPage(this.currentPage || 1).then(page => {
|
|
|
const scale = 2
|
|
|
const viewport = page.getViewport({ scale: scale })
|
|
|
|
|
|
@@ -58,11 +73,9 @@ canvas {
|
|
|
outline: none;
|
|
|
display: inline-block;
|
|
|
direction: ltr;
|
|
|
- box-shadow: 0 4px 8px -2px rgba(0, 0, 0, 0.1);
|
|
|
-}
|
|
|
-
|
|
|
-canvas {
|
|
|
margin: 2px;
|
|
|
+ box-shadow: 0 4px 8px -2px rgba(0, 0, 0, 0.1);
|
|
|
+ background-color: white;
|
|
|
}
|
|
|
|
|
|
@media (min-width: 1001px) {
|