@toolspack/ttd-common 1.0.0 → 1.0.1

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-common",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "private": false,
5
5
  "main": "lib/ttd-common.umd.min.js",
6
6
  "scripts": {
@@ -16,7 +16,6 @@
16
16
  "core-js": "^3.6.5",
17
17
  "less": "^3.8.1",
18
18
  "less-loader": "^4.1.0",
19
- "pdfjs-dist": "2.16.105",
20
19
  "vue": "^2.6.12"
21
20
  },
22
21
  "devDependencies": {
package/src/App.vue CHANGED
@@ -6,17 +6,14 @@
6
6
  <input type="hidden" name="bucketName" :value="uName">
7
7
  <input type="submit" value="提交">
8
8
  </form>
9
- <PdfView :pdfurl="url" />
10
9
  </div>
11
10
  </template>
12
11
 
13
12
  <script>
14
- import PdfView from './packages/pdfjs/PdfView216.vue'
15
13
 
16
14
  const _baseUrl = 'http://peys.totodi.com:37811/'
17
15
 
18
16
  export default {
19
- components: { PdfView },
20
17
  name: 'App',
21
18
  data() {
22
19
  return {
@@ -4,13 +4,10 @@ import WzhSign from './ukey/WzhSign.vue'
4
4
  import SignNew from './ukey/SignNew.vue'
5
5
  import WzhSignChrome from './ukey/WzhSignChrome.vue'
6
6
 
7
- import PdfView216 from './pdfjs/PdfView216.vue'
8
-
9
7
  export default {
10
8
  CfcaPdf,
11
9
  Ukey,
12
10
  WzhSign,
13
11
  WzhSignChrome,
14
12
  SignNew,
15
- PdfView216,
16
13
  }
@@ -43,17 +43,18 @@ export default {
43
43
  return true
44
44
  }
45
45
  // 360的急速模式,需要使用ie签署控件(無法實現,或不稳定,360会快速修复让用户无法检测)
46
+ // 测试后,360的急速模式 可以和chrome 用一个签署代码了
46
47
  // const plugin360 = [
47
48
  // '360', '360SoftMgrPlugin', 'ActiveX hosting plugin for Firefox/Chrome',
48
49
  // 'GamePlugin', 'QQMail Plugin', 'Tencent QQ', 'npQQPhotoDrawEx']
49
- if (plugins['360SoftMgrPlugin']) {
50
- this.isIE = true
51
- return true
52
- }
53
- if (mimeTypes['application/360softmgrplugin']) {
54
- this.isIE = true
55
- return true
56
- }
50
+ // if (plugins['360SoftMgrPlugin']) {
51
+ // this.isIE = true
52
+ // return true
53
+ // }
54
+ // if (mimeTypes['application/360softmgrplugin']) {
55
+ // this.isIE = true
56
+ // return true
57
+ // }
57
58
  this.isIE = false
58
59
  },
59
60
  },
@@ -2,7 +2,7 @@
2
2
  <template>
3
3
  <div class="CryptoAgent-wrapper">
4
4
  <object v-if="isIE" ref="CryptoAgent" :codebase="publicPath + codebase" :classid="classid"></object>
5
- <embed v-else ref="CryptoAgent" type="application/npCryptoKit.ToToDi.x86" style="height: 0px; width: 0px">
5
+ <embed v-else ref="CryptoAgent" type="application/npCryptoKit.ToToDi.x86" style="height: 0px; width: 0px" />
6
6
  </div>
7
7
  </template>
8
8
  <script>
@@ -164,7 +164,7 @@ export default {
164
164
  console.log('wzh SelectCertResult', bSelectCertResult)
165
165
  return true
166
166
  } catch (e) {
167
- console.log('wzh SelectCertResult catch error: ')
167
+ console.log('wzh SelectCertResult error: ', e)
168
168
  this.ShowErrorInfo(e)
169
169
  return false
170
170
  }
@@ -292,17 +292,17 @@ export default {
292
292
  console.log('multipleSign 签章的结果', result)
293
293
  return result
294
294
  },
295
- },
296
- ShowErrorInfo(response = '') {
297
- if (!this.CryptoAgent || !this.CryptoAgent.GetLastErrorDesc) {
298
- alert('不支持该功能!');
299
- } else { // host error
300
- let errorDesc = this.CryptoAgent.GetLastErrorDesc()
301
- if (response) {
302
- errorDesc = `${errorDesc}[${response}]`
295
+ ShowErrorInfo(response = '') {
296
+ if (!this.CryptoAgent || !this.CryptoAgent.GetLastErrorDesc) {
297
+ alert('不支持该功能!');
298
+ } else { // host error
299
+ let errorDesc = this.CryptoAgent.GetLastErrorDesc()
300
+ if (response) {
301
+ errorDesc = `${errorDesc}[${response}]`
302
+ }
303
+ alert(errorDesc)
303
304
  }
304
- alert(errorDesc)
305
- }
305
+ },
306
306
  },
307
307
  }
308
308
 
@@ -94,7 +94,7 @@ export default {
94
94
  console.log(5444444, version)
95
95
  } catch (response) {
96
96
  console.log(44444, response)
97
- // alert('扩展初始化失败,请联系管理员!')
97
+ alert('扩展初始化失败,请联系管理员!')
98
98
  this.ShowErrorInfo(response);
99
99
  return Promise.reject()
100
100
  }
@@ -1,331 +0,0 @@
1
- <template>
2
- <div class="pdf-view">
3
- <div class="pdf-view-control" v-if="showPages">
4
- <switch-page ref="switchPage" @page="onChangePage" :numPages="page_count"></switch-page>
5
- </div>
6
- <div class="pdf-view-area-wapper">
7
- <div :style="style">
8
- <div
9
- class="center pdf-view-area"
10
- @drop="onDrop"
11
- @dragover="onDragOver"
12
- :style="{'border': border?'1px solid #666': ''}"
13
- v-if="pdfurl"
14
- >
15
- <div v-if="fileLoading" class="pdf-view-loading">文件加载中...</div>
16
- <!-- <div v-else-if="pageRendering" class="pdf-view-rendering">内容渲染中...</div> -->
17
- <canvas class="canvasstyle" ref="canvas"></canvas>
18
- <div class="label-area">
19
- <slot></slot>
20
- </div>
21
- </div>
22
- <div v-else class="pdf-view-empty">未找到资源,请联系管理员!</div>
23
- </div>
24
- </div>
25
- </div>
26
- </template>
27
- <script>
28
-
29
- const PDFJS = require('pdfjs-dist')
30
-
31
- const defautScale = 1.0
32
-
33
- PDFJS.GlobalWorkerOptions.workerSrc = require('pdfjs-dist/legacy/build/pdf.worker.entry')
34
-
35
- export default {
36
- props: {
37
- pdfurl: {
38
- default: '',
39
- },
40
- scale: {
41
- type: Number,
42
- default: defautScale,
43
- },
44
- showPages: {
45
- type: [String, Number, Boolean],
46
- default: true,
47
- },
48
- border: {
49
- type: [String, Number, Boolean],
50
- default: true,
51
- },
52
- marginAuto: {
53
- type: [String, Number, Boolean],
54
- default: false,
55
- },
56
- page: {
57
- type: [String, Number],
58
- default: 1,
59
- },
60
- showWidth: {
61
- type: [String, Number],
62
- default: 0,
63
- },
64
- },
65
- data() {
66
- return {
67
- pdfDoc: null, // pdfjs 生成的对象
68
- pageNum: 1, // 当前页数
69
- pageRendering: false,
70
- fileLoading: true,
71
- pageNumPending: null,
72
- compuscale: defautScale, // 放大倍数
73
- page_count: 0, // 总页数
74
- maxscale: 1.5, // 最大放大倍数
75
- minscale: 0.8, // 最小放大倍数
76
- isready: false,
77
- initPage: true, // 初始化页面
78
- style: {
79
- width: '860px', // 先给个默认值,当渲染后,后自动按实际值渲染,否则打标签那里,会显示异常
80
- margin: this.marginAuto === '' || this.marginAuto ? '0 auto' : '0',
81
- },
82
- }
83
- },
84
- methods: {
85
- async renderPage(num) {
86
- // 渲染pdf
87
- const vm = this
88
- this.pageRendering = true
89
- // Using promise to fetch the page
90
- try {
91
- const page = await this.pdfDoc.getPage(num)
92
- let scaleNum = vm.compuscale
93
- let viewport = ''
94
- const viewboxWidth = this.showWidth
95
- if (this.initPage && viewboxWidth) {
96
- const desiredWidth = parseInt(viewboxWidth, 10) - 2
97
- // 首先获得pdf 原本宽度,然后根据showWidth 计算缩放倍数
98
- viewport = page.getViewport({ scale: 1.0 })
99
- scaleNum = desiredWidth / viewport.width
100
- this.initPage = false
101
- this.compuscale = scaleNum
102
- this.maxscale = scaleNum
103
- }
104
- // 重新渲染 缩放过的PDF
105
- viewport = page.getViewport({ scale: scaleNum })
106
-
107
- // 将 canvas 尺寸 传给父组件
108
- this.$emit('size', viewport, num)
109
-
110
- // Render PDF page into canvas context
111
- vm.isready = true
112
-
113
- const { canvas } = vm.$refs
114
-
115
- this.style.width = `${viewport.width + 2}px`;
116
- canvas.height = viewport.height
117
- canvas.width = viewport.width
118
-
119
- const renderContext = {
120
- canvasContext: canvas.getContext('2d'),
121
- viewport,
122
- }
123
- const renderTask = page.render(renderContext)
124
-
125
- // Wait for rendering to finish
126
- await renderTask.promise
127
- vm.pageRendering = false
128
- if (vm.pageNumPending !== null) {
129
- // New page rendering is pending
130
- vm.renderPage(vm.pageNumPending)
131
- vm.pageNumPending = null
132
- }
133
- this.$emit('renderSuccess')
134
- } catch (error) {
135
- console.error(error)
136
- } finally {
137
- this.pageRendering = false
138
- }
139
- },
140
- prev() {
141
- // 上一页
142
- if (this.pageNum <= 1) {
143
- return
144
- }
145
- this.pageNum--
146
- this.queueRenderPage(this.pageNum)
147
- },
148
- next() {
149
- // 下一页
150
- if (this.pageNum >= this.page_count) {
151
- return
152
- }
153
- this.pageNum++
154
- this.queueRenderPage(this.pageNum)
155
- },
156
- onChangePage(page) {
157
- this.emitPage(page)
158
- // switch page 改变页码
159
- this.queueRenderPage(page)
160
- },
161
- emitPage(page) {
162
- this.$emit('pageChange', page, this.page_count, page === this.page_count)
163
- },
164
- closepdf() {
165
- // 关闭PDF
166
- if (this.pdfDoc) {
167
- this.pdfDoc.destroy();
168
- }
169
- this.pdfDoc = null
170
- this.isready = false
171
- this.compuscale = this.scale
172
- this.$emit('closepdf')
173
- },
174
- queueRenderPage(num) {
175
- if (this.pageRendering) {
176
- this.pageNumPending = num
177
- } else {
178
- this.renderPage(num)
179
- }
180
- },
181
- async loadUrl(url) {
182
- if (!PDFJS) {
183
- return false
184
- }
185
- this.fileLoading = true
186
- // 此处无法确定,到底是否使用encodeURI
187
- // var reg = /[\u4e00-\u9fa5]+/
188
- // if (reg.test(url)) {
189
- // url = encodeURI(url)
190
- // console.log('-----encodeURI------', url)
191
- // }
192
- console.log('----PdfView---', url)
193
- let pdfDoc_
194
- try {
195
- console.log('888--')
196
- // const pdfData = await fetch(
197
- // new URL(url, window.location).href,
198
- // );
199
- // const arrayBufferPdf = await pdfData.arrayBuffer(); // 转成 ArrayBuffer 塞给 pdf.js
200
- // pdfDoc_ = await PDFJS.getDocument({ data: arrayBufferPdf }).promise;
201
- pdfDoc_ = await PDFJS.getDocument({
202
- url: encodeURI(url),
203
- cMapUrl: 'https://unpkg.com/pdfjs-dist@2.16.105/cmaps/',
204
- cMapPacked: true,
205
- }).promise
206
- } catch (error) {
207
- console.log('999999--')
208
- console.error(error)
209
-
210
- const pdfData = await fetch(
211
- new URL(url, window.location).href,
212
- );
213
- const arrayBufferPdf = await pdfData.arrayBuffer(); // 转成 ArrayBuffer 塞给 pdf.js
214
- pdfDoc_ = await PDFJS.getDocument({ data: arrayBufferPdf }).promise;
215
- } finally {
216
- this.fileLoading = false
217
- }
218
-
219
- // 初始化pdf
220
- if (this.pdfDoc) {
221
- console.log('pdfDocument is ready destroy,,')
222
- await this.pdfDoc.destroy();
223
- this.pdfDoc = null
224
- console.log('pdfDocument is destroy')
225
- }
226
- this.pdfDoc = pdfDoc_
227
- this.page_count = pdfDoc_.numPages
228
- console.log('this.page_count', this.page_count)
229
- this.$emit('numPages', pdfDoc_.numPages)
230
- this.renderPage(this.pageNum)
231
- this.emitPage(this.pageNum)
232
- },
233
- onDrop(event) {
234
- this.$emit('drop', event)
235
- },
236
- onDragOver(event) {
237
- // 默认地,无法将数据/元素放置到其他元素中。如果需要设置允许放置,我们必须阻止对元素的默认处理方式。
238
- // 这要通过调用 ondragover 事件的 event.preventDefault() 方法:
239
- event.preventDefault()
240
- },
241
- },
242
- mounted() {
243
- this.compuscale = this.scale
244
- // this.initPage = true
245
- // if (this.pdfurl) {
246
- // this.loadUrl(this.pdfurl)
247
- // }
248
- },
249
- beforeDestroy() {
250
- if (this.pdfDoc) {
251
- this.pdfDoc.destroy();
252
- }
253
- },
254
- watch: {
255
- scale(val) {
256
- if (val) {
257
- this.compuscale = val
258
- }
259
- },
260
- pdfurl: {
261
- handler(val) {
262
- this.$nextTick(() => {
263
- if (val) {
264
- this.pageNum = 1
265
- this.initPage = true
266
- this.loadUrl(val)
267
- if (this.pdfDoc) {
268
- this.pdfDoc.destroy();
269
- }
270
- }
271
- if (this.showPages) {
272
- this.$refs.switchPage.setPage(1)
273
- }
274
- })
275
- },
276
- immediate: true,
277
- },
278
- // 监听页码变化,渲染对应合同页
279
- page(newPage, oldPage) {
280
- this.queueRenderPage(newPage)
281
- },
282
- },
283
- }
284
- </script>
285
-
286
- <style lang="less" scoped>
287
- .pdf-view {
288
- height: 100%;
289
- width: 100%;
290
- display: flex;
291
- flex-direction: column;
292
- }
293
- .pdf-view-control {
294
- text-align: center;
295
- margin: 10px 0;
296
- }
297
- .pdf-view-area-wapper {
298
- flex: 1 1 0%;
299
- overflow: auto;
300
- width: 100%;
301
- flex-shrink: 0%;
302
- }
303
- .pdf-view-area {
304
- position: relative;
305
- min-height: 700px;
306
- .canvasstyle {
307
- display: block;
308
- margin: 0 auto;
309
- }
310
- .label-area {
311
- position: absolute;
312
- right: 0;
313
- bottom: 0;
314
- top: 0;
315
- left: 0;
316
- }
317
- }
318
- .pdf-view-empty {
319
- text-align: center;
320
- line-height: 150px;
321
- font-size: 14px;
322
- color: #999;
323
- }
324
-
325
- .pdf-view-loading, .pdf-view-rendering {
326
- margin-top: 40px;
327
- text-align: center;
328
- font-size: 14px;
329
- color: #999;
330
- }
331
- </style>