@toolspack/ttd-pdfjs 0.0.2 → 0.0.4
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/README.md +3 -0
- package/lib/ttd-pdfjs.common.js +87 -70
- package/lib/ttd-pdfjs.umd.js +87 -70
- package/lib/ttd-pdfjs.umd.min.js +5 -5
- package/package.json +1 -1
- package/src/App.vue +50 -23
- package/src/main.js +2 -1
- package/src/packages/pdfjs/PdfView216.vue +24 -4
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div id="app">
|
|
3
|
-
|
|
3
|
+
<el-upload
|
|
4
4
|
ref="baseUpload"
|
|
5
5
|
:show-file-list="false"
|
|
6
|
-
:accept="accept"
|
|
7
6
|
name="files"
|
|
8
7
|
:action="actionInner"
|
|
9
8
|
:on-success="handleAvatarSuccess"
|
|
10
9
|
:on-progress="handelProgress"
|
|
11
10
|
:before-upload="beforeAvatarUpload"
|
|
12
|
-
:headers="uploadHeader
|
|
11
|
+
:headers="uploadHeader"
|
|
13
12
|
:data="uploadData"
|
|
14
13
|
:on-exceed="onExceed"
|
|
15
|
-
:disabled="disabled"
|
|
16
14
|
list-type="text"
|
|
17
|
-
:multiple="multiple"
|
|
18
|
-
:limit="limit"
|
|
19
15
|
>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
</template>
|
|
23
|
-
</el-upload> -->
|
|
16
|
+
<el-button>上传</el-button>
|
|
17
|
+
</el-upload>
|
|
24
18
|
<PdfView :pdfurl="url" />
|
|
25
19
|
</div>
|
|
26
20
|
</template>
|
|
@@ -28,32 +22,65 @@
|
|
|
28
22
|
<script>
|
|
29
23
|
import PdfView from './packages/pdfjs/PdfView216.vue'
|
|
30
24
|
|
|
31
|
-
const
|
|
25
|
+
const mybaseUrl = 'https://petx.totodi.com/'
|
|
32
26
|
|
|
33
27
|
export default {
|
|
34
28
|
components: { PdfView },
|
|
35
29
|
name: 'App',
|
|
36
30
|
data() {
|
|
37
31
|
return {
|
|
38
|
-
|
|
32
|
+
maxSize: 10,
|
|
33
|
+
uploadData: { debug: true, bucketName: 'totodi-temp' },
|
|
34
|
+
actionInner: `${mybaseUrl}zuul/file-service/oos/uploadFile`,
|
|
35
|
+
uploadHeader: {},
|
|
36
|
+
url: '',
|
|
39
37
|
uName: 'totodi-contract',
|
|
40
|
-
action: `${_baseUrl}zuul/file-service/oos/uploadFile`,
|
|
41
38
|
}
|
|
42
39
|
},
|
|
43
40
|
mounted() {
|
|
44
41
|
},
|
|
45
42
|
methods: {
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
beforeAvatarUpload(file) {
|
|
44
|
+
const isLt2M = file.size / 1024 / 1024 < this.maxSize
|
|
45
|
+
if (!isLt2M) {
|
|
46
|
+
console.log(`上传文件大小不能超过${ this.maxSize }MB!`)
|
|
47
|
+
}
|
|
48
|
+
if (isLt2M) {
|
|
49
|
+
this.progress = file
|
|
50
|
+
}
|
|
51
|
+
return isLt2M
|
|
52
|
+
},
|
|
53
|
+
onExceed(files, fileList) {
|
|
54
|
+
console.log(`当前限制选择 ${this.limit} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
|
|
55
|
+
},
|
|
56
|
+
handelProgress(event, file, fileList) {
|
|
57
|
+
this.progressCurrent = event.percent
|
|
58
|
+
console.log('progress', event, file, fileList)
|
|
59
|
+
},
|
|
60
|
+
tips(words = []) {
|
|
61
|
+
if (Array.isArray(words) && words.length > 0) {
|
|
62
|
+
const cfile = [...words]
|
|
63
|
+
const lastType = cfile.length > 1 ? cfile.pop() : ''
|
|
64
|
+
return `仅支持 ${cfile.join('、')}${lastType ? ` 或者 ${ lastType}` : ''} 格式`
|
|
65
|
+
}
|
|
66
|
+
return '文件类型不正确'
|
|
67
|
+
},
|
|
68
|
+
handleAvatarSuccess(res, file, fileList) {
|
|
69
|
+
const { code, data, msg } = res
|
|
70
|
+
// this.progress = null
|
|
71
|
+
if (code === 0) {
|
|
72
|
+
const { list } = data
|
|
73
|
+
// let obj = {
|
|
74
|
+
// fileName: file.fileName,
|
|
75
|
+
// bucketName: file.oosBucket,
|
|
76
|
+
// objectKey: file.objectKey,
|
|
77
|
+
// url: file.url,
|
|
78
|
+
// fileMD5: file.fileMD5
|
|
79
|
+
// }
|
|
80
|
+
this.url = list[0].url
|
|
81
|
+
} else {
|
|
82
|
+
console.log(msg || '上传失败!')
|
|
53
83
|
}
|
|
54
|
-
|
|
55
|
-
// 添加其他字段数据到表单中
|
|
56
|
-
formData.append('u_name', this.uName);
|
|
57
84
|
},
|
|
58
85
|
},
|
|
59
86
|
}
|
package/src/main.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import Vue from 'vue';
|
|
2
|
-
import { Button, Input } from 'element-ui';
|
|
2
|
+
import { Button, Input, Upload } from 'element-ui';
|
|
3
3
|
import App from './App.vue';
|
|
4
4
|
|
|
5
5
|
Vue.config.productionTip = false;
|
|
6
6
|
|
|
7
7
|
Vue.component(Button.name, Button);
|
|
8
8
|
Vue.component(Input.name, Input);
|
|
9
|
+
Vue.component(Upload.name, Upload);
|
|
9
10
|
|
|
10
11
|
new Vue({
|
|
11
12
|
render: (h) => h(App),
|
|
@@ -33,6 +33,14 @@ const PDFJS = require('pdfjs-dist')
|
|
|
33
33
|
const defautScale = 1.0
|
|
34
34
|
|
|
35
35
|
PDFJS.GlobalWorkerOptions.workerSrc = require('pdfjs-dist/build/pdf.worker.js')
|
|
36
|
+
// https://unpkg.com/pdfjs-dist@2.16.105/cmaps/
|
|
37
|
+
// 使用代理的cmaps,会导致加载很慢,改用本地
|
|
38
|
+
|
|
39
|
+
const cMapUrl = 'https://wsp.totodi.com/staticfiles_web/web/pdfjs/cmaps/'
|
|
40
|
+
|
|
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'
|
|
36
44
|
|
|
37
45
|
export default {
|
|
38
46
|
components: { SwitchPage },
|
|
@@ -68,6 +76,7 @@ export default {
|
|
|
68
76
|
data() {
|
|
69
77
|
return {
|
|
70
78
|
pdfDoc: null, // pdfjs 生成的对象
|
|
79
|
+
viewport: null,
|
|
71
80
|
pageNum: 1, // 当前页数
|
|
72
81
|
pageRendering: false,
|
|
73
82
|
fileLoading: true,
|
|
@@ -106,6 +115,7 @@ export default {
|
|
|
106
115
|
}
|
|
107
116
|
// 重新渲染 缩放过的PDF
|
|
108
117
|
viewport = page.getViewport({ scale: scaleNum })
|
|
118
|
+
this.viewport = viewport
|
|
109
119
|
|
|
110
120
|
// 将 canvas 尺寸 传给父组件
|
|
111
121
|
this.$emit('size', viewport, num)
|
|
@@ -166,7 +176,14 @@ export default {
|
|
|
166
176
|
},
|
|
167
177
|
closepdf() {
|
|
168
178
|
// 关闭PDF
|
|
179
|
+
console.log('closepdf - begin')
|
|
169
180
|
if (this.pdfDoc) {
|
|
181
|
+
if (this.viewport) {
|
|
182
|
+
const { canvas } = this.$refs
|
|
183
|
+
const cxt = canvas.getContext('2d')
|
|
184
|
+
cxt.clearRect(0, 0, this.viewport.width, this.viewport.height);
|
|
185
|
+
}
|
|
186
|
+
this.viewport = null
|
|
170
187
|
this.pdfDoc.destroy();
|
|
171
188
|
}
|
|
172
189
|
this.pdfDoc = null
|
|
@@ -203,7 +220,7 @@ export default {
|
|
|
203
220
|
// pdfDoc_ = await PDFJS.getDocument({ data: arrayBufferPdf }).promise;
|
|
204
221
|
pdfDoc_ = await PDFJS.getDocument({
|
|
205
222
|
url: encodeURI(url),
|
|
206
|
-
cMapUrl
|
|
223
|
+
cMapUrl,
|
|
207
224
|
cMapPacked: true,
|
|
208
225
|
}).promise
|
|
209
226
|
} catch (error) {
|
|
@@ -222,7 +239,7 @@ export default {
|
|
|
222
239
|
// 初始化pdf
|
|
223
240
|
if (this.pdfDoc) {
|
|
224
241
|
console.log('pdfDocument is ready destroy,,')
|
|
225
|
-
|
|
242
|
+
this.closepdf();
|
|
226
243
|
this.pdfDoc = null
|
|
227
244
|
console.log('pdfDocument is destroy')
|
|
228
245
|
}
|
|
@@ -250,8 +267,9 @@ export default {
|
|
|
250
267
|
// }
|
|
251
268
|
},
|
|
252
269
|
beforeDestroy() {
|
|
270
|
+
console.log('---', this.pdfDoc)
|
|
253
271
|
if (this.pdfDoc) {
|
|
254
|
-
this.
|
|
272
|
+
this.closepdf();
|
|
255
273
|
}
|
|
256
274
|
},
|
|
257
275
|
watch: {
|
|
@@ -268,7 +286,9 @@ export default {
|
|
|
268
286
|
this.initPage = true
|
|
269
287
|
this.loadUrl(val)
|
|
270
288
|
if (this.pdfDoc) {
|
|
271
|
-
|
|
289
|
+
console.log('wtach 3333')
|
|
290
|
+
this.closepdf();
|
|
291
|
+
console.log('wtach 444')
|
|
272
292
|
}
|
|
273
293
|
}
|
|
274
294
|
if (this.showPages) {
|