@toolspack/ttd-common 0.5.5 → 1.0.0

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": "0.5.5",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "main": "lib/ttd-common.umd.min.js",
6
6
  "scripts": {
@@ -16,6 +16,7 @@
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",
19
20
  "vue": "^2.6.12"
20
21
  },
21
22
  "devDependencies": {
@@ -30,6 +31,7 @@
30
31
  "eslint-plugin-node": "^11.1.0",
31
32
  "eslint-plugin-promise": "^4.2.1",
32
33
  "eslint-plugin-vue": "^6.2.2",
34
+ "sockjs-client": "^1.5.1",
33
35
  "vue-template-compiler": "^2.6.12"
34
36
  }
35
37
  }
package/src/App.vue CHANGED
@@ -1,22 +1,44 @@
1
1
  <template>
2
2
  <div id="app">
3
- <el-button @click="viewImg">预览</el-button>
4
- <img :src="pdfurl+'&w=120'" />
3
+ <form id="myForm" @submit.prevent="uploadFile">
4
+ <label for="">请上传:</label>
5
+ <input type="file" ref="fileInput" multiple name="files"><br>
6
+ <input type="hidden" name="bucketName" :value="uName">
7
+ <input type="submit" value="提交">
8
+ </form>
9
+ <PdfView :pdfurl="url" />
5
10
  </div>
6
11
  </template>
7
12
 
8
13
  <script>
14
+ import PdfView from './packages/pdfjs/PdfView216.vue'
15
+
16
+ const _baseUrl = 'http://peys.totodi.com:37811/'
9
17
 
10
18
  export default {
19
+ components: { PdfView },
11
20
  name: 'App',
12
21
  data() {
13
22
  return {
23
+ url: 'https://petx.totodi.com/visit/totodi-contract/20230905-e777d0d33a6f440db4b5276b397121fd-无法翻页-40.pdf?expireDataTime=1693900521328',
24
+ uName: 'totodi-contract',
25
+ action: `${_baseUrl}zuul/file-service/oos/uploadFile`,
14
26
  }
15
27
  },
28
+ mounted() {
29
+ },
16
30
  methods: {
17
- showImg(url) {
18
- },
19
- viewImg(url) {
31
+ uploadFile() {
32
+ const formData = new FormData();
33
+ const files = this.$refs.fileInput.files;
34
+
35
+ // 添加文件数据到表单中
36
+ for (let i = 0; i < files.length; i++) {
37
+ formData.append('files', files[i]);
38
+ }
39
+
40
+ // 添加其他字段数据到表单中
41
+ formData.append('u_name', this.uName);
20
42
  },
21
43
  },
22
44
  }
@@ -4,10 +4,13 @@ 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
+
7
9
  export default {
8
10
  CfcaPdf,
9
11
  Ukey,
10
12
  WzhSign,
11
13
  WzhSignChrome,
12
14
  SignNew,
15
+ PdfView216,
13
16
  }
@@ -0,0 +1,331 @@
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>
@@ -13,7 +13,7 @@ export default {
13
13
  data() {
14
14
  return {
15
15
  child: null,
16
- isIE: false,
16
+ isIE: true,
17
17
  }
18
18
  },
19
19
  props: {
@@ -27,27 +27,34 @@ export default {
27
27
  },
28
28
  mounted() {
29
29
  if (this.isIE) {
30
+ console.log('--- ie sign')
30
31
  this.child = this.$refs.signIe
31
32
  } else {
33
+ console.log('--- chrome sign')
32
34
  this.child = this.$refs.signChrome
33
35
  }
34
36
  },
35
37
  methods: {
36
38
  getBrowserInfo() {
37
- const { appVersion, appName } = navigator
38
- if (appName.indexOf('Internet') >= 0) {
39
+ const { userAgent, plugins, mimeTypes } = navigator
40
+
41
+ if (userAgent.indexOf('Trident') >= 0) {
39
42
  this.isIE = true
40
- return false
43
+ return true
41
44
  }
42
- if (appVersion.indexOf('Trident') >= 0) {
45
+ // 360的急速模式,需要使用ie签署控件(無法實現,或不稳定,360会快速修复让用户无法检测)
46
+ // const plugin360 = [
47
+ // '360', '360SoftMgrPlugin', 'ActiveX hosting plugin for Firefox/Chrome',
48
+ // 'GamePlugin', 'QQMail Plugin', 'Tencent QQ', 'npQQPhotoDrawEx']
49
+ if (plugins['360SoftMgrPlugin']) {
43
50
  this.isIE = true
44
- return false
51
+ return true
45
52
  }
46
-
47
- // 360的急速模式,需要使用id签署控件
48
- if (appVersion.indexOf(' WOW64') >= 0) {
53
+ if (mimeTypes['application/360softmgrplugin']) {
49
54
  this.isIE = true
55
+ return true
50
56
  }
57
+ this.isIE = false
51
58
  },
52
59
  },
53
60
  }
@@ -167,4 +167,4 @@ export default {
167
167
  position: absoute;
168
168
  left: -5000px;
169
169
  }
170
- </style>>
170
+ </style>
@@ -6,8 +6,6 @@
6
6
  </div>
7
7
  </template>
8
8
  <script>
9
- // import { getSignHash, mergeHash } from '@/api/ess'
10
-
11
9
  import { getUrl } from '../utils'
12
10
 
13
11
  export default {
@@ -24,8 +22,11 @@ export default {
24
22
  classid = 'clsid:8BF7E683-630E-4B59-9E61-C996B671EBDF'
25
23
  // classid = 'clsid:63F9892E-D854-476E-A839-C8BA79254EC1'
26
24
  }
25
+
26
+ const { userAgent } = navigator
27
+ const isIE = userAgent.indexOf('Trident') >= 0
27
28
  return {
28
- isIE: navigator.appName.indexOf('Internet') >= 0 || navigator.appVersion.indexOf('Trident') >= 0,
29
+ isIE,
29
30
  publicPath: 'https://wsp.totodi.com/jz/', // 为了获取public下的静态文件
30
31
  codebase,
31
32
  classid,
@@ -51,8 +52,6 @@ export default {
51
52
  if (this.CryptoAgent) {
52
53
  return false
53
54
  }
54
- // 使用refs 拿到的元素 不能ukey签章
55
- // this.CryptoAgent = document.getElementById('CryptoAgent')
56
55
  this.CryptoAgent = this.$refs.CryptoAgent
57
56
  if (!this.CryptoAgent) {
58
57
  alert('验签插件加载失败!')
@@ -315,4 +314,4 @@ export default {
315
314
  position: absolute;
316
315
  left: -5000px;
317
316
  }
318
- </style>>
317
+ </style>
@@ -1,11 +1,8 @@
1
1
  <!--无纸化 签署-->
2
2
  <template>
3
- <div class="CryptoAgent-wrapper">
4
- </div>
3
+ <div class="CryptoAgent-wrapper"></div>
5
4
  </template>
6
5
  <script>
7
- // import { getSignHash, mergeHash } from '@/api/ess'
8
-
9
6
  import { getUrl } from '../utils'
10
7
 
11
8
  import WZHforChrome from './WZHforChrome'
@@ -14,7 +11,6 @@ export default {
14
11
  mixins: [WZHforChrome],
15
12
  data() {
16
13
  return {
17
- isIE: navigator.appName.indexOf('Internet') >= 0 || navigator.appVersion.indexOf('Trident') >= 0,
18
14
  sourceData: '', // 签名原文, 动态随机字符串
19
15
  certType: 'RSA', // 签名算法
20
16
  CryptoAgent: null,
@@ -244,4 +240,4 @@ export default {
244
240
  position: absolute;
245
241
  left: -5000px;
246
242
  }
247
- </style>>
243
+ </style>