Kaynağa Gözat

feat: 优化性能

332777428@qq.com 4 ay önce
ebeveyn
işleme
6a183d11f7
1 değiştirilmiş dosya ile 19 ekleme ve 13 silme
  1. 19 13
      src/pages/explain/index.vue

+ 19 - 13
src/pages/explain/index.vue

@@ -1,6 +1,10 @@
 <template>
   <div class="container_all">
-    <div class="container_public" :style="{ transform: `scale(${scale})` }">
+    <div
+      v-if="loadedPages > 0"
+      class="container_public"
+      :style="{ transform: `scale(${scale})` }"
+    >
       <!-- @page-loaded="onPageLoaded" -->
       <div v-for="pageNumber in loadedPages" :key="pageNumber">
         <vue-pdf
@@ -74,7 +78,7 @@ export default {
       currentPage: 1,
       numPages: 0,
       scale: 1,
-      loadedPages: 1,
+      loadedPages: 0,
     };
   },
 
@@ -101,6 +105,7 @@ export default {
       //   this.loadedPages += 1; // 加载下一页
       // }
     },
+
     ///接口获取数据
     getDetail() {
       var that = this;
@@ -109,24 +114,25 @@ export default {
       detail(id).then((res) => {
         if (res.code === 0) {
           that.name = res.data.name;
-          that.fileUrl = res.data.fileUrl;
-          that.fileName = that.getFileExtension(that.fileUrl);
-          that.getPdfPages();
+          var fileUrl = res.data.fileUrl;
+          that.getPdfPages(fileUrl);
         }
       });
     },
 
-    async getPdfPages() {
+    async getPdfPages(fileUrl) {
       var that = this;
-      const loadingTask = VuePdf.createLoadingTask(that.fileUrl);
+      const loadingTask = VuePdf.createLoadingTask(fileUrl);
       const pdf = await loadingTask.promise;
-      this.numPages = pdf.numPages;
-      // this.loadedPages = this.numPages;
-      if (this.numPages == 0) {
+      var length = pdf.numPages;
+      // that.numPages = length;
+      // that.loadedPages = that.numPages;
+      if (length == 0) {
         return;
       }
-      this.loadedPages = this.numPages;
-      // this.loadedPages = this.numPages > 2 ? 2 : this.numPages;
+      that.fileUrl = fileUrl;
+      that.loadedPages = length;
+      // that.loadedPages = that.numPages > 2 ? 2 : that.numPages;
     },
 
     ///截取文件
@@ -176,7 +182,7 @@ export default {
       var that = this;
       var name = that.name;
       var fileUrl = that.fileUrl;
-      var fileName = that.fileName;
+      var fileName = that.getFileExtension(that.fileUrl);
 
       var finalName = "";
       if (name != null && name != "") {