|
|
@@ -1,5 +1,8 @@
|
|
|
<template>
|
|
|
- <canvas class="pdf pdf-canvas" id="pdf-canvas" :class="showDiscussion ? '' : 'full-size'"></canvas>
|
|
|
+ <div>
|
|
|
+ <canvas class="pdf pdf-canvas" id="pdf-canvas" :class="classList"></canvas>
|
|
|
+ <div v-if="loading" class="loading">加载中...</div>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
@@ -9,16 +12,23 @@ import { mapState } from 'vuex'
|
|
|
import { SET_TOTAL_PAGES, USE_SCREEN_SHOT } from '@/store/types/pdf-types'
|
|
|
|
|
|
export default {
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ loading: true
|
|
|
+ }
|
|
|
+ },
|
|
|
mounted () {
|
|
|
+ this.loading = true
|
|
|
this._canvas = document.getElementById('pdf-canvas')
|
|
|
this._context = this._canvas.getContext('2d')
|
|
|
|
|
|
// Default size
|
|
|
this._canvas.height = 1080
|
|
|
- this._canvas.width = 1920
|
|
|
+ this._canvas.width = 1440
|
|
|
|
|
|
const loadingTask = pdfjs.getDocument(this.src)
|
|
|
loadingTask.promise.then(pdf => {
|
|
|
+ this.loading = false
|
|
|
this._pdf = pdf
|
|
|
this.$store.commit(SET_TOTAL_PAGES, { totalPages: pdf.numPages })
|
|
|
this.showPage()
|
|
|
@@ -30,7 +40,12 @@ export default {
|
|
|
showDiscussion: state => state.pdf.showDiscussion,
|
|
|
currentPage: state => state.pdf.currentPage,
|
|
|
screenShot: state => state.pdf.screenShot
|
|
|
- })
|
|
|
+ }),
|
|
|
+ classList () {
|
|
|
+ return {
|
|
|
+ 'full-size': this.showDiscussion
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
watch: {
|
|
|
currentPage () {
|
|
|
@@ -58,7 +73,7 @@ export default {
|
|
|
}
|
|
|
page.render(renderContext)
|
|
|
}).catch(() => {
|
|
|
- // todo 超出页码
|
|
|
+ this.$setInfoMessage('PDF 当前页解析错误')
|
|
|
})
|
|
|
},
|
|
|
getScreenShot () {
|
|
|
@@ -72,6 +87,10 @@ export default {
|
|
|
<style lang="scss" scoped>
|
|
|
@import '~@/style/theme.scss';
|
|
|
|
|
|
+div {
|
|
|
+ position: relative;
|
|
|
+}
|
|
|
+
|
|
|
canvas {
|
|
|
outline: none;
|
|
|
display: inline-block;
|
|
|
@@ -81,6 +100,20 @@ canvas {
|
|
|
border: 1px solid #aabaca;
|
|
|
}
|
|
|
|
|
|
+.loading {
|
|
|
+ position: absolute;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ height: 100%;
|
|
|
+ width: 100%;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ color: #7a8a9a;
|
|
|
+ font-size: 40px;
|
|
|
+ font-weight: bold;
|
|
|
+}
|
|
|
+
|
|
|
.full-size {
|
|
|
max-width: 90vw;
|
|
|
min-width: unset;
|