@toolspack/ttd-pdfjs 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolspack/ttd-pdfjs",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "private": false,
5
5
  "main": "lib/ttd-pdfjs.umd.min.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "babel-cli": "^6.26.0",
14
14
  "babel-laoder": "0.0.1-security",
15
15
  "babel-polyfill": "^6.26.0",
16
- "core-js": "^3.6.5",
16
+ "core-js": "^3.34.0",
17
17
  "element-ui": "^2.15.14",
18
18
  "less": "^3.8.1",
19
19
  "less-loader": "^4.1.0",
package/src/App.vue CHANGED
@@ -55,7 +55,7 @@ export default {
55
55
  },
56
56
  handelProgress(event, file, fileList) {
57
57
  this.progressCurrent = event.percent
58
- console.log('progress', event, file, fileList)
58
+ // console.log('progress', event, file, fileList)
59
59
  },
60
60
  tips(words = []) {
61
61
  if (Array.isArray(words) && words.length > 0) {
@@ -77,6 +77,7 @@ export default {
77
77
  // url: file.url,
78
78
  // fileMD5: file.fileMD5
79
79
  // }
80
+ console.log('upload: ', list[0])
80
81
  this.url = list[0].url
81
82
  } else {
82
83
  console.log(msg || '上传失败!')
@@ -26,22 +26,45 @@
26
26
  </template>
27
27
  <script>
28
28
 
29
+ import { Message } from 'element-ui';
29
30
  import SwitchPage from './SwitchPage.vue'
30
31
 
32
+ function getChromeVersion() {
33
+ const arr = navigator.userAgent.split(' ');
34
+ let chromeVersion = '';
35
+ for (let i = 0; i < arr.length; i++) {
36
+ if (/chrome/i.test(arr[i])) chromeVersion = arr[i]
37
+ }
38
+ if (chromeVersion) {
39
+ return Number(chromeVersion.split('/')[1].split('.')[0]);
40
+ }
41
+ return false;
42
+ }
43
+ let version = ''
44
+ if (getChromeVersion()) {
45
+ version = getChromeVersion();
46
+ if (version < 98) {
47
+ Message({
48
+ message: `您使用的谷歌浏览器版本过低【version:${version}】,为了更好地体验请将浏览器升级到最新版本!`,
49
+ type: 'error',
50
+ duration: 3000,
51
+ })
52
+ }
53
+ }
54
+
55
+ // const PDFJS = require('pdfjs-dist/legacy/build/pdf.js')
31
56
  const PDFJS = require('pdfjs-dist')
32
57
 
33
58
  const defautScale = 1.0
34
59
 
35
- PDFJS.GlobalWorkerOptions.workerSrc = require('pdfjs-dist/legacy/build/pdf.worker.min.js')
60
+ // PDFJS.GlobalWorkerOptions.workerSrc = require('pdfjs-dist/legacy/build/pdf.worker.min.js')
61
+ PDFJS.GlobalWorkerOptions.workerSrc = require('pdfjs-dist/build/pdf.worker.min.js')
36
62
  // https://unpkg.com/pdfjs-dist@2.16.105/cmaps/
63
+ // const cMapUrl = 'https://cdn.jsdelivr.net/npm/pdfjs-dist@3.11.174/cmaps/'
37
64
  // 使用代理的cmaps,会导致加载很慢,改用本地
38
65
 
39
66
  const cMapUrl = 'https://wsp.totodi.com/staticfiles_web/web/pdfjs/cmaps/'
40
67
 
41
- // const cMapUrl = 'https://cdn.jsdelivr.net/npm/pdfjs-dist@3.11.174/cmaps/'
42
-
43
- // const cMapUrl = 'https://petx.totodi.com/jz/pdfjs/cmaps'
44
-
45
68
  export default {
46
69
  components: { SwitchPage },
47
70
  props: {
@@ -133,7 +156,7 @@ export default {
133
156
  canvasContext: canvas.getContext('2d'),
134
157
  viewport,
135
158
  }
136
- const renderTask = page.render(renderContext)
159
+ const renderTask = await page.render(renderContext)
137
160
 
138
161
  // Wait for rendering to finish
139
162
  await renderTask.promise
@@ -176,12 +199,13 @@ export default {
176
199
  },
177
200
  closepdf() {
178
201
  // 关闭PDF
179
- console.log('closepdf - begin')
180
202
  if (this.pdfDoc) {
181
203
  if (this.viewport) {
182
204
  const { canvas } = this.$refs
183
- const cxt = canvas.getContext('2d')
184
- cxt.clearRect(0, 0, this.viewport.width, this.viewport.height);
205
+ if (canvas) {
206
+ const cxt = canvas.getContext('2d')
207
+ cxt.clearRect(0, 0, this.viewport.width, this.viewport.height);
208
+ }
185
209
  }
186
210
  this.viewport = null
187
211
  this.pdfDoc.destroy();
@@ -212,7 +236,6 @@ export default {
212
236
  console.log('----PdfView---', url)
213
237
  let pdfDoc_
214
238
  try {
215
- console.log('888--')
216
239
  // const pdfData = await fetch(
217
240
  // new URL(url, window.location).href,
218
241
  // );
@@ -224,7 +247,6 @@ export default {
224
247
  cMapPacked: true,
225
248
  }).promise
226
249
  } catch (error) {
227
- console.log('999999--')
228
250
  console.error(error)
229
251
 
230
252
  const pdfData = await fetch(
@@ -239,13 +261,11 @@ export default {
239
261
  // 初始化pdf
240
262
  if (this.pdfDoc) {
241
263
  console.log('pdfDocument is ready destroy,,')
242
- this.closepdf();
264
+ await this.closepdf();
243
265
  this.pdfDoc = null
244
- console.log('pdfDocument is destroy')
245
266
  }
246
267
  this.pdfDoc = pdfDoc_
247
268
  this.page_count = pdfDoc_.numPages
248
- console.log('this.page_count', this.page_count)
249
269
  this.$emit('numPages', pdfDoc_.numPages)
250
270
  this.renderPage(this.pageNum)
251
271
  this.emitPage(this.pageNum)
@@ -286,9 +306,7 @@ export default {
286
306
  this.initPage = true
287
307
  this.loadUrl(val)
288
308
  if (this.pdfDoc) {
289
- console.log('wtach 3333')
290
309
  this.closepdf();
291
- console.log('wtach 444')
292
310
  }
293
311
  }
294
312
  if (this.showPages) {