@toolspack/ttd-pdfjs 0.1.6 → 0.1.8

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.1.6",
3
+ "version": "0.1.8",
4
4
  "private": false,
5
5
  "main": "lib/ttd-pdfjs.umd.min.js",
6
6
  "scripts": {
@@ -6,24 +6,22 @@
6
6
  @page="onChangePage" @zoom="onScale" @rotate="onRotate"></switch-page>
7
7
  </div>
8
8
  <div class="pdf-view-area-wapper">
9
- <div>
10
- <div
11
- class="center pdf-view-area"
12
- @drop="onDrop"
13
- @dragover="onDragOver"
14
- :key="pdfurl"
15
- :style="{'border': border?'1px solid #666': ''}"
16
- v-if="pdfurl"
17
- >
18
- <div v-if="fileLoading" class="pdf-view-loading">文件加载中...</div>
19
- <div v-else-if="pageRendering" class="pdf-view-rendering">内容渲染中...</div>
20
- <canvas :key="pdfurl +'canvas'" class="canvasstyle" ref="canvas"></canvas>
21
- <div class="label-area">
22
- <slot></slot>
23
- </div>
9
+ <div
10
+ class="center pdf-view-area"
11
+ @drop="onDrop"
12
+ @dragover="onDragOver"
13
+ :key="pdfurl"
14
+ :style="{'border': border?'1px solid #666': ''}"
15
+ v-if="pdfurl"
16
+ >
17
+ <div v-if="fileLoading" class="pdf-view-loading">文件加载中...</div>
18
+ <div v-else-if="pageRendering" class="pdf-view-rendering">内容渲染中...</div>
19
+ <canvas :key="pdfurl +'canvas'" class="canvasstyle" :style="{with: showWidth?showWidth+'px':'auto'}" ref="canvas"></canvas>
20
+ <div class="label-area">
21
+ <slot></slot>
24
22
  </div>
25
- <div v-else class="pdf-view-empty">未找到资源,请联系管理员!</div>
26
23
  </div>
24
+ <div v-else class="pdf-view-empty">未找到资源,请联系管理员!</div>
27
25
  </div>
28
26
  </div>
29
27
  </template>
@@ -121,6 +119,7 @@ export default {
121
119
  pageNumPending: null,
122
120
  compuscale: defautScale, // 放大倍数
123
121
  compuRotate: undefined, // 实际旋转度数, 默认值必须是 undefined
122
+ pdf_rotation: 0, // pdf 的旋转度数
124
123
  page_count: 0, // 总页数
125
124
  maxscale, // 最大放大倍数
126
125
  minscale, // 最小放大倍数
@@ -135,7 +134,7 @@ export default {
135
134
  },
136
135
  methods: {
137
136
  async renderPage(num) {
138
- console.log('renderPage ', this.pageRendering)
137
+ // console.log('renderPage ', num, this.pageRendering)
139
138
  if (this.pageRendering) {
140
139
  this.pageNumPending = num;
141
140
  } else {
@@ -152,22 +151,22 @@ export default {
152
151
  let viewport = ''
153
152
  const viewboxWidth = this.showWidth
154
153
  if (this.initPage) {
155
- viewport = page.getViewport({ scale: 1.0 })
154
+ const viewportInit = await page.getViewport({ scale: 1.0 })
156
155
  if (viewboxWidth) {
157
156
  const desiredWidth = parseInt(viewboxWidth, 10) - 2
158
157
  // 首先获得pdf 原本宽度,然后根据showWidth 计算缩放倍数
159
- scaleNum = desiredWidth / viewport.width
158
+ scaleNum = desiredWidth / viewportInit.width
160
159
  this.compuscale = scaleNum
161
160
  this.maxscale = scaleNum
162
161
  }
163
162
  // console.log('xxxxxx', this.compuRotate, viewport.rotation)
164
- this.compuRotate = viewport.rotation
163
+ this.pdf_rotation = viewportInit.rotation
165
164
  this.initPage = false
166
165
  }
167
166
  // 重新渲染 缩放过的PDF
168
- viewport = page.getViewport({ scale: scaleNum, rotation: this.compuRotate })
167
+ viewport = await page.getViewport({ scale: scaleNum, rotation: this.compuRotate })
169
168
  this.viewport = viewport
170
-
169
+ // console.log('rotation -', num, viewport.rotation)
171
170
  // 将 canvas 尺寸 传给父组件
172
171
  this.$emit('size', viewport, num)
173
172
 
@@ -178,7 +177,8 @@ export default {
178
177
  if (!canvas) {
179
178
  return false
180
179
  }
181
- this.style.width = `${viewport.width + 18}px`;
180
+ // pdf 组件不应该 有滚动条
181
+ this.style.width = `${viewport.width + 2}px`;
182
182
  this.pdfWidth = `${viewport.width}px`;
183
183
  canvas.height = viewport.height
184
184
  canvas.width = viewport.width
@@ -219,9 +219,12 @@ export default {
219
219
  return
220
220
  }
221
221
  this.pageNum++
222
+ // console.log('next', this.pageNum)
222
223
  this.queueRenderPage(this.pageNum)
223
224
  },
224
225
  onChangePage(page) {
226
+ this.pageNum = page
227
+ // console.log('onChangePage', page)
225
228
  this.emitPage(page)
226
229
  // switch page 改变页码
227
230
  this.queueRenderPage(page)
@@ -267,7 +270,6 @@ export default {
267
270
  // url = encodeURI(url)
268
271
  // console.log('-----encodeURI------', url)
269
272
  // }
270
- console.log('----PdfView---', url)
271
273
  if (this.pdfDoc) {
272
274
  // console.log('pdfDocument is ready destroy,,')
273
275
  this.pdfDoc.destroy();
@@ -318,7 +320,12 @@ export default {
318
320
  this.renderPage(this.pageNum)
319
321
  },
320
322
  onRotate(rotate) {
321
- this.compuRotate += rotate
323
+ // console.log('rotate -', rotate, this.compuRotate, this.pageNum)
324
+ if (this.compuRotate === undefined) {
325
+ this.compuRotate = this.pdf_rotation + rotate
326
+ } else {
327
+ this.compuRotate += rotate
328
+ }
322
329
  this.renderPage(this.pageNum)
323
330
  },
324
331
  },
@@ -375,10 +382,6 @@ export default {
375
382
 
376
383
  <style lang="less" scoped>
377
384
  .pdf-view {
378
- height: 100%;
379
- width: 100%;
380
- display: flex;
381
- flex-direction: column;
382
385
  box-sizing: border-box;
383
386
  min-width: 688px;
384
387
  }
@@ -387,11 +390,7 @@ export default {
387
390
  margin: 10px 0;
388
391
  }
389
392
  .pdf-view-area-wapper {
390
- flex: 1 1 0%;
391
- overflow: auto;
392
- width: 100%;
393
- flex-shrink: 0%;
394
- box-sizing: border-box;
393
+ overflow: hidden;
395
394
  }
396
395
  .pdf-view-area {
397
396
  position: relative;