askbot-dragon 1.6.57-beta → 1.6.59-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.
Files changed (84) hide show
  1. package/README.md +27 -27
  2. package/babel.config.js +6 -6
  3. package/dragon.iml +7 -7
  4. package/package.json +54 -54
  5. package/public/index.html +72 -72
  6. package/src/App.vue +31 -31
  7. package/src/api/index.js +1 -1
  8. package/src/api/mock.http +2 -2
  9. package/src/api/requestUrl.js +185 -185
  10. package/src/assets/js/AliyunlssUtil.js +92 -92
  11. package/src/assets/js/Base64Util.js +22 -22
  12. package/src/assets/js/common.js +252 -250
  13. package/src/assets/js/hammer.js +100 -100
  14. package/src/assets/js/script.js +36 -36
  15. package/src/assets/less/common.css +6773 -6773
  16. package/src/assets/less/converSationContainer/common.less +199 -199
  17. package/src/assets/less/converSationContainer/converSatonContainer.less +493 -493
  18. package/src/assets/less/iconfont.css +37 -37
  19. package/src/assets/less/ticketMessage.less +294 -294
  20. package/src/components/ActionAlertIframe.vue +177 -177
  21. package/src/components/AiGuide.vue +466 -466
  22. package/src/components/AnswerDocknowledge.vue +701 -693
  23. package/src/components/AnswerVoice.vue +285 -285
  24. package/src/components/AskIFrame.vue +15 -15
  25. package/src/components/ConversationContainer.vue +5130 -5317
  26. package/src/components/FileType.vue +86 -86
  27. package/src/components/Message.vue +27 -27
  28. package/src/components/MyEditor.vue +350 -350
  29. package/src/components/actionSatisfaction.vue +107 -107
  30. package/src/components/actionSendToBot.vue +62 -62
  31. package/src/components/answerDissatisfaction.vue +62 -62
  32. package/src/components/answerRadio.vue +186 -186
  33. package/src/components/ask-components/DissatisfactionOptions.vue +57 -57
  34. package/src/components/ask-components/Msgloading.vue +37 -37
  35. package/src/components/ask-components/SatisfactionV2.vue +15 -15
  36. package/src/components/askVideo.vue +162 -162
  37. package/src/components/assetDetails.vue +378 -378
  38. package/src/components/assetMessage.vue +228 -228
  39. package/src/components/associationIntention.vue +355 -355
  40. package/src/components/attachmentPreview.vue +90 -90
  41. package/src/components/botActionSatisfactor.vue +68 -68
  42. package/src/components/chatContent.vue +513 -513
  43. package/src/components/feedBack.vue +136 -136
  44. package/src/components/fielListView.vue +351 -351
  45. package/src/components/file/AliyunOssComponents.vue +108 -108
  46. package/src/components/formTemplate.vue +3572 -3572
  47. package/src/components/intelligentSummary.vue +209 -209
  48. package/src/components/kkview.vue +1138 -1138
  49. package/src/components/loadingProcess.vue +164 -164
  50. package/src/components/message/ActionAlertIframe.vue +112 -112
  51. package/src/components/message/ShopMessage.vue +164 -164
  52. package/src/components/message/TextMessage.vue +924 -924
  53. package/src/components/message/TicketMessage.vue +201 -201
  54. package/src/components/message/swiper/index.js +4 -4
  55. package/src/components/message/swiper/ticketSwiper.vue +503 -503
  56. package/src/components/message/swiper/ticketSwiperItem.vue +61 -61
  57. package/src/components/msgLoading.vue +231 -231
  58. package/src/components/myPopup.vue +70 -70
  59. package/src/components/newPdfPosition.vue +877 -877
  60. package/src/components/pdfPosition.vue +1509 -1509
  61. package/src/components/popup.vue +227 -227
  62. package/src/components/previewDoc.vue +247 -247
  63. package/src/components/previewPdf.vue +653 -599
  64. package/src/components/receiverMessagePlatform.vue +65 -65
  65. package/src/components/recommend.vue +80 -80
  66. package/src/components/selector/hOption.vue +20 -20
  67. package/src/components/selector/hSelector.vue +199 -199
  68. package/src/components/selector/hWrapper.vue +216 -216
  69. package/src/components/senderMessagePlatform.vue +50 -50
  70. package/src/components/source/BotMessage.vue +24 -24
  71. package/src/components/source/CustomMessage.vue +24 -24
  72. package/src/components/test.vue +260 -260
  73. package/src/components/tree.vue +294 -294
  74. package/src/components/utils/AliyunIssUtil.js +81 -81
  75. package/src/components/utils/ckeditor.js +174 -174
  76. package/src/components/utils/format_date.js +25 -25
  77. package/src/components/utils/index.js +6 -6
  78. package/src/components/utils/math_utils.js +29 -29
  79. package/src/components/voiceComponent.vue +119 -119
  80. package/src/components/welcomeKnowledgeFile.vue +332 -332
  81. package/src/components/welcomeLlmCard.vue +140 -140
  82. package/src/components/welcomeSuggest.vue +97 -97
  83. package/src/main.js +57 -57
  84. package/vue.config.js +54 -54
@@ -1,1510 +1,1510 @@
1
- <template>
2
- <div class="pdf_view" id="pdf_view" :style="{
3
- marginTop: isPC ? '50px' : '',
4
- marginBottom: tagIds.length > 1 ? '60px' : '0px',
5
- height: setHeight
6
- }">
7
- <div class="change_scale" v-if="isPC">
8
- <section @click="changeScale('reduce')">
9
- <i class="el-icon-minus"></i>
10
- </section>
11
- <el-divider direction="vertical"></el-divider>
12
- <section @click="changeScale('zoom')">
13
- <i class="el-icon-plus"></i>
14
- </section>
15
- <el-select size="small" v-model="handScale" @change="changeScale" placeholder="请选择">
16
- <el-option v-for="item in scaleList" :key="item.value" :label="item.label" :value="item.value">
17
- </el-option>
18
- </el-select>
19
- </div>
20
- <div class="pdf_container_view" id="pdf_container_view" @scroll="pdfScroll" ref="pdfView"></div>
21
- <div class="btn_footer" v-if="tagIds.length > 1 && !isPC">
22
- <div class="prev" @click="prev">上一段</div>
23
- <div class="next" @click="next">下一段</div>
24
- </div>
25
- <div id="pagination" v-if="tagIds.length > 1 && isPC">
26
- <el-pagination :current-page="currentPage + 1" @current-change="currentChange" @prev-click="prev"
27
- @next-click="next" layout="slot, prev, pager, next" :page-size="1" :total="tagIds.length">
28
- <span class="total-class">答案由{{ tagIds.length }}段内容生成</span>
29
- </el-pagination>
30
- </div>
31
- </div>
32
- </template>
33
-
34
- <script>
35
- import _ from 'lodash'
36
- import { newInitWaterMark } from "../assets/js/common";
37
- // import * as pdfjsLib from 'pdfjs-dist'
38
- // pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker';
39
- // import { TextLayerBuilder } from "pdfjs-dist/web/pdf_viewer";
40
- // EventBus pdf_viewer 支持绑定自定义事件,一版不做
41
- // import 'pdfjs-dist/web/pdf_viewer.css'
42
- /* eslint-disable */
43
- const pdfjsLib = window['pdfjsLib']
44
- if (pdfjsLib) {
45
- pdfjsLib.GlobalWorkerOptions.workerSrc = window['pdfjs-dist/build/pdf.worker']
46
- // 'pdfjs-dist/build/pdf.worker';
47
- }
48
- const { TextLayerBuilder } = window['pdfjs-dist/web/pdf_viewer']
49
- const CSS_UNITS = 96.0 / 72.0
50
- // import { zoomElement } from '../assets/js/hammer'
51
- export default {
52
- name: 'pdfView',
53
- props: ['tagIds', 'isMessageRecord','fileName', "knowledgeItem",'textWatermarkStr'],
54
- data () {
55
- return {
56
- url: '',
57
- pages: [],
58
- pageLoadStatus: {
59
- WAIT: 0,
60
- LOADED: 1,
61
- },
62
- scale: 1,
63
- rotation: 0,
64
- pageSize: {},
65
- PAGE_INTVERVAL: 15,
66
- SLICE_COUNT: 5,
67
- contentView: null,
68
- fisrtLoad: true,
69
- TextLayerBuilder: null,
70
- totalPageCount: 0,
71
- identifyTextPostion: {
72
- top: 0,
73
- left: 0,
74
- width: 100,
75
- height: 0,
76
- page: 1,
77
- pageHeight: 0,
78
- pageWidth: 0,
79
- extractInfo: {},
80
- currentPageAllLine: []
81
- },
82
- currentPageAllLine: [],
83
- pdfUrl: '',
84
- cachePdf: [],
85
- newViewer: null,
86
- currentPage: 0,
87
- changetoolbar: false,
88
- allTr: [],
89
- preViewType: 'pdf',
90
- displacement: {
91
- pageX: 0,
92
- pageY: 0,
93
- moveable: false,
94
- pageX2: 0,
95
- pageY2: 0,
96
- originScale: 1,
97
- },
98
- isTouchMoved: false,
99
- transformSalce: null,
100
- defaultTransform:0.8,
101
- isPC: false,
102
- handScale: 'auto',
103
- scaleList: [
104
- {
105
- label: '自动缩放',
106
- value: 'auto'
107
- },
108
- {
109
- label: '实际比例',
110
- value: 'reality'
111
- },
112
- {
113
- label: '100%',
114
- value: 1
115
- },
116
- {
117
- label: '120%',
118
- value: 1.2
119
- },
120
- {
121
- label: '150%',
122
- value: 1.5
123
- },
124
- {
125
- label: '170%',
126
- value: 1.7
127
- }
128
- ,
129
- {
130
- label: '200%',
131
- value: 2
132
- }
133
- ],
134
- scrollTop: 0,
135
- scrollLeft: 0
136
- }
137
- },
138
- methods: {
139
- getpdfResloutePage (pdfResloute) {
140
- // 根据当前页面宽度设置缩放比例
141
- // this.scale = Math.round(this.$refs.pdfView.clientWidth / pdfResloute.pageWidth * 100) / 100
142
- if (this.isMessageRecord) {
143
- this.scale = Math.round(this.$refs.pdfView.clientWidth / pdfResloute.pageWidth * 100) / 100
144
- } else {
145
- this.scale = 2
146
- }
147
- // 从后端获取到当前分片后所有的pdf页码,初始化数组,数组下{} 对应每页pdf文件
148
- this.pdfUrl = pdfResloute.publicPageFileUrl.substring(0, pdfResloute.publicPageFileUrl.lastIndexOf('/') + 1)
149
- this.initPages(pdfResloute.total)
150
- // 定位功能,加载对应页码位置
151
- this.loadPdfData(pdfResloute.page)
152
- },
153
- async loadPdfData (loadPage) {
154
- if (this.pages[loadPage - 1] && ((this.pages[loadPage - 1].dom && this.pages[loadPage - 1].dom.children.length > 0) || this.pages[loadPage - 1].loadStatus)) {
155
- return
156
- } else {
157
- if (this.changetoolbar) {
158
- this.$nextTick(() => {
159
- this.renderHighlights()
160
- })
161
- this.changetoolbar = false
162
- }
163
- }
164
- // 记录开始缓存的状态
165
- // pdfjsLib.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/legacy/build/pdf.worker.entry.js");
166
- // 拿到第一个分片
167
- const { startPage, url } = await this.fetchPdfFragment(loadPage);
168
- let loadingTask = pdfjsLib.getDocument(url)
169
- loadingTask.promise.then(async (pdfDoc) => {
170
- // 将已经下载的分片保存到 pages 数组中
171
- // for (let i = 0; i < pdfDoc.numPages; i += 1) {
172
- // const pageIndex = startPage + i;
173
- // const page = this.pages[pageIndex - 1];
174
- // // // 不在缓存列表内,重新获取本页pdf
175
- // // if (page.loadStatus !== this.pageLoadStatus.LOADED) {
176
-
177
- // // } else {
178
- // // if (this.changetoolbar) {
179
- // // this.$nextTick(() => {
180
- // // this.renderHighlights()
181
- // // })
182
- // // this.changetoolbar = false
183
- // // }
184
- // // }
185
- // }
186
- const page = this.pages[loadPage - 1]
187
- await pdfDoc.getPage(1).then(async (pdfPage) => {
188
- this.pages[loadPage - 1].loadStatus = true
189
- this.pages[loadPage - 1].pdfPage = pdfPage;
190
- // 通知可以进行渲染了
191
- await this.startRenderPages(pdfPage, page, loadPage)
192
- });
193
- });
194
- },
195
- initPages (totalPage) {
196
- // const pages = [];
197
- this.totalPageCount = totalPage
198
- for (let i = 0; i < totalPage; i += 1) {
199
- this.pages.push({
200
- pageNo: i + 1,
201
- loadStatus: false,
202
- pdfPage: null,
203
- dom: null
204
- });
205
- }
206
- },
207
- async fetchPdfFragment (pageIndex) {
208
- // 置换加签后的文件地址。
209
- let obj = {}
210
- await this.$http.post(
211
- '/knowledge-api/temporary-certificate/or-origin?expired=30',
212
- this.pdfUrl + pageIndex + '.pdf',
213
- {
214
- headers: {
215
- "Content-Type": "application/json",
216
- },
217
- }).then(async res => {
218
- if (res.bodyText) {
219
- // 最后返回一个 包含这4个参数的对象
220
- obj = await {
221
- "startPage": pageIndex, // 分片的开始页码
222
- "endPage": pageIndex + 5, // 分片结束页码
223
- "totalPage": this.totalPageCount, // pdf 总页数
224
- "url": res.bodyText // 分片内容下载地址
225
- }
226
- }
227
- if (res.data) {
228
- // 最后返回一个 包含这4个参数的对象
229
- obj = await {
230
- "startPage": pageIndex, // 分片的开始页码
231
- "endPage": pageIndex + 5, // 分片结束页码
232
- "totalPage": this.totalPageCount, // pdf 总页数
233
- "url": res.data // 分片内容下载地址
234
- }
235
- }
236
- })
237
- return obj
238
- },
239
- startRenderPages (pdfPage, page, pageIndex) {
240
- if (Object.keys(this.pageSize).length == 0) {
241
- const viewport = pdfPage.getViewport({
242
- scale: this.scale, // 缩放的比例
243
- rotation: this.rotation, // 旋转的角度
244
- });
245
- // 记录pdf页面高度
246
- const pageSize = {
247
- width: viewport.width,
248
- height: viewport.height,
249
- }
250
- this.pageSize = pageSize
251
- // 创建内容绘制区,并设置大小
252
- if (this.$refs.pdfView.clientWidth / this.pageSize.width >= 1 || this.isMessageRecord) {
253
- this.contentView.style.width = `${pageSize.width - 10}px`;
254
- this.contentView.style.height = `${(this.totalPageCount * (pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
255
- } else {
256
- this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
257
- this.contentView.style.width = `${pageSize.width * this.transformSalce - 10}px`;
258
- this.contentView.style.height = `${(this.totalPageCount * (pageSize.height * (this.transformSalce) + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
259
- }
260
- this.contentView.style.margin = '0 auto 0'
261
- this.contentView.style.position = 'relative'
262
- this.contentView.style.paddingBottom = '60px'
263
- // contentView.style.overflowY = 'auto'
264
- this.$refs.pdfView.appendChild(this.contentView);
265
- if (this.textWatermarkStr){
266
- newInitWaterMark('pdf_container_view',this.textWatermarkStr)
267
- }
268
- }
269
- this.renderPages(pageIndex)
270
- },
271
- // 渲染需要展示的页面,不需展示的页码将其清除
272
- renderPages (pageIndex) {
273
- const pagesToRender = this.getRenderScope(pageIndex);
274
- for (const i of this.pages) {
275
- if (pagesToRender.some(p => { return p.pageNo == i.pageNo })) {
276
- if (i.loadStatus === true) {
277
- this.renderPageContent(i, i.pageNo)
278
- } else {
279
- this.renderPageLoading(i, i.pageNo)
280
- }
281
- } else {
282
- this.clearPage(i);
283
- }
284
- }
285
-
286
- },
287
- async renderPageContent (page, pageIndex) {
288
- const { pdfPage, pageNo, dom } = page;
289
- // dom 元素已存在,无须重新渲染,直接返回
290
- if ((dom && dom.children.length != 0) || page.loading) {
291
- return;
292
- }
293
- page.loading = true
294
- const viewport = pdfPage.getViewport({
295
- scale: this.scale,
296
- rotation: this.rotation,
297
- });
298
- // 创建新的canvas
299
- const canvas = document.createElement('canvas');
300
- const context = canvas.getContext('2d');
301
- // canvas.getContext('2d');
302
- canvas.height = this.pageSize.height;
303
- canvas.width = this.pageSize.width;
304
- canvas.style.position = 'relative'
305
- canvas.style.top = -3 + 'px'
306
- // 创建渲染的dom
307
- const pageDom = document.createElement('div');
308
- pageDom.style.position = 'absolute';
309
- pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
310
- pageDom.style.width = `${this.pageSize.width}px`;
311
- pageDom.style.height = `${this.pageSize.height}px`;
312
- pageDom.setAttribute('data-id', 'page' + pageNo)
313
- pageDom.appendChild(canvas);
314
- // 渲染内容
315
- let renderContext = {
316
- canvasContext: context,
317
- viewport: viewport,
318
- }
319
- await pdfPage.render(renderContext).promise.then(() => {
320
- return pdfPage.getTextContent()
321
- }).then(async (textContent) => {
322
- const textLayerDiv = document.createElement('div');
323
- textLayerDiv.setAttribute('class', 'textLayer');
324
- // 将文本图层div添加至每页pdf的div中
325
- // 创建新的TextLayerBuilder实例
326
- let textLayer = new TextLayerBuilder({
327
- textLayerDiv: textLayerDiv,
328
- pageIndex: pdfPage._pageIndex,
329
- viewport: viewport,
330
- });
331
- let findPage = this.currentPageAllLine.find(l => { return l.page == pageIndex })
332
- let rectdomTop = 0
333
- if (findPage) {
334
- let AllLines = findPage.allLines
335
- // setTimeout(() => {
336
- if (AllLines.length > 0) {
337
- for (let j = 0; j < AllLines.length; j++) {
338
- let lines = AllLines[j].lines
339
- let rectdom = document.createElement('div')
340
- rectdom.setAttribute('react-count', AllLines[j].pageCount);
341
- rectdom.style.position = 'absolute';
342
- rectdom.style.top = 0
343
- rectdom.style.left = 0
344
- rectdom.classList.add('rectdom')
345
- for (let index = 0; index < lines.length; index++) {
346
- if (!/^\s+$/g.test(lines[index].content)) {
347
- let postionArr = lines[index].location
348
- let div = document.createElement('div')
349
- div.style.position = 'absolute';
350
- div.style.left = postionArr[0] * this.scale + 'px',
351
- // 后端返回的坐标有基线对齐的问题,top 值是后端算好(基线top - 文字高度),在此加上文字高度的 1/9 (大致比例)为实际展示出文字的top值
352
- div.style.top = postionArr[1] * this.scale + 'px'
353
- div.style.height = postionArr[3] * this.scale + 'px';
354
- div.style.width = postionArr[2] * this.scale + 'px'
355
- div.style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
356
- div.classList.add('lineHeight')
357
- rectdom.appendChild(div)
358
- if (index == 0 && j == 0) {
359
- if (this.transformSalce !== null) {
360
- rectdomTop = postionArr[1] * this.scale * this.transformSalce
361
- } else {
362
- rectdomTop = postionArr[1] * this.scale
363
- }
364
- // if(this.isPC) {
365
- // rectdomTop = rectdomTop - 50 < 0 ? 0 : rectdomTop - 50
366
- // }
367
- }
368
- }
369
- }
370
- if (rectdom.children.length > 0) {
371
- pageDom.appendChild(rectdom)
372
- }
373
- }
374
- }
375
- }
376
- textLayer.setTextContent(textContent);
377
- textLayer.render()
378
- pageDom.appendChild(textLayerDiv);
379
-
380
- let backgroundDom = document.getElementById('backgroundLoad' + pageNo)
381
- if (backgroundDom) {
382
- this.contentView.removeChild(backgroundDom);
383
- }
384
- page.dom = await pageDom;
385
- page.loading = false
386
- this.contentView.appendChild(pageDom);
387
- let pdf_view = document.getElementsByClassName('pdf_view');
388
- if (pdf_view && pdf_view[0]){
389
- pdf_view[0].style.backgroundImage = 'none'
390
- }
391
- if (this.transformSalce !== null) {
392
- this.contentView.style.transform = `scale(${this.transformSalce}, ${this.transformSalce})`
393
- }
394
- if (this.changetoolbar) {
395
- setTimeout(() => {
396
- this.renderHighlights()
397
- this.changetoolbar = false
398
- }, 500)
399
- }
400
- if (this.fisrtLoad) {
401
- setTimeout(() => {
402
- let pageoffsetHeight = 0
403
- if (this.transformSalce !== null) {
404
- pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce
405
- } else {
406
- pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL)
407
- }
408
- if (this.$refs.pdfView.clientHeight - pageoffsetHeight > 0 && pageIndex == 1) {
409
- const height = this.$refs.pdfView.clientHeight;
410
- let startNum = 0
411
- let endNum = 0
412
- if (this.transformSalce !== null) {
413
- startNum = Math.ceil(this.$refs.pdfView.scrollTop / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
414
- endNum = startNum + Math.ceil(height / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
415
- } else {
416
- startNum = Math.ceil(this.$refs.pdfView.scrollTop / (this.pageSize.height + this.PAGE_INTVERVAL))
417
- endNum = startNum + Math.ceil(height / (this.pageSize.height + this.PAGE_INTVERVAL))
418
-
419
- }
420
- for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
421
- if (pageIndex > 0 && pageIndex <= this.pages.length) {
422
- this.loadPdfData(pageIndex)
423
- }
424
- }
425
- }
426
- if (this.$refs.pdfView.scrollTop == Math.floor((pageNo - 1) * pageoffsetHeight)) {
427
- this.$refs.pdfView.scrollTop = rectdomTop
428
- this.fisrtLoad = false
429
- } else {
430
- this.$refs.pdfView.scrollTop = `${((pageNo - 1) * pageoffsetHeight) + rectdomTop - this.PAGE_INTVERVAL}`
431
- this.fisrtLoad = false
432
- }
433
- this.renderHighlights()
434
- // zoomElement(this.contentView)
435
- }, 100)
436
- }
437
- })
438
- },
439
- // 监听容器的滚动事件,触发 scrollPdf 方法
440
- // 这里加了防抖保证不会一次产生过多请求
441
- debounceScrollPdf: _.debounce(function (e, that) {
442
- if (this.fisrtLoad) {
443
- this.fisrtLoad = false
444
- return
445
- }
446
- const scrollTop = e.target.scrollTop;
447
- const height = e.target.clientHeight;
448
- let startNum = 0
449
- let endNum = 0
450
- if (this.transformSalce !== null) {
451
- startNum = Math.ceil(scrollTop / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
452
- endNum = startNum + Math.ceil(height / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
453
- } else {
454
- startNum = Math.ceil(scrollTop / (that.pageSize.height + that.PAGE_INTVERVAL))
455
- endNum = startNum + Math.ceil(height / (that.pageSize.height + that.PAGE_INTVERVAL))
456
- }
457
- for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
458
- if (pageIndex > 0 && pageIndex <= that.pages.length) {
459
- that.loadPdfData(pageIndex)
460
- }
461
- }
462
- }, 200),
463
- directScrolling (e, that) {
464
- if (this.fisrtLoad) {
465
- this.fisrtLoad = false
466
- return
467
- }
468
- const scrollTop = e.target.scrollTop;
469
- const height = e.target.clientHeight;
470
- // 根据内容可视区域中心点计算页码, 没有滚动时,指向第一页
471
- const pageIndex = scrollTop > 0 ?
472
- Math.ceil((scrollTop + (height / 2)) / (that.pageSize.height + that.PAGE_INTVERVAL)) :
473
- 1;
474
- this.loadPdfData(pageIndex)
475
- },
476
- pdfScroll (e) {
477
- if (this.preViewType !== 'pdf' || this.isTouchMoved) {
478
- return
479
- }
480
- if (this.scrollLeft != e.target.scrollLeft) {
481
- this.scrollLeft = e.target.scrollLeft
482
- }
483
- if (this.scrollTop != e.target.scrollTop) {
484
- this.scrollTop = e.target.scrollTop
485
- this.debounceScrollPdf(e, this)
486
- }
487
- },
488
- // 分片每次只做一次处理,所以不考虑多片情况
489
- loadBefore (pageIndex) {
490
- this.loadPdfData(pageIndex)
491
- },
492
- loadAfter (pageIndex) {
493
- this.loadPdfData(pageIndex)
494
- },
495
- // 首先我们获取到需要渲染的范围
496
- // 根据当前的可视范围内的页码,我们前后只保留 8 页
497
- getRenderScope (pageIndex) {
498
- const pagesToRender = [];
499
- let i = pageIndex - 1;
500
- let j = pageIndex + 1;
501
- // pageIndex - 1 表示当前页码数 对应的下标位置
502
- pagesToRender.push(this.pages[pageIndex - 1]);
503
- while (pagesToRender.length < 8 && pagesToRender.length < this.pages.length) {
504
- if (i > 0) {
505
- pagesToRender.push(this.pages[i - 1]);
506
- i -= 1;
507
- }
508
- if (pagesToRender.length >= 8) {
509
- break;
510
- }
511
- if (j <= this.pages.length) {
512
- pagesToRender.push(this.pages[j - 1]);
513
- j += 1;
514
- }
515
- }
516
- // for (let index = 0; index < array.length; index++) {
517
- // const element = array[index];
518
-
519
- // }
520
- return pagesToRender;
521
- },
522
-
523
- // 清除页面 dom
524
- clearPage (page) {
525
- if (this.contentView.contains(page.dom) && page.dom) {
526
- this.contentView.removeChild(page.dom);
527
- page.loadStatus = false
528
- page.loading = false
529
- page.dom = undefined;
530
- }
531
- },
532
- // 页面正在下载时渲染loading视图
533
- renderPageLoading (page) {
534
- const { pageNo, dom } = page;
535
- if (dom && dom.children.length != 0) {
536
- return;
537
- }
538
- let backgroundDom = document.getElementById('backgroundLoad' + pageNo)
539
- if (this.contentView.contains(backgroundDom)) {
540
- return
541
- }
542
- const pageDom = document.createElement('div');
543
- pageDom.style.width = `${this.pageSize.width}px`;
544
- pageDom.style.height = `${this.pageSize.height}px`;
545
- pageDom.style.position = 'absolute';
546
- pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL
547
- }px`;
548
- pageDom.style.backgroundImage = `url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif')`
549
- pageDom.style.backgroundPosition = 'center'
550
- pageDom.style.backgroundRepeat = 'no-repeat'
551
- pageDom.style.backgroundColor = '#FFF'
552
- pageDom.setAttribute('id', 'backgroundLoad' + pageNo)
553
- page.dom = pageDom;
554
- this.contentView.appendChild(pageDom);
555
- },
556
- prev () {
557
- this.currentPage--
558
- if (this.currentPage < 0) {
559
- this.currentPage = 0
560
- if (!this.isPC) {
561
- this.$toast({
562
- message: '当前已经是第一段了',
563
- duration: 2000,
564
- })
565
- return
566
- }
567
- }
568
- if (this.preViewType == 'pdf') {
569
- this.scrollToUplaodePage(this.currentPage)
570
- } else {
571
- this.scrollToExcalTop(this.currentPage)
572
- }
573
- // this.getpdfResloutePage(this.cachePdf[this.currentPage - 1])
574
- },
575
- next () {
576
- this.currentPage++
577
- if (this.currentPage >= this.tagIds.length) {
578
- this.currentPage = this.tagIds.length - 1
579
- if (!this.isPC) {
580
- this.$toast({
581
- message: '当前已经是最后一段了',
582
- duration: 2000,
583
- })
584
- return
585
- }
586
- }
587
- if (this.preViewType == 'pdf') {
588
- this.scrollToUplaodePage(this.currentPage)
589
- } else {
590
- this.scrollToExcalTop(this.currentPage)
591
- }
592
- },
593
- currentChange (value) {
594
- this.currentPage = value - 1
595
- if (this.preViewType == 'pdf') {
596
- this.scrollToUplaodePage(this.currentPage)
597
- } else {
598
- this.scrollToExcalTop(this.currentPage)
599
- }
600
- },
601
- scrollToUplaodePage (currentPage) {
602
- this.changetoolbar = true
603
- if (this.preViewType !== 'pdf') {
604
- return
605
- }
606
-
607
- let pdfResloute = this.cachePdf[currentPage]
608
- this.identifyTextPostion.extractInfo = pdfResloute.extractInfo
609
- this.identifyTextPostion.left = pdfResloute.extractInfo.location[0]
610
- this.identifyTextPostion.top = pdfResloute.extractInfo.location[1]
611
- this.identifyTextPostion.width = pdfResloute.extractInfo.location[2]
612
- this.identifyTextPostion.height = pdfResloute.extractInfo.location[3]
613
- this.identifyTextPostion.page = pdfResloute.page
614
- this.identifyTextPostion.pageHeight = pdfResloute.pageHeight
615
- this.identifyTextPostion.pageWidth = pdfResloute.pageWidth
616
- // 在当前段落在最后一页pdf时,根据计算的高度并不能触发滚动,在此执行重新渲染方法,非次情况会执行两次,待优化
617
- this.$nextTick(() => {
618
- this.renderHighlights()
619
- })
620
- if (this.transformSalce !== null) {
621
- this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce) + (this.identifyTextPostion.top * this.scale * this.transformSalce)}`
622
- } else {
623
- this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + (this.identifyTextPostion.top * this.scale * this.transformSalce)}`
624
- }
625
- },
626
- scrollToExcalTop (currentPage) {
627
- for (let index = 0; index < this.allTr.length; index++) {
628
- if (index == currentPage) {
629
- Array.from(this.allTr[index].children).forEach(item => {
630
- item.style.background = 'rgba(255, 136, 0, 0.6)'
631
- item.classList.add('animation')
632
- setTimeout(() => {
633
- item.classList.remove('animation')
634
- }, 4000)
635
- })
636
- // getBoundingClientRect().top 当前元素距离屏幕顶部的高度 + 弹窗header 高度
637
- if (!this.isPC) {
638
- let top = this.allTr[index].getBoundingClientRect().top - this.$refs.pdfView.getBoundingClientRect().top
639
- this.$refs.pdfView.scrollTop = top
640
- } else {
641
- let top = this.allTr[index].getBoundingClientRect().top
642
- this.$refs.pdfView.scrollTop = top - 50
643
- }
644
- } else {
645
- Array.from(this.allTr[index].children).forEach(item => {
646
- item.style.background = 'rgba(54, 106, 255, 0.6)'
647
- item.classList.remove('animation')
648
- })
649
- }
650
- }
651
- },
652
- // pdf是否需要重新渲染高亮位置
653
- renderHighlights () {
654
- let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
655
- if (lineHeightDom) {
656
- lineHeightDom.forEach((d) => {
657
- for (let i = 0; i < d.children.length; i++) {
658
- if (d.getAttribute('react-count') == this.currentPage) {
659
- d.children[i].style.backgroundColor = 'rgba(255, 136, 0, 0.3)'
660
- d.children[i].classList.add('animation')
661
- setTimeout(() => {
662
- d.children[i].classList.remove('animation')
663
- }, 4000)
664
- } else {
665
- d.children[i].style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
666
- d.children[i].classList.remove('animation')
667
- }
668
- }
669
- })
670
- }
671
- },
672
- displayHiglight (pageIndex) {
673
- let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
674
- if (lineHeightDom) {
675
- lineHeightDom.forEach((d) => {
676
- if (d.getAttribute('page-index') == pageIndex) {
677
- d.style.display = 'none'
678
- }
679
- })
680
- }
681
- },
682
- // 前端暂时缓存多页
683
- autoLoadMore (pageIndex) {
684
- let pdfResloute = this.cachePdf.find(cache => {
685
- return cache.page == pageIndex
686
- })
687
- if (pdfResloute) {
688
- this.getpdfResloutePage(pdfResloute)
689
- } else {
690
- this.loadPdfData(pageIndex)
691
- }
692
- },
693
- setPageAllLine (arr) {
694
- this.currentPageAllLine = []
695
- arr.forEach((item, index) => {
696
- let i = this.currentPageAllLine.findIndex(l => { return l.page && l.page == item.page })
697
- if (i != -1) {
698
- // this.currentPageAllLine[i].allLines.lines.push(item.extractInfo.lines)
699
- this.currentPageAllLine[i].allLines.push({
700
- pageCount: index,
701
- lines: item.extractInfo.lines
702
- })
703
- } else {
704
- this.currentPageAllLine.push({
705
- page: item.page,
706
- allLines: [{
707
- pageCount: index,
708
- lines: item.extractInfo.lines
709
- }],
710
- })
711
- }
712
- })
713
- },
714
- openTouch () {
715
- // this.$nextTick()将回调延迟到下次 DOM 更新循环之后执行
716
- let that = this;
717
- this.$nextTick(() => {
718
- // setInterval(() => {
719
- // this.scale = this.scale + 0.1
720
- // that.pages.forEach((item, index) =>{
721
- // if(item.dom) {
722
- // item.dom.children.forEach( childDom =>{
723
- // if(childDom.getAttribute('react-count')) {
724
- // childDom.style.transform = "scale(" + this.scale + ")";
725
- // childDom.style.transformOrigin = "0px 0px 0px";
726
- // } else {
727
- // item.dom = null
728
- // this.startRenderPages(item.pdfPage, null, index)
729
- // }
730
- // } )
731
- // }
732
- // })
733
- // }, 100);
734
- // 获取放大或缩小的区域DOM
735
- let matrix_box = this.contentView
736
- matrix_box.addEventListener("touchstart", function (event) {
737
- this.isTouchMoved = true
738
- let touches = event.touches;
739
- let events = touches[0];
740
- let events2 = touches[1];
741
-
742
- // event.preventDefault();
743
-
744
- // 第一个触摸点的坐标
745
- that.displacement.pageX = events.pageX;
746
- that.displacement.pageY = events.pageY;
747
-
748
- that.displacement.moveable = true;
749
-
750
- if (events2) {
751
- that.displacement.pageX2 = events2.pageX;
752
- that.displacement.pageY2 = events2.pageY;
753
- }
754
-
755
- that.displacement.originScale = this.scale || 1;
756
- });
757
- document.addEventListener("touchmove", function (event) {
758
- if (!that.displacement.moveable) {
759
- return;
760
- }
761
- // event.preventDefault();
762
- let touches = event.touches;
763
- let events = touches[0];
764
- let events2 = touches[1];
765
- // 双指移动
766
- if (events2) {
767
- // 第2个指头坐标在touchmove时候获取
768
- if (!that.displacement.pageX2) {
769
- that.displacement.pageX2 = events2.pageX;
770
- }
771
- if (!that.displacement.pageY2) {
772
- that.displacement.pageY2 = events2.pageY;
773
- }
774
- // 双指缩放比例计算
775
- let zoom = that.getDistance({
776
- x: events.pageX,
777
- y: events.pageY
778
- },
779
- {
780
- x: events2.pageX,
781
- y: events2.pageY
782
- }
783
- ) / that.getDistance(
784
- {
785
- x: that.displacement.pageX,
786
- y: that.displacement.pageY
787
- },
788
- {
789
- x: that.displacement.pageX2,
790
- y: that.displacement.pageY2
791
- }
792
- );
793
- // 应用在元素上的缩放比例
794
- let newScale = that.displacement.originScale * zoom;
795
- // 最大缩放比例限制
796
- if (newScale > 2) {
797
- newScale = 2;
798
- }
799
- // 最大缩放比例限制
800
- if (newScale < 1) {
801
- newScale = 1;
802
- }
803
- // 记住使用的缩放值
804
- that.displacement.scale = newScale;
805
- // console.log(newScale);
806
- matrix_box.style.transform = "scale(" + newScale + ")";
807
- // 设置旋转元素的基点位置
808
- matrix_box.style.transformOrigin = "0px 0px 0px";
809
- }
810
- }, { passive: false });
811
- document.addEventListener('touchend', function () {
812
- that.isTouchMoved = false
813
- }, { passive: false })
814
- });
815
- },
816
- getDistance (start, stop) {
817
- // Math.hypot()计算参数的平方根
818
- return Math.hypot(stop.x - start.x, stop.y - start.y);
819
- },
820
- setupCanvas (canvas, width, height) {
821
- const dpr = 1;
822
- // const rect = canvas.getBoundingClientRect();
823
- canvas.width = width
824
- canvas.height = height
825
- const ctx = canvas.getContext('2d');
826
- ctx?.scale(dpr, dpr);
827
- return ctx;
828
- },
829
- changeScale (value) {
830
- if (value == 'zoom') {
831
- this.handScale = 'auto'
832
- this.transformSalce = (this.transformSalce + 0.2).toFixed(1)
833
- } else if (value == 'reduce') {
834
- if ((this.transformSalce - 0.2).toFixed(1) <= 0) {
835
- return
836
- }
837
- this.handScale = 'auto'
838
- this.transformSalce = (this.transformSalce - 0.2).toFixed(1)
839
- } else if (value == 'auto') {
840
- this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
841
- } else if (value == 'reality') {
842
- this.transformSalce = 0.5
843
- } else {
844
- this.transformSalce = (value / 2).toFixed(1)
845
- }
846
- this.transformSalce = Number(this.transformSalce)
847
- this.contentView.style.transform = 'scale(' + this.transformSalce + ')';
848
- // this.getpdfResloutePage(this.cachePdf[0])
849
- },
850
- //添加水印
851
- watermark() {
852
- //默认设置
853
- var defaultSettings = {
854
- watermark_txt:"",
855
- watermark_x: 0,//水印起始位置x轴坐标
856
- watermark_y: 0,//水印起始位置Y轴坐标
857
- watermark_rows: 0,//水印行数
858
- watermark_cols: 0,//水印列数
859
- watermark_x_space: 40,//水印x轴间隔
860
- watermark_y_space: 60,//水印y轴间隔
861
- watermark_color: 'black',//水印字体颜色
862
- watermark_alpha: .3,//水印透明度
863
- watermark_fontsize: 12,//水印字体大小
864
- watermark_font: '微软雅黑',//水印字体
865
- watermark_width: 100,//水印宽度
866
- watermark_height: 80,//水印长度
867
- watermark_angle: 20,//水印倾斜度数***
868
- visitorWatermark_txt:""
869
- };
870
- if(this.knowledgeItem.textWatermarkValue){
871
- defaultSettings.watermark_txt = this.knowledgeItem.textWatermarkValue;
872
- }
873
- if (this.knowledgeItem.visitorWatermarkValue){
874
- defaultSettings.visitorWatermark_txt = this.knowledgeItem.visitorWatermarkValue
875
- }
876
- //采用配置项替换默认值,作用类似jquery.extend
877
- if (arguments.length === 1 && typeof arguments[0] === "object") {
878
- console.log("arguments = " + JSON.stringify(arguments[0]));
879
- // 获取参数配置
880
- var src = arguments[0];
881
- for (let key in src) {
882
- if (src[key] && defaultSettings[key] && src[key] === defaultSettings[key])
883
- continue;
884
- else if (src[key])
885
- defaultSettings[key] = src[key];
886
- }
887
- }
888
- var oTemp = document.createDocumentFragment();
889
- //获取页面最大宽度
890
- console.debug('pdf_view',document.getElementById('pdf_view'))
891
- let scrollWidth = document.getElementById('pdf_view').scrollWidth;
892
- let clientWidth = document.getElementById('pdf_view').clientWidth;
893
- var page_width = Math.max(scrollWidth, clientWidth);
894
-
895
- var cutWidth = page_width * 0.0150;
896
-
897
- page_width = page_width - cutWidth;
898
-
899
- //获取页面最大高度
900
- let height = parseInt(this.totalPageCount * this.pageSize.height)
901
- var page_height = Math.max(document.getElementById('pdf_container_view').scrollHeight,height);
902
-
903
- console.debug('page_height',page_height,this.totalPageCount * this.pageSize.height);
904
-
905
- // var page_height = document.body.scrollHeight+document.body.scrollTop;
906
-
907
- //如果将水印列数设置为0,或水印列数设置过大,超过页面最大宽度,则重新计算水印列数和水印x轴间隔
908
-
909
- if (defaultSettings.watermark_cols == 0 || (parseInt(defaultSettings.watermark_x + defaultSettings
910
- .watermark_width * defaultSettings.watermark_cols + defaultSettings.watermark_x_space *
911
- (defaultSettings.watermark_cols - 1)) > page_width)) {
912
- defaultSettings.watermark_cols = parseInt((page_width - defaultSettings.watermark_x + defaultSettings
913
- .watermark_x_space) / (defaultSettings.watermark_width + defaultSettings
914
- .watermark_x_space));
915
- defaultSettings.watermark_x_space = parseInt((page_width - defaultSettings.watermark_x -
916
- defaultSettings
917
- .watermark_width * defaultSettings.watermark_cols) / (defaultSettings.watermark_cols - 1));
918
- }
919
-
920
- //如果将水印行数设置为0,或水印行数设置过大,超过页面最大长度,则重新计算水印行数和水印y轴间隔
921
-
922
- if (defaultSettings.watermark_rows == 0 || (parseInt(defaultSettings.watermark_y + defaultSettings
923
-
924
- .watermark_height * defaultSettings.watermark_rows + defaultSettings.watermark_y_space * (
925
-
926
- defaultSettings.watermark_rows - 1)) > page_height)) {
927
-
928
- defaultSettings.watermark_rows = parseInt((defaultSettings.watermark_y_space + page_height -
929
-
930
- defaultSettings
931
-
932
- .watermark_y) / (defaultSettings.watermark_height + defaultSettings.watermark_y_space));
933
-
934
- defaultSettings.watermark_y_space = parseInt(((page_height - defaultSettings.watermark_y) -
935
-
936
- defaultSettings
937
-
938
- .watermark_height * defaultSettings.watermark_rows) / (defaultSettings.watermark_rows - 1));
939
-
940
- }
941
-
942
- var x;
943
-
944
- var y;
945
-
946
- for (var i = 0; i < defaultSettings.watermark_rows; i++) {
947
- y = defaultSettings.watermark_y + (defaultSettings.watermark_y_space + defaultSettings.watermark_height) * i;
948
- for (var j = 0; j < defaultSettings.watermark_cols; j++) {
949
- x = defaultSettings.watermark_x + (defaultSettings.watermark_width + defaultSettings.watermark_x_space) * j;
950
-
951
- var mask_div = document.createElement('div');
952
- mask_div.id = 'mask_div' + i + j;
953
- mask_div.className = 'mask_div';
954
-
955
- //注意看这里加了图片水印
956
- mask_div.style.webkitTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
957
- mask_div.style.MozTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
958
- mask_div.style.msTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
959
- mask_div.style.OTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
960
- mask_div.style.transform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
961
- mask_div.style.visibility = "";
962
- mask_div.style.position = "absolute";
963
- //奇偶行错开,这样水印就不对齐,显的不呆板
964
- console.debug('x',x)
965
- if (i % 2 != 0) {
966
- mask_div.style.left = x + 'px';
967
- if (j % 2 != 0 && this.knowledgeItem.visitorWatermarkValue){
968
- mask_div.appendChild(document.createTextNode(defaultSettings.visitorWatermark_txt));
969
- } else {
970
- if (!this.knowledgeItem.textWatermarkValue){
971
- mask_div.appendChild(document.createTextNode(defaultSettings.visitorWatermark_txt));
972
- } else {
973
- mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
974
- }
975
- }
976
- } else {
977
- mask_div.style.left = x + 'px';
978
- if (j % 2 != 0 && this.knowledgeItem.textWatermarkValue){
979
- mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
980
- } else {
981
- if (!this.knowledgeItem.visitorWatermarkValue){
982
- mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
983
- } else {
984
- mask_div.appendChild(document.createTextNode(defaultSettings.visitorWatermark_txt));
985
- }
986
- }
987
- }
988
-
989
- mask_div.style.top = y + 'px';
990
- mask_div.style.overflow = "hidden";
991
- mask_div.style.zIndex = "9999";
992
- mask_div.style.pointerEvents = 'none'; //让水印不遮挡页面的点击事件
993
- mask_div.style.opacity = defaultSettings.watermark_alpha;
994
- mask_div.style.fontSize = defaultSettings.watermark_fontsize;
995
- mask_div.style.fontFamily = defaultSettings.watermark_font;
996
- mask_div.style.color = defaultSettings.watermark_color;
997
- mask_div.style.textAlign = "center";
998
- mask_div.style.width = defaultSettings.watermark_width + 'px';
999
- mask_div.style.height = defaultSettings.watermark_height + 'px';
1000
- mask_div.style.display = "block";
1001
- oTemp.appendChild(mask_div);
1002
- }
1003
- }
1004
- let pageDom = document.getElementById('pdf_container_view')
1005
- pageDom.appendChild(oTemp);
1006
-
1007
- },
1008
- },
1009
- computed: {
1010
- perviewUrl () {
1011
- return '/web/viewer.html?file=' + '/pdflist/pdf4split-1.pdf'
1012
- },
1013
- setHeight () {
1014
- if (this.tagIds.length > 1) {
1015
- if (this.isPC) {
1016
- return 'calc(100% - 110px)'
1017
- } else {
1018
- return 'calc(100% - 60px)'
1019
- }
1020
- } else {
1021
- if (this.isPC) {
1022
- return 'calc(100% - 50px)'
1023
- } else {
1024
- return '100%'
1025
- }
1026
- }
1027
- }
1028
- },
1029
- watch: {
1030
- tagIds: {
1031
- handler (value) {
1032
- if (value && value.length) {
1033
- // 在 pdf_view 下创建 所有canvs的容器
1034
- this.contentView = document.createElement('div')
1035
- this.contentView.setAttribute('id','contentView')
1036
- this.contentView.style.transformOrigin = '0px 0px 0px'
1037
- this.contentView.setAttribute('id','contentView');
1038
-
1039
- this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res => {
1040
- // 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}
1041
- // res.data = {"data":[{"id":"64590ce1eb1320043401cc90","knowledgeId":"64590cd5017b461d67e282e1","mainId":"fb348d095c0b4fd7bbd37826563dac7d","page":2,"total":5,"pageHeight":841.8898,"pageWidth":595.30396,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/fb348d095c0b4fd7bbd37826563dac7d/2023/05/08/10/53/20/64590ce0eb1320043401cc7b/2.pdf","extractInfo":{"location":[89.32981,638.1907,415.15512,98.63251],"content":":北京地铁 13\r号线 :藤黄\r色 :西直门站—\r东直门站 :17 :41.\r5 :6\r准\rB :2002年\r09月\r28日 ","lines":[{"content":":北京地铁 13\r号线 ","location":[89.32981,638.1907,99.44599,98.63251]},{"content":":藤黄\r色 ","location":[188.7758,638.1907,46.79959,98.63251]},{"content":":西直门站—\r东直门站 ","location":[235.5754,638.1907,86.09996,98.63251]},{"content":":17 ","location":[321.67535,638.1907,36.200012,98.63251]},{"content":":41.\r5 ","location":[357.87537,638.1907,39.400696,98.63251]},{"content":":6\r准\rB ","location":[397.27606,638.1907,41.099,98.63251]},{"content":":2002年\r09月\r28日 ","location":[438.37506,638.1907,66.10986,98.63251]}],"tagId":null}}],"code":"0","msg":null,"traceId":null}
1042
- // 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}
1043
- // res.data = {"data":[{"id":"6475eab868110215ab821a80","knowledgeId":"6475e7eac724c54c46cbfa2d","mainId":"5ecf2fcd704541149201ab9c1c31162d","page":0,"total":1,"pageHeight":0.0,"pageWidth":0.0,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/5ecf2fcd704541149201ab9c1c31162d/2023/05/30/08/23/20/6475eab63339db423f26b196/0.html","extractInfo":{"location":null,"content":"产品:系统配置,产品型号:存储,VX30:4G+16G,VX50:16G+256G","lines":null,"tagId":"6475eab868110215ab821a80"}}],"code":"0","msg":null,"traceId":null}
1044
- // res.data = {"data":[{"id":"6475e9393339db423f26af01","knowledgeId":"6475e44fc724c54c46cbfa21","mainId":"5ecf2fcd704541149201ab9c1c31162d","page":2,"total":2,"pageHeight":510.25,"pageWidth":1559.05,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/5ecf2fcd704541149201ab9c1c31162d/2023/05/30/08/00/29/6475e55d3339db423f26a9b8/2.pdf","extractInfo":{"location":[327.70532,288.0498,414.9734,12.241608],"content":"三、指示灯状态说明1.白色常亮:开机/开机中2.红色常亮:待机3.白色呼吸:息屏4.红色闪烁:升级1.LAN:通过网线连接到主机的Camera端口2.电源开关:电源切换开关","lines":[{"content":"三、指示灯状态说明","location":[634.3203,288.0498,108.3584,12.0]},{"content":"1.白色常亮:开机/开机中","location":[634.3203,320.08978,108.23407,9.0]},{"content":"2.红色常亮:待机","location":[634.3204,341.3298,78.597046,9.0]},{"content":"3.白色呼吸:息屏","location":[634.32043,362.45282,78.597046,9.0]},{"content":"4.红色闪烁:升级","location":[634.3205,383.6928,78.597046,9.0]},{"content":"1.LAN:通过网线连接到主机的","location":[327.70535,291.2914,144.35995,9.0]},{"content":"Camera端口","location":[327.70532,306.88843,55.322998,9.0]},{"content":"2.电源开关:电源切换开关","location":[482.74832,291.2914,105.36301,9.0]}],"tagId":null}}],"code":"0","msg":null,"traceId":null}
1045
- // if(value.length === 1) {
1046
- // this.$refs.pdfView.style.height = 'calc(100% - 50px)'
1047
- // }
1048
- // res.data = {
1049
- // "data": [
1050
- // {
1051
- // "id": "64e746120372d778849d2e8e",
1052
- // "knowledgeId": "64e30035edffac0ec96a2d39",
1053
- // "mainId": "e0f6898c6b0d47fa98e8f71ceab1bde8",
1054
- // "page": 14,
1055
- // "total": 60,
1056
- // "pageHeight": 728.504,
1057
- // "pageWidth": 515.906,
1058
- // "publicPageFileUrl": "https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/e0f6898c6b0d47fa98e8f71ceab1bde8/2023/08/21/02/12/07/64e300378c3dfb3bc434f51a/15.pdf",
1059
- // "extractInfo": {
1060
- // "location": [
1061
- // 52.665375,
1062
- // 312.01306,
1063
- // 404.98618,
1064
- // 142.5199
1065
- // ],
1066
- // "content": null,
1067
- // "lines": [
1068
- // {
1069
- // "content": null,
1070
- // "location": [
1071
- // 52.665375,
1072
- // 312.01306,
1073
- // 404.98618,
1074
- // 142.5199
1075
- // ]
1076
- // }
1077
- // ],
1078
- // "tagId": null
1079
- // },
1080
- // "block": {
1081
- // "type": "TEXT",
1082
- // "location": [
1083
- // 52.665375,
1084
- // 312.01306,
1085
- // 404.98618,
1086
- // 142.5199
1087
- // ],
1088
- // "color": "#366AFF",
1089
- // "flowChart": {
1090
- // "content": ""
1091
- // },
1092
- // "image": {
1093
- // "url": null,
1094
- // "desc": ""
1095
- // },
1096
- // "table": {
1097
- // "title": null,
1098
- // "table": null
1099
- // },
1100
- // "text": {
1101
- // "originText": "① 头部防护:安全帽\n佩戴要求:\n①存在坠物或对头部产生碰撞风险的作业场所需要佩戴安全帽 ;\n②安全帽必须戴正、戴牢、不能晃动,要系紧下颏带,调节好后箍以\n防安全帽脱落 ;\n③受强力撞击及超过有效期的安全帽必须更换。",
1102
- // "indexText": "① 头部防护:安全帽\n佩戴要求:\n①存在坠物或对头部产生碰撞风险的作业场所需要佩戴安全帽 ;\n②安全帽必须戴正、戴牢、不能晃动,要系紧下颏带,调节好后箍以\n防安全帽脱落 ;\n③受强力撞击及超过有效期的安全帽必须更换。",
1103
- // "lines": [
1104
- // {
1105
- // "location": [
1106
- // 69.08148,
1107
- // 368.92072,
1108
- // 65.90851,
1109
- // 10.5
1110
- // ]
1111
- // },
1112
- // {
1113
- // "location": [
1114
- // 86.290985,
1115
- // 384.67072,
1116
- // 31.5,
1117
- // 10.5
1118
- // ]
1119
- // },
1120
- // {
1121
- // "location": [
1122
- // 286.2992,
1123
- // 315.73584,
1124
- // 37.656006,
1125
- // 12.0
1126
- // ]
1127
- // },
1128
- // {
1129
- // "location": [
1130
- // 324.6939,
1131
- // 316.79932,
1132
- // 122.74487,
1133
- // 10.5
1134
- // ]
1135
- // },
1136
- // {
1137
- // "location": [
1138
- // 286.2954,
1139
- // 336.0458,
1140
- // 149.625,
1141
- // 10.5
1142
- // ]
1143
- // },
1144
- // {
1145
- // "location": [
1146
- // 286.2954,
1147
- // 356.0483,
1148
- // 161.15405,
1149
- // 10.5
1150
- // ]
1151
- // },
1152
- // {
1153
- // "location": [
1154
- // 286.2954,
1155
- // 376.0508,
1156
- // 161.15405,
1157
- // 10.5
1158
- // ]
1159
- // },
1160
- // {
1161
- // "location": [
1162
- // 286.2954,
1163
- // 396.0533,
1164
- // 76.125,
1165
- // 10.5
1166
- // ]
1167
- // },
1168
- // {
1169
- // "location": [
1170
- // 286.2954,
1171
- // 416.05582,
1172
- // 161.17517,
1173
- // 10.5
1174
- // ]
1175
- // },
1176
- // {
1177
- // "location": [
1178
- // 286.2954,
1179
- // 436.8038,
1180
- // 52.5,
1181
- // 10.5
1182
- // ]
1183
- // },
1184
- // {
1185
- // "location": [
1186
- // 338.7992,
1187
- // 435.73584,
1188
- // 12.0,
1189
- // 12.0
1190
- // ]
1191
- // }
1192
- // ]
1193
- // }
1194
- // }
1195
- // }
1196
- // ],
1197
- // "code": "0",
1198
- // "msg": null,
1199
- // "traceId": null
1200
- // }
1201
- if (res.data.code == 0) {
1202
- // tagIds 会按照gpt识别的生成有序的数组,前端直接按照下标的顺序取就可以了
1203
- // 缓存拿到的所有数据
1204
- this.cachePdf = res.data.data
1205
- let publicPageFileUrl = res.data.data && res.data.data[0] ? res.data.data[0].publicPageFileUrl : ''
1206
- this.currentPage = 0
1207
- if (publicPageFileUrl && publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')) === '.pdf') {
1208
- this.preViewType = 'pdf'
1209
- this.setPageAllLine(this.cachePdf)
1210
- this.getpdfResloutePage(res.data.data[0])
1211
- } else {
1212
- this.preViewType = 'excal'
1213
- this.$http.post(
1214
- '/knowledge-api/temporary-certificate/or-origin?expired=30',
1215
- publicPageFileUrl,
1216
- {
1217
- headers: {
1218
- "Content-Type": "application/json",
1219
- },
1220
- }).then(res => {
1221
- // 使用原声请求方式 axios会带有不需要的请求头
1222
- let xhr = new XMLHttpRequest();
1223
- xhr.open('GET', res.data || res.bodyText, true);
1224
- // 定义请求完成的处理函数,请求前也可以增加加载框/禁用下载按钮逻辑
1225
- xhr.onload = ({ currentTarget }) => {
1226
- // 请求完成
1227
- if (currentTarget.status === 200) { // 返回200
1228
- let pdf_view = document.getElementsByClassName('pdf_view');
1229
- if (pdf_view && pdf_view[0]){
1230
- pdf_view[0].style.backgroundImage = 'none'
1231
- }
1232
- this.contentView.innerHTML = currentTarget.response
1233
- this.contentView.style.padding = '10px'
1234
- // this.contentView.style.position = 'relative'
1235
- this.$refs.pdfView.style.backgroundColor = '#FFFFFF'
1236
- this.$refs.pdfView.appendChild(this.contentView)
1237
-
1238
- let allTr = Array.from(this.$refs.pdfView.getElementsByTagName('tr'))
1239
- this.allTr = []
1240
- for (let index = 0; index < allTr.length; index++) {
1241
- if (value.includes(allTr[index].getAttribute('tag-id'))) {
1242
- this.allTr.push(allTr[index])
1243
- }
1244
- }
1245
- this.currentChange(1)
1246
-
1247
- }
1248
- }
1249
- xhr.send();
1250
- })
1251
- }
1252
- } else {
1253
- let div = document.createElement('div')
1254
- div.innerText = '文件加载异常'
1255
- this.contentView.appendChild(div)
1256
- this.$refs.pdfView.appendChild(this.contentView)
1257
- }
1258
- })
1259
- }
1260
- },
1261
- deep: true,
1262
- immediate: true
1263
- }
1264
- },
1265
- mounted () {
1266
- if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
1267
- this.isPC = false
1268
- } else {
1269
- this.isPC = true
1270
- }
1271
- }
1272
- }
1273
- </script>
1274
-
1275
- <style lang="less" scoped>
1276
- .pdf_view {
1277
- width: 100%;
1278
- height: calc(100% - 110px);
1279
- overflow: auto;
1280
- //overflow-y: scroll;
1281
- background-color: #f5f7fb;
1282
- // margin-bottom: 60px;
1283
- box-sizing: border-box;
1284
- background-image: url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif');
1285
- background-position: center;
1286
- background-size: 50px;
1287
- background-repeat: no-repeat;
1288
- // position: relative;
1289
- // > div {
1290
- // width: 100%;
1291
- // height: 100%;
1292
- // overflow: hidden;
1293
- // overflow-y: auto;
1294
- // position: relative;
1295
- // }
1296
- >iframe {
1297
- width: 100%;
1298
- height: 100%;
1299
- }
1300
-
1301
- a:link {
1302
- color: none;
1303
- }
1304
-
1305
- a:visited {
1306
- color: none;
1307
- }
1308
-
1309
- a:hover {
1310
- color: none;
1311
- }
1312
-
1313
- a:active {
1314
- color: none;
1315
- }
1316
- .btn_footer {
1317
- width: 100%;
1318
- height: 60px;
1319
- display: flex;
1320
- align-items: center;
1321
- justify-content: space-around;
1322
- position: absolute;
1323
- bottom: 0px;
1324
- left: 0;
1325
- z-index: 999;
1326
- background: #ffffff;
1327
-
1328
- .prev,
1329
- .next {
1330
- width: 35%;
1331
- height: 40px;
1332
- display: flex;
1333
- align-items: center;
1334
- justify-content: center;
1335
- border-radius: 50px;
1336
- cursor: pointer;
1337
- }
1338
-
1339
- .prev {
1340
- background: #F2F5FA;
1341
- color: #000;
1342
- }
1343
-
1344
- .next {
1345
- background: #366aff;
1346
- color: #ffffff;
1347
- }
1348
- }
1349
-
1350
- #pagination {
1351
- .total-class {
1352
- margin-right: 13px;
1353
- font-weight: 400;
1354
- }
1355
-
1356
- position: absolute;
1357
- bottom: 0px;
1358
- right: 0;
1359
- width: 100%;
1360
- display: flex;
1361
- align-items: center;
1362
- justify-content: center;
1363
- height: 50px;
1364
- background-color: white;
1365
- box-shadow: 0px 0px 18px 0px rgba(29, 55, 129, 0.07);
1366
- border-radius: 5px;
1367
- z-index: 1000;
1368
-
1369
-
1370
-
1371
- /deep/.el-pagination {
1372
- margin-right: 110px;
1373
- }
1374
-
1375
- /deep/.el-pager {
1376
- background: #EDF0F6;
1377
- border-radius: 15px;
1378
- }
1379
-
1380
- /deep/.el-pagination.is-background .btn-next {
1381
- width: 30px;
1382
- height: 30px;
1383
- background: #EDF0F6;
1384
- border-radius: 50%;
1385
- }
1386
-
1387
- /deep/.el-pagination .btn-next {
1388
- width: 30px;
1389
- height: 30px;
1390
- background: #EDF0F6;
1391
- border-radius: 50%;
1392
- padding-left: 0;
1393
- margin-left: 5px;
1394
- }
1395
-
1396
- /deep/.el-pagination .btn-prev {
1397
- width: 30px;
1398
- height: 30px;
1399
- background: #EDF0F6;
1400
- border-radius: 50%;
1401
- padding-right: 0;
1402
- margin-right: 5px;
1403
- }
1404
-
1405
- /deep/.el-pagination button {
1406
- padding: 0;
1407
- min-width: 30px;
1408
- }
1409
-
1410
- /deep/.el-pager li {
1411
- background: #EDF0F6;
1412
- height: 30px;
1413
- min-width: 30px;
1414
- line-height: 30px;
1415
- font-size: 12px;
1416
- color: #717b90;
1417
- }
1418
-
1419
- /deep/.el-pager li:first-child {
1420
- border-bottom-left-radius: 15px !important;
1421
- border-top-left-radius: 15px !important;
1422
- }
1423
-
1424
- /deep/.el-pager li:last-child {
1425
- border-top-right-radius: 15px !important;
1426
- border-bottom-right-radius: 15px !important;
1427
- }
1428
-
1429
- /deep/.el-pager li.active {
1430
- width: 30px;
1431
- height: 30px;
1432
- min-width: 30px;
1433
- background: #366AFF;
1434
- border: 3px solid #A1B9FF;
1435
- border-radius: 50%;
1436
- line-height: 24px;
1437
- color: white;
1438
- }
1439
-
1440
- /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
1441
- background: #366AFF;
1442
- }
1443
- }
1444
-
1445
- .change_scale {
1446
- width: 100%;
1447
- height: 50px;
1448
- position: absolute;
1449
- top: 50px;
1450
- left: 0;
1451
- background: #ffffff;
1452
- display: flex;
1453
- align-items: center;
1454
- padding: 0 10px;
1455
- box-sizing: border-box;
1456
-
1457
- section {
1458
- cursor: pointer;
1459
- width: 30px;
1460
- height: 30px;
1461
- margin-right: 5px;
1462
- border-radius: 5px;
1463
- display: flex;
1464
- align-items: center;
1465
- justify-content: center;
1466
-
1467
- i {
1468
- font-weight: 900;
1469
- }
1470
- }
1471
-
1472
- section:hover {
1473
- background: rgba(221, 222, 223, 1);
1474
- }
1475
- }
1476
- .pdf_container_view{
1477
- height: 100%;
1478
- width: 100%;
1479
- position: relative;
1480
- overflow: auto;
1481
- }
1482
- }
1483
- </style>
1484
- <style lang="less">
1485
- .animation {
1486
- animation-name: highlight;
1487
- animation-duration: 4s;
1488
- }
1489
-
1490
- @keyframes highlight {
1491
- 0% {
1492
- background: rgba(255, 136, 0, 0.3);
1493
- }
1494
-
1495
- 25% {
1496
- background: rgba(255, 136, 0, 0.6);
1497
- }
1498
-
1499
- 50% {
1500
- background: rgba(255, 136, 0, 0.3);
1501
- }
1502
-
1503
- 75% {
1504
- background: rgba(255, 136, 0, 0.6);
1505
- }
1506
-
1507
- 100% {
1508
- background: rgba(255, 136, 0, 0.3);
1509
- }
1
+ <template>
2
+ <div class="pdf_view" id="pdf_view" :style="{
3
+ marginTop: isPC ? '50px' : '',
4
+ marginBottom: tagIds.length > 1 ? '60px' : '0px',
5
+ height: setHeight
6
+ }">
7
+ <div class="change_scale" v-if="isPC">
8
+ <section @click="changeScale('reduce')">
9
+ <i class="el-icon-minus"></i>
10
+ </section>
11
+ <el-divider direction="vertical"></el-divider>
12
+ <section @click="changeScale('zoom')">
13
+ <i class="el-icon-plus"></i>
14
+ </section>
15
+ <el-select size="small" v-model="handScale" @change="changeScale" placeholder="请选择">
16
+ <el-option v-for="item in scaleList" :key="item.value" :label="item.label" :value="item.value">
17
+ </el-option>
18
+ </el-select>
19
+ </div>
20
+ <div class="pdf_container_view" id="pdf_container_view" @scroll="pdfScroll" ref="pdfView"></div>
21
+ <div class="btn_footer" v-if="tagIds.length > 1 && !isPC">
22
+ <div class="prev" @click="prev">上一段</div>
23
+ <div class="next" @click="next">下一段</div>
24
+ </div>
25
+ <div id="pagination" v-if="tagIds.length > 1 && isPC">
26
+ <el-pagination :current-page="currentPage + 1" @current-change="currentChange" @prev-click="prev"
27
+ @next-click="next" layout="slot, prev, pager, next" :page-size="1" :total="tagIds.length">
28
+ <span class="total-class">答案由{{ tagIds.length }}段内容生成</span>
29
+ </el-pagination>
30
+ </div>
31
+ </div>
32
+ </template>
33
+
34
+ <script>
35
+ import _ from 'lodash'
36
+ import { newInitWaterMark } from "../assets/js/common";
37
+ // import * as pdfjsLib from 'pdfjs-dist'
38
+ // pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker';
39
+ // import { TextLayerBuilder } from "pdfjs-dist/web/pdf_viewer";
40
+ // EventBus pdf_viewer 支持绑定自定义事件,一版不做
41
+ // import 'pdfjs-dist/web/pdf_viewer.css'
42
+ /* eslint-disable */
43
+ const pdfjsLib = window['pdfjsLib']
44
+ if (pdfjsLib) {
45
+ pdfjsLib.GlobalWorkerOptions.workerSrc = window['pdfjs-dist/build/pdf.worker']
46
+ // 'pdfjs-dist/build/pdf.worker';
47
+ }
48
+ const { TextLayerBuilder } = window['pdfjs-dist/web/pdf_viewer']
49
+ const CSS_UNITS = 96.0 / 72.0
50
+ // import { zoomElement } from '../assets/js/hammer'
51
+ export default {
52
+ name: 'pdfView',
53
+ props: ['tagIds', 'isMessageRecord','fileName', "knowledgeItem",'textWatermarkStr'],
54
+ data () {
55
+ return {
56
+ url: '',
57
+ pages: [],
58
+ pageLoadStatus: {
59
+ WAIT: 0,
60
+ LOADED: 1,
61
+ },
62
+ scale: 1,
63
+ rotation: 0,
64
+ pageSize: {},
65
+ PAGE_INTVERVAL: 15,
66
+ SLICE_COUNT: 5,
67
+ contentView: null,
68
+ fisrtLoad: true,
69
+ TextLayerBuilder: null,
70
+ totalPageCount: 0,
71
+ identifyTextPostion: {
72
+ top: 0,
73
+ left: 0,
74
+ width: 100,
75
+ height: 0,
76
+ page: 1,
77
+ pageHeight: 0,
78
+ pageWidth: 0,
79
+ extractInfo: {},
80
+ currentPageAllLine: []
81
+ },
82
+ currentPageAllLine: [],
83
+ pdfUrl: '',
84
+ cachePdf: [],
85
+ newViewer: null,
86
+ currentPage: 0,
87
+ changetoolbar: false,
88
+ allTr: [],
89
+ preViewType: 'pdf',
90
+ displacement: {
91
+ pageX: 0,
92
+ pageY: 0,
93
+ moveable: false,
94
+ pageX2: 0,
95
+ pageY2: 0,
96
+ originScale: 1,
97
+ },
98
+ isTouchMoved: false,
99
+ transformSalce: null,
100
+ defaultTransform:0.8,
101
+ isPC: false,
102
+ handScale: 'auto',
103
+ scaleList: [
104
+ {
105
+ label: '自动缩放',
106
+ value: 'auto'
107
+ },
108
+ {
109
+ label: '实际比例',
110
+ value: 'reality'
111
+ },
112
+ {
113
+ label: '100%',
114
+ value: 1
115
+ },
116
+ {
117
+ label: '120%',
118
+ value: 1.2
119
+ },
120
+ {
121
+ label: '150%',
122
+ value: 1.5
123
+ },
124
+ {
125
+ label: '170%',
126
+ value: 1.7
127
+ }
128
+ ,
129
+ {
130
+ label: '200%',
131
+ value: 2
132
+ }
133
+ ],
134
+ scrollTop: 0,
135
+ scrollLeft: 0
136
+ }
137
+ },
138
+ methods: {
139
+ getpdfResloutePage (pdfResloute) {
140
+ // 根据当前页面宽度设置缩放比例
141
+ // this.scale = Math.round(this.$refs.pdfView.clientWidth / pdfResloute.pageWidth * 100) / 100
142
+ if (this.isMessageRecord) {
143
+ this.scale = Math.round(this.$refs.pdfView.clientWidth / pdfResloute.pageWidth * 100) / 100
144
+ } else {
145
+ this.scale = 2
146
+ }
147
+ // 从后端获取到当前分片后所有的pdf页码,初始化数组,数组下{} 对应每页pdf文件
148
+ this.pdfUrl = pdfResloute.publicPageFileUrl.substring(0, pdfResloute.publicPageFileUrl.lastIndexOf('/') + 1)
149
+ this.initPages(pdfResloute.total)
150
+ // 定位功能,加载对应页码位置
151
+ this.loadPdfData(pdfResloute.page)
152
+ },
153
+ async loadPdfData (loadPage) {
154
+ if (this.pages[loadPage - 1] && ((this.pages[loadPage - 1].dom && this.pages[loadPage - 1].dom.children.length > 0) || this.pages[loadPage - 1].loadStatus)) {
155
+ return
156
+ } else {
157
+ if (this.changetoolbar) {
158
+ this.$nextTick(() => {
159
+ this.renderHighlights()
160
+ })
161
+ this.changetoolbar = false
162
+ }
163
+ }
164
+ // 记录开始缓存的状态
165
+ // pdfjsLib.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/legacy/build/pdf.worker.entry.js");
166
+ // 拿到第一个分片
167
+ const { startPage, url } = await this.fetchPdfFragment(loadPage);
168
+ let loadingTask = pdfjsLib.getDocument(url)
169
+ loadingTask.promise.then(async (pdfDoc) => {
170
+ // 将已经下载的分片保存到 pages 数组中
171
+ // for (let i = 0; i < pdfDoc.numPages; i += 1) {
172
+ // const pageIndex = startPage + i;
173
+ // const page = this.pages[pageIndex - 1];
174
+ // // // 不在缓存列表内,重新获取本页pdf
175
+ // // if (page.loadStatus !== this.pageLoadStatus.LOADED) {
176
+
177
+ // // } else {
178
+ // // if (this.changetoolbar) {
179
+ // // this.$nextTick(() => {
180
+ // // this.renderHighlights()
181
+ // // })
182
+ // // this.changetoolbar = false
183
+ // // }
184
+ // // }
185
+ // }
186
+ const page = this.pages[loadPage - 1]
187
+ await pdfDoc.getPage(1).then(async (pdfPage) => {
188
+ this.pages[loadPage - 1].loadStatus = true
189
+ this.pages[loadPage - 1].pdfPage = pdfPage;
190
+ // 通知可以进行渲染了
191
+ await this.startRenderPages(pdfPage, page, loadPage)
192
+ });
193
+ });
194
+ },
195
+ initPages (totalPage) {
196
+ // const pages = [];
197
+ this.totalPageCount = totalPage
198
+ for (let i = 0; i < totalPage; i += 1) {
199
+ this.pages.push({
200
+ pageNo: i + 1,
201
+ loadStatus: false,
202
+ pdfPage: null,
203
+ dom: null
204
+ });
205
+ }
206
+ },
207
+ async fetchPdfFragment (pageIndex) {
208
+ // 置换加签后的文件地址。
209
+ let obj = {}
210
+ await this.$http.post(
211
+ '/knowledge-api/temporary-certificate/or-origin?expired=30',
212
+ this.pdfUrl + pageIndex + '.pdf',
213
+ {
214
+ headers: {
215
+ "Content-Type": "application/json",
216
+ },
217
+ }).then(async res => {
218
+ if (res.bodyText) {
219
+ // 最后返回一个 包含这4个参数的对象
220
+ obj = await {
221
+ "startPage": pageIndex, // 分片的开始页码
222
+ "endPage": pageIndex + 5, // 分片结束页码
223
+ "totalPage": this.totalPageCount, // pdf 总页数
224
+ "url": res.bodyText // 分片内容下载地址
225
+ }
226
+ }
227
+ if (res.data) {
228
+ // 最后返回一个 包含这4个参数的对象
229
+ obj = await {
230
+ "startPage": pageIndex, // 分片的开始页码
231
+ "endPage": pageIndex + 5, // 分片结束页码
232
+ "totalPage": this.totalPageCount, // pdf 总页数
233
+ "url": res.data // 分片内容下载地址
234
+ }
235
+ }
236
+ })
237
+ return obj
238
+ },
239
+ startRenderPages (pdfPage, page, pageIndex) {
240
+ if (Object.keys(this.pageSize).length == 0) {
241
+ const viewport = pdfPage.getViewport({
242
+ scale: this.scale, // 缩放的比例
243
+ rotation: this.rotation, // 旋转的角度
244
+ });
245
+ // 记录pdf页面高度
246
+ const pageSize = {
247
+ width: viewport.width,
248
+ height: viewport.height,
249
+ }
250
+ this.pageSize = pageSize
251
+ // 创建内容绘制区,并设置大小
252
+ if (this.$refs.pdfView.clientWidth / this.pageSize.width >= 1 || this.isMessageRecord) {
253
+ this.contentView.style.width = `${pageSize.width - 10}px`;
254
+ this.contentView.style.height = `${(this.totalPageCount * (pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
255
+ } else {
256
+ this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
257
+ this.contentView.style.width = `${pageSize.width * this.transformSalce - 10}px`;
258
+ this.contentView.style.height = `${(this.totalPageCount * (pageSize.height * (this.transformSalce) + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
259
+ }
260
+ this.contentView.style.margin = '0 auto 0'
261
+ this.contentView.style.position = 'relative'
262
+ this.contentView.style.paddingBottom = '60px'
263
+ // contentView.style.overflowY = 'auto'
264
+ this.$refs.pdfView.appendChild(this.contentView);
265
+ if (this.textWatermarkStr){
266
+ newInitWaterMark('pdf_container_view',this.textWatermarkStr)
267
+ }
268
+ }
269
+ this.renderPages(pageIndex)
270
+ },
271
+ // 渲染需要展示的页面,不需展示的页码将其清除
272
+ renderPages (pageIndex) {
273
+ const pagesToRender = this.getRenderScope(pageIndex);
274
+ for (const i of this.pages) {
275
+ if (pagesToRender.some(p => { return p.pageNo == i.pageNo })) {
276
+ if (i.loadStatus === true) {
277
+ this.renderPageContent(i, i.pageNo)
278
+ } else {
279
+ this.renderPageLoading(i, i.pageNo)
280
+ }
281
+ } else {
282
+ this.clearPage(i);
283
+ }
284
+ }
285
+
286
+ },
287
+ async renderPageContent (page, pageIndex) {
288
+ const { pdfPage, pageNo, dom } = page;
289
+ // dom 元素已存在,无须重新渲染,直接返回
290
+ if ((dom && dom.children.length != 0) || page.loading) {
291
+ return;
292
+ }
293
+ page.loading = true
294
+ const viewport = pdfPage.getViewport({
295
+ scale: this.scale,
296
+ rotation: this.rotation,
297
+ });
298
+ // 创建新的canvas
299
+ const canvas = document.createElement('canvas');
300
+ const context = canvas.getContext('2d');
301
+ // canvas.getContext('2d');
302
+ canvas.height = this.pageSize.height;
303
+ canvas.width = this.pageSize.width;
304
+ canvas.style.position = 'relative'
305
+ canvas.style.top = -3 + 'px'
306
+ // 创建渲染的dom
307
+ const pageDom = document.createElement('div');
308
+ pageDom.style.position = 'absolute';
309
+ pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
310
+ pageDom.style.width = `${this.pageSize.width}px`;
311
+ pageDom.style.height = `${this.pageSize.height}px`;
312
+ pageDom.setAttribute('data-id', 'page' + pageNo)
313
+ pageDom.appendChild(canvas);
314
+ // 渲染内容
315
+ let renderContext = {
316
+ canvasContext: context,
317
+ viewport: viewport,
318
+ }
319
+ await pdfPage.render(renderContext).promise.then(() => {
320
+ return pdfPage.getTextContent()
321
+ }).then(async (textContent) => {
322
+ const textLayerDiv = document.createElement('div');
323
+ textLayerDiv.setAttribute('class', 'textLayer');
324
+ // 将文本图层div添加至每页pdf的div中
325
+ // 创建新的TextLayerBuilder实例
326
+ let textLayer = new TextLayerBuilder({
327
+ textLayerDiv: textLayerDiv,
328
+ pageIndex: pdfPage._pageIndex,
329
+ viewport: viewport,
330
+ });
331
+ let findPage = this.currentPageAllLine.find(l => { return l.page == pageIndex })
332
+ let rectdomTop = 0
333
+ if (findPage) {
334
+ let AllLines = findPage.allLines
335
+ // setTimeout(() => {
336
+ if (AllLines.length > 0) {
337
+ for (let j = 0; j < AllLines.length; j++) {
338
+ let lines = AllLines[j].lines
339
+ let rectdom = document.createElement('div')
340
+ rectdom.setAttribute('react-count', AllLines[j].pageCount);
341
+ rectdom.style.position = 'absolute';
342
+ rectdom.style.top = 0
343
+ rectdom.style.left = 0
344
+ rectdom.classList.add('rectdom')
345
+ for (let index = 0; index < lines.length; index++) {
346
+ if (!/^\s+$/g.test(lines[index].content)) {
347
+ let postionArr = lines[index].location
348
+ let div = document.createElement('div')
349
+ div.style.position = 'absolute';
350
+ div.style.left = postionArr[0] * this.scale + 'px',
351
+ // 后端返回的坐标有基线对齐的问题,top 值是后端算好(基线top - 文字高度),在此加上文字高度的 1/9 (大致比例)为实际展示出文字的top值
352
+ div.style.top = postionArr[1] * this.scale + 'px'
353
+ div.style.height = postionArr[3] * this.scale + 'px';
354
+ div.style.width = postionArr[2] * this.scale + 'px'
355
+ div.style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
356
+ div.classList.add('lineHeight')
357
+ rectdom.appendChild(div)
358
+ if (index == 0 && j == 0) {
359
+ if (this.transformSalce !== null) {
360
+ rectdomTop = postionArr[1] * this.scale * this.transformSalce
361
+ } else {
362
+ rectdomTop = postionArr[1] * this.scale
363
+ }
364
+ // if(this.isPC) {
365
+ // rectdomTop = rectdomTop - 50 < 0 ? 0 : rectdomTop - 50
366
+ // }
367
+ }
368
+ }
369
+ }
370
+ if (rectdom.children.length > 0) {
371
+ pageDom.appendChild(rectdom)
372
+ }
373
+ }
374
+ }
375
+ }
376
+ textLayer.setTextContent(textContent);
377
+ textLayer.render()
378
+ pageDom.appendChild(textLayerDiv);
379
+
380
+ let backgroundDom = document.getElementById('backgroundLoad' + pageNo)
381
+ if (backgroundDom) {
382
+ this.contentView.removeChild(backgroundDom);
383
+ }
384
+ page.dom = await pageDom;
385
+ page.loading = false
386
+ this.contentView.appendChild(pageDom);
387
+ let pdf_view = document.getElementsByClassName('pdf_view');
388
+ if (pdf_view && pdf_view[0]){
389
+ pdf_view[0].style.backgroundImage = 'none'
390
+ }
391
+ if (this.transformSalce !== null) {
392
+ this.contentView.style.transform = `scale(${this.transformSalce}, ${this.transformSalce})`
393
+ }
394
+ if (this.changetoolbar) {
395
+ setTimeout(() => {
396
+ this.renderHighlights()
397
+ this.changetoolbar = false
398
+ }, 500)
399
+ }
400
+ if (this.fisrtLoad) {
401
+ setTimeout(() => {
402
+ let pageoffsetHeight = 0
403
+ if (this.transformSalce !== null) {
404
+ pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce
405
+ } else {
406
+ pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL)
407
+ }
408
+ if (this.$refs.pdfView.clientHeight - pageoffsetHeight > 0 && pageIndex == 1) {
409
+ const height = this.$refs.pdfView.clientHeight;
410
+ let startNum = 0
411
+ let endNum = 0
412
+ if (this.transformSalce !== null) {
413
+ startNum = Math.ceil(this.$refs.pdfView.scrollTop / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
414
+ endNum = startNum + Math.ceil(height / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
415
+ } else {
416
+ startNum = Math.ceil(this.$refs.pdfView.scrollTop / (this.pageSize.height + this.PAGE_INTVERVAL))
417
+ endNum = startNum + Math.ceil(height / (this.pageSize.height + this.PAGE_INTVERVAL))
418
+
419
+ }
420
+ for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
421
+ if (pageIndex > 0 && pageIndex <= this.pages.length) {
422
+ this.loadPdfData(pageIndex)
423
+ }
424
+ }
425
+ }
426
+ if (this.$refs.pdfView.scrollTop == Math.floor((pageNo - 1) * pageoffsetHeight)) {
427
+ this.$refs.pdfView.scrollTop = rectdomTop
428
+ this.fisrtLoad = false
429
+ } else {
430
+ this.$refs.pdfView.scrollTop = `${((pageNo - 1) * pageoffsetHeight) + rectdomTop - this.PAGE_INTVERVAL}`
431
+ this.fisrtLoad = false
432
+ }
433
+ this.renderHighlights()
434
+ // zoomElement(this.contentView)
435
+ }, 100)
436
+ }
437
+ })
438
+ },
439
+ // 监听容器的滚动事件,触发 scrollPdf 方法
440
+ // 这里加了防抖保证不会一次产生过多请求
441
+ debounceScrollPdf: _.debounce(function (e, that) {
442
+ if (this.fisrtLoad) {
443
+ this.fisrtLoad = false
444
+ return
445
+ }
446
+ const scrollTop = e.target.scrollTop;
447
+ const height = e.target.clientHeight;
448
+ let startNum = 0
449
+ let endNum = 0
450
+ if (this.transformSalce !== null) {
451
+ startNum = Math.ceil(scrollTop / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
452
+ endNum = startNum + Math.ceil(height / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
453
+ } else {
454
+ startNum = Math.ceil(scrollTop / (that.pageSize.height + that.PAGE_INTVERVAL))
455
+ endNum = startNum + Math.ceil(height / (that.pageSize.height + that.PAGE_INTVERVAL))
456
+ }
457
+ for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
458
+ if (pageIndex > 0 && pageIndex <= that.pages.length) {
459
+ that.loadPdfData(pageIndex)
460
+ }
461
+ }
462
+ }, 200),
463
+ directScrolling (e, that) {
464
+ if (this.fisrtLoad) {
465
+ this.fisrtLoad = false
466
+ return
467
+ }
468
+ const scrollTop = e.target.scrollTop;
469
+ const height = e.target.clientHeight;
470
+ // 根据内容可视区域中心点计算页码, 没有滚动时,指向第一页
471
+ const pageIndex = scrollTop > 0 ?
472
+ Math.ceil((scrollTop + (height / 2)) / (that.pageSize.height + that.PAGE_INTVERVAL)) :
473
+ 1;
474
+ this.loadPdfData(pageIndex)
475
+ },
476
+ pdfScroll (e) {
477
+ if (this.preViewType !== 'pdf' || this.isTouchMoved) {
478
+ return
479
+ }
480
+ if (this.scrollLeft != e.target.scrollLeft) {
481
+ this.scrollLeft = e.target.scrollLeft
482
+ }
483
+ if (this.scrollTop != e.target.scrollTop) {
484
+ this.scrollTop = e.target.scrollTop
485
+ this.debounceScrollPdf(e, this)
486
+ }
487
+ },
488
+ // 分片每次只做一次处理,所以不考虑多片情况
489
+ loadBefore (pageIndex) {
490
+ this.loadPdfData(pageIndex)
491
+ },
492
+ loadAfter (pageIndex) {
493
+ this.loadPdfData(pageIndex)
494
+ },
495
+ // 首先我们获取到需要渲染的范围
496
+ // 根据当前的可视范围内的页码,我们前后只保留 8 页
497
+ getRenderScope (pageIndex) {
498
+ const pagesToRender = [];
499
+ let i = pageIndex - 1;
500
+ let j = pageIndex + 1;
501
+ // pageIndex - 1 表示当前页码数 对应的下标位置
502
+ pagesToRender.push(this.pages[pageIndex - 1]);
503
+ while (pagesToRender.length < 8 && pagesToRender.length < this.pages.length) {
504
+ if (i > 0) {
505
+ pagesToRender.push(this.pages[i - 1]);
506
+ i -= 1;
507
+ }
508
+ if (pagesToRender.length >= 8) {
509
+ break;
510
+ }
511
+ if (j <= this.pages.length) {
512
+ pagesToRender.push(this.pages[j - 1]);
513
+ j += 1;
514
+ }
515
+ }
516
+ // for (let index = 0; index < array.length; index++) {
517
+ // const element = array[index];
518
+
519
+ // }
520
+ return pagesToRender;
521
+ },
522
+
523
+ // 清除页面 dom
524
+ clearPage (page) {
525
+ if (this.contentView.contains(page.dom) && page.dom) {
526
+ this.contentView.removeChild(page.dom);
527
+ page.loadStatus = false
528
+ page.loading = false
529
+ page.dom = undefined;
530
+ }
531
+ },
532
+ // 页面正在下载时渲染loading视图
533
+ renderPageLoading (page) {
534
+ const { pageNo, dom } = page;
535
+ if (dom && dom.children.length != 0) {
536
+ return;
537
+ }
538
+ let backgroundDom = document.getElementById('backgroundLoad' + pageNo)
539
+ if (this.contentView.contains(backgroundDom)) {
540
+ return
541
+ }
542
+ const pageDom = document.createElement('div');
543
+ pageDom.style.width = `${this.pageSize.width}px`;
544
+ pageDom.style.height = `${this.pageSize.height}px`;
545
+ pageDom.style.position = 'absolute';
546
+ pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL
547
+ }px`;
548
+ pageDom.style.backgroundImage = `url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif')`
549
+ pageDom.style.backgroundPosition = 'center'
550
+ pageDom.style.backgroundRepeat = 'no-repeat'
551
+ pageDom.style.backgroundColor = '#FFF'
552
+ pageDom.setAttribute('id', 'backgroundLoad' + pageNo)
553
+ page.dom = pageDom;
554
+ this.contentView.appendChild(pageDom);
555
+ },
556
+ prev () {
557
+ this.currentPage--
558
+ if (this.currentPage < 0) {
559
+ this.currentPage = 0
560
+ if (!this.isPC) {
561
+ this.$toast({
562
+ message: '当前已经是第一段了',
563
+ duration: 2000,
564
+ })
565
+ return
566
+ }
567
+ }
568
+ if (this.preViewType == 'pdf') {
569
+ this.scrollToUplaodePage(this.currentPage)
570
+ } else {
571
+ this.scrollToExcalTop(this.currentPage)
572
+ }
573
+ // this.getpdfResloutePage(this.cachePdf[this.currentPage - 1])
574
+ },
575
+ next () {
576
+ this.currentPage++
577
+ if (this.currentPage >= this.tagIds.length) {
578
+ this.currentPage = this.tagIds.length - 1
579
+ if (!this.isPC) {
580
+ this.$toast({
581
+ message: '当前已经是最后一段了',
582
+ duration: 2000,
583
+ })
584
+ return
585
+ }
586
+ }
587
+ if (this.preViewType == 'pdf') {
588
+ this.scrollToUplaodePage(this.currentPage)
589
+ } else {
590
+ this.scrollToExcalTop(this.currentPage)
591
+ }
592
+ },
593
+ currentChange (value) {
594
+ this.currentPage = value - 1
595
+ if (this.preViewType == 'pdf') {
596
+ this.scrollToUplaodePage(this.currentPage)
597
+ } else {
598
+ this.scrollToExcalTop(this.currentPage)
599
+ }
600
+ },
601
+ scrollToUplaodePage (currentPage) {
602
+ this.changetoolbar = true
603
+ if (this.preViewType !== 'pdf') {
604
+ return
605
+ }
606
+
607
+ let pdfResloute = this.cachePdf[currentPage]
608
+ this.identifyTextPostion.extractInfo = pdfResloute.extractInfo
609
+ this.identifyTextPostion.left = pdfResloute.extractInfo.location[0]
610
+ this.identifyTextPostion.top = pdfResloute.extractInfo.location[1]
611
+ this.identifyTextPostion.width = pdfResloute.extractInfo.location[2]
612
+ this.identifyTextPostion.height = pdfResloute.extractInfo.location[3]
613
+ this.identifyTextPostion.page = pdfResloute.page
614
+ this.identifyTextPostion.pageHeight = pdfResloute.pageHeight
615
+ this.identifyTextPostion.pageWidth = pdfResloute.pageWidth
616
+ // 在当前段落在最后一页pdf时,根据计算的高度并不能触发滚动,在此执行重新渲染方法,非次情况会执行两次,待优化
617
+ this.$nextTick(() => {
618
+ this.renderHighlights()
619
+ })
620
+ if (this.transformSalce !== null) {
621
+ this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce) + (this.identifyTextPostion.top * this.scale * this.transformSalce)}`
622
+ } else {
623
+ this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + (this.identifyTextPostion.top * this.scale * this.transformSalce)}`
624
+ }
625
+ },
626
+ scrollToExcalTop (currentPage) {
627
+ for (let index = 0; index < this.allTr.length; index++) {
628
+ if (index == currentPage) {
629
+ Array.from(this.allTr[index].children).forEach(item => {
630
+ item.style.background = 'rgba(255, 136, 0, 0.6)'
631
+ item.classList.add('animation')
632
+ setTimeout(() => {
633
+ item.classList.remove('animation')
634
+ }, 4000)
635
+ })
636
+ // getBoundingClientRect().top 当前元素距离屏幕顶部的高度 + 弹窗header 高度
637
+ if (!this.isPC) {
638
+ let top = this.allTr[index].getBoundingClientRect().top - this.$refs.pdfView.getBoundingClientRect().top
639
+ this.$refs.pdfView.scrollTop = top
640
+ } else {
641
+ let top = this.allTr[index].getBoundingClientRect().top
642
+ this.$refs.pdfView.scrollTop = top - 50
643
+ }
644
+ } else {
645
+ Array.from(this.allTr[index].children).forEach(item => {
646
+ item.style.background = 'rgba(54, 106, 255, 0.6)'
647
+ item.classList.remove('animation')
648
+ })
649
+ }
650
+ }
651
+ },
652
+ // pdf是否需要重新渲染高亮位置
653
+ renderHighlights () {
654
+ let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
655
+ if (lineHeightDom) {
656
+ lineHeightDom.forEach((d) => {
657
+ for (let i = 0; i < d.children.length; i++) {
658
+ if (d.getAttribute('react-count') == this.currentPage) {
659
+ d.children[i].style.backgroundColor = 'rgba(255, 136, 0, 0.3)'
660
+ d.children[i].classList.add('animation')
661
+ setTimeout(() => {
662
+ d.children[i].classList.remove('animation')
663
+ }, 4000)
664
+ } else {
665
+ d.children[i].style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
666
+ d.children[i].classList.remove('animation')
667
+ }
668
+ }
669
+ })
670
+ }
671
+ },
672
+ displayHiglight (pageIndex) {
673
+ let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
674
+ if (lineHeightDom) {
675
+ lineHeightDom.forEach((d) => {
676
+ if (d.getAttribute('page-index') == pageIndex) {
677
+ d.style.display = 'none'
678
+ }
679
+ })
680
+ }
681
+ },
682
+ // 前端暂时缓存多页
683
+ autoLoadMore (pageIndex) {
684
+ let pdfResloute = this.cachePdf.find(cache => {
685
+ return cache.page == pageIndex
686
+ })
687
+ if (pdfResloute) {
688
+ this.getpdfResloutePage(pdfResloute)
689
+ } else {
690
+ this.loadPdfData(pageIndex)
691
+ }
692
+ },
693
+ setPageAllLine (arr) {
694
+ this.currentPageAllLine = []
695
+ arr.forEach((item, index) => {
696
+ let i = this.currentPageAllLine.findIndex(l => { return l.page && l.page == item.page })
697
+ if (i != -1) {
698
+ // this.currentPageAllLine[i].allLines.lines.push(item.extractInfo.lines)
699
+ this.currentPageAllLine[i].allLines.push({
700
+ pageCount: index,
701
+ lines: item.extractInfo.lines
702
+ })
703
+ } else {
704
+ this.currentPageAllLine.push({
705
+ page: item.page,
706
+ allLines: [{
707
+ pageCount: index,
708
+ lines: item.extractInfo.lines
709
+ }],
710
+ })
711
+ }
712
+ })
713
+ },
714
+ openTouch () {
715
+ // this.$nextTick()将回调延迟到下次 DOM 更新循环之后执行
716
+ let that = this;
717
+ this.$nextTick(() => {
718
+ // setInterval(() => {
719
+ // this.scale = this.scale + 0.1
720
+ // that.pages.forEach((item, index) =>{
721
+ // if(item.dom) {
722
+ // item.dom.children.forEach( childDom =>{
723
+ // if(childDom.getAttribute('react-count')) {
724
+ // childDom.style.transform = "scale(" + this.scale + ")";
725
+ // childDom.style.transformOrigin = "0px 0px 0px";
726
+ // } else {
727
+ // item.dom = null
728
+ // this.startRenderPages(item.pdfPage, null, index)
729
+ // }
730
+ // } )
731
+ // }
732
+ // })
733
+ // }, 100);
734
+ // 获取放大或缩小的区域DOM
735
+ let matrix_box = this.contentView
736
+ matrix_box.addEventListener("touchstart", function (event) {
737
+ this.isTouchMoved = true
738
+ let touches = event.touches;
739
+ let events = touches[0];
740
+ let events2 = touches[1];
741
+
742
+ // event.preventDefault();
743
+
744
+ // 第一个触摸点的坐标
745
+ that.displacement.pageX = events.pageX;
746
+ that.displacement.pageY = events.pageY;
747
+
748
+ that.displacement.moveable = true;
749
+
750
+ if (events2) {
751
+ that.displacement.pageX2 = events2.pageX;
752
+ that.displacement.pageY2 = events2.pageY;
753
+ }
754
+
755
+ that.displacement.originScale = this.scale || 1;
756
+ });
757
+ document.addEventListener("touchmove", function (event) {
758
+ if (!that.displacement.moveable) {
759
+ return;
760
+ }
761
+ // event.preventDefault();
762
+ let touches = event.touches;
763
+ let events = touches[0];
764
+ let events2 = touches[1];
765
+ // 双指移动
766
+ if (events2) {
767
+ // 第2个指头坐标在touchmove时候获取
768
+ if (!that.displacement.pageX2) {
769
+ that.displacement.pageX2 = events2.pageX;
770
+ }
771
+ if (!that.displacement.pageY2) {
772
+ that.displacement.pageY2 = events2.pageY;
773
+ }
774
+ // 双指缩放比例计算
775
+ let zoom = that.getDistance({
776
+ x: events.pageX,
777
+ y: events.pageY
778
+ },
779
+ {
780
+ x: events2.pageX,
781
+ y: events2.pageY
782
+ }
783
+ ) / that.getDistance(
784
+ {
785
+ x: that.displacement.pageX,
786
+ y: that.displacement.pageY
787
+ },
788
+ {
789
+ x: that.displacement.pageX2,
790
+ y: that.displacement.pageY2
791
+ }
792
+ );
793
+ // 应用在元素上的缩放比例
794
+ let newScale = that.displacement.originScale * zoom;
795
+ // 最大缩放比例限制
796
+ if (newScale > 2) {
797
+ newScale = 2;
798
+ }
799
+ // 最大缩放比例限制
800
+ if (newScale < 1) {
801
+ newScale = 1;
802
+ }
803
+ // 记住使用的缩放值
804
+ that.displacement.scale = newScale;
805
+ // console.log(newScale);
806
+ matrix_box.style.transform = "scale(" + newScale + ")";
807
+ // 设置旋转元素的基点位置
808
+ matrix_box.style.transformOrigin = "0px 0px 0px";
809
+ }
810
+ }, { passive: false });
811
+ document.addEventListener('touchend', function () {
812
+ that.isTouchMoved = false
813
+ }, { passive: false })
814
+ });
815
+ },
816
+ getDistance (start, stop) {
817
+ // Math.hypot()计算参数的平方根
818
+ return Math.hypot(stop.x - start.x, stop.y - start.y);
819
+ },
820
+ setupCanvas (canvas, width, height) {
821
+ const dpr = 1;
822
+ // const rect = canvas.getBoundingClientRect();
823
+ canvas.width = width
824
+ canvas.height = height
825
+ const ctx = canvas.getContext('2d');
826
+ ctx?.scale(dpr, dpr);
827
+ return ctx;
828
+ },
829
+ changeScale (value) {
830
+ if (value == 'zoom') {
831
+ this.handScale = 'auto'
832
+ this.transformSalce = (this.transformSalce + 0.2).toFixed(1)
833
+ } else if (value == 'reduce') {
834
+ if ((this.transformSalce - 0.2).toFixed(1) <= 0) {
835
+ return
836
+ }
837
+ this.handScale = 'auto'
838
+ this.transformSalce = (this.transformSalce - 0.2).toFixed(1)
839
+ } else if (value == 'auto') {
840
+ this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
841
+ } else if (value == 'reality') {
842
+ this.transformSalce = 0.5
843
+ } else {
844
+ this.transformSalce = (value / 2).toFixed(1)
845
+ }
846
+ this.transformSalce = Number(this.transformSalce)
847
+ this.contentView.style.transform = 'scale(' + this.transformSalce + ')';
848
+ // this.getpdfResloutePage(this.cachePdf[0])
849
+ },
850
+ //添加水印
851
+ watermark() {
852
+ //默认设置
853
+ var defaultSettings = {
854
+ watermark_txt:"",
855
+ watermark_x: 0,//水印起始位置x轴坐标
856
+ watermark_y: 0,//水印起始位置Y轴坐标
857
+ watermark_rows: 0,//水印行数
858
+ watermark_cols: 0,//水印列数
859
+ watermark_x_space: 40,//水印x轴间隔
860
+ watermark_y_space: 60,//水印y轴间隔
861
+ watermark_color: 'black',//水印字体颜色
862
+ watermark_alpha: .3,//水印透明度
863
+ watermark_fontsize: 12,//水印字体大小
864
+ watermark_font: '微软雅黑',//水印字体
865
+ watermark_width: 100,//水印宽度
866
+ watermark_height: 80,//水印长度
867
+ watermark_angle: 20,//水印倾斜度数***
868
+ visitorWatermark_txt:""
869
+ };
870
+ if(this.knowledgeItem.textWatermarkValue){
871
+ defaultSettings.watermark_txt = this.knowledgeItem.textWatermarkValue;
872
+ }
873
+ if (this.knowledgeItem.visitorWatermarkValue){
874
+ defaultSettings.visitorWatermark_txt = this.knowledgeItem.visitorWatermarkValue
875
+ }
876
+ //采用配置项替换默认值,作用类似jquery.extend
877
+ if (arguments.length === 1 && typeof arguments[0] === "object") {
878
+ console.log("arguments = " + JSON.stringify(arguments[0]));
879
+ // 获取参数配置
880
+ var src = arguments[0];
881
+ for (let key in src) {
882
+ if (src[key] && defaultSettings[key] && src[key] === defaultSettings[key])
883
+ continue;
884
+ else if (src[key])
885
+ defaultSettings[key] = src[key];
886
+ }
887
+ }
888
+ var oTemp = document.createDocumentFragment();
889
+ //获取页面最大宽度
890
+ console.debug('pdf_view',document.getElementById('pdf_view'))
891
+ let scrollWidth = document.getElementById('pdf_view').scrollWidth;
892
+ let clientWidth = document.getElementById('pdf_view').clientWidth;
893
+ var page_width = Math.max(scrollWidth, clientWidth);
894
+
895
+ var cutWidth = page_width * 0.0150;
896
+
897
+ page_width = page_width - cutWidth;
898
+
899
+ //获取页面最大高度
900
+ let height = parseInt(this.totalPageCount * this.pageSize.height)
901
+ var page_height = Math.max(document.getElementById('pdf_container_view').scrollHeight,height);
902
+
903
+ console.debug('page_height',page_height,this.totalPageCount * this.pageSize.height);
904
+
905
+ // var page_height = document.body.scrollHeight+document.body.scrollTop;
906
+
907
+ //如果将水印列数设置为0,或水印列数设置过大,超过页面最大宽度,则重新计算水印列数和水印x轴间隔
908
+
909
+ if (defaultSettings.watermark_cols == 0 || (parseInt(defaultSettings.watermark_x + defaultSettings
910
+ .watermark_width * defaultSettings.watermark_cols + defaultSettings.watermark_x_space *
911
+ (defaultSettings.watermark_cols - 1)) > page_width)) {
912
+ defaultSettings.watermark_cols = parseInt((page_width - defaultSettings.watermark_x + defaultSettings
913
+ .watermark_x_space) / (defaultSettings.watermark_width + defaultSettings
914
+ .watermark_x_space));
915
+ defaultSettings.watermark_x_space = parseInt((page_width - defaultSettings.watermark_x -
916
+ defaultSettings
917
+ .watermark_width * defaultSettings.watermark_cols) / (defaultSettings.watermark_cols - 1));
918
+ }
919
+
920
+ //如果将水印行数设置为0,或水印行数设置过大,超过页面最大长度,则重新计算水印行数和水印y轴间隔
921
+
922
+ if (defaultSettings.watermark_rows == 0 || (parseInt(defaultSettings.watermark_y + defaultSettings
923
+
924
+ .watermark_height * defaultSettings.watermark_rows + defaultSettings.watermark_y_space * (
925
+
926
+ defaultSettings.watermark_rows - 1)) > page_height)) {
927
+
928
+ defaultSettings.watermark_rows = parseInt((defaultSettings.watermark_y_space + page_height -
929
+
930
+ defaultSettings
931
+
932
+ .watermark_y) / (defaultSettings.watermark_height + defaultSettings.watermark_y_space));
933
+
934
+ defaultSettings.watermark_y_space = parseInt(((page_height - defaultSettings.watermark_y) -
935
+
936
+ defaultSettings
937
+
938
+ .watermark_height * defaultSettings.watermark_rows) / (defaultSettings.watermark_rows - 1));
939
+
940
+ }
941
+
942
+ var x;
943
+
944
+ var y;
945
+
946
+ for (var i = 0; i < defaultSettings.watermark_rows; i++) {
947
+ y = defaultSettings.watermark_y + (defaultSettings.watermark_y_space + defaultSettings.watermark_height) * i;
948
+ for (var j = 0; j < defaultSettings.watermark_cols; j++) {
949
+ x = defaultSettings.watermark_x + (defaultSettings.watermark_width + defaultSettings.watermark_x_space) * j;
950
+
951
+ var mask_div = document.createElement('div');
952
+ mask_div.id = 'mask_div' + i + j;
953
+ mask_div.className = 'mask_div';
954
+
955
+ //注意看这里加了图片水印
956
+ mask_div.style.webkitTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
957
+ mask_div.style.MozTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
958
+ mask_div.style.msTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
959
+ mask_div.style.OTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
960
+ mask_div.style.transform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
961
+ mask_div.style.visibility = "";
962
+ mask_div.style.position = "absolute";
963
+ //奇偶行错开,这样水印就不对齐,显的不呆板
964
+ console.debug('x',x)
965
+ if (i % 2 != 0) {
966
+ mask_div.style.left = x + 'px';
967
+ if (j % 2 != 0 && this.knowledgeItem.visitorWatermarkValue){
968
+ mask_div.appendChild(document.createTextNode(defaultSettings.visitorWatermark_txt));
969
+ } else {
970
+ if (!this.knowledgeItem.textWatermarkValue){
971
+ mask_div.appendChild(document.createTextNode(defaultSettings.visitorWatermark_txt));
972
+ } else {
973
+ mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
974
+ }
975
+ }
976
+ } else {
977
+ mask_div.style.left = x + 'px';
978
+ if (j % 2 != 0 && this.knowledgeItem.textWatermarkValue){
979
+ mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
980
+ } else {
981
+ if (!this.knowledgeItem.visitorWatermarkValue){
982
+ mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
983
+ } else {
984
+ mask_div.appendChild(document.createTextNode(defaultSettings.visitorWatermark_txt));
985
+ }
986
+ }
987
+ }
988
+
989
+ mask_div.style.top = y + 'px';
990
+ mask_div.style.overflow = "hidden";
991
+ mask_div.style.zIndex = "9999";
992
+ mask_div.style.pointerEvents = 'none'; //让水印不遮挡页面的点击事件
993
+ mask_div.style.opacity = defaultSettings.watermark_alpha;
994
+ mask_div.style.fontSize = defaultSettings.watermark_fontsize;
995
+ mask_div.style.fontFamily = defaultSettings.watermark_font;
996
+ mask_div.style.color = defaultSettings.watermark_color;
997
+ mask_div.style.textAlign = "center";
998
+ mask_div.style.width = defaultSettings.watermark_width + 'px';
999
+ mask_div.style.height = defaultSettings.watermark_height + 'px';
1000
+ mask_div.style.display = "block";
1001
+ oTemp.appendChild(mask_div);
1002
+ }
1003
+ }
1004
+ let pageDom = document.getElementById('pdf_container_view')
1005
+ pageDom.appendChild(oTemp);
1006
+
1007
+ },
1008
+ },
1009
+ computed: {
1010
+ perviewUrl () {
1011
+ return '/web/viewer.html?file=' + '/pdflist/pdf4split-1.pdf'
1012
+ },
1013
+ setHeight () {
1014
+ if (this.tagIds.length > 1) {
1015
+ if (this.isPC) {
1016
+ return 'calc(100% - 110px)'
1017
+ } else {
1018
+ return 'calc(100% - 60px)'
1019
+ }
1020
+ } else {
1021
+ if (this.isPC) {
1022
+ return 'calc(100% - 50px)'
1023
+ } else {
1024
+ return '100%'
1025
+ }
1026
+ }
1027
+ }
1028
+ },
1029
+ watch: {
1030
+ tagIds: {
1031
+ handler (value) {
1032
+ if (value && value.length) {
1033
+ // 在 pdf_view 下创建 所有canvs的容器
1034
+ this.contentView = document.createElement('div')
1035
+ this.contentView.setAttribute('id','contentView')
1036
+ this.contentView.style.transformOrigin = '0px 0px 0px'
1037
+ this.contentView.setAttribute('id','contentView');
1038
+
1039
+ this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res => {
1040
+ // 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}
1041
+ // res.data = {"data":[{"id":"64590ce1eb1320043401cc90","knowledgeId":"64590cd5017b461d67e282e1","mainId":"fb348d095c0b4fd7bbd37826563dac7d","page":2,"total":5,"pageHeight":841.8898,"pageWidth":595.30396,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/fb348d095c0b4fd7bbd37826563dac7d/2023/05/08/10/53/20/64590ce0eb1320043401cc7b/2.pdf","extractInfo":{"location":[89.32981,638.1907,415.15512,98.63251],"content":":北京地铁 13\r号线 :藤黄\r色 :西直门站—\r东直门站 :17 :41.\r5 :6\r准\rB :2002年\r09月\r28日 ","lines":[{"content":":北京地铁 13\r号线 ","location":[89.32981,638.1907,99.44599,98.63251]},{"content":":藤黄\r色 ","location":[188.7758,638.1907,46.79959,98.63251]},{"content":":西直门站—\r东直门站 ","location":[235.5754,638.1907,86.09996,98.63251]},{"content":":17 ","location":[321.67535,638.1907,36.200012,98.63251]},{"content":":41.\r5 ","location":[357.87537,638.1907,39.400696,98.63251]},{"content":":6\r准\rB ","location":[397.27606,638.1907,41.099,98.63251]},{"content":":2002年\r09月\r28日 ","location":[438.37506,638.1907,66.10986,98.63251]}],"tagId":null}}],"code":"0","msg":null,"traceId":null}
1042
+ // 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}
1043
+ // res.data = {"data":[{"id":"6475eab868110215ab821a80","knowledgeId":"6475e7eac724c54c46cbfa2d","mainId":"5ecf2fcd704541149201ab9c1c31162d","page":0,"total":1,"pageHeight":0.0,"pageWidth":0.0,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/5ecf2fcd704541149201ab9c1c31162d/2023/05/30/08/23/20/6475eab63339db423f26b196/0.html","extractInfo":{"location":null,"content":"产品:系统配置,产品型号:存储,VX30:4G+16G,VX50:16G+256G","lines":null,"tagId":"6475eab868110215ab821a80"}}],"code":"0","msg":null,"traceId":null}
1044
+ // res.data = {"data":[{"id":"6475e9393339db423f26af01","knowledgeId":"6475e44fc724c54c46cbfa21","mainId":"5ecf2fcd704541149201ab9c1c31162d","page":2,"total":2,"pageHeight":510.25,"pageWidth":1559.05,"publicPageFileUrl":"https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/5ecf2fcd704541149201ab9c1c31162d/2023/05/30/08/00/29/6475e55d3339db423f26a9b8/2.pdf","extractInfo":{"location":[327.70532,288.0498,414.9734,12.241608],"content":"三、指示灯状态说明1.白色常亮:开机/开机中2.红色常亮:待机3.白色呼吸:息屏4.红色闪烁:升级1.LAN:通过网线连接到主机的Camera端口2.电源开关:电源切换开关","lines":[{"content":"三、指示灯状态说明","location":[634.3203,288.0498,108.3584,12.0]},{"content":"1.白色常亮:开机/开机中","location":[634.3203,320.08978,108.23407,9.0]},{"content":"2.红色常亮:待机","location":[634.3204,341.3298,78.597046,9.0]},{"content":"3.白色呼吸:息屏","location":[634.32043,362.45282,78.597046,9.0]},{"content":"4.红色闪烁:升级","location":[634.3205,383.6928,78.597046,9.0]},{"content":"1.LAN:通过网线连接到主机的","location":[327.70535,291.2914,144.35995,9.0]},{"content":"Camera端口","location":[327.70532,306.88843,55.322998,9.0]},{"content":"2.电源开关:电源切换开关","location":[482.74832,291.2914,105.36301,9.0]}],"tagId":null}}],"code":"0","msg":null,"traceId":null}
1045
+ // if(value.length === 1) {
1046
+ // this.$refs.pdfView.style.height = 'calc(100% - 50px)'
1047
+ // }
1048
+ // res.data = {
1049
+ // "data": [
1050
+ // {
1051
+ // "id": "64e746120372d778849d2e8e",
1052
+ // "knowledgeId": "64e30035edffac0ec96a2d39",
1053
+ // "mainId": "e0f6898c6b0d47fa98e8f71ceab1bde8",
1054
+ // "page": 14,
1055
+ // "total": 60,
1056
+ // "pageHeight": 728.504,
1057
+ // "pageWidth": 515.906,
1058
+ // "publicPageFileUrl": "https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/e0f6898c6b0d47fa98e8f71ceab1bde8/2023/08/21/02/12/07/64e300378c3dfb3bc434f51a/15.pdf",
1059
+ // "extractInfo": {
1060
+ // "location": [
1061
+ // 52.665375,
1062
+ // 312.01306,
1063
+ // 404.98618,
1064
+ // 142.5199
1065
+ // ],
1066
+ // "content": null,
1067
+ // "lines": [
1068
+ // {
1069
+ // "content": null,
1070
+ // "location": [
1071
+ // 52.665375,
1072
+ // 312.01306,
1073
+ // 404.98618,
1074
+ // 142.5199
1075
+ // ]
1076
+ // }
1077
+ // ],
1078
+ // "tagId": null
1079
+ // },
1080
+ // "block": {
1081
+ // "type": "TEXT",
1082
+ // "location": [
1083
+ // 52.665375,
1084
+ // 312.01306,
1085
+ // 404.98618,
1086
+ // 142.5199
1087
+ // ],
1088
+ // "color": "#366AFF",
1089
+ // "flowChart": {
1090
+ // "content": ""
1091
+ // },
1092
+ // "image": {
1093
+ // "url": null,
1094
+ // "desc": ""
1095
+ // },
1096
+ // "table": {
1097
+ // "title": null,
1098
+ // "table": null
1099
+ // },
1100
+ // "text": {
1101
+ // "originText": "① 头部防护:安全帽\n佩戴要求:\n①存在坠物或对头部产生碰撞风险的作业场所需要佩戴安全帽 ;\n②安全帽必须戴正、戴牢、不能晃动,要系紧下颏带,调节好后箍以\n防安全帽脱落 ;\n③受强力撞击及超过有效期的安全帽必须更换。",
1102
+ // "indexText": "① 头部防护:安全帽\n佩戴要求:\n①存在坠物或对头部产生碰撞风险的作业场所需要佩戴安全帽 ;\n②安全帽必须戴正、戴牢、不能晃动,要系紧下颏带,调节好后箍以\n防安全帽脱落 ;\n③受强力撞击及超过有效期的安全帽必须更换。",
1103
+ // "lines": [
1104
+ // {
1105
+ // "location": [
1106
+ // 69.08148,
1107
+ // 368.92072,
1108
+ // 65.90851,
1109
+ // 10.5
1110
+ // ]
1111
+ // },
1112
+ // {
1113
+ // "location": [
1114
+ // 86.290985,
1115
+ // 384.67072,
1116
+ // 31.5,
1117
+ // 10.5
1118
+ // ]
1119
+ // },
1120
+ // {
1121
+ // "location": [
1122
+ // 286.2992,
1123
+ // 315.73584,
1124
+ // 37.656006,
1125
+ // 12.0
1126
+ // ]
1127
+ // },
1128
+ // {
1129
+ // "location": [
1130
+ // 324.6939,
1131
+ // 316.79932,
1132
+ // 122.74487,
1133
+ // 10.5
1134
+ // ]
1135
+ // },
1136
+ // {
1137
+ // "location": [
1138
+ // 286.2954,
1139
+ // 336.0458,
1140
+ // 149.625,
1141
+ // 10.5
1142
+ // ]
1143
+ // },
1144
+ // {
1145
+ // "location": [
1146
+ // 286.2954,
1147
+ // 356.0483,
1148
+ // 161.15405,
1149
+ // 10.5
1150
+ // ]
1151
+ // },
1152
+ // {
1153
+ // "location": [
1154
+ // 286.2954,
1155
+ // 376.0508,
1156
+ // 161.15405,
1157
+ // 10.5
1158
+ // ]
1159
+ // },
1160
+ // {
1161
+ // "location": [
1162
+ // 286.2954,
1163
+ // 396.0533,
1164
+ // 76.125,
1165
+ // 10.5
1166
+ // ]
1167
+ // },
1168
+ // {
1169
+ // "location": [
1170
+ // 286.2954,
1171
+ // 416.05582,
1172
+ // 161.17517,
1173
+ // 10.5
1174
+ // ]
1175
+ // },
1176
+ // {
1177
+ // "location": [
1178
+ // 286.2954,
1179
+ // 436.8038,
1180
+ // 52.5,
1181
+ // 10.5
1182
+ // ]
1183
+ // },
1184
+ // {
1185
+ // "location": [
1186
+ // 338.7992,
1187
+ // 435.73584,
1188
+ // 12.0,
1189
+ // 12.0
1190
+ // ]
1191
+ // }
1192
+ // ]
1193
+ // }
1194
+ // }
1195
+ // }
1196
+ // ],
1197
+ // "code": "0",
1198
+ // "msg": null,
1199
+ // "traceId": null
1200
+ // }
1201
+ if (res.data.code == 0) {
1202
+ // tagIds 会按照gpt识别的生成有序的数组,前端直接按照下标的顺序取就可以了
1203
+ // 缓存拿到的所有数据
1204
+ this.cachePdf = res.data.data
1205
+ let publicPageFileUrl = res.data.data && res.data.data[0] ? res.data.data[0].publicPageFileUrl : ''
1206
+ this.currentPage = 0
1207
+ if (publicPageFileUrl && publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')) === '.pdf') {
1208
+ this.preViewType = 'pdf'
1209
+ this.setPageAllLine(this.cachePdf)
1210
+ this.getpdfResloutePage(res.data.data[0])
1211
+ } else {
1212
+ this.preViewType = 'excal'
1213
+ this.$http.post(
1214
+ '/knowledge-api/temporary-certificate/or-origin?expired=30',
1215
+ publicPageFileUrl,
1216
+ {
1217
+ headers: {
1218
+ "Content-Type": "application/json",
1219
+ },
1220
+ }).then(res => {
1221
+ // 使用原声请求方式 axios会带有不需要的请求头
1222
+ let xhr = new XMLHttpRequest();
1223
+ xhr.open('GET', res.data || res.bodyText, true);
1224
+ // 定义请求完成的处理函数,请求前也可以增加加载框/禁用下载按钮逻辑
1225
+ xhr.onload = ({ currentTarget }) => {
1226
+ // 请求完成
1227
+ if (currentTarget.status === 200) { // 返回200
1228
+ let pdf_view = document.getElementsByClassName('pdf_view');
1229
+ if (pdf_view && pdf_view[0]){
1230
+ pdf_view[0].style.backgroundImage = 'none'
1231
+ }
1232
+ this.contentView.innerHTML = currentTarget.response
1233
+ this.contentView.style.padding = '10px'
1234
+ // this.contentView.style.position = 'relative'
1235
+ this.$refs.pdfView.style.backgroundColor = '#FFFFFF'
1236
+ this.$refs.pdfView.appendChild(this.contentView)
1237
+
1238
+ let allTr = Array.from(this.$refs.pdfView.getElementsByTagName('tr'))
1239
+ this.allTr = []
1240
+ for (let index = 0; index < allTr.length; index++) {
1241
+ if (value.includes(allTr[index].getAttribute('tag-id'))) {
1242
+ this.allTr.push(allTr[index])
1243
+ }
1244
+ }
1245
+ this.currentChange(1)
1246
+
1247
+ }
1248
+ }
1249
+ xhr.send();
1250
+ })
1251
+ }
1252
+ } else {
1253
+ let div = document.createElement('div')
1254
+ div.innerText = '文件加载异常'
1255
+ this.contentView.appendChild(div)
1256
+ this.$refs.pdfView.appendChild(this.contentView)
1257
+ }
1258
+ })
1259
+ }
1260
+ },
1261
+ deep: true,
1262
+ immediate: true
1263
+ }
1264
+ },
1265
+ mounted () {
1266
+ if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
1267
+ this.isPC = false
1268
+ } else {
1269
+ this.isPC = true
1270
+ }
1271
+ }
1272
+ }
1273
+ </script>
1274
+
1275
+ <style lang="less" scoped>
1276
+ .pdf_view {
1277
+ width: 100%;
1278
+ height: calc(100% - 110px);
1279
+ overflow: auto;
1280
+ //overflow-y: scroll;
1281
+ background-color: #f5f7fb;
1282
+ // margin-bottom: 60px;
1283
+ box-sizing: border-box;
1284
+ background-image: url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif');
1285
+ background-position: center;
1286
+ background-size: 50px;
1287
+ background-repeat: no-repeat;
1288
+ // position: relative;
1289
+ // > div {
1290
+ // width: 100%;
1291
+ // height: 100%;
1292
+ // overflow: hidden;
1293
+ // overflow-y: auto;
1294
+ // position: relative;
1295
+ // }
1296
+ >iframe {
1297
+ width: 100%;
1298
+ height: 100%;
1299
+ }
1300
+
1301
+ a:link {
1302
+ color: none;
1303
+ }
1304
+
1305
+ a:visited {
1306
+ color: none;
1307
+ }
1308
+
1309
+ a:hover {
1310
+ color: none;
1311
+ }
1312
+
1313
+ a:active {
1314
+ color: none;
1315
+ }
1316
+ .btn_footer {
1317
+ width: 100%;
1318
+ height: 60px;
1319
+ display: flex;
1320
+ align-items: center;
1321
+ justify-content: space-around;
1322
+ position: absolute;
1323
+ bottom: 0px;
1324
+ left: 0;
1325
+ z-index: 999;
1326
+ background: #ffffff;
1327
+
1328
+ .prev,
1329
+ .next {
1330
+ width: 35%;
1331
+ height: 40px;
1332
+ display: flex;
1333
+ align-items: center;
1334
+ justify-content: center;
1335
+ border-radius: 50px;
1336
+ cursor: pointer;
1337
+ }
1338
+
1339
+ .prev {
1340
+ background: #F2F5FA;
1341
+ color: #000;
1342
+ }
1343
+
1344
+ .next {
1345
+ background: #366aff;
1346
+ color: #ffffff;
1347
+ }
1348
+ }
1349
+
1350
+ #pagination {
1351
+ .total-class {
1352
+ margin-right: 13px;
1353
+ font-weight: 400;
1354
+ }
1355
+
1356
+ position: absolute;
1357
+ bottom: 0px;
1358
+ right: 0;
1359
+ width: 100%;
1360
+ display: flex;
1361
+ align-items: center;
1362
+ justify-content: center;
1363
+ height: 50px;
1364
+ background-color: white;
1365
+ box-shadow: 0px 0px 18px 0px rgba(29, 55, 129, 0.07);
1366
+ border-radius: 5px;
1367
+ z-index: 1000;
1368
+
1369
+
1370
+
1371
+ /deep/.el-pagination {
1372
+ margin-right: 110px;
1373
+ }
1374
+
1375
+ /deep/.el-pager {
1376
+ background: #EDF0F6;
1377
+ border-radius: 15px;
1378
+ }
1379
+
1380
+ /deep/.el-pagination.is-background .btn-next {
1381
+ width: 30px;
1382
+ height: 30px;
1383
+ background: #EDF0F6;
1384
+ border-radius: 50%;
1385
+ }
1386
+
1387
+ /deep/.el-pagination .btn-next {
1388
+ width: 30px;
1389
+ height: 30px;
1390
+ background: #EDF0F6;
1391
+ border-radius: 50%;
1392
+ padding-left: 0;
1393
+ margin-left: 5px;
1394
+ }
1395
+
1396
+ /deep/.el-pagination .btn-prev {
1397
+ width: 30px;
1398
+ height: 30px;
1399
+ background: #EDF0F6;
1400
+ border-radius: 50%;
1401
+ padding-right: 0;
1402
+ margin-right: 5px;
1403
+ }
1404
+
1405
+ /deep/.el-pagination button {
1406
+ padding: 0;
1407
+ min-width: 30px;
1408
+ }
1409
+
1410
+ /deep/.el-pager li {
1411
+ background: #EDF0F6;
1412
+ height: 30px;
1413
+ min-width: 30px;
1414
+ line-height: 30px;
1415
+ font-size: 12px;
1416
+ color: #717b90;
1417
+ }
1418
+
1419
+ /deep/.el-pager li:first-child {
1420
+ border-bottom-left-radius: 15px !important;
1421
+ border-top-left-radius: 15px !important;
1422
+ }
1423
+
1424
+ /deep/.el-pager li:last-child {
1425
+ border-top-right-radius: 15px !important;
1426
+ border-bottom-right-radius: 15px !important;
1427
+ }
1428
+
1429
+ /deep/.el-pager li.active {
1430
+ width: 30px;
1431
+ height: 30px;
1432
+ min-width: 30px;
1433
+ background: #366AFF;
1434
+ border: 3px solid #A1B9FF;
1435
+ border-radius: 50%;
1436
+ line-height: 24px;
1437
+ color: white;
1438
+ }
1439
+
1440
+ /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
1441
+ background: #366AFF;
1442
+ }
1443
+ }
1444
+
1445
+ .change_scale {
1446
+ width: 100%;
1447
+ height: 50px;
1448
+ position: absolute;
1449
+ top: 50px;
1450
+ left: 0;
1451
+ background: #ffffff;
1452
+ display: flex;
1453
+ align-items: center;
1454
+ padding: 0 10px;
1455
+ box-sizing: border-box;
1456
+
1457
+ section {
1458
+ cursor: pointer;
1459
+ width: 30px;
1460
+ height: 30px;
1461
+ margin-right: 5px;
1462
+ border-radius: 5px;
1463
+ display: flex;
1464
+ align-items: center;
1465
+ justify-content: center;
1466
+
1467
+ i {
1468
+ font-weight: 900;
1469
+ }
1470
+ }
1471
+
1472
+ section:hover {
1473
+ background: rgba(221, 222, 223, 1);
1474
+ }
1475
+ }
1476
+ .pdf_container_view{
1477
+ height: 100%;
1478
+ width: 100%;
1479
+ position: relative;
1480
+ overflow: auto;
1481
+ }
1482
+ }
1483
+ </style>
1484
+ <style lang="less">
1485
+ .animation {
1486
+ animation-name: highlight;
1487
+ animation-duration: 4s;
1488
+ }
1489
+
1490
+ @keyframes highlight {
1491
+ 0% {
1492
+ background: rgba(255, 136, 0, 0.3);
1493
+ }
1494
+
1495
+ 25% {
1496
+ background: rgba(255, 136, 0, 0.6);
1497
+ }
1498
+
1499
+ 50% {
1500
+ background: rgba(255, 136, 0, 0.3);
1501
+ }
1502
+
1503
+ 75% {
1504
+ background: rgba(255, 136, 0, 0.6);
1505
+ }
1506
+
1507
+ 100% {
1508
+ background: rgba(255, 136, 0, 0.3);
1509
+ }
1510
1510
  }</style>