askbot-dragon 1.6.75-beta → 1.6.77-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 +55 -55
  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 -252
  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 +1059 -1059
  23. package/src/components/AnswerVoice.vue +285 -285
  24. package/src/components/AskIFrame.vue +15 -15
  25. package/src/components/ConversationContainer.vue +4934 -4934
  26. package/src/components/FileType.vue +86 -86
  27. package/src/components/Message.vue +27 -27
  28. package/src/components/MyEditor.vue +351 -351
  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 +227 -227
  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 +1508 -1506
  61. package/src/components/popup.vue +227 -227
  62. package/src/components/previewDoc.vue +247 -247
  63. package/src/components/previewPdf.vue +788 -833
  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 +340 -340
  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,1139 +1,1139 @@
1
- <template>
2
- <div class="pdf_view" ref="pdfView" @scroll="pdfScroll" :style="{
3
- marginTop: isPC ? '50px' : '',
4
- marginBottom: tagIds.length > 1 ? '60px' : '0px',
5
- height: setHeight
6
- }">
7
-
8
- <div class="btn_footer" v-if="tagIds.length > 1 && !isPC">
9
- <div class="prev" @click="prev">上一段</div>
10
- <div class="next" @click="next">下一段</div>
11
- </div>
12
- <div id="pagination" v-if="tagIds.length > 1 && isPC">
13
- <el-pagination :current-page="currentPage + 1" @current-change="currentChange" @prev-click="prev"
14
- @next-click="next" layout="slot, prev, pager, next" :page-size="1" :total="tagIds.length">
15
- <span class="total-class">答案由{{ tagIds.length }}段内容生成</span>
16
- </el-pagination>
17
- </div>
18
- </div>
19
- </template>
20
-
21
- <script>
22
- import _ from 'lodash'
23
- // import * as pdfjsLib from 'pdfjs-dist'
24
- // pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker';
25
- // import { TextLayerBuilder } from "pdfjs-dist/web/pdf_viewer";
26
- // EventBus pdf_viewer 支持绑定自定义事件,一版不做
27
- // import 'pdfjs-dist/web/pdf_viewer.css'
28
- /* eslint-disable */
29
- const pdfjsLib = window['pdfjsLib']
30
- if (pdfjsLib) {
31
- pdfjsLib.GlobalWorkerOptions.workerSrc = window['pdfjs-dist/build/pdf.worker']
32
- // 'pdfjs-dist/build/pdf.worker';
33
- }
34
- const { TextLayerBuilder } = window['pdfjs-dist/web/pdf_viewer']
35
- // import { zoomElement } from '../assets/js/hammer'
36
- export default {
37
- name: 'pdfView',
38
- props: ['tagIds', 'isMessageRecord'],
39
- data () {
40
- return {
41
- url: '',
42
- pages: [],
43
- pageLoadStatus: {
44
- WAIT: 0,
45
- LOADED: 1,
46
- },
47
- scale: 1,
48
- rotation: 0,
49
- pageSize: {},
50
- PAGE_INTVERVAL: 15,
51
- SLICE_COUNT: 5,
52
- contentView: null,
53
- fisrtLoad: true,
54
- TextLayerBuilder: null,
55
- totalPageCount: 0,
56
- identifyTextPostion: {
57
- top: 0,
58
- left: 0,
59
- width: 100,
60
- height: 0,
61
- page: 1,
62
- pageHeight: 0,
63
- pageWidth: 0,
64
- extractInfo: {},
65
- currentPageAllLine: []
66
- },
67
- currentPageAllLine: [],
68
- pdfUrl: '',
69
- cachePdf: [],
70
- newViewer: null,
71
- currentPage: 0,
72
- changetoolbar: false,
73
- allTr: [],
74
- preViewType: 'pdf',
75
- displacement: {
76
- pageX: 0,
77
- pageY: 0,
78
- moveable: false,
79
- pageX2: 0,
80
- pageY2: 0,
81
- originScale: 1,
82
- },
83
- isTouchMoved: false,
84
- transformSalce: null,
85
- isPC: false,
86
- handScale: 'auto',
87
- scaleList: [
88
- {
89
- label: '自动缩放',
90
- value: 'auto'
91
- },
92
- {
93
- label: '实际比例',
94
- value: 'reality'
95
- },
96
- {
97
- label: '100%',
98
- value: 1
99
- },
100
- {
101
- label: '120%',
102
- value: 1.2
103
- },
104
- {
105
- label: '150%',
106
- value: 1.5
107
- },
108
- {
109
- label: '170%',
110
- value: 1.7
111
- }
112
- ,
113
- {
114
- label: '200%',
115
- value: 2
116
- }
117
- ],
118
- scrollTop: 0,
119
- scrollLeft: 0
120
- }
121
- },
122
- methods: {
123
- getpdfResloutePage (pdfResloute) {
124
- // 根据当前页面宽度设置缩放比例
125
- // this.scale = Math.round(this.$refs.pdfView.clientWidth / pdfResloute.pageWidth * 100) / 100
126
- // console.log(this.scale,'this.scale');
127
- if (this.isMessageRecord) {
128
- this.scale = Math.round(this.$refs.pdfView.clientWidth / pdfResloute.pageWidth * 100) / 100
129
- } else {
130
- this.scale = 2
131
- }
132
- // 从后端获取到当前分片后所有的pdf页码,初始化数组,数组下{} 对应每页pdf文件
133
- this.pdfUrl = pdfResloute.publicPageFileUrl.substring(0, pdfResloute.publicPageFileUrl.lastIndexOf('/') + 1)
134
- this.initPages(pdfResloute.total)
135
- // 定位功能,加载对应页码位置
136
- this.loadPdfData(pdfResloute.page)
137
- },
138
- async loadPdfData (loadPage) {
139
- if (this.pages[loadPage - 1] && ((this.pages[loadPage - 1].dom && this.pages[loadPage - 1].dom.children.length > 0) || this.pages[loadPage - 1].loading)) {
140
- return
141
- }
142
- this.pages[loadPage - 1].loading = true
143
- // pdfjsLib.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/legacy/build/pdf.worker.entry.js");
144
- // 拿到第一个分片
145
- const { startPage, url } = await this.fetchPdfFragment(loadPage);
146
- let loadingTask = pdfjsLib.getDocument(url)
147
- loadingTask.promise.then((pdfDoc) => {
148
- // 将已经下载的分片保存到 pages 数组中
149
- for (let i = 0; i < pdfDoc.numPages; i += 1) {
150
- const pageIndex = startPage + i;
151
- const page = this.pages[pageIndex - 1];
152
- // 不在缓存列表内,重新获取本页pdf
153
- if (page.loadStatus !== this.pageLoadStatus.LOADED) {
154
- pdfDoc.getPage(i + 1).then((pdfPage) => {
155
- page.pdfPage = pdfPage;
156
- page.loadStatus = this.pageLoadStatus.LOADED;
157
- // 通知可以进行渲染了
158
- this.startRenderPages(pdfPage, page, pageIndex)
159
- });
160
- } else {
161
- if (this.changetoolbar) {
162
- this.$nextTick(() => {
163
- this.renderHighlights()
164
- })
165
- this.changetoolbar = false
166
- }
167
- }
168
- }
169
- });
170
- },
171
- initPages (totalPage) {
172
- // const pages = [];
173
- this.totalPageCount = totalPage
174
- for (let i = 0; i < totalPage; i += 1) {
175
- this.pages.push({
176
- pageNo: i + 1,
177
- loadStatus: this.pageLoadStatus.WAIT,
178
- pdfPage: null,
179
- dom: null
180
- });
181
- }
182
- },
183
- async fetchPdfFragment (pageIndex) {
184
- // 置换加签后的文件地址。
185
- let obj = {}
186
- await this.$http.post(
187
- '/knowledge-api/temporary-certificate/or-origin?expired=30',
188
- 'https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/fb348d095c0b4fd7bbd37826563dac7d/2023/05/08/11/55/18/64591b638bb8ab1b91c65eed/3.pdf',
189
- {
190
- headers: {
191
- "Content-Type": "application/json",
192
- },
193
- }).then(async res => {
194
- if (res.bodyText) {
195
- // 最后返回一个 包含这4个参数的对象
196
- obj = await {
197
- "startPage": pageIndex, // 分片的开始页码
198
- "endPage": pageIndex + 5, // 分片结束页码
199
- "totalPage": this.totalPageCount, // pdf 总页数
200
- "url": res.bodyText // 分片内容下载地址
201
- }
202
- }
203
- if (res.data) {
204
- // 最后返回一个 包含这4个参数的对象
205
- obj = await {
206
- "startPage": pageIndex, // 分片的开始页码
207
- "endPage": pageIndex + 5, // 分片结束页码
208
- "totalPage": this.totalPageCount, // pdf 总页数
209
- "url": res.data // 分片内容下载地址
210
- }
211
- }
212
- })
213
- return obj
214
- },
215
- startRenderPages (pdfPage, page, pageIndex) {
216
- if (Object.keys(this.pageSize).length == 0) {
217
- const viewport = pdfPage.getViewport({
218
- scale: this.scale, // 缩放的比例
219
- rotation: this.rotation, // 旋转的角度
220
- });
221
- // 记录pdf页面高度
222
- const pageSize = {
223
- width: viewport.width,
224
- height: viewport.height,
225
- }
226
- this.pageSize = pageSize
227
- // 创建内容绘制区,并设置大小
228
- if (this.$refs.pdfView.clientWidth / this.pageSize.width >= 1 || this.isMessageRecord) {
229
- this.contentView.style.width = `${pageSize.width - 10}px`;
230
- this.contentView.style.height = `${(this.totalPageCount * (pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
231
- } else {
232
- this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
233
- this.contentView.style.width = `${pageSize.width * this.transformSalce - 10}px`;
234
- this.contentView.style.height = `${(this.totalPageCount * (pageSize.height * (this.transformSalce) + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
235
- }
236
- this.contentView.style.margin = '0 auto 0'
237
- this.contentView.style.position = 'relative'
238
- this.contentView.style.paddingBottom = '60px'
239
- // contentView.style.overflowY = 'auto'
240
- this.$refs.pdfView.appendChild(this.contentView);
241
- }
242
- this.renderPages(pageIndex)
243
- },
244
- renderPageContent (page, pageIndex) {
245
- const { pdfPage, pageNo, dom } = page;
246
- // dom 元素已存在,无须重新渲染,直接返回
247
- if (dom && dom.children.length != 0) {
248
- return;
249
- }
250
- const viewport = pdfPage.getViewport({
251
- scale: this.scale,
252
- rotation: this.rotation,
253
- });
254
- // 创建新的canvas
255
- const canvas = document.createElement('canvas');
256
- const context = canvas.getContext('2d');
257
- // canvas.getContext('2d');
258
- canvas.height = this.pageSize.height;
259
- canvas.width = this.pageSize.width;
260
- // 创建渲染的dom
261
- const pageDom = document.createElement('div');
262
- pageDom.style.position = 'absolute';
263
- pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
264
- pageDom.style.width = `${this.pageSize.width}px`;
265
- pageDom.style.height = `${this.pageSize.height}px`;
266
- pageDom.appendChild(canvas);
267
- // 渲染内容
268
- let renderContext = {
269
- canvasContext: context,
270
- viewport: viewport,
271
- }
272
- pdfPage.render(renderContext).promise.then(() => {
273
- console.log(pdfPage.getTextContent(), 'getTextContent');
274
- return pdfPage.getTextContent()
275
- }).then((textContent) => {
276
- const textLayerDiv = document.createElement('div');
277
- textLayerDiv.setAttribute('class', 'textLayer');
278
- // 将文本图层div添加至每页pdf的div中
279
- // 创建新的TextLayerBuilder实例
280
- let textLayer = new TextLayerBuilder({
281
- textLayerDiv: textLayerDiv,
282
- pageIndex: pdfPage._pageIndex,
283
- viewport: viewport,
284
- });
285
- let findPage = this.currentPageAllLine.find(l => { return l.page == pageIndex })
286
- let rectdomTop = 0
287
- if (findPage) {
288
- let AllLines = findPage.allLines
289
- // setTimeout(() => {
290
- console.log(findPage, 'findPage');
291
- if (AllLines.length > 0) {
292
- for (let j = 0; j < AllLines.length; j++) {
293
- let lines = AllLines[j].lines
294
- let rectdom = document.createElement('div')
295
- rectdom.setAttribute('react-count', AllLines[j].pageCount);
296
- rectdom.style.position = 'absolute';
297
- rectdom.style.top = 0
298
- rectdom.style.left = 0
299
- rectdom.classList.add('rectdom')
300
- for (let index = 0; index < lines.length; index++) {
301
- if (!/^\s+$/g.test(lines[index].content)) {
302
- let postionArr = lines[index].location
303
- let div = document.createElement('div')
304
- div.style.position = 'absolute';
305
- div.style.left = postionArr[0] * this.scale + 'px',
306
- // 后端返回的坐标有基线对齐的问题,top 值是后端算好(基线top - 文字高度),在此加上文字高度的 1/9 (大致比例)为实际展示出文字的top值
307
- div.style.top = (postionArr[1] + postionArr[3] / 9) * this.scale + 'px'
308
- div.style.height = postionArr[3] * this.scale + 'px';
309
- div.style.width = postionArr[2] * this.scale + 'px'
310
- div.style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
311
- div.classList.add('lineHeight')
312
- rectdom.appendChild(div)
313
- if (index == 0 && j == 0) {
314
- if (this.transformSalce !== null) {
315
- rectdomTop = (postionArr[1] + postionArr[3] / 9) * this.scale * this.transformSalce
316
- } else {
317
- rectdomTop = (postionArr[1] + postionArr[3] / 9) * this.scale
318
- }
319
- // if(this.isPC) {
320
- // rectdomTop = rectdomTop - 50 < 0 ? 0 : rectdomTop - 50
321
- // }
322
- // console.log(rectdomTop,div.style.top, (postionArr[1] + postionArr[3] / 9) * this.scale);
323
- }
324
- }
325
- }
326
- if (rectdom.children.length > 0) {
327
- pageDom.appendChild(rectdom)
328
- }
329
- }
330
- }
331
- }
332
- textLayer.setTextContent(textContent);
333
- textLayer.render()
334
- pageDom.appendChild(textLayer.textLayerDiv);
335
- page.dom = pageDom;
336
- page.loading = false
337
- this.contentView.appendChild(pageDom);
338
- if (this.transformSalce !== null) {
339
- this.contentView.style.transform = `scale(${this.transformSalce}, ${this.transformSalce})`
340
- }
341
- if (this.changetoolbar) {
342
- setTimeout(() => {
343
- this.renderHighlights()
344
- this.changetoolbar = false
345
- }, 100)
346
- }
347
- // console.log(this.fisrtLoad,'this.fisrtLoad');
348
- if (this.fisrtLoad) {
349
- setTimeout(() => {
350
- let pageoffsetHeight = 0
351
- if (this.transformSalce !== null) {
352
- pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce
353
- } else {
354
- pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL)
355
- }
356
- if (this.$refs.pdfView.clientHeight - pageoffsetHeight > 0 && pageIndex == 1) {
357
- const height = this.$refs.pdfView.clientHeight;
358
- let startNum = 0
359
- let endNum = 0
360
- if (this.transformSalce !== null) {
361
- startNum = Math.ceil(this.$refs.pdfView.scrollTop / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
362
- endNum = startNum + Math.ceil(height / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
363
- console.log(Math.ceil(height / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce)), this.pageSize.height, this.PAGE_INTVERVAL, height, this.transformSalce, 'startNum');
364
-
365
- } else {
366
- startNum = Math.ceil(this.$refs.pdfView.scrollTop / (this.pageSize.height + this.PAGE_INTVERVAL))
367
- endNum = startNum + Math.ceil(height / (this.pageSize.height + this.PAGE_INTVERVAL))
368
-
369
- }
370
- for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
371
- if (pageIndex > 0 && pageIndex <= this.pages.length) {
372
- this.loadPdfData(pageIndex)
373
- }
374
- }
375
- }
376
- if (this.$refs.pdfView.scrollTop == Math.floor((pageNo - 1) * pageoffsetHeight)) {
377
- this.$refs.pdfView.scrollTop = rectdomTop
378
- this.fisrtLoad = false
379
- } else {
380
- this.$refs.pdfView.scrollTop = `${((pageNo - 1) * pageoffsetHeight) + rectdomTop - this.PAGE_INTVERVAL}`
381
- this.fisrtLoad = false
382
- }
383
- this.renderHighlights()
384
- // zoomElement(this.contentView)
385
- }, 100)
386
- }
387
- })
388
- },
389
- // 监听容器的滚动事件,触发 scrollPdf 方法
390
- // 这里加了防抖保证不会一次产生过多请求
391
- debounceScrollPdf: _.debounce(function (e, that) {
392
- if (this.fisrtLoad) {
393
- this.fisrtLoad = false
394
- return
395
- }
396
- const scrollTop = e.target.scrollTop;
397
- const height = e.target.clientHeight;
398
- let startNum = 0
399
- let endNum = 0
400
- if (this.transformSalce !== null) {
401
- startNum = Math.ceil(scrollTop / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
402
- endNum = startNum + Math.ceil(height / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
403
- } else {
404
- startNum = Math.ceil(scrollTop / (that.pageSize.height + that.PAGE_INTVERVAL))
405
- endNum = startNum + Math.ceil(height / (that.pageSize.height + that.PAGE_INTVERVAL))
406
- }
407
- for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
408
- if (pageIndex > 0 && pageIndex <= that.pages.length) {
409
- that.loadPdfData(pageIndex)
410
- }
411
- }
412
- console.log('=======');
413
- }, 200),
414
- directScrolling (e, that) {
415
- if (this.fisrtLoad) {
416
- this.fisrtLoad = false
417
- return
418
- }
419
- const scrollTop = e.target.scrollTop;
420
- const height = e.target.clientHeight;
421
- // 根据内容可视区域中心点计算页码, 没有滚动时,指向第一页
422
- const pageIndex = scrollTop > 0 ?
423
- Math.ceil((scrollTop + (height / 2)) / (that.pageSize.height + that.PAGE_INTVERVAL)) :
424
- 1;
425
- this.loadPdfData(pageIndex)
426
- },
427
- pdfScroll (e) {
428
- if (this.preViewType !== 'pdf' || this.isTouchMoved) {
429
- return
430
- }
431
- if (this.scrollLeft != e.target.scrollLeft) {
432
- this.scrollLeft = e.target.scrollLeft
433
- }
434
- if (this.scrollTop != e.target.scrollTop) {
435
- this.scrollTop = e.target.scrollTop
436
- this.debounceScrollPdf(e, this)
437
- }
438
- },
439
- // 分片每次只做一次处理,所以不考虑多片情况
440
- loadBefore (pageIndex) {
441
- this.loadPdfData(pageIndex)
442
- },
443
- loadAfter (pageIndex) {
444
- this.loadPdfData(pageIndex)
445
- },
446
- // 首先我们获取到需要渲染的范围
447
- // 根据当前的可视范围内的页码,我们前后只保留 8 页
448
- getRenderScope (pageIndex) {
449
- const pagesToRender = [];
450
- let i = pageIndex - 1;
451
- let j = pageIndex + 1;
452
- // pageIndex - 1 表示当前页码数 对应的下标位置
453
- pagesToRender.push(this.pages[pageIndex - 1]);
454
- while (pagesToRender.length < 8 && pagesToRender.length < this.pages.length) {
455
- if (i > 0) {
456
- pagesToRender.push(this.pages[i - 1]);
457
- i -= 1;
458
- }
459
- if (pagesToRender.length >= 8) {
460
- break;
461
- }
462
- if (j <= this.pages.length) {
463
- pagesToRender.push(this.pages[j - 1]);
464
- j += 1;
465
- }
466
- }
467
- return pagesToRender;
468
- },
469
- // 渲染需要展示的页面,不需展示的页码将其清除
470
- renderPages (pageIndex) {
471
- const pagesToRender = this.getRenderScope(pageIndex);
472
- for (const i of this.pages) {
473
- if (pagesToRender.includes(i)) {
474
- i.loadStatus === this.pageLoadStatus.LOADED ?
475
- this.renderPageContent(i, pageIndex) :
476
- this.renderPageLoading(i);
477
- } else {
478
- this.clearPage(i);
479
- }
480
- }
481
- },
482
- // 清除页面 dom
483
- clearPage (page) {
484
- if (page.dom) {
485
- this.contentView.removeChild(page.dom);
486
- page.loadStatus = 0
487
- page.loading = false
488
- page.dom = undefined;
489
- }
490
- },
491
- // 页面正在下载时渲染loading视图
492
- renderPageLoading (page) {
493
- const { pageNo, dom } = page;
494
- if (dom && dom.children.length != 0) {
495
- return;
496
- }
497
- const pageDom = document.createElement('div');
498
- pageDom.style.width = `${this.pageSize.width}px`;
499
- pageDom.style.height = `${this.pageSize.height}px`;
500
- pageDom.style.position = 'absolute';
501
- pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL
502
- }px`;
503
- pageDom.style.backgroundImage = `url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif')`
504
- pageDom.style.backgroundPosition = 'center'
505
- pageDom.style.backgroundRepeat = 'no-repeat'
506
- pageDom.style.backgroundColor = '#FFF'
507
- page.dom = pageDom;
508
- this.contentView.appendChild(pageDom);
509
- },
510
- prev () {
511
- this.currentPage--
512
- if (this.currentPage < 0) {
513
- this.currentPage = 0
514
- if (!this.isPC) {
515
- this.$toast({
516
- message: '当前已经是第一段了',
517
- duration: 2000,
518
- })
519
- return
520
- }
521
- }
522
- if (this.preViewType == 'pdf') {
523
- this.scrollToUplaodePage(this.currentPage)
524
- } else {
525
- this.scrollToExcalTop(this.currentPage)
526
- }
527
- // this.getpdfResloutePage(this.cachePdf[this.currentPage - 1])
528
- },
529
- next () {
530
- this.currentPage++
531
- if (this.currentPage >= this.tagIds.length) {
532
- this.currentPage = this.tagIds.length - 1
533
- if (!this.isPC) {
534
- this.$toast({
535
- message: '当前已经是最后一段了',
536
- duration: 2000,
537
- })
538
- return
539
- }
540
- }
541
- if (this.preViewType == 'pdf') {
542
- this.scrollToUplaodePage(this.currentPage)
543
- } else {
544
- this.scrollToExcalTop(this.currentPage)
545
- }
546
- },
547
- currentChange (value) {
548
- this.currentPage = value - 1
549
- if (this.preViewType == 'pdf') {
550
- this.scrollToUplaodePage(this.currentPage)
551
- } else {
552
- this.scrollToExcalTop(this.currentPage)
553
- }
554
- },
555
- scrollToUplaodePage (currentPage) {
556
- this.changetoolbar = true
557
- if (this.preViewType !== 'pdf') {
558
- return
559
- }
560
-
561
- let pdfResloute = this.cachePdf[currentPage]
562
- this.identifyTextPostion.extractInfo = pdfResloute.extractInfo
563
- this.identifyTextPostion.left = pdfResloute.extractInfo.location[0]
564
- this.identifyTextPostion.top = pdfResloute.extractInfo.location[1]
565
- this.identifyTextPostion.width = pdfResloute.extractInfo.location[2]
566
- this.identifyTextPostion.height = pdfResloute.extractInfo.location[3]
567
- this.identifyTextPostion.page = pdfResloute.page
568
- this.identifyTextPostion.pageHeight = pdfResloute.pageHeight
569
- this.identifyTextPostion.pageWidth = pdfResloute.pageWidth
570
- // 在当前段落在最后一页pdf时,根据计算的高度并不能触发滚动,在此执行重新渲染方法,非次情况会执行两次,待优化
571
- this.$nextTick(() => {
572
- this.renderHighlights()
573
- })
574
- if (this.transformSalce !== null) {
575
- this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce) + this.identifyTextPostion.top}`
576
- } else {
577
- this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.identifyTextPostion.top}`
578
- }
579
- },
580
- scrollToExcalTop (currentPage) {
581
- for (let index = 0; index < this.allTr.length; index++) {
582
- if (index == currentPage) {
583
- Array.from(this.allTr[index].children).forEach(item => {
584
- item.style.background = 'rgba(255, 136, 0, 0.6)'
585
- item.classList.add('animation')
586
- setTimeout(() => {
587
- item.classList.remove('animation')
588
- }, 4000)
589
- })
590
- // getBoundingClientRect().top 当前元素距离屏幕顶部的高度 + 弹窗header 高度
591
- if (!this.isPC) {
592
- let top = this.allTr[index].getBoundingClientRect().top - this.$refs.pdfView.getBoundingClientRect().top
593
- this.$refs.pdfView.scrollTop = top
594
- } else {
595
- let top = this.allTr[index].getBoundingClientRect().top
596
- this.$refs.pdfView.scrollTop = top - 50
597
- }
598
- } else {
599
- Array.from(this.allTr[index].children).forEach(item => {
600
- item.style.background = 'rgba(54, 106, 255, 0.6)'
601
- item.classList.remove('animation')
602
- })
603
- }
604
- }
605
- },
606
- // pdf是否需要重新渲染高亮位置
607
- renderHighlights () {
608
- let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
609
- console.log(lineHeightDom, this.currentPage, 'this.currentPage');
610
- if (lineHeightDom) {
611
- lineHeightDom.forEach((d) => {
612
- for (let i = 0; i < d.children.length; i++) {
613
- if (d.getAttribute('react-count') == this.currentPage) {
614
- d.children[i].style.backgroundColor = 'rgba(255, 136, 0, 0.3)'
615
- d.children[i].classList.add('animation')
616
- setTimeout(() => {
617
- d.children[i].classList.remove('animation')
618
- }, 4000)
619
- } else {
620
- d.children[i].style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
621
- d.children[i].classList.remove('animation')
622
- }
623
- }
624
- })
625
- }
626
- },
627
- displayHiglight (pageIndex) {
628
- let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
629
- if (lineHeightDom) {
630
- lineHeightDom.forEach((d) => {
631
- if (d.getAttribute('page-index') == pageIndex) {
632
- d.style.display = 'none'
633
- }
634
- })
635
- }
636
- },
637
- // 前端暂时缓存多页
638
- autoLoadMore (pageIndex) {
639
- let pdfResloute = this.cachePdf.find(cache => {
640
- return cache.page == pageIndex
641
- })
642
- if (pdfResloute) {
643
- this.getpdfResloutePage(pdfResloute)
644
- } else {
645
- this.loadPdfData(pageIndex)
646
- }
647
- },
648
- setPageAllLine (arr) {
649
- this.currentPageAllLine = []
650
- arr.forEach((item, index) => {
651
- let i = this.currentPageAllLine.findIndex(l => { return l.page && l.page == item.page })
652
- if (i != -1) {
653
- // this.currentPageAllLine[i].allLines.lines.push(item.extractInfo.lines)
654
- this.currentPageAllLine[i].allLines.push({
655
- pageCount: index,
656
- lines: item.extractInfo.lines
657
- })
658
- } else {
659
- this.currentPageAllLine.push({
660
- page: item.page,
661
- allLines: [{
662
- pageCount: index,
663
- lines: item.extractInfo.lines
664
- }],
665
- })
666
- }
667
- })
668
- },
669
- openTouch () {
670
- // this.$nextTick()将回调延迟到下次 DOM 更新循环之后执行
671
- let that = this;
672
- this.$nextTick(() => {
673
- // setInterval(() => {
674
- // this.scale = this.scale + 0.1
675
- // that.pages.forEach((item, index) =>{
676
- // if(item.dom) {
677
- // item.dom.children.forEach( childDom =>{
678
- // if(childDom.getAttribute('react-count')) {
679
- // childDom.style.transform = "scale(" + this.scale + ")";
680
- // childDom.style.transformOrigin = "0px 0px 0px";
681
- // } else {
682
- // item.dom = null
683
- // this.startRenderPages(item.pdfPage, null, index)
684
- // }
685
- // } )
686
- // }
687
- // })
688
- // }, 100);
689
- // 获取放大或缩小的区域DOM
690
- let matrix_box = this.contentView
691
- matrix_box.addEventListener("touchstart", function (event) {
692
- this.isTouchMoved = true
693
- let touches = event.touches;
694
- let events = touches[0];
695
- let events2 = touches[1];
696
-
697
- // event.preventDefault();
698
-
699
- // 第一个触摸点的坐标
700
- that.displacement.pageX = events.pageX;
701
- that.displacement.pageY = events.pageY;
702
-
703
- that.displacement.moveable = true;
704
-
705
- if (events2) {
706
- that.displacement.pageX2 = events2.pageX;
707
- that.displacement.pageY2 = events2.pageY;
708
- }
709
-
710
- that.displacement.originScale = this.scale || 1;
711
- // console.log(that.displacement);
712
- });
713
- document.addEventListener("touchmove", function (event) {
714
- if (!that.displacement.moveable) {
715
- return;
716
- }
717
- // event.preventDefault();
718
- let touches = event.touches;
719
- let events = touches[0];
720
- let events2 = touches[1];
721
- // 双指移动
722
- if (events2) {
723
- // 第2个指头坐标在touchmove时候获取
724
- if (!that.displacement.pageX2) {
725
- that.displacement.pageX2 = events2.pageX;
726
- }
727
- if (!that.displacement.pageY2) {
728
- that.displacement.pageY2 = events2.pageY;
729
- }
730
- // 双指缩放比例计算
731
- let zoom = that.getDistance({
732
- x: events.pageX,
733
- y: events.pageY
734
- },
735
- {
736
- x: events2.pageX,
737
- y: events2.pageY
738
- }
739
- ) / that.getDistance(
740
- {
741
- x: that.displacement.pageX,
742
- y: that.displacement.pageY
743
- },
744
- {
745
- x: that.displacement.pageX2,
746
- y: that.displacement.pageY2
747
- }
748
- );
749
- // 应用在元素上的缩放比例
750
- let newScale = that.displacement.originScale * zoom;
751
- console.log(zoom, newScale, this.scale, 'newScale');
752
- // 最大缩放比例限制
753
- if (newScale > 2) {
754
- newScale = 2;
755
- }
756
- // 最大缩放比例限制
757
- if (newScale < 1) {
758
- newScale = 1;
759
- }
760
- // 记住使用的缩放值
761
- that.displacement.scale = newScale;
762
- // console.log(newScale);
763
- matrix_box.style.transform = "scale(" + newScale + ")";
764
- // 设置旋转元素的基点位置
765
- matrix_box.style.transformOrigin = "0px 0px 0px";
766
- }
767
- }, { passive: false });
768
- document.addEventListener('touchend', function () {
769
- that.isTouchMoved = false
770
- }, { passive: false })
771
- });
772
- },
773
- getDistance (start, stop) {
774
- // Math.hypot()计算参数的平方根
775
- return Math.hypot(stop.x - start.x, stop.y - start.y);
776
- },
777
- setupCanvas (canvas, width, height) {
778
- const dpr = 1;
779
- // const rect = canvas.getBoundingClientRect();
780
- canvas.width = width
781
- canvas.height = height
782
- const ctx = canvas.getContext('2d');
783
- console.log(canvas.width, canvas.height, dpr, this.scale);
784
- ctx?.scale(dpr, dpr);
785
- return ctx;
786
- },
787
- changeScale (value) {
788
- if (value == 'zoom') {
789
- this.handScale = 'auto'
790
- this.transformSalce = (this.transformSalce + 0.2).toFixed(1)
791
- } else if (value == 'reduce') {
792
- if ((this.transformSalce - 0.2).toFixed(1) <= 0) {
793
- return
794
- }
795
- this.handScale = 'auto'
796
- this.transformSalce = (this.transformSalce - 0.2).toFixed(1)
797
- } else if (value == 'auto') {
798
- this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
799
- } else if (value == 'reality') {
800
- this.transformSalce = 0.5
801
- } else {
802
- this.transformSalce = (value / 2).toFixed(1)
803
- }
804
- this.transformSalce = Number(this.transformSalce)
805
- this.contentView.style.transform = 'scale(' + this.transformSalce + ')';
806
- // this.getpdfResloutePage(this.cachePdf[0])
807
- },
808
- },
809
- computed: {
810
- perviewUrl () {
811
- return '/web/viewer.html?file=' + '/pdflist/pdf4split-1.pdf'
812
- },
813
- setHeight () {
814
- if (this.tagIds.length > 1) {
815
- if (this.isPC) {
816
- return 'calc(100% - 110px)'
817
- } else {
818
- return 'calc(100% - 60px)'
819
- }
820
- } else {
821
- if (this.isPC) {
822
- return 'calc(100% - 50px)'
823
- } else {
824
- return '100%'
825
- }
826
- }
827
- }
828
- },
829
- watch: {
830
- tagIds: {
831
- handler (value) {
832
- if (value && value.length) {
833
- // 在 pdf_view 下创建 所有canvs的容器
834
- this.contentView = document.createElement('div')
835
- this.contentView.style.transformOrigin = '0px 0px 0px'
836
- this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res => {
837
- 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}
838
- // 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}
839
- // 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}
840
- // 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}
841
- // 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}
842
- // if(value.length === 1) {
843
- // this.$refs.pdfView.style.height = 'calc(100% - 50px)'
844
- // }
845
- if (res.data.code == 0) {
846
- // tagIds 会按照gpt识别的生成有序的数组,前端直接按照下标的顺序取就可以了
847
- // 缓存拿到的所有数据
848
- this.cachePdf = res.data.data
849
- let publicPageFileUrl = res.data.data[0].publicPageFileUrl
850
- this.currentPage = 0
851
- // console.log(publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')));
852
- if (publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')) === '.pdf') {
853
- this.preViewType = 'pdf'
854
- // this.setPageAllLine(this.cachePdf)
855
- this.getpdfResloutePage(res.data.data[0])
856
- } else {
857
- this.preViewType = 'excal'
858
- this.$http.post(
859
- '/knowledge-api/temporary-certificate/or-origin?expired=30',
860
- publicPageFileUrl,
861
- {
862
- headers: {
863
- "Content-Type": "application/json",
864
- },
865
- }).then(res => {
866
- // 使用原声请求方式 axios会带有不需要的请求头
867
- let xhr = new XMLHttpRequest();
868
- xhr.open('GET', res.data || res.bodyText, true);
869
- // 定义请求完成的处理函数,请求前也可以增加加载框/禁用下载按钮逻辑
870
- xhr.onload = ({ currentTarget }) => {
871
- // 请求完成
872
- if (currentTarget.status === 200) { // 返回200
873
- this.contentView.innerHTML = currentTarget.response
874
- this.contentView.style.padding = '10px'
875
- // this.contentView.style.position = 'relative'
876
- this.$refs.pdfView.style.backgroundColor = '#FFFFFF'
877
- this.$refs.pdfView.appendChild(this.contentView)
878
- let allTr = Array.from(this.$refs.pdfView.getElementsByTagName('tr'))
879
- this.allTr = []
880
- for (let index = 0; index < allTr.length; index++) {
881
- if (value.includes(allTr[index].getAttribute('tag-id'))) {
882
- this.allTr.push(allTr[index])
883
- }
884
- }
885
- this.currentChange(1)
886
-
887
- }
888
- }
889
- xhr.send();
890
- })
891
- }
892
- } else {
893
- let div = document.createElement('div')
894
- div.innerText = '文件加载异常'
895
- this.contentView.appendChild(div)
896
- this.$refs.pdfView.appendChild(this.contentView)
897
- }
898
- })
899
- }
900
- },
901
- deep: true,
902
- immediate: true
903
- }
904
- },
905
- mounted () {
906
- if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
907
- this.isPC = false
908
- } else {
909
- this.isPC = true
910
- }
911
- }
912
- }
913
- </script>
914
-
915
- <style lang="less" scoped>
916
- .pdf_view {
917
- width: 100%;
918
- height: calc(100% - 110px);
919
- overflow: auto;
920
- background-color: #f5f7fb;
921
- // margin-bottom: 60px;
922
- box-sizing: border-box;
923
-
924
- // position: relative;
925
- // > div {
926
- // width: 100%;
927
- // height: 100%;
928
- // overflow: hidden;
929
- // overflow-y: auto;
930
- // position: relative;
931
- // }
932
- >iframe {
933
- width: 100%;
934
- height: 100%;
935
- }
936
-
937
- a:link {
938
- color: none;
939
- }
940
-
941
- a:visited {
942
- color: none;
943
- }
944
-
945
- a:hover {
946
- color: none;
947
- }
948
-
949
- a:active {
950
- color: none;
951
- }
952
-
953
- .btn_footer {
954
- width: 100%;
955
- height: 60px;
956
- display: flex;
957
- align-items: center;
958
- justify-content: space-around;
959
- position: absolute;
960
- bottom: 0px;
961
- left: 0;
962
- z-index: 999;
963
- background: #ffffff;
964
-
965
- .prev,
966
- .next {
967
- width: 35%;
968
- height: 40px;
969
- display: flex;
970
- align-items: center;
971
- justify-content: center;
972
- border-radius: 50px;
973
- cursor: pointer;
974
- }
975
-
976
- .prev {
977
- background: #F2F5FA;
978
- color: #000;
979
- }
980
-
981
- .next {
982
- background: #366aff;
983
- color: #ffffff;
984
- }
985
- }
986
-
987
- #pagination {
988
- .total-class {
989
- margin-right: 13px;
990
- font-weight: 400;
991
- }
992
-
993
- position: absolute;
994
- bottom: 0px;
995
- right: 0;
996
- width: 100%;
997
- display: flex;
998
- align-items: center;
999
- justify-content: center;
1000
- height: 50px;
1001
- background-color: white;
1002
- box-shadow: 0px 0px 18px 0px rgba(29, 55, 129, 0.07);
1003
- border-radius: 5px;
1004
- z-index: 1000;
1005
-
1006
- /deep/.el-pagination {
1007
- margin-right: 110px;
1008
- }
1009
-
1010
- /deep/.el-pager {
1011
- background: #EDF0F6;
1012
- border-radius: 15px;
1013
- }
1014
-
1015
- /deep/.el-pagination.is-background .btn-next {
1016
- width: 30px;
1017
- height: 30px;
1018
- background: #EDF0F6;
1019
- border-radius: 50%;
1020
- }
1021
-
1022
- /deep/.el-pagination .btn-next {
1023
- width: 30px;
1024
- height: 30px;
1025
- background: #EDF0F6;
1026
- border-radius: 50%;
1027
- padding-left: 0;
1028
- margin-left: 5px;
1029
- }
1030
-
1031
- /deep/.el-pagination .btn-prev {
1032
- width: 30px;
1033
- height: 30px;
1034
- background: #EDF0F6;
1035
- border-radius: 50%;
1036
- padding-right: 0;
1037
- margin-right: 5px;
1038
- }
1039
-
1040
- /deep/.el-pagination button {
1041
- padding: 0;
1042
- min-width: 30px;
1043
- }
1044
-
1045
- /deep/.el-pager li {
1046
- background: #EDF0F6;
1047
- height: 30px;
1048
- min-width: 30px;
1049
- line-height: 30px;
1050
- font-size: 12px;
1051
- color: #717b90;
1052
- }
1053
-
1054
- /deep/.el-pager li:first-child {
1055
- border-bottom-left-radius: 15px !important;
1056
- border-top-left-radius: 15px !important;
1057
- }
1058
-
1059
- /deep/.el-pager li:last-child {
1060
- border-top-right-radius: 15px !important;
1061
- border-bottom-right-radius: 15px !important;
1062
- }
1063
-
1064
- /deep/.el-pager li.active {
1065
- width: 30px;
1066
- height: 30px;
1067
- min-width: 30px;
1068
- background: #366AFF;
1069
- border: 3px solid #A1B9FF;
1070
- border-radius: 50%;
1071
- line-height: 24px;
1072
- color: white;
1073
- }
1074
-
1075
- /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
1076
- background: #366AFF;
1077
- }
1078
- }
1079
-
1080
- .change_scale {
1081
- width: 100%;
1082
- height: 50px;
1083
- position: absolute;
1084
- top: 50px;
1085
- left: 0;
1086
- background: #ffffff;
1087
- display: flex;
1088
- align-items: center;
1089
- padding: 0 10px;
1090
- box-sizing: border-box;
1091
-
1092
- section {
1093
- cursor: pointer;
1094
- width: 30px;
1095
- height: 30px;
1096
- margin-right: 5px;
1097
- border-radius: 5px;
1098
- display: flex;
1099
- align-items: center;
1100
- justify-content: center;
1101
-
1102
- i {
1103
- font-weight: 900;
1104
- }
1105
- }
1106
-
1107
- section:hover {
1108
- background: rgba(221, 222, 223, 1);
1109
- }
1110
- }
1111
- }
1112
- </style>
1113
- <style lang="less">
1114
- .animation {
1115
- animation-name: highlight;
1116
- animation-duration: 4s;
1117
- }
1118
-
1119
- @keyframes highlight {
1120
- 0% {
1121
- background: rgba(255, 136, 0, 0.3);
1122
- }
1123
-
1124
- 25% {
1125
- background: rgba(255, 136, 0, 0.6);
1126
- }
1127
-
1128
- 50% {
1129
- background: rgba(255, 136, 0, 0.3);
1130
- }
1131
-
1132
- 75% {
1133
- background: rgba(255, 136, 0, 0.6);
1134
- }
1135
-
1136
- 100% {
1137
- background: rgba(255, 136, 0, 0.3);
1138
- }
1
+ <template>
2
+ <div class="pdf_view" ref="pdfView" @scroll="pdfScroll" :style="{
3
+ marginTop: isPC ? '50px' : '',
4
+ marginBottom: tagIds.length > 1 ? '60px' : '0px',
5
+ height: setHeight
6
+ }">
7
+
8
+ <div class="btn_footer" v-if="tagIds.length > 1 && !isPC">
9
+ <div class="prev" @click="prev">上一段</div>
10
+ <div class="next" @click="next">下一段</div>
11
+ </div>
12
+ <div id="pagination" v-if="tagIds.length > 1 && isPC">
13
+ <el-pagination :current-page="currentPage + 1" @current-change="currentChange" @prev-click="prev"
14
+ @next-click="next" layout="slot, prev, pager, next" :page-size="1" :total="tagIds.length">
15
+ <span class="total-class">答案由{{ tagIds.length }}段内容生成</span>
16
+ </el-pagination>
17
+ </div>
18
+ </div>
19
+ </template>
20
+
21
+ <script>
22
+ import _ from 'lodash'
23
+ // import * as pdfjsLib from 'pdfjs-dist'
24
+ // pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker';
25
+ // import { TextLayerBuilder } from "pdfjs-dist/web/pdf_viewer";
26
+ // EventBus pdf_viewer 支持绑定自定义事件,一版不做
27
+ // import 'pdfjs-dist/web/pdf_viewer.css'
28
+ /* eslint-disable */
29
+ const pdfjsLib = window['pdfjsLib']
30
+ if (pdfjsLib) {
31
+ pdfjsLib.GlobalWorkerOptions.workerSrc = window['pdfjs-dist/build/pdf.worker']
32
+ // 'pdfjs-dist/build/pdf.worker';
33
+ }
34
+ const { TextLayerBuilder } = window['pdfjs-dist/web/pdf_viewer']
35
+ // import { zoomElement } from '../assets/js/hammer'
36
+ export default {
37
+ name: 'pdfView',
38
+ props: ['tagIds', 'isMessageRecord'],
39
+ data () {
40
+ return {
41
+ url: '',
42
+ pages: [],
43
+ pageLoadStatus: {
44
+ WAIT: 0,
45
+ LOADED: 1,
46
+ },
47
+ scale: 1,
48
+ rotation: 0,
49
+ pageSize: {},
50
+ PAGE_INTVERVAL: 15,
51
+ SLICE_COUNT: 5,
52
+ contentView: null,
53
+ fisrtLoad: true,
54
+ TextLayerBuilder: null,
55
+ totalPageCount: 0,
56
+ identifyTextPostion: {
57
+ top: 0,
58
+ left: 0,
59
+ width: 100,
60
+ height: 0,
61
+ page: 1,
62
+ pageHeight: 0,
63
+ pageWidth: 0,
64
+ extractInfo: {},
65
+ currentPageAllLine: []
66
+ },
67
+ currentPageAllLine: [],
68
+ pdfUrl: '',
69
+ cachePdf: [],
70
+ newViewer: null,
71
+ currentPage: 0,
72
+ changetoolbar: false,
73
+ allTr: [],
74
+ preViewType: 'pdf',
75
+ displacement: {
76
+ pageX: 0,
77
+ pageY: 0,
78
+ moveable: false,
79
+ pageX2: 0,
80
+ pageY2: 0,
81
+ originScale: 1,
82
+ },
83
+ isTouchMoved: false,
84
+ transformSalce: null,
85
+ isPC: false,
86
+ handScale: 'auto',
87
+ scaleList: [
88
+ {
89
+ label: '自动缩放',
90
+ value: 'auto'
91
+ },
92
+ {
93
+ label: '实际比例',
94
+ value: 'reality'
95
+ },
96
+ {
97
+ label: '100%',
98
+ value: 1
99
+ },
100
+ {
101
+ label: '120%',
102
+ value: 1.2
103
+ },
104
+ {
105
+ label: '150%',
106
+ value: 1.5
107
+ },
108
+ {
109
+ label: '170%',
110
+ value: 1.7
111
+ }
112
+ ,
113
+ {
114
+ label: '200%',
115
+ value: 2
116
+ }
117
+ ],
118
+ scrollTop: 0,
119
+ scrollLeft: 0
120
+ }
121
+ },
122
+ methods: {
123
+ getpdfResloutePage (pdfResloute) {
124
+ // 根据当前页面宽度设置缩放比例
125
+ // this.scale = Math.round(this.$refs.pdfView.clientWidth / pdfResloute.pageWidth * 100) / 100
126
+ // console.log(this.scale,'this.scale');
127
+ if (this.isMessageRecord) {
128
+ this.scale = Math.round(this.$refs.pdfView.clientWidth / pdfResloute.pageWidth * 100) / 100
129
+ } else {
130
+ this.scale = 2
131
+ }
132
+ // 从后端获取到当前分片后所有的pdf页码,初始化数组,数组下{} 对应每页pdf文件
133
+ this.pdfUrl = pdfResloute.publicPageFileUrl.substring(0, pdfResloute.publicPageFileUrl.lastIndexOf('/') + 1)
134
+ this.initPages(pdfResloute.total)
135
+ // 定位功能,加载对应页码位置
136
+ this.loadPdfData(pdfResloute.page)
137
+ },
138
+ async loadPdfData (loadPage) {
139
+ if (this.pages[loadPage - 1] && ((this.pages[loadPage - 1].dom && this.pages[loadPage - 1].dom.children.length > 0) || this.pages[loadPage - 1].loading)) {
140
+ return
141
+ }
142
+ this.pages[loadPage - 1].loading = true
143
+ // pdfjsLib.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/legacy/build/pdf.worker.entry.js");
144
+ // 拿到第一个分片
145
+ const { startPage, url } = await this.fetchPdfFragment(loadPage);
146
+ let loadingTask = pdfjsLib.getDocument(url)
147
+ loadingTask.promise.then((pdfDoc) => {
148
+ // 将已经下载的分片保存到 pages 数组中
149
+ for (let i = 0; i < pdfDoc.numPages; i += 1) {
150
+ const pageIndex = startPage + i;
151
+ const page = this.pages[pageIndex - 1];
152
+ // 不在缓存列表内,重新获取本页pdf
153
+ if (page.loadStatus !== this.pageLoadStatus.LOADED) {
154
+ pdfDoc.getPage(i + 1).then((pdfPage) => {
155
+ page.pdfPage = pdfPage;
156
+ page.loadStatus = this.pageLoadStatus.LOADED;
157
+ // 通知可以进行渲染了
158
+ this.startRenderPages(pdfPage, page, pageIndex)
159
+ });
160
+ } else {
161
+ if (this.changetoolbar) {
162
+ this.$nextTick(() => {
163
+ this.renderHighlights()
164
+ })
165
+ this.changetoolbar = false
166
+ }
167
+ }
168
+ }
169
+ });
170
+ },
171
+ initPages (totalPage) {
172
+ // const pages = [];
173
+ this.totalPageCount = totalPage
174
+ for (let i = 0; i < totalPage; i += 1) {
175
+ this.pages.push({
176
+ pageNo: i + 1,
177
+ loadStatus: this.pageLoadStatus.WAIT,
178
+ pdfPage: null,
179
+ dom: null
180
+ });
181
+ }
182
+ },
183
+ async fetchPdfFragment (pageIndex) {
184
+ // 置换加签后的文件地址。
185
+ let obj = {}
186
+ await this.$http.post(
187
+ '/knowledge-api/temporary-certificate/or-origin?expired=30',
188
+ 'https://askbot-pdf-all.oss-cn-zhangjiakou.aliyuncs.com/fb348d095c0b4fd7bbd37826563dac7d/2023/05/08/11/55/18/64591b638bb8ab1b91c65eed/3.pdf',
189
+ {
190
+ headers: {
191
+ "Content-Type": "application/json",
192
+ },
193
+ }).then(async res => {
194
+ if (res.bodyText) {
195
+ // 最后返回一个 包含这4个参数的对象
196
+ obj = await {
197
+ "startPage": pageIndex, // 分片的开始页码
198
+ "endPage": pageIndex + 5, // 分片结束页码
199
+ "totalPage": this.totalPageCount, // pdf 总页数
200
+ "url": res.bodyText // 分片内容下载地址
201
+ }
202
+ }
203
+ if (res.data) {
204
+ // 最后返回一个 包含这4个参数的对象
205
+ obj = await {
206
+ "startPage": pageIndex, // 分片的开始页码
207
+ "endPage": pageIndex + 5, // 分片结束页码
208
+ "totalPage": this.totalPageCount, // pdf 总页数
209
+ "url": res.data // 分片内容下载地址
210
+ }
211
+ }
212
+ })
213
+ return obj
214
+ },
215
+ startRenderPages (pdfPage, page, pageIndex) {
216
+ if (Object.keys(this.pageSize).length == 0) {
217
+ const viewport = pdfPage.getViewport({
218
+ scale: this.scale, // 缩放的比例
219
+ rotation: this.rotation, // 旋转的角度
220
+ });
221
+ // 记录pdf页面高度
222
+ const pageSize = {
223
+ width: viewport.width,
224
+ height: viewport.height,
225
+ }
226
+ this.pageSize = pageSize
227
+ // 创建内容绘制区,并设置大小
228
+ if (this.$refs.pdfView.clientWidth / this.pageSize.width >= 1 || this.isMessageRecord) {
229
+ this.contentView.style.width = `${pageSize.width - 10}px`;
230
+ this.contentView.style.height = `${(this.totalPageCount * (pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
231
+ } else {
232
+ this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
233
+ this.contentView.style.width = `${pageSize.width * this.transformSalce - 10}px`;
234
+ this.contentView.style.height = `${(this.totalPageCount * (pageSize.height * (this.transformSalce) + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
235
+ }
236
+ this.contentView.style.margin = '0 auto 0'
237
+ this.contentView.style.position = 'relative'
238
+ this.contentView.style.paddingBottom = '60px'
239
+ // contentView.style.overflowY = 'auto'
240
+ this.$refs.pdfView.appendChild(this.contentView);
241
+ }
242
+ this.renderPages(pageIndex)
243
+ },
244
+ renderPageContent (page, pageIndex) {
245
+ const { pdfPage, pageNo, dom } = page;
246
+ // dom 元素已存在,无须重新渲染,直接返回
247
+ if (dom && dom.children.length != 0) {
248
+ return;
249
+ }
250
+ const viewport = pdfPage.getViewport({
251
+ scale: this.scale,
252
+ rotation: this.rotation,
253
+ });
254
+ // 创建新的canvas
255
+ const canvas = document.createElement('canvas');
256
+ const context = canvas.getContext('2d');
257
+ // canvas.getContext('2d');
258
+ canvas.height = this.pageSize.height;
259
+ canvas.width = this.pageSize.width;
260
+ // 创建渲染的dom
261
+ const pageDom = document.createElement('div');
262
+ pageDom.style.position = 'absolute';
263
+ pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
264
+ pageDom.style.width = `${this.pageSize.width}px`;
265
+ pageDom.style.height = `${this.pageSize.height}px`;
266
+ pageDom.appendChild(canvas);
267
+ // 渲染内容
268
+ let renderContext = {
269
+ canvasContext: context,
270
+ viewport: viewport,
271
+ }
272
+ pdfPage.render(renderContext).promise.then(() => {
273
+ console.log(pdfPage.getTextContent(), 'getTextContent');
274
+ return pdfPage.getTextContent()
275
+ }).then((textContent) => {
276
+ const textLayerDiv = document.createElement('div');
277
+ textLayerDiv.setAttribute('class', 'textLayer');
278
+ // 将文本图层div添加至每页pdf的div中
279
+ // 创建新的TextLayerBuilder实例
280
+ let textLayer = new TextLayerBuilder({
281
+ textLayerDiv: textLayerDiv,
282
+ pageIndex: pdfPage._pageIndex,
283
+ viewport: viewport,
284
+ });
285
+ let findPage = this.currentPageAllLine.find(l => { return l.page == pageIndex })
286
+ let rectdomTop = 0
287
+ if (findPage) {
288
+ let AllLines = findPage.allLines
289
+ // setTimeout(() => {
290
+ console.log(findPage, 'findPage');
291
+ if (AllLines.length > 0) {
292
+ for (let j = 0; j < AllLines.length; j++) {
293
+ let lines = AllLines[j].lines
294
+ let rectdom = document.createElement('div')
295
+ rectdom.setAttribute('react-count', AllLines[j].pageCount);
296
+ rectdom.style.position = 'absolute';
297
+ rectdom.style.top = 0
298
+ rectdom.style.left = 0
299
+ rectdom.classList.add('rectdom')
300
+ for (let index = 0; index < lines.length; index++) {
301
+ if (!/^\s+$/g.test(lines[index].content)) {
302
+ let postionArr = lines[index].location
303
+ let div = document.createElement('div')
304
+ div.style.position = 'absolute';
305
+ div.style.left = postionArr[0] * this.scale + 'px',
306
+ // 后端返回的坐标有基线对齐的问题,top 值是后端算好(基线top - 文字高度),在此加上文字高度的 1/9 (大致比例)为实际展示出文字的top值
307
+ div.style.top = (postionArr[1] + postionArr[3] / 9) * this.scale + 'px'
308
+ div.style.height = postionArr[3] * this.scale + 'px';
309
+ div.style.width = postionArr[2] * this.scale + 'px'
310
+ div.style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
311
+ div.classList.add('lineHeight')
312
+ rectdom.appendChild(div)
313
+ if (index == 0 && j == 0) {
314
+ if (this.transformSalce !== null) {
315
+ rectdomTop = (postionArr[1] + postionArr[3] / 9) * this.scale * this.transformSalce
316
+ } else {
317
+ rectdomTop = (postionArr[1] + postionArr[3] / 9) * this.scale
318
+ }
319
+ // if(this.isPC) {
320
+ // rectdomTop = rectdomTop - 50 < 0 ? 0 : rectdomTop - 50
321
+ // }
322
+ // console.log(rectdomTop,div.style.top, (postionArr[1] + postionArr[3] / 9) * this.scale);
323
+ }
324
+ }
325
+ }
326
+ if (rectdom.children.length > 0) {
327
+ pageDom.appendChild(rectdom)
328
+ }
329
+ }
330
+ }
331
+ }
332
+ textLayer.setTextContent(textContent);
333
+ textLayer.render()
334
+ pageDom.appendChild(textLayer.textLayerDiv);
335
+ page.dom = pageDom;
336
+ page.loading = false
337
+ this.contentView.appendChild(pageDom);
338
+ if (this.transformSalce !== null) {
339
+ this.contentView.style.transform = `scale(${this.transformSalce}, ${this.transformSalce})`
340
+ }
341
+ if (this.changetoolbar) {
342
+ setTimeout(() => {
343
+ this.renderHighlights()
344
+ this.changetoolbar = false
345
+ }, 100)
346
+ }
347
+ // console.log(this.fisrtLoad,'this.fisrtLoad');
348
+ if (this.fisrtLoad) {
349
+ setTimeout(() => {
350
+ let pageoffsetHeight = 0
351
+ if (this.transformSalce !== null) {
352
+ pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce
353
+ } else {
354
+ pageoffsetHeight = (this.pageSize.height + this.PAGE_INTVERVAL)
355
+ }
356
+ if (this.$refs.pdfView.clientHeight - pageoffsetHeight > 0 && pageIndex == 1) {
357
+ const height = this.$refs.pdfView.clientHeight;
358
+ let startNum = 0
359
+ let endNum = 0
360
+ if (this.transformSalce !== null) {
361
+ startNum = Math.ceil(this.$refs.pdfView.scrollTop / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
362
+ endNum = startNum + Math.ceil(height / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce))
363
+ console.log(Math.ceil(height / ((this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce)), this.pageSize.height, this.PAGE_INTVERVAL, height, this.transformSalce, 'startNum');
364
+
365
+ } else {
366
+ startNum = Math.ceil(this.$refs.pdfView.scrollTop / (this.pageSize.height + this.PAGE_INTVERVAL))
367
+ endNum = startNum + Math.ceil(height / (this.pageSize.height + this.PAGE_INTVERVAL))
368
+
369
+ }
370
+ for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
371
+ if (pageIndex > 0 && pageIndex <= this.pages.length) {
372
+ this.loadPdfData(pageIndex)
373
+ }
374
+ }
375
+ }
376
+ if (this.$refs.pdfView.scrollTop == Math.floor((pageNo - 1) * pageoffsetHeight)) {
377
+ this.$refs.pdfView.scrollTop = rectdomTop
378
+ this.fisrtLoad = false
379
+ } else {
380
+ this.$refs.pdfView.scrollTop = `${((pageNo - 1) * pageoffsetHeight) + rectdomTop - this.PAGE_INTVERVAL}`
381
+ this.fisrtLoad = false
382
+ }
383
+ this.renderHighlights()
384
+ // zoomElement(this.contentView)
385
+ }, 100)
386
+ }
387
+ })
388
+ },
389
+ // 监听容器的滚动事件,触发 scrollPdf 方法
390
+ // 这里加了防抖保证不会一次产生过多请求
391
+ debounceScrollPdf: _.debounce(function (e, that) {
392
+ if (this.fisrtLoad) {
393
+ this.fisrtLoad = false
394
+ return
395
+ }
396
+ const scrollTop = e.target.scrollTop;
397
+ const height = e.target.clientHeight;
398
+ let startNum = 0
399
+ let endNum = 0
400
+ if (this.transformSalce !== null) {
401
+ startNum = Math.ceil(scrollTop / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
402
+ endNum = startNum + Math.ceil(height / ((that.pageSize.height + that.PAGE_INTVERVAL) * this.transformSalce))
403
+ } else {
404
+ startNum = Math.ceil(scrollTop / (that.pageSize.height + that.PAGE_INTVERVAL))
405
+ endNum = startNum + Math.ceil(height / (that.pageSize.height + that.PAGE_INTVERVAL))
406
+ }
407
+ for (let pageIndex = startNum; pageIndex <= endNum; pageIndex++) {
408
+ if (pageIndex > 0 && pageIndex <= that.pages.length) {
409
+ that.loadPdfData(pageIndex)
410
+ }
411
+ }
412
+ console.log('=======');
413
+ }, 200),
414
+ directScrolling (e, that) {
415
+ if (this.fisrtLoad) {
416
+ this.fisrtLoad = false
417
+ return
418
+ }
419
+ const scrollTop = e.target.scrollTop;
420
+ const height = e.target.clientHeight;
421
+ // 根据内容可视区域中心点计算页码, 没有滚动时,指向第一页
422
+ const pageIndex = scrollTop > 0 ?
423
+ Math.ceil((scrollTop + (height / 2)) / (that.pageSize.height + that.PAGE_INTVERVAL)) :
424
+ 1;
425
+ this.loadPdfData(pageIndex)
426
+ },
427
+ pdfScroll (e) {
428
+ if (this.preViewType !== 'pdf' || this.isTouchMoved) {
429
+ return
430
+ }
431
+ if (this.scrollLeft != e.target.scrollLeft) {
432
+ this.scrollLeft = e.target.scrollLeft
433
+ }
434
+ if (this.scrollTop != e.target.scrollTop) {
435
+ this.scrollTop = e.target.scrollTop
436
+ this.debounceScrollPdf(e, this)
437
+ }
438
+ },
439
+ // 分片每次只做一次处理,所以不考虑多片情况
440
+ loadBefore (pageIndex) {
441
+ this.loadPdfData(pageIndex)
442
+ },
443
+ loadAfter (pageIndex) {
444
+ this.loadPdfData(pageIndex)
445
+ },
446
+ // 首先我们获取到需要渲染的范围
447
+ // 根据当前的可视范围内的页码,我们前后只保留 8 页
448
+ getRenderScope (pageIndex) {
449
+ const pagesToRender = [];
450
+ let i = pageIndex - 1;
451
+ let j = pageIndex + 1;
452
+ // pageIndex - 1 表示当前页码数 对应的下标位置
453
+ pagesToRender.push(this.pages[pageIndex - 1]);
454
+ while (pagesToRender.length < 8 && pagesToRender.length < this.pages.length) {
455
+ if (i > 0) {
456
+ pagesToRender.push(this.pages[i - 1]);
457
+ i -= 1;
458
+ }
459
+ if (pagesToRender.length >= 8) {
460
+ break;
461
+ }
462
+ if (j <= this.pages.length) {
463
+ pagesToRender.push(this.pages[j - 1]);
464
+ j += 1;
465
+ }
466
+ }
467
+ return pagesToRender;
468
+ },
469
+ // 渲染需要展示的页面,不需展示的页码将其清除
470
+ renderPages (pageIndex) {
471
+ const pagesToRender = this.getRenderScope(pageIndex);
472
+ for (const i of this.pages) {
473
+ if (pagesToRender.includes(i)) {
474
+ i.loadStatus === this.pageLoadStatus.LOADED ?
475
+ this.renderPageContent(i, pageIndex) :
476
+ this.renderPageLoading(i);
477
+ } else {
478
+ this.clearPage(i);
479
+ }
480
+ }
481
+ },
482
+ // 清除页面 dom
483
+ clearPage (page) {
484
+ if (page.dom) {
485
+ this.contentView.removeChild(page.dom);
486
+ page.loadStatus = 0
487
+ page.loading = false
488
+ page.dom = undefined;
489
+ }
490
+ },
491
+ // 页面正在下载时渲染loading视图
492
+ renderPageLoading (page) {
493
+ const { pageNo, dom } = page;
494
+ if (dom && dom.children.length != 0) {
495
+ return;
496
+ }
497
+ const pageDom = document.createElement('div');
498
+ pageDom.style.width = `${this.pageSize.width}px`;
499
+ pageDom.style.height = `${this.pageSize.height}px`;
500
+ pageDom.style.position = 'absolute';
501
+ pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL
502
+ }px`;
503
+ pageDom.style.backgroundImage = `url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif')`
504
+ pageDom.style.backgroundPosition = 'center'
505
+ pageDom.style.backgroundRepeat = 'no-repeat'
506
+ pageDom.style.backgroundColor = '#FFF'
507
+ page.dom = pageDom;
508
+ this.contentView.appendChild(pageDom);
509
+ },
510
+ prev () {
511
+ this.currentPage--
512
+ if (this.currentPage < 0) {
513
+ this.currentPage = 0
514
+ if (!this.isPC) {
515
+ this.$toast({
516
+ message: '当前已经是第一段了',
517
+ duration: 2000,
518
+ })
519
+ return
520
+ }
521
+ }
522
+ if (this.preViewType == 'pdf') {
523
+ this.scrollToUplaodePage(this.currentPage)
524
+ } else {
525
+ this.scrollToExcalTop(this.currentPage)
526
+ }
527
+ // this.getpdfResloutePage(this.cachePdf[this.currentPage - 1])
528
+ },
529
+ next () {
530
+ this.currentPage++
531
+ if (this.currentPage >= this.tagIds.length) {
532
+ this.currentPage = this.tagIds.length - 1
533
+ if (!this.isPC) {
534
+ this.$toast({
535
+ message: '当前已经是最后一段了',
536
+ duration: 2000,
537
+ })
538
+ return
539
+ }
540
+ }
541
+ if (this.preViewType == 'pdf') {
542
+ this.scrollToUplaodePage(this.currentPage)
543
+ } else {
544
+ this.scrollToExcalTop(this.currentPage)
545
+ }
546
+ },
547
+ currentChange (value) {
548
+ this.currentPage = value - 1
549
+ if (this.preViewType == 'pdf') {
550
+ this.scrollToUplaodePage(this.currentPage)
551
+ } else {
552
+ this.scrollToExcalTop(this.currentPage)
553
+ }
554
+ },
555
+ scrollToUplaodePage (currentPage) {
556
+ this.changetoolbar = true
557
+ if (this.preViewType !== 'pdf') {
558
+ return
559
+ }
560
+
561
+ let pdfResloute = this.cachePdf[currentPage]
562
+ this.identifyTextPostion.extractInfo = pdfResloute.extractInfo
563
+ this.identifyTextPostion.left = pdfResloute.extractInfo.location[0]
564
+ this.identifyTextPostion.top = pdfResloute.extractInfo.location[1]
565
+ this.identifyTextPostion.width = pdfResloute.extractInfo.location[2]
566
+ this.identifyTextPostion.height = pdfResloute.extractInfo.location[3]
567
+ this.identifyTextPostion.page = pdfResloute.page
568
+ this.identifyTextPostion.pageHeight = pdfResloute.pageHeight
569
+ this.identifyTextPostion.pageWidth = pdfResloute.pageWidth
570
+ // 在当前段落在最后一页pdf时,根据计算的高度并不能触发滚动,在此执行重新渲染方法,非次情况会执行两次,待优化
571
+ this.$nextTick(() => {
572
+ this.renderHighlights()
573
+ })
574
+ if (this.transformSalce !== null) {
575
+ this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL) * this.transformSalce) + this.identifyTextPostion.top}`
576
+ } else {
577
+ this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.identifyTextPostion.top}`
578
+ }
579
+ },
580
+ scrollToExcalTop (currentPage) {
581
+ for (let index = 0; index < this.allTr.length; index++) {
582
+ if (index == currentPage) {
583
+ Array.from(this.allTr[index].children).forEach(item => {
584
+ item.style.background = 'rgba(255, 136, 0, 0.6)'
585
+ item.classList.add('animation')
586
+ setTimeout(() => {
587
+ item.classList.remove('animation')
588
+ }, 4000)
589
+ })
590
+ // getBoundingClientRect().top 当前元素距离屏幕顶部的高度 + 弹窗header 高度
591
+ if (!this.isPC) {
592
+ let top = this.allTr[index].getBoundingClientRect().top - this.$refs.pdfView.getBoundingClientRect().top
593
+ this.$refs.pdfView.scrollTop = top
594
+ } else {
595
+ let top = this.allTr[index].getBoundingClientRect().top
596
+ this.$refs.pdfView.scrollTop = top - 50
597
+ }
598
+ } else {
599
+ Array.from(this.allTr[index].children).forEach(item => {
600
+ item.style.background = 'rgba(54, 106, 255, 0.6)'
601
+ item.classList.remove('animation')
602
+ })
603
+ }
604
+ }
605
+ },
606
+ // pdf是否需要重新渲染高亮位置
607
+ renderHighlights () {
608
+ let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
609
+ console.log(lineHeightDom, this.currentPage, 'this.currentPage');
610
+ if (lineHeightDom) {
611
+ lineHeightDom.forEach((d) => {
612
+ for (let i = 0; i < d.children.length; i++) {
613
+ if (d.getAttribute('react-count') == this.currentPage) {
614
+ d.children[i].style.backgroundColor = 'rgba(255, 136, 0, 0.3)'
615
+ d.children[i].classList.add('animation')
616
+ setTimeout(() => {
617
+ d.children[i].classList.remove('animation')
618
+ }, 4000)
619
+ } else {
620
+ d.children[i].style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
621
+ d.children[i].classList.remove('animation')
622
+ }
623
+ }
624
+ })
625
+ }
626
+ },
627
+ displayHiglight (pageIndex) {
628
+ let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
629
+ if (lineHeightDom) {
630
+ lineHeightDom.forEach((d) => {
631
+ if (d.getAttribute('page-index') == pageIndex) {
632
+ d.style.display = 'none'
633
+ }
634
+ })
635
+ }
636
+ },
637
+ // 前端暂时缓存多页
638
+ autoLoadMore (pageIndex) {
639
+ let pdfResloute = this.cachePdf.find(cache => {
640
+ return cache.page == pageIndex
641
+ })
642
+ if (pdfResloute) {
643
+ this.getpdfResloutePage(pdfResloute)
644
+ } else {
645
+ this.loadPdfData(pageIndex)
646
+ }
647
+ },
648
+ setPageAllLine (arr) {
649
+ this.currentPageAllLine = []
650
+ arr.forEach((item, index) => {
651
+ let i = this.currentPageAllLine.findIndex(l => { return l.page && l.page == item.page })
652
+ if (i != -1) {
653
+ // this.currentPageAllLine[i].allLines.lines.push(item.extractInfo.lines)
654
+ this.currentPageAllLine[i].allLines.push({
655
+ pageCount: index,
656
+ lines: item.extractInfo.lines
657
+ })
658
+ } else {
659
+ this.currentPageAllLine.push({
660
+ page: item.page,
661
+ allLines: [{
662
+ pageCount: index,
663
+ lines: item.extractInfo.lines
664
+ }],
665
+ })
666
+ }
667
+ })
668
+ },
669
+ openTouch () {
670
+ // this.$nextTick()将回调延迟到下次 DOM 更新循环之后执行
671
+ let that = this;
672
+ this.$nextTick(() => {
673
+ // setInterval(() => {
674
+ // this.scale = this.scale + 0.1
675
+ // that.pages.forEach((item, index) =>{
676
+ // if(item.dom) {
677
+ // item.dom.children.forEach( childDom =>{
678
+ // if(childDom.getAttribute('react-count')) {
679
+ // childDom.style.transform = "scale(" + this.scale + ")";
680
+ // childDom.style.transformOrigin = "0px 0px 0px";
681
+ // } else {
682
+ // item.dom = null
683
+ // this.startRenderPages(item.pdfPage, null, index)
684
+ // }
685
+ // } )
686
+ // }
687
+ // })
688
+ // }, 100);
689
+ // 获取放大或缩小的区域DOM
690
+ let matrix_box = this.contentView
691
+ matrix_box.addEventListener("touchstart", function (event) {
692
+ this.isTouchMoved = true
693
+ let touches = event.touches;
694
+ let events = touches[0];
695
+ let events2 = touches[1];
696
+
697
+ // event.preventDefault();
698
+
699
+ // 第一个触摸点的坐标
700
+ that.displacement.pageX = events.pageX;
701
+ that.displacement.pageY = events.pageY;
702
+
703
+ that.displacement.moveable = true;
704
+
705
+ if (events2) {
706
+ that.displacement.pageX2 = events2.pageX;
707
+ that.displacement.pageY2 = events2.pageY;
708
+ }
709
+
710
+ that.displacement.originScale = this.scale || 1;
711
+ // console.log(that.displacement);
712
+ });
713
+ document.addEventListener("touchmove", function (event) {
714
+ if (!that.displacement.moveable) {
715
+ return;
716
+ }
717
+ // event.preventDefault();
718
+ let touches = event.touches;
719
+ let events = touches[0];
720
+ let events2 = touches[1];
721
+ // 双指移动
722
+ if (events2) {
723
+ // 第2个指头坐标在touchmove时候获取
724
+ if (!that.displacement.pageX2) {
725
+ that.displacement.pageX2 = events2.pageX;
726
+ }
727
+ if (!that.displacement.pageY2) {
728
+ that.displacement.pageY2 = events2.pageY;
729
+ }
730
+ // 双指缩放比例计算
731
+ let zoom = that.getDistance({
732
+ x: events.pageX,
733
+ y: events.pageY
734
+ },
735
+ {
736
+ x: events2.pageX,
737
+ y: events2.pageY
738
+ }
739
+ ) / that.getDistance(
740
+ {
741
+ x: that.displacement.pageX,
742
+ y: that.displacement.pageY
743
+ },
744
+ {
745
+ x: that.displacement.pageX2,
746
+ y: that.displacement.pageY2
747
+ }
748
+ );
749
+ // 应用在元素上的缩放比例
750
+ let newScale = that.displacement.originScale * zoom;
751
+ console.log(zoom, newScale, this.scale, 'newScale');
752
+ // 最大缩放比例限制
753
+ if (newScale > 2) {
754
+ newScale = 2;
755
+ }
756
+ // 最大缩放比例限制
757
+ if (newScale < 1) {
758
+ newScale = 1;
759
+ }
760
+ // 记住使用的缩放值
761
+ that.displacement.scale = newScale;
762
+ // console.log(newScale);
763
+ matrix_box.style.transform = "scale(" + newScale + ")";
764
+ // 设置旋转元素的基点位置
765
+ matrix_box.style.transformOrigin = "0px 0px 0px";
766
+ }
767
+ }, { passive: false });
768
+ document.addEventListener('touchend', function () {
769
+ that.isTouchMoved = false
770
+ }, { passive: false })
771
+ });
772
+ },
773
+ getDistance (start, stop) {
774
+ // Math.hypot()计算参数的平方根
775
+ return Math.hypot(stop.x - start.x, stop.y - start.y);
776
+ },
777
+ setupCanvas (canvas, width, height) {
778
+ const dpr = 1;
779
+ // const rect = canvas.getBoundingClientRect();
780
+ canvas.width = width
781
+ canvas.height = height
782
+ const ctx = canvas.getContext('2d');
783
+ console.log(canvas.width, canvas.height, dpr, this.scale);
784
+ ctx?.scale(dpr, dpr);
785
+ return ctx;
786
+ },
787
+ changeScale (value) {
788
+ if (value == 'zoom') {
789
+ this.handScale = 'auto'
790
+ this.transformSalce = (this.transformSalce + 0.2).toFixed(1)
791
+ } else if (value == 'reduce') {
792
+ if ((this.transformSalce - 0.2).toFixed(1) <= 0) {
793
+ return
794
+ }
795
+ this.handScale = 'auto'
796
+ this.transformSalce = (this.transformSalce - 0.2).toFixed(1)
797
+ } else if (value == 'auto') {
798
+ this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
799
+ } else if (value == 'reality') {
800
+ this.transformSalce = 0.5
801
+ } else {
802
+ this.transformSalce = (value / 2).toFixed(1)
803
+ }
804
+ this.transformSalce = Number(this.transformSalce)
805
+ this.contentView.style.transform = 'scale(' + this.transformSalce + ')';
806
+ // this.getpdfResloutePage(this.cachePdf[0])
807
+ },
808
+ },
809
+ computed: {
810
+ perviewUrl () {
811
+ return '/web/viewer.html?file=' + '/pdflist/pdf4split-1.pdf'
812
+ },
813
+ setHeight () {
814
+ if (this.tagIds.length > 1) {
815
+ if (this.isPC) {
816
+ return 'calc(100% - 110px)'
817
+ } else {
818
+ return 'calc(100% - 60px)'
819
+ }
820
+ } else {
821
+ if (this.isPC) {
822
+ return 'calc(100% - 50px)'
823
+ } else {
824
+ return '100%'
825
+ }
826
+ }
827
+ }
828
+ },
829
+ watch: {
830
+ tagIds: {
831
+ handler (value) {
832
+ if (value && value.length) {
833
+ // 在 pdf_view 下创建 所有canvs的容器
834
+ this.contentView = document.createElement('div')
835
+ this.contentView.style.transformOrigin = '0px 0px 0px'
836
+ this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res => {
837
+ 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}
838
+ // 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}
839
+ // 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}
840
+ // 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}
841
+ // 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}
842
+ // if(value.length === 1) {
843
+ // this.$refs.pdfView.style.height = 'calc(100% - 50px)'
844
+ // }
845
+ if (res.data.code == 0) {
846
+ // tagIds 会按照gpt识别的生成有序的数组,前端直接按照下标的顺序取就可以了
847
+ // 缓存拿到的所有数据
848
+ this.cachePdf = res.data.data
849
+ let publicPageFileUrl = res.data.data[0].publicPageFileUrl
850
+ this.currentPage = 0
851
+ // console.log(publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')));
852
+ if (publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')) === '.pdf') {
853
+ this.preViewType = 'pdf'
854
+ // this.setPageAllLine(this.cachePdf)
855
+ this.getpdfResloutePage(res.data.data[0])
856
+ } else {
857
+ this.preViewType = 'excal'
858
+ this.$http.post(
859
+ '/knowledge-api/temporary-certificate/or-origin?expired=30',
860
+ publicPageFileUrl,
861
+ {
862
+ headers: {
863
+ "Content-Type": "application/json",
864
+ },
865
+ }).then(res => {
866
+ // 使用原声请求方式 axios会带有不需要的请求头
867
+ let xhr = new XMLHttpRequest();
868
+ xhr.open('GET', res.data || res.bodyText, true);
869
+ // 定义请求完成的处理函数,请求前也可以增加加载框/禁用下载按钮逻辑
870
+ xhr.onload = ({ currentTarget }) => {
871
+ // 请求完成
872
+ if (currentTarget.status === 200) { // 返回200
873
+ this.contentView.innerHTML = currentTarget.response
874
+ this.contentView.style.padding = '10px'
875
+ // this.contentView.style.position = 'relative'
876
+ this.$refs.pdfView.style.backgroundColor = '#FFFFFF'
877
+ this.$refs.pdfView.appendChild(this.contentView)
878
+ let allTr = Array.from(this.$refs.pdfView.getElementsByTagName('tr'))
879
+ this.allTr = []
880
+ for (let index = 0; index < allTr.length; index++) {
881
+ if (value.includes(allTr[index].getAttribute('tag-id'))) {
882
+ this.allTr.push(allTr[index])
883
+ }
884
+ }
885
+ this.currentChange(1)
886
+
887
+ }
888
+ }
889
+ xhr.send();
890
+ })
891
+ }
892
+ } else {
893
+ let div = document.createElement('div')
894
+ div.innerText = '文件加载异常'
895
+ this.contentView.appendChild(div)
896
+ this.$refs.pdfView.appendChild(this.contentView)
897
+ }
898
+ })
899
+ }
900
+ },
901
+ deep: true,
902
+ immediate: true
903
+ }
904
+ },
905
+ mounted () {
906
+ if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
907
+ this.isPC = false
908
+ } else {
909
+ this.isPC = true
910
+ }
911
+ }
912
+ }
913
+ </script>
914
+
915
+ <style lang="less" scoped>
916
+ .pdf_view {
917
+ width: 100%;
918
+ height: calc(100% - 110px);
919
+ overflow: auto;
920
+ background-color: #f5f7fb;
921
+ // margin-bottom: 60px;
922
+ box-sizing: border-box;
923
+
924
+ // position: relative;
925
+ // > div {
926
+ // width: 100%;
927
+ // height: 100%;
928
+ // overflow: hidden;
929
+ // overflow-y: auto;
930
+ // position: relative;
931
+ // }
932
+ >iframe {
933
+ width: 100%;
934
+ height: 100%;
935
+ }
936
+
937
+ a:link {
938
+ color: none;
939
+ }
940
+
941
+ a:visited {
942
+ color: none;
943
+ }
944
+
945
+ a:hover {
946
+ color: none;
947
+ }
948
+
949
+ a:active {
950
+ color: none;
951
+ }
952
+
953
+ .btn_footer {
954
+ width: 100%;
955
+ height: 60px;
956
+ display: flex;
957
+ align-items: center;
958
+ justify-content: space-around;
959
+ position: absolute;
960
+ bottom: 0px;
961
+ left: 0;
962
+ z-index: 999;
963
+ background: #ffffff;
964
+
965
+ .prev,
966
+ .next {
967
+ width: 35%;
968
+ height: 40px;
969
+ display: flex;
970
+ align-items: center;
971
+ justify-content: center;
972
+ border-radius: 50px;
973
+ cursor: pointer;
974
+ }
975
+
976
+ .prev {
977
+ background: #F2F5FA;
978
+ color: #000;
979
+ }
980
+
981
+ .next {
982
+ background: #366aff;
983
+ color: #ffffff;
984
+ }
985
+ }
986
+
987
+ #pagination {
988
+ .total-class {
989
+ margin-right: 13px;
990
+ font-weight: 400;
991
+ }
992
+
993
+ position: absolute;
994
+ bottom: 0px;
995
+ right: 0;
996
+ width: 100%;
997
+ display: flex;
998
+ align-items: center;
999
+ justify-content: center;
1000
+ height: 50px;
1001
+ background-color: white;
1002
+ box-shadow: 0px 0px 18px 0px rgba(29, 55, 129, 0.07);
1003
+ border-radius: 5px;
1004
+ z-index: 1000;
1005
+
1006
+ /deep/.el-pagination {
1007
+ margin-right: 110px;
1008
+ }
1009
+
1010
+ /deep/.el-pager {
1011
+ background: #EDF0F6;
1012
+ border-radius: 15px;
1013
+ }
1014
+
1015
+ /deep/.el-pagination.is-background .btn-next {
1016
+ width: 30px;
1017
+ height: 30px;
1018
+ background: #EDF0F6;
1019
+ border-radius: 50%;
1020
+ }
1021
+
1022
+ /deep/.el-pagination .btn-next {
1023
+ width: 30px;
1024
+ height: 30px;
1025
+ background: #EDF0F6;
1026
+ border-radius: 50%;
1027
+ padding-left: 0;
1028
+ margin-left: 5px;
1029
+ }
1030
+
1031
+ /deep/.el-pagination .btn-prev {
1032
+ width: 30px;
1033
+ height: 30px;
1034
+ background: #EDF0F6;
1035
+ border-radius: 50%;
1036
+ padding-right: 0;
1037
+ margin-right: 5px;
1038
+ }
1039
+
1040
+ /deep/.el-pagination button {
1041
+ padding: 0;
1042
+ min-width: 30px;
1043
+ }
1044
+
1045
+ /deep/.el-pager li {
1046
+ background: #EDF0F6;
1047
+ height: 30px;
1048
+ min-width: 30px;
1049
+ line-height: 30px;
1050
+ font-size: 12px;
1051
+ color: #717b90;
1052
+ }
1053
+
1054
+ /deep/.el-pager li:first-child {
1055
+ border-bottom-left-radius: 15px !important;
1056
+ border-top-left-radius: 15px !important;
1057
+ }
1058
+
1059
+ /deep/.el-pager li:last-child {
1060
+ border-top-right-radius: 15px !important;
1061
+ border-bottom-right-radius: 15px !important;
1062
+ }
1063
+
1064
+ /deep/.el-pager li.active {
1065
+ width: 30px;
1066
+ height: 30px;
1067
+ min-width: 30px;
1068
+ background: #366AFF;
1069
+ border: 3px solid #A1B9FF;
1070
+ border-radius: 50%;
1071
+ line-height: 24px;
1072
+ color: white;
1073
+ }
1074
+
1075
+ /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
1076
+ background: #366AFF;
1077
+ }
1078
+ }
1079
+
1080
+ .change_scale {
1081
+ width: 100%;
1082
+ height: 50px;
1083
+ position: absolute;
1084
+ top: 50px;
1085
+ left: 0;
1086
+ background: #ffffff;
1087
+ display: flex;
1088
+ align-items: center;
1089
+ padding: 0 10px;
1090
+ box-sizing: border-box;
1091
+
1092
+ section {
1093
+ cursor: pointer;
1094
+ width: 30px;
1095
+ height: 30px;
1096
+ margin-right: 5px;
1097
+ border-radius: 5px;
1098
+ display: flex;
1099
+ align-items: center;
1100
+ justify-content: center;
1101
+
1102
+ i {
1103
+ font-weight: 900;
1104
+ }
1105
+ }
1106
+
1107
+ section:hover {
1108
+ background: rgba(221, 222, 223, 1);
1109
+ }
1110
+ }
1111
+ }
1112
+ </style>
1113
+ <style lang="less">
1114
+ .animation {
1115
+ animation-name: highlight;
1116
+ animation-duration: 4s;
1117
+ }
1118
+
1119
+ @keyframes highlight {
1120
+ 0% {
1121
+ background: rgba(255, 136, 0, 0.3);
1122
+ }
1123
+
1124
+ 25% {
1125
+ background: rgba(255, 136, 0, 0.6);
1126
+ }
1127
+
1128
+ 50% {
1129
+ background: rgba(255, 136, 0, 0.3);
1130
+ }
1131
+
1132
+ 75% {
1133
+ background: rgba(255, 136, 0, 0.6);
1134
+ }
1135
+
1136
+ 100% {
1137
+ background: rgba(255, 136, 0, 0.3);
1138
+ }
1139
1139
  }</style>