askbot-dragon 1.5.66-beta → 1.5.67-beta

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.
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="pdf_view" ref="pdfView" @scroll="pdfScroll" :style="{
2
+ <div id="pdf_view" class="pdf_view" :style="{
3
3
  marginTop: isPC ? '50px' : '',
4
4
  marginBottom: tagIds.length > 1 ? '60px' : '0px',
5
5
  height: setHeight
@@ -17,6 +17,7 @@
17
17
  </el-option>
18
18
  </el-select>
19
19
  </div>
20
+ <div class="pdf_container_view" id="pdf_container_view" @scroll="pdfScroll" ref="pdfView"></div>
20
21
  <div class="btn_footer" v-if="tagIds.length > 1 && !isPC">
21
22
  <div class="prev" @click="prev">上一段</div>
22
23
  <div class="next" @click="next">下一段</div>
@@ -44,10 +45,11 @@ if (pdfjsLib) {
44
45
  // 'pdfjs-dist/build/pdf.worker';
45
46
  }
46
47
  const { TextLayerBuilder } = window['pdfjs-dist/web/pdf_viewer']
48
+ const CSS_UNITS = 96.0 / 72.0
47
49
  // import { zoomElement } from '../assets/js/hammer'
48
50
  export default {
49
51
  name: 'pdfView',
50
- props: ['tagIds', 'isMessageRecord'],
52
+ props: ['tagIds', 'isMessageRecord','fileName'],
51
53
  data () {
52
54
  return {
53
55
  url: '',
@@ -94,6 +96,7 @@ export default {
94
96
  },
95
97
  isTouchMoved: false,
96
98
  transformSalce: null,
99
+ defaultTransform:0.8,
97
100
  isPC: false,
98
101
  handScale: 'auto',
99
102
  scaleList: [
@@ -248,12 +251,13 @@ export default {
248
251
  if (this.$refs.pdfView.clientWidth / this.pageSize.width >= 1 || this.isMessageRecord) {
249
252
  this.contentView.style.width = `${pageSize.width - 10}px`;
250
253
  this.contentView.style.height = `${(this.totalPageCount * (pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
254
+ this.contentView.style.margin = '0 auto 0'
251
255
  } else {
252
- this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
256
+ this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width / CSS_UNITS
253
257
  this.contentView.style.width = `${pageSize.width * this.transformSalce - 10}px`;
254
258
  this.contentView.style.height = `${(this.totalPageCount * (pageSize.height * (this.transformSalce) + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
255
259
  }
256
- this.contentView.style.margin = '0 auto 0'
260
+ // this.contentView.style.margin = '0 auto 0'
257
261
  this.contentView.style.position = 'relative'
258
262
  this.contentView.style.paddingBottom = '60px'
259
263
  // contentView.style.overflowY = 'auto'
@@ -281,36 +285,41 @@ export default {
281
285
  const { pdfPage, pageNo, dom } = page;
282
286
  // dom 元素已存在,无须重新渲染,直接返回
283
287
  if ((dom && dom.children.length != 0) || page.loading) {
284
- return;
288
+ return;
285
289
  }
286
290
  page.loading = true
287
291
  const viewport = pdfPage.getViewport({
288
- scale: this.scale,
289
- rotation: this.rotation,
292
+ scale: this.scale,
293
+ rotation: this.rotation,
290
294
  });
291
295
  // 创建新的canvas
292
296
  const canvas = document.createElement('canvas');
293
297
  const context = canvas.getContext('2d');
294
298
  // canvas.getContext('2d');
295
- canvas.height = this.pageSize.height;
296
- canvas.width = this.pageSize.width;
299
+ canvas.height = this.pageSize.height * (this.fileName ? CSS_UNITS : 1);
300
+ canvas.width = this.pageSize.width * (this.fileName ? CSS_UNITS : 1);
297
301
  canvas.style.position = 'relative'
298
302
  canvas.style.top = -3 + 'px'
299
303
  // 创建渲染的dom
300
304
  const pageDom = document.createElement('div');
301
305
  pageDom.style.position = 'absolute';
302
- pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
303
- pageDom.style.width = `${this.pageSize.width}px`;
304
- pageDom.style.height = `${this.pageSize.height}px`;
306
+ pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL) * (this.fileName ? CSS_UNITS : 1)) + this.PAGE_INTVERVAL}px`;
307
+ pageDom.style.width = `${this.pageSize.width * (this.fileName ? CSS_UNITS : 1)}px`;
308
+ pageDom.style.height = `${this.pageSize.height * (this.fileName ? CSS_UNITS : 1)}px`;
305
309
  pageDom.setAttribute('data-id', 'page' + pageNo)
306
- pageDom.appendChild(canvas);
310
+ // pageDom.appendChild(canvas);
307
311
  // 渲染内容
308
312
  let renderContext = {
309
313
  canvasContext: context,
310
314
  viewport: viewport,
315
+ transform: this.fileName ? [CSS_UNITS, 0, 0, CSS_UNITS, 0, 0] : '',
311
316
  }
312
317
  await pdfPage.render(renderContext).promise.then(() => {
313
- return pdfPage.getTextContent()
318
+ const html = canvas.toDataURL();
319
+ let image = document.createElement('img');
320
+ image.setAttribute('src',html)
321
+ pageDom.appendChild(image);
322
+ return pdfPage.getTextContent()
314
323
  }).then(async (textContent) => {
315
324
  const textLayerDiv = document.createElement('div');
316
325
  textLayerDiv.setAttribute('class', 'textLayer');
@@ -340,36 +349,35 @@ export default {
340
349
  let postionArr = lines[index].location
341
350
  let div = document.createElement('div')
342
351
  div.style.position = 'absolute';
343
- div.style.left = postionArr[0] * this.scale + 'px',
352
+ div.style.left = postionArr[0] * this.scale * (this.fileName ? CSS_UNITS : 1) + 'px',
344
353
  // 后端返回的坐标有基线对齐的问题,top 值是后端算好(基线top - 文字高度),在此加上文字高度的 1/9 (大致比例)为实际展示出文字的top值
345
- div.style.top = postionArr[1] * this.scale + 'px'
346
- div.style.height = postionArr[3] * this.scale + 'px';
347
- div.style.width = postionArr[2] * this.scale + 'px'
354
+ div.style.top = postionArr[1] * this.scale * (this.fileName ? CSS_UNITS : 1) + 'px'
355
+ div.style.height = postionArr[3] * this.scale * (this.fileName ? CSS_UNITS : 1) + 'px';
356
+ div.style.width = postionArr[2] * this.scale * (this.fileName ? CSS_UNITS : 1) + 'px'
348
357
  div.style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
349
358
  div.classList.add('lineHeight')
350
359
  rectdom.appendChild(div)
351
360
  if (index == 0 && j == 0) {
352
361
  if (this.transformSalce !== null) {
353
- rectdomTop = postionArr[1] * this.scale * this.transformSalce
354
- } else {
355
- rectdomTop = postionArr[1] * this.scale
356
- }
357
- // if(this.isPC) {
358
- // rectdomTop = rectdomTop - 50 < 0 ? 0 : rectdomTop - 50
359
- // }
360
- }
361
- }
362
- }
363
- if (rectdom.children.length > 0) {
364
- pageDom.appendChild(rectdom)
365
- }
362
+ rectdomTop = postionArr[1]* this.scale * (this.fileName ? CSS_UNITS : 1) * this.transformSalce
363
+ } else {
364
+ rectdomTop = postionArr[1] * this.scale * (this.fileName ? CSS_UNITS : 1) * this.defaultTransform
365
+ }
366
+ // if(this.isPC) {
367
+ // rectdomTop = rectdomTop - 50 < 0 ? 0 : rectdomTop - 50
368
+ // }
366
369
  }
370
+ }
367
371
  }
372
+ if (rectdom.children.length > 0) {
373
+ pageDom.appendChild(rectdom)
374
+ }
375
+ }
368
376
  }
369
- textLayer.setTextContent(textContent);
370
- textLayer.render()
371
- pageDom.appendChild(textLayerDiv);
372
-
377
+ }
378
+ textLayer.setTextContent(textContent);
379
+ textLayer.render()
380
+ pageDom.appendChild(textLayerDiv);
373
381
  let backgroundDom = document.getElementById('backgroundLoad' + pageNo)
374
382
  if (backgroundDom) {
375
383
  this.contentView.removeChild(backgroundDom);
@@ -377,8 +385,22 @@ export default {
377
385
  page.dom = await pageDom;
378
386
  page.loading = false
379
387
  this.contentView.appendChild(pageDom);
380
- if (this.transformSalce !== null) {
381
- this.contentView.style.transform = `scale(${this.transformSalce}, ${this.transformSalce})`
388
+ let pdf_view = document.getElementsByClassName('pdf_view');
389
+ if (pdf_view && pdf_view[0]){
390
+ pdf_view[0].style.backgroundImage = 'none'
391
+ }
392
+ let postionArr = []
393
+ if (findPage){
394
+ let AllLines = findPage.allLines
395
+ if (AllLines.length){
396
+ postionArr = AllLines[0].lines[0].location
397
+ }
398
+ }
399
+ if(this.transformSalce !== null && this.fileName) {
400
+ this.contentView.style.transform = `scale(${this.transformSalce}, ${this.transformSalce})`
401
+ } else {
402
+ this.contentView.style.transform = `scale(${this.defaultTransform})`;
403
+
382
404
  }
383
405
  if (this.changetoolbar) {
384
406
  setTimeout(() => {
@@ -390,22 +412,21 @@ export default {
390
412
  setTimeout(() => {
391
413
  let pageoffsetHeight = 0
392
414
  if (this.transformSalce !== null) {
393
- pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce
415
+ pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce * (this.fileName ? CSS_UNITS : 1)
394
416
  } else {
395
- pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL)
417
+ pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL) * this.defaultTransform *(this.fileName ? CSS_UNITS : 1)
396
418
  }
397
419
  if (this.$refs.pdfView.clientHeight - pageoffsetHeight > 0 && pageIndex == 1) {
398
420
  const height = this.$refs.pdfView.clientHeight;
399
421
  let startNum = 0
400
422
  let endNum = 0
401
423
  if (this.transformSalce !== null) {
402
- startNum = Math.ceil(this.$refs.pdfView.scrollTop / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
403
- endNum = startNum + Math.ceil(height / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
404
- } else {
405
- startNum = Math.ceil(this.$refs.pdfView.scrollTop / (this.pageSize.height + this.PAGE_INTVERVAL))
406
- endNum = startNum + Math.ceil(height / (this.pageSize.height + this.PAGE_INTVERVAL))
407
-
408
- }
424
+ startNum = Math.ceil(this.$refs.pdfView.scrollTop / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce* (this.fileName ? CSS_UNITS : 1)))
425
+ endNum = startNum + Math.ceil(height / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce* (this.fileName ? CSS_UNITS : 1)))
426
+ } else {
427
+ startNum = Math.ceil(this.$refs.pdfView.scrollTop / ((this.pageSize.height + this.PAGE_INTVERVAL) * (this.fileName ? CSS_UNITS : 1) * this.defaultTransform))
428
+ endNum = startNum + Math.ceil(height / ((this.pageSize.height + this.PAGE_INTVERVAL) * (this.fileName ? CSS_UNITS : 1) * this.defaultTransform))}
429
+ console.log(this.$refs.pdfView.scrollTop, startNum, endNum, 'endNumendNum');
409
430
  for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
410
431
  if (pageIndex > 0 && pageIndex <= this.pages.length) {
411
432
  this.loadPdfData(pageIndex)
@@ -437,14 +458,14 @@ export default {
437
458
  let startNum = 0
438
459
  let endNum = 0
439
460
  if (this.transformSalce !== null) {
440
- startNum = Math.ceil(scrollTop / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
441
- endNum = startNum + Math.ceil(height / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
461
+ startNum = Math.ceil(scrollTop / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce * (this.fileName ? CSS_UNITS : 1)))
462
+ endNum = startNum + Math.ceil(height / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce * (this.fileName ? CSS_UNITS : 1)))
442
463
  } else {
443
- startNum = Math.ceil(scrollTop / (that.pageSize.height + that.PAGE_INTVERVAL))
444
- endNum = startNum + Math.ceil(height / (that.pageSize.height + that.PAGE_INTVERVAL))
464
+ startNum = Math.ceil(scrollTop / ((that.pageSize.height + that.PAGE_INTVERVAL) * (this.fileName ? CSS_UNITS : 1) * this.defaultTransform))
465
+ endNum = startNum + Math.ceil(height / ((that.pageSize.height + that.PAGE_INTVERVAL) * (this.fileName ? CSS_UNITS : 1) * this.defaultTransform))
445
466
  }
446
- for (let pageIndex = startNum; pageIndex < endNum; pageIndex++) {
447
- if (pageIndex > 0 && pageIndex < that.pages.length) {
467
+ for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
468
+ if (pageIndex > 0 && pageIndex <= that.pages.length) {
448
469
  that.loadPdfData(pageIndex)
449
470
  }
450
471
  }
@@ -529,10 +550,10 @@ export default {
529
550
  return
530
551
  }
531
552
  const pageDom = document.createElement('div');
532
- pageDom.style.width = `${this.pageSize.width}px`;
533
- pageDom.style.height = `${this.pageSize.height}px`;
553
+ pageDom.style.width = `${this.pageSize.width * (this.fileName ? CSS_UNITS : 1)}px`;
554
+ pageDom.style.height = `${this.pageSize.height * (this.fileName ? CSS_UNITS : 1)}px`;
534
555
  pageDom.style.position = 'absolute';
535
- pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL
556
+ pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL) * (this.fileName ? CSS_UNITS : 1)) + this.PAGE_INTVERVAL
536
557
  }px`;
537
558
  pageDom.style.backgroundImage = `url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif')`
538
559
  pageDom.style.backgroundPosition = 'center'
@@ -607,9 +628,9 @@ export default {
607
628
  this.renderHighlights()
608
629
  })
609
630
  if (this.transformSalce !== null) {
610
- this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce) + (this.identifyTextPostion.top * this.scale * this.transformSalce)}`
631
+ this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce * (this.fileName ? CSS_UNITS : 1)) + (this.identifyTextPostion.top * this.scale * this.transformSalce * (this.fileName ? CSS_UNITS : 1))}`
611
632
  } else {
612
- this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + (this.identifyTextPostion.top * this.scale * this.transformSalce)}`
633
+ this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL) * this.defaultTransform * (this.fileName ? CSS_UNITS : 1)) + (this.identifyTextPostion.top * this.scale * this.defaultTransform * (this.fileName ? CSS_UNITS : 1))}`
613
634
  }
614
635
  },
615
636
  scrollToExcalTop (currentPage) {
@@ -863,6 +884,7 @@ export default {
863
884
  if (value && value.length) {
864
885
  // 在 pdf_view 下创建 所有canvs的容器
865
886
  this.contentView = document.createElement('div')
887
+ this.contentView.setAttribute('id','contentView')
866
888
  this.contentView.style.transformOrigin = '0px 0px 0px'
867
889
  this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res => {
868
890
  // res.data = {"data":[{"id":"64591b7d8bb8ab1b91c65f24","knowledgeId":"64591a9c8da27649473f3b4b","mainId":"fb348d095c0b4fd7bbd37826563dac7d","page":3,"total":18,"pageHeight":540.0,"pageWidth":960.00946,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/fb348d095c0b4fd7bbd37826563dac7d/2023/05/08/11/55/18/64591b638bb8ab1b91c65eed/3.pdf","extractInfo":{"location":[280.488,161.32,398.71573,61.99298],"content":"黄花城水长城旅游区位于北京市怀柔区九渡河镇境内,距北京市区65公里,是以奇而著称,融山川、碧水、古长城为一体的旅游休闲胜地。而这里的“三绝景”更是引人入","lines":[{"content":"黄花城水长城旅游区位于北京市怀柔区九渡河镇境内,距","location":[280.488,161.32,398.71573,15.9869995]},{"content":"北京市区65公里,是以奇而著称,融山川、碧水、古长","location":[283.691,184.30899,392.3055,15.9869995]},{"content":"城为一体的旅游休闲胜地。而这里的“三绝景”更是引人入","location":[282.699,207.32599,394.3033,15.9869995]}],"tagId":null}}],"code":"0","msg":null,"traceId":null}
@@ -1053,11 +1075,16 @@ export default {
1053
1075
  xhr.onload = ({ currentTarget }) => {
1054
1076
  // 请求完成
1055
1077
  if (currentTarget.status === 200) { // 返回200
1078
+ let pdf_view = document.getElementsByClassName('pdf_view');
1079
+ if (pdf_view && pdf_view[0]){
1080
+ pdf_view[0].style.backgroundImage = 'none'
1081
+ }
1056
1082
  this.contentView.innerHTML = currentTarget.response
1057
1083
  this.contentView.style.padding = '10px'
1058
1084
  // this.contentView.style.position = 'relative'
1059
1085
  this.$refs.pdfView.style.backgroundColor = '#FFFFFF'
1060
1086
  this.$refs.pdfView.appendChild(this.contentView)
1087
+
1061
1088
  let allTr = Array.from(this.$refs.pdfView.getElementsByTagName('tr'))
1062
1089
  this.allTr = []
1063
1090
  for (let index = 0; index < allTr.length; index++) {
@@ -1100,10 +1127,14 @@ export default {
1100
1127
  width: 100%;
1101
1128
  height: calc(100% - 110px);
1102
1129
  overflow: auto;
1130
+ //overflow-y: scroll;
1103
1131
  background-color: #f5f7fb;
1104
1132
  // margin-bottom: 60px;
1105
1133
  box-sizing: border-box;
1106
-
1134
+ background-image: url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif');
1135
+ background-position: center;
1136
+ background-size: 50px;
1137
+ background-repeat: no-repeat;
1107
1138
  // position: relative;
1108
1139
  // > div {
1109
1140
  // width: 100%;
@@ -1292,6 +1323,12 @@ export default {
1292
1323
  background: rgba(221, 222, 223, 1);
1293
1324
  }
1294
1325
  }
1326
+ .pdf_container_view{
1327
+ height: 100%;
1328
+ width: 100%;
1329
+ position: relative;
1330
+ overflow: auto;
1331
+ }
1295
1332
  }
1296
1333
  </style>
1297
1334
  <style lang="less">
@@ -1304,7 +1341,6 @@ export default {
1304
1341
  0% {
1305
1342
  background: rgba(255, 136, 0, 0.3);
1306
1343
  }
1307
-
1308
1344
  25% {
1309
1345
  background: rgba(255, 136, 0, 0.6);
1310
1346
  }
@@ -54,7 +54,7 @@
54
54
  </div>
55
55
  <div id="drawer_content_pre">
56
56
  <template v-if="tagIds && tagIds.length != 0 && drawer">
57
- <pdfPosition :tagIds="tagIds" :isMessageRecord="isMessageRecord"></pdfPosition>
57
+ <pdfPosition :tagIds="tagIds" :isMessageRecord="isMessageRecord" :fileName="fileName" ref="pdfPosition"></pdfPosition>
58
58
  </template>
59
59
  <template v-else>
60
60
  <div v-if="fileType == 'VIDEO'" style="width: 100%;">
@@ -97,6 +97,7 @@ export default {
97
97
  tagIds: [],
98
98
  // '6454aa1a70573a6ead6f0f7d', '6454aa1a70573a6ead6f0f81',
99
99
  loading:true,
100
+ fileName:''
100
101
  }
101
102
  },
102
103
  mounted() {
@@ -117,6 +118,9 @@ export default {
117
118
  sourceFileType:{
118
119
  type: String,
119
120
  default: '',
121
+ },
122
+ watermark:{
123
+ type: Object
120
124
  }
121
125
  },
122
126
  components:{
@@ -126,9 +130,20 @@ export default {
126
130
  drawer(value) {
127
131
  if(value) {
128
132
  this.$nextTick(() =>{
129
- zoomElement(document.getElementById('drawer_content_pre'))
133
+ if (this.tagIds && this.tagIds.length != 0){
134
+ zoomElement(document.getElementById('pdf_container_view'))
135
+ }
130
136
  })
131
137
  }
138
+ setTimeout(() => {
139
+ let previewIframe = document.getElementsByClassName('preview_iframe')
140
+ Array.from(previewIframe).forEach(item =>{
141
+ item.onload = () =>{
142
+ console.debug('previewIframe 106',previewIframe,this.drawer)
143
+ item.style.backgroundImage = 'none'
144
+ }
145
+ })
146
+ })
132
147
  }
133
148
  },
134
149
  computed:{
@@ -143,8 +158,10 @@ export default {
143
158
  // }
144
159
  // }
145
160
  url = url + this.url
146
- if(this.sourceFileType == '.ppt' || this.sourceFileType == '.pptx') {
147
- url += '&officePreviewType=pdf'
161
+ url += '&officePreviewType=pdf'
162
+ if(this.watermark) {
163
+ url = this.watermark.textWatermarkValue ? (url += this.watermark.textWatermarkValue) : url
164
+ url = this.watermark.visitorWatermarkValue ? (url += this.watermark.visitorWatermarkValue) : url
148
165
  }
149
166
  return url
150
167
  },
@@ -282,10 +299,6 @@ export default {
282
299
  overflow: auto;
283
300
  height: calc(100% - 50px);
284
301
  background: #FFF;
285
- background-image: url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif');
286
- background-position: center;
287
- background-size: 50px;
288
- background-repeat: no-repeat;
289
302
  }
290
303
  }
291
304
  @media screen and (min-width: 768px) {