Pārlūkot izejas kodu

feat: add pdfjs-dist

zhangyuhan 4 gadi atpakaļ
vecāks
revīzija
4de9c0aed6

+ 2 - 1
jydocs-mobile/.eslintrc.js

@@ -17,6 +17,7 @@ module.exports = {
     'no-any': [0, { 'ignore-rest-args': 0 }],
     "@typescript-eslint/ban-ts-ignore": ['off'],
     '@typescript-eslint/no-explicit-any': ['off'],
-    '@typescript-eslint/camelcase': ['off']
+    '@typescript-eslint/camelcase': ['off'],
+    '@typescript-eslint/no-var-requires': 0,
   }
 }

+ 2 - 0
jydocs-mobile/package.json

@@ -14,6 +14,7 @@
     "html2canvas": "^1.0.0-rc.6",
     "js-cookie": "^2.2.1",
     "moment": "^2.24.0",
+    "pdfjs-dist": "^2.6.347",
     "vant": "^2.8.2",
     "vue": "^2.6.11",
     "vue-class-component": "^7.2.3",
@@ -23,6 +24,7 @@
   },
   "devDependencies": {
     "@types/js-cookie": "^2.2.6",
+    "@types/pdfjs-dist": "^2.7.0",
     "@types/qs": "^6.9.4",
     "@typescript-eslint/eslint-plugin": "^2.33.0",
     "@typescript-eslint/parser": "^2.33.0",

+ 18 - 16
jydocs-mobile/src/views/details/details.vue

@@ -41,6 +41,8 @@ import { Icon, Toast, GoodsAction, GoodsActionIcon, GoodsActionButton } from 'va
 import Recharge from '@/components/Recharge.vue'
 import sharePop from '@/components/SharePopup.vue'
 import { MixinTop } from '@/utils/mixin-top'
+const pdfjsLib = require('pdfjs-dist/build/pdf.js')
+const pdfjsViewer = require('pdfjs-dist/web/pdf_viewer.js')
 
 @Component({
   name: 'details-p',
@@ -152,22 +154,22 @@ export default class extends Vue {
   //   })
   // }
 
-  // init () {
-  //   console.log(this.conts)
-  //   const loadingTask = pdfjsLib.getDocument({
-  //     url: this.conts
-  //   })
-  //   loadingTask.promise.then((pdfDocument: any) => {
-  //     this.pdfDocument = pdfDocument
-  //     console.log(this.pdfDocument.numPages)
-  //     // this.updateText({type: 'count', value: this.pdfDocument.numPages})
-  //     // this.updateText({type: 'num', value: 1})
-  //     for (let i = 0; i < this.pdfDocument.numPages; i++) {
-  //       this.config.PAGE_TO_VIEW++
-  //       this.renders()
-  //     }
-  //   })
-  // }
+  init () {
+    console.log(this.conts)
+    const loadingTask = pdfjsLib.getDocument({
+      url: this.conts
+    })
+    loadingTask.promise.then((pdfDocument: any) => {
+      this.pdfDocument = pdfDocument
+      console.log(this.pdfDocument.numPages)
+      // this.updateText({type: 'count', value: this.pdfDocument.numPages})
+      // this.updateText({type: 'num', value: 1})
+      for (let i = 0; i < this.pdfDocument.numPages; i++) {
+        this.config.PAGE_TO_VIEW++
+        // this.renders()
+      }
+    })
+  }
 
   watchPage () {
     const top = window.scrollY

+ 10 - 0
jydocs-mobile/yarn.lock

@@ -1001,6 +1001,11 @@
   resolved "https://registry.npm.taobao.org/@types/normalize-package-data/download/@types/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
   integrity sha1-5IbQ2XOW15vu3QpuM/RTT/a0lz4=
 
+"@types/pdfjs-dist@^2.7.0":
+  version "2.7.0"
+  resolved "https://registry.npm.taobao.org/@types/pdfjs-dist/download/@types/pdfjs-dist-2.7.0.tgz#2fca369320ce87c0a0d09e1fc7840adb5ae7de68"
+  integrity sha1-L8o2kyDOh8Cg0J4fx4QK21rn3mg=
+
 "@types/q@^1.5.1":
   version "1.5.4"
   resolved "https://registry.npm.taobao.org/@types/q/download/@types/q-1.5.4.tgz#15925414e0ad2cd765bfef58842f7e26a7accb24"
@@ -6942,6 +6947,11 @@ pbkdf2@^3.0.3:
     safe-buffer "^5.0.1"
     sha.js "^2.4.8"
 
+pdfjs-dist@^2.6.347:
+  version "2.6.347"
+  resolved "https://registry.npm.taobao.org/pdfjs-dist/download/pdfjs-dist-2.6.347.tgz#f257ed66e83be900cd0fd28524a2187fb9e25cd5"
+  integrity sha1-8lftZug76QDND9KFJKIYf7niXNU=
+
 performance-now@^2.1.0:
   version "2.1.0"
   resolved "https://registry.npm.taobao.org/performance-now/download/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"