Przeglądaj źródła

fix: 修正从消息链接处跳转不能加载出pdf的问题

ChenYangfan 6 lat temu
rodzic
commit
8cde90081f

+ 8 - 6
src/components/DiscussionTab/CMessage.vue

@@ -59,12 +59,14 @@ export default {
     },
     handlePush () {
       if (this.message.slideId) {
-        const handler = getSlideInfo({ slideId: this.message.slideId }).then(res => {
-          this.$store.commit(SET_SLIDE_INFO, { slideInfo: res })
-          this.$router.push({ name: 'pdf-reader' })
-        }).catch(err => {
-          this.$setErrorMessage('跳转过程出错,可能是相关幻灯片已不存在:' + err.response.data.msg)
-        })
+        const handler = () => {
+          getSlideInfo({ slideId: this.message.slideId }).then(res => {
+            this.$store.commit(SET_SLIDE_INFO, { slideInfo: res })
+            this.$router.push({ name: 'pdf-reader' })
+          }).catch(err => {
+            this.$setErrorMessage('跳转过程出错,可能是相关幻灯片已不存在:' + err.response.data.msg)
+          })
+        }
 
         if (this.edit) {
           const msg = '编辑模式跳转到幻灯片页面将会丢失选中的内容,您确定继续跳转吗。'

+ 17 - 7
src/components/PDF/Pdf.vue

@@ -26,13 +26,9 @@ export default {
     this._canvas.height = 1080
     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()
-    })
+    if (this.src) {
+      this.load(this.src)
+    }
   },
   computed: {
     ...mapState({
@@ -56,9 +52,23 @@ export default {
         this.getScreenShot()
         this.$store.commit(USE_SCREEN_SHOT)
       }
+    },
+    src (value) {
+      if (value) {
+        this.load(value)
+      }
     }
   },
   methods: {
+    load (src) {
+      const loadingTask = pdfjs.getDocument(src)
+      loadingTask.promise.then(pdf => {
+        this.loading = false
+        this._pdf = pdf
+        this.$store.commit(SET_TOTAL_PAGES, { totalPages: pdf.numPages })
+        this.showPage()
+      })
+    },
     showPage () {
       this._pdf && this._pdf.getPage(this.currentPage || 1).then(page => {
         const scale = 2.5

+ 0 - 1
src/views/reader/PdfReader.vue

@@ -31,7 +31,6 @@ export default {
   mounted () {
     this.$store.commit(RESET)
     getSlideUrl({ slideId: this.slide.id }).then(res => {
-      this.slideUrl = res
       this.$store.commit(SET_SRC, { src: res })
     }).catch(err => {
       this.$setErrorMessage('获取课件链接的过程中:' + err.response.data.msg)

+ 1 - 1
src/views/student/components/StudentCourseSlides.vue

@@ -29,7 +29,7 @@
                   :click-handler="handleSlideCardClick"></slide-card>
     </template>
     <template v-for="courseFile of courseFiles">
-      <course-file-card :key="courseFile.id" :hide-time="!showMore" :click-handler="handleCourseFileCardClick"
+      <course-file-card :key="'file-' + courseFile.id" :hide-time="!showMore" :click-handler="handleCourseFileCardClick"
                         :courseFile="courseFile">
       </course-file-card>
     </template>

+ 1 - 1
src/views/teacher/components/TeacherSlideDetail.vue

@@ -87,7 +87,7 @@ export default {
   },
   methods: {
     handleReadSlide () {
-      this.$router.push({ name: 'pdf-reader', params: { slide: this.slide } })
+      this.$router.push({ name: 'pdf-reader' })
     },
     handleQuizSetting () {
       this.$router.push({ name: 'teacher-quiz-setting', params: { slideId: this.slide.id } })