Sfoglia il codice sorgente

fix: 课件加载中显示为课件正在加载

ChenYangfan 6 anni fa
parent
commit
24d5d51271

+ 1 - 0
src/components/DiscussionArea.vue

@@ -58,6 +58,7 @@ export default {
   },
   methods: {
     updateComments () {
+      this.comments = null
       getComments({ slideId: this.slide.id, pageNumber: this.currentPage }).then(res => {
         this.comments = res.data
       }).catch(err => {

+ 37 - 4
src/components/PDF/Pdf.vue

@@ -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;

+ 1 - 1
src/components/PDF/PdfViewer.vue

@@ -1,6 +1,6 @@
 <template>
   <div>
-    <pdf ref="pdf"></pdf>
+    <pdf></pdf>
     <pdf-controller></pdf-controller>
   </div>
 </template>

+ 1 - 1
src/router/index.js

@@ -20,7 +20,7 @@ const routes = [{
   meta: { roles: ['teacher'] },
   path: '/pdf-reader',
   name: 'pdf-reader',
-  component: () => import(/* webpackChunkName: "pdf-reader" */ '../views/reader/PdfReader.vue')
+  component: () => import('../views/reader/PdfReader.vue')
 }, {
   meta: { roles: ['teacher'] },
   path: '/quiz-setting/:slideId',