askbot-dragon 1.7.83-beta → 1.7.85-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 (95) 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 +60 -60
  5. package/public/index.html +73 -73
  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 +141 -141
  11. package/src/assets/js/Base64Util.js +22 -22
  12. package/src/assets/js/common.js +261 -261
  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 +178 -178
  21. package/src/components/AiGuide.vue +434 -434
  22. package/src/components/AnswerDocknowledge.vue +1203 -1203
  23. package/src/components/AnswerVoice.vue +285 -285
  24. package/src/components/AskIFrame.vue +15 -15
  25. package/src/components/ConversationContainer.vue +10684 -10684
  26. package/src/components/FileType.vue +86 -86
  27. package/src/components/Message.vue +27 -27
  28. package/src/components/MyEditor.vue +342 -342
  29. package/src/components/QwFeedback.vue +302 -302
  30. package/src/components/actionSatisfaction.vue +107 -107
  31. package/src/components/actionSendToBot.vue +62 -62
  32. package/src/components/answerDissatisfaction.vue +62 -62
  33. package/src/components/answerRadio.vue +259 -259
  34. package/src/components/ask-components/DissatisfactionOptions.vue +57 -57
  35. package/src/components/ask-components/Msgloading.vue +37 -37
  36. package/src/components/ask-components/SatisfactionV2.vue +15 -15
  37. package/src/components/askVideo.vue +162 -162
  38. package/src/components/assetDetails.vue +378 -378
  39. package/src/components/assetMessage.vue +229 -229
  40. package/src/components/associationIntention.vue +378 -378
  41. package/src/components/attachmentPreview.vue +90 -90
  42. package/src/components/botActionSatisfactor.vue +68 -68
  43. package/src/components/chatContent.vue +513 -513
  44. package/src/components/feedBack.vue +136 -136
  45. package/src/components/fielListView.vue +351 -351
  46. package/src/components/file/AliyunOssComponents.vue +108 -108
  47. package/src/components/formTemplate.vue +3522 -3522
  48. package/src/components/imgView.vue +31 -31
  49. package/src/components/intelligentSummary.vue +234 -234
  50. package/src/components/kkview.vue +1128 -1128
  51. package/src/components/loadingProcess.vue +164 -164
  52. package/src/components/markDownText.vue +959 -960
  53. package/src/components/message/ActionAlertIframe.vue +112 -112
  54. package/src/components/message/ShopMessage.vue +164 -164
  55. package/src/components/message/TextMessage.vue +928 -928
  56. package/src/components/message/TicketMessage.vue +201 -201
  57. package/src/components/message/swiper/index.js +4 -4
  58. package/src/components/message/swiper/ticketSwiper.vue +503 -503
  59. package/src/components/message/swiper/ticketSwiperItem.vue +61 -61
  60. package/src/components/msgLoading.vue +231 -231
  61. package/src/components/myPopup.vue +73 -73
  62. package/src/components/newPdfPosition.vue +877 -877
  63. package/src/components/pagination.vue +128 -128
  64. package/src/components/pdfPosition.vue +1514 -1514
  65. package/src/components/popup.vue +228 -228
  66. package/src/components/preview/docView.vue +122 -113
  67. package/src/components/preview/excelView.vue +206 -198
  68. package/src/components/preview/newPositionPreview.vue +390 -388
  69. package/src/components/preview/pdfView.vue +831 -831
  70. package/src/components/previewDoc.vue +252 -252
  71. package/src/components/previewPdf.vue +1119 -1119
  72. package/src/components/receiverMessagePlatform.vue +69 -69
  73. package/src/components/recommend.vue +80 -80
  74. package/src/components/selector/hOption.vue +20 -20
  75. package/src/components/selector/hSelector.vue +199 -199
  76. package/src/components/selector/hWrapper.vue +216 -216
  77. package/src/components/senderMessagePlatform.vue +58 -58
  78. package/src/components/source/BotMessage.vue +24 -24
  79. package/src/components/source/CustomMessage.vue +24 -24
  80. package/src/components/test.vue +260 -260
  81. package/src/components/tree.vue +307 -307
  82. package/src/components/utils/AliyunIssUtil.js +103 -103
  83. package/src/components/utils/ckeditor.js +185 -185
  84. package/src/components/utils/format_date.js +25 -25
  85. package/src/components/utils/index.js +6 -6
  86. package/src/components/utils/math_utils.js +29 -29
  87. package/src/components/voiceComponent.vue +119 -119
  88. package/src/components/welcomeKnowledgeFile.vue +347 -347
  89. package/src/components/welcomeLlmCard.vue +144 -144
  90. package/src/components/welcomeSuggest.vue +97 -97
  91. package/src/locales/cn.json +98 -98
  92. package/src/locales/en.json +98 -98
  93. package/src/locales/jp.json +72 -72
  94. package/src/main.js +76 -76
  95. package/vue.config.js +54 -54
@@ -1,1129 +1,1129 @@
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
- changeScale (value) {
778
- if (value == 'zoom') {
779
- this.handScale = 'auto'
780
- this.transformSalce = (this.transformSalce + 0.2).toFixed(1)
781
- } else if (value == 'reduce') {
782
- if ((this.transformSalce - 0.2).toFixed(1) <= 0) {
783
- return
784
- }
785
- this.handScale = 'auto'
786
- this.transformSalce = (this.transformSalce - 0.2).toFixed(1)
787
- } else if (value == 'auto') {
788
- this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
789
- } else if (value == 'reality') {
790
- this.transformSalce = 0.5
791
- } else {
792
- this.transformSalce = (value / 2).toFixed(1)
793
- }
794
- this.transformSalce = Number(this.transformSalce)
795
- this.contentView.style.transform = 'scale(' + this.transformSalce + ')';
796
- // this.getpdfResloutePage(this.cachePdf[0])
797
- },
798
- },
799
- computed: {
800
- perviewUrl () {
801
- return '/web/viewer.html?file=' + '/pdflist/pdf4split-1.pdf'
802
- },
803
- setHeight () {
804
- if (this.tagIds.length > 1) {
805
- if (this.isPC) {
806
- return 'calc(100% - 110px)'
807
- } else {
808
- return 'calc(100% - 60px)'
809
- }
810
- } else {
811
- if (this.isPC) {
812
- return 'calc(100% - 50px)'
813
- } else {
814
- return '100%'
815
- }
816
- }
817
- }
818
- },
819
- watch: {
820
- tagIds: {
821
- handler (value) {
822
- if (value && value.length) {
823
- // 在 pdf_view 下创建 所有canvs的容器
824
- this.contentView = document.createElement('div')
825
- this.contentView.style.transformOrigin = '0px 0px 0px'
826
- this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res => {
827
- 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}
828
- // 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}
829
- // 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}
830
- // 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}
831
- // 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}
832
- // if(value.length === 1) {
833
- // this.$refs.pdfView.style.height = 'calc(100% - 50px)'
834
- // }
835
- if (res.data.code == 0) {
836
- // tagIds 会按照gpt识别的生成有序的数组,前端直接按照下标的顺序取就可以了
837
- // 缓存拿到的所有数据
838
- this.cachePdf = res.data.data
839
- let publicPageFileUrl = res.data.data[0].publicPageFileUrl
840
- this.currentPage = 0
841
- // console.log(publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')));
842
- if (publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')) === '.pdf') {
843
- this.preViewType = 'pdf'
844
- // this.setPageAllLine(this.cachePdf)
845
- this.getpdfResloutePage(res.data.data[0])
846
- } else {
847
- this.preViewType = 'excal'
848
- this.$http.post(
849
- '/knowledge-api/temporary-certificate/or-origin?expired=30',
850
- publicPageFileUrl,
851
- {
852
- headers: {
853
- "Content-Type": "application/json",
854
- },
855
- }).then(res => {
856
- // 使用原声请求方式 axios会带有不需要的请求头
857
- let xhr = new XMLHttpRequest();
858
- xhr.open('GET', res.data || res.bodyText, true);
859
- // 定义请求完成的处理函数,请求前也可以增加加载框/禁用下载按钮逻辑
860
- xhr.onload = ({ currentTarget }) => {
861
- // 请求完成
862
- if (currentTarget.status === 200) { // 返回200
863
- this.contentView.innerHTML = currentTarget.response
864
- this.contentView.style.padding = '10px'
865
- // this.contentView.style.position = 'relative'
866
- this.$refs.pdfView.style.backgroundColor = '#FFFFFF'
867
- this.$refs.pdfView.appendChild(this.contentView)
868
- let allTr = Array.from(this.$refs.pdfView.getElementsByTagName('tr'))
869
- this.allTr = []
870
- for (let index = 0; index < allTr.length; index++) {
871
- if (value.includes(allTr[index].getAttribute('tag-id'))) {
872
- this.allTr.push(allTr[index])
873
- }
874
- }
875
- this.currentChange(1)
876
-
877
- }
878
- }
879
- xhr.send();
880
- })
881
- }
882
- } else {
883
- let div = document.createElement('div')
884
- div.innerText = '文件加载异常'
885
- this.contentView.appendChild(div)
886
- this.$refs.pdfView.appendChild(this.contentView)
887
- }
888
- })
889
- }
890
- },
891
- deep: true,
892
- immediate: true
893
- }
894
- },
895
- mounted () {
896
- if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
897
- this.isPC = false
898
- } else {
899
- this.isPC = true
900
- }
901
- }
902
- }
903
- </script>
904
-
905
- <style lang="less" scoped>
906
- .pdf_view {
907
- width: 100%;
908
- height: calc(100% - 110px);
909
- overflow: auto;
910
- background-color: #f5f7fb;
911
- // margin-bottom: 60px;
912
- box-sizing: border-box;
913
-
914
- // position: relative;
915
- // > div {
916
- // width: 100%;
917
- // height: 100%;
918
- // overflow: hidden;
919
- // overflow-y: auto;
920
- // position: relative;
921
- // }
922
- >iframe {
923
- width: 100%;
924
- height: 100%;
925
- }
926
-
927
- a:link {
928
- color: none;
929
- }
930
-
931
- a:visited {
932
- color: none;
933
- }
934
-
935
- a:hover {
936
- color: none;
937
- }
938
-
939
- a:active {
940
- color: none;
941
- }
942
-
943
- .btn_footer {
944
- width: 100%;
945
- height: 60px;
946
- display: flex;
947
- align-items: center;
948
- justify-content: space-around;
949
- position: absolute;
950
- bottom: 0px;
951
- left: 0;
952
- z-index: 999;
953
- background: #ffffff;
954
-
955
- .prev,
956
- .next {
957
- width: 35%;
958
- height: 40px;
959
- display: flex;
960
- align-items: center;
961
- justify-content: center;
962
- border-radius: 50px;
963
- cursor: pointer;
964
- }
965
-
966
- .prev {
967
- background: #F2F5FA;
968
- color: #000;
969
- }
970
-
971
- .next {
972
- background: #366aff;
973
- color: #ffffff;
974
- }
975
- }
976
-
977
- #pagination {
978
- .total-class {
979
- margin-right: 13px;
980
- font-weight: 400;
981
- }
982
-
983
- position: absolute;
984
- bottom: 0px;
985
- right: 0;
986
- width: 100%;
987
- display: flex;
988
- align-items: center;
989
- justify-content: center;
990
- height: 50px;
991
- background-color: white;
992
- box-shadow: 0px 0px 18px 0px rgba(29, 55, 129, 0.07);
993
- border-radius: 5px;
994
- z-index: 1000;
995
-
996
- /deep/.el-pagination {
997
- margin-right: 110px;
998
- }
999
-
1000
- /deep/.el-pager {
1001
- background: #EDF0F6;
1002
- border-radius: 15px;
1003
- }
1004
-
1005
- /deep/.el-pagination.is-background .btn-next {
1006
- width: 30px;
1007
- height: 30px;
1008
- background: #EDF0F6;
1009
- border-radius: 50%;
1010
- }
1011
-
1012
- /deep/.el-pagination .btn-next {
1013
- width: 30px;
1014
- height: 30px;
1015
- background: #EDF0F6;
1016
- border-radius: 50%;
1017
- padding-left: 0;
1018
- margin-left: 5px;
1019
- }
1020
-
1021
- /deep/.el-pagination .btn-prev {
1022
- width: 30px;
1023
- height: 30px;
1024
- background: #EDF0F6;
1025
- border-radius: 50%;
1026
- padding-right: 0;
1027
- margin-right: 5px;
1028
- }
1029
-
1030
- /deep/.el-pagination button {
1031
- padding: 0;
1032
- min-width: 30px;
1033
- }
1034
-
1035
- /deep/.el-pager li {
1036
- background: #EDF0F6;
1037
- height: 30px;
1038
- min-width: 30px;
1039
- line-height: 30px;
1040
- font-size: 12px;
1041
- color: #717b90;
1042
- }
1043
-
1044
- /deep/.el-pager li:first-child {
1045
- border-bottom-left-radius: 15px !important;
1046
- border-top-left-radius: 15px !important;
1047
- }
1048
-
1049
- /deep/.el-pager li:last-child {
1050
- border-top-right-radius: 15px !important;
1051
- border-bottom-right-radius: 15px !important;
1052
- }
1053
-
1054
- /deep/.el-pager li.active {
1055
- width: 30px;
1056
- height: 30px;
1057
- min-width: 30px;
1058
- background: #366AFF;
1059
- border: 3px solid #A1B9FF;
1060
- border-radius: 50%;
1061
- line-height: 24px;
1062
- color: white;
1063
- }
1064
-
1065
- /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
1066
- background: #366AFF;
1067
- }
1068
- }
1069
-
1070
- .change_scale {
1071
- width: 100%;
1072
- height: 50px;
1073
- position: absolute;
1074
- top: 50px;
1075
- left: 0;
1076
- background: #ffffff;
1077
- display: flex;
1078
- align-items: center;
1079
- padding: 0 10px;
1080
- box-sizing: border-box;
1081
-
1082
- section {
1083
- cursor: pointer;
1084
- width: 30px;
1085
- height: 30px;
1086
- margin-right: 5px;
1087
- border-radius: 5px;
1088
- display: flex;
1089
- align-items: center;
1090
- justify-content: center;
1091
-
1092
- i {
1093
- font-weight: 900;
1094
- }
1095
- }
1096
-
1097
- section:hover {
1098
- background: rgba(221, 222, 223, 1);
1099
- }
1100
- }
1101
- }
1102
- </style>
1103
- <style lang="less">
1104
- .animation {
1105
- animation-name: highlight;
1106
- animation-duration: 4s;
1107
- }
1108
-
1109
- @keyframes highlight {
1110
- 0% {
1111
- background: rgba(255, 136, 0, 0.3);
1112
- }
1113
-
1114
- 25% {
1115
- background: rgba(255, 136, 0, 0.6);
1116
- }
1117
-
1118
- 50% {
1119
- background: rgba(255, 136, 0, 0.3);
1120
- }
1121
-
1122
- 75% {
1123
- background: rgba(255, 136, 0, 0.6);
1124
- }
1125
-
1126
- 100% {
1127
- background: rgba(255, 136, 0, 0.3);
1128
- }
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
+ changeScale (value) {
778
+ if (value == 'zoom') {
779
+ this.handScale = 'auto'
780
+ this.transformSalce = (this.transformSalce + 0.2).toFixed(1)
781
+ } else if (value == 'reduce') {
782
+ if ((this.transformSalce - 0.2).toFixed(1) <= 0) {
783
+ return
784
+ }
785
+ this.handScale = 'auto'
786
+ this.transformSalce = (this.transformSalce - 0.2).toFixed(1)
787
+ } else if (value == 'auto') {
788
+ this.transformSalce = this.$refs.pdfView.clientWidth / this.pageSize.width
789
+ } else if (value == 'reality') {
790
+ this.transformSalce = 0.5
791
+ } else {
792
+ this.transformSalce = (value / 2).toFixed(1)
793
+ }
794
+ this.transformSalce = Number(this.transformSalce)
795
+ this.contentView.style.transform = 'scale(' + this.transformSalce + ')';
796
+ // this.getpdfResloutePage(this.cachePdf[0])
797
+ },
798
+ },
799
+ computed: {
800
+ perviewUrl () {
801
+ return '/web/viewer.html?file=' + '/pdflist/pdf4split-1.pdf'
802
+ },
803
+ setHeight () {
804
+ if (this.tagIds.length > 1) {
805
+ if (this.isPC) {
806
+ return 'calc(100% - 110px)'
807
+ } else {
808
+ return 'calc(100% - 60px)'
809
+ }
810
+ } else {
811
+ if (this.isPC) {
812
+ return 'calc(100% - 50px)'
813
+ } else {
814
+ return '100%'
815
+ }
816
+ }
817
+ }
818
+ },
819
+ watch: {
820
+ tagIds: {
821
+ handler (value) {
822
+ if (value && value.length) {
823
+ // 在 pdf_view 下创建 所有canvs的容器
824
+ this.contentView = document.createElement('div')
825
+ this.contentView.style.transformOrigin = '0px 0px 0px'
826
+ this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res => {
827
+ 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}
828
+ // 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}
829
+ // 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}
830
+ // 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}
831
+ // 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}
832
+ // if(value.length === 1) {
833
+ // this.$refs.pdfView.style.height = 'calc(100% - 50px)'
834
+ // }
835
+ if (res.data.code == 0) {
836
+ // tagIds 会按照gpt识别的生成有序的数组,前端直接按照下标的顺序取就可以了
837
+ // 缓存拿到的所有数据
838
+ this.cachePdf = res.data.data
839
+ let publicPageFileUrl = res.data.data[0].publicPageFileUrl
840
+ this.currentPage = 0
841
+ // console.log(publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')));
842
+ if (publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')) === '.pdf') {
843
+ this.preViewType = 'pdf'
844
+ // this.setPageAllLine(this.cachePdf)
845
+ this.getpdfResloutePage(res.data.data[0])
846
+ } else {
847
+ this.preViewType = 'excal'
848
+ this.$http.post(
849
+ '/knowledge-api/temporary-certificate/or-origin?expired=30',
850
+ publicPageFileUrl,
851
+ {
852
+ headers: {
853
+ "Content-Type": "application/json",
854
+ },
855
+ }).then(res => {
856
+ // 使用原声请求方式 axios会带有不需要的请求头
857
+ let xhr = new XMLHttpRequest();
858
+ xhr.open('GET', res.data || res.bodyText, true);
859
+ // 定义请求完成的处理函数,请求前也可以增加加载框/禁用下载按钮逻辑
860
+ xhr.onload = ({ currentTarget }) => {
861
+ // 请求完成
862
+ if (currentTarget.status === 200) { // 返回200
863
+ this.contentView.innerHTML = currentTarget.response
864
+ this.contentView.style.padding = '10px'
865
+ // this.contentView.style.position = 'relative'
866
+ this.$refs.pdfView.style.backgroundColor = '#FFFFFF'
867
+ this.$refs.pdfView.appendChild(this.contentView)
868
+ let allTr = Array.from(this.$refs.pdfView.getElementsByTagName('tr'))
869
+ this.allTr = []
870
+ for (let index = 0; index < allTr.length; index++) {
871
+ if (value.includes(allTr[index].getAttribute('tag-id'))) {
872
+ this.allTr.push(allTr[index])
873
+ }
874
+ }
875
+ this.currentChange(1)
876
+
877
+ }
878
+ }
879
+ xhr.send();
880
+ })
881
+ }
882
+ } else {
883
+ let div = document.createElement('div')
884
+ div.innerText = '文件加载异常'
885
+ this.contentView.appendChild(div)
886
+ this.$refs.pdfView.appendChild(this.contentView)
887
+ }
888
+ })
889
+ }
890
+ },
891
+ deep: true,
892
+ immediate: true
893
+ }
894
+ },
895
+ mounted () {
896
+ if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
897
+ this.isPC = false
898
+ } else {
899
+ this.isPC = true
900
+ }
901
+ }
902
+ }
903
+ </script>
904
+
905
+ <style lang="less" scoped>
906
+ .pdf_view {
907
+ width: 100%;
908
+ height: calc(100% - 110px);
909
+ overflow: auto;
910
+ background-color: #f5f7fb;
911
+ // margin-bottom: 60px;
912
+ box-sizing: border-box;
913
+
914
+ // position: relative;
915
+ // > div {
916
+ // width: 100%;
917
+ // height: 100%;
918
+ // overflow: hidden;
919
+ // overflow-y: auto;
920
+ // position: relative;
921
+ // }
922
+ >iframe {
923
+ width: 100%;
924
+ height: 100%;
925
+ }
926
+
927
+ a:link {
928
+ color: none;
929
+ }
930
+
931
+ a:visited {
932
+ color: none;
933
+ }
934
+
935
+ a:hover {
936
+ color: none;
937
+ }
938
+
939
+ a:active {
940
+ color: none;
941
+ }
942
+
943
+ .btn_footer {
944
+ width: 100%;
945
+ height: 60px;
946
+ display: flex;
947
+ align-items: center;
948
+ justify-content: space-around;
949
+ position: absolute;
950
+ bottom: 0px;
951
+ left: 0;
952
+ z-index: 999;
953
+ background: #ffffff;
954
+
955
+ .prev,
956
+ .next {
957
+ width: 35%;
958
+ height: 40px;
959
+ display: flex;
960
+ align-items: center;
961
+ justify-content: center;
962
+ border-radius: 50px;
963
+ cursor: pointer;
964
+ }
965
+
966
+ .prev {
967
+ background: #F2F5FA;
968
+ color: #000;
969
+ }
970
+
971
+ .next {
972
+ background: #366aff;
973
+ color: #ffffff;
974
+ }
975
+ }
976
+
977
+ #pagination {
978
+ .total-class {
979
+ margin-right: 13px;
980
+ font-weight: 400;
981
+ }
982
+
983
+ position: absolute;
984
+ bottom: 0px;
985
+ right: 0;
986
+ width: 100%;
987
+ display: flex;
988
+ align-items: center;
989
+ justify-content: center;
990
+ height: 50px;
991
+ background-color: white;
992
+ box-shadow: 0px 0px 18px 0px rgba(29, 55, 129, 0.07);
993
+ border-radius: 5px;
994
+ z-index: 1000;
995
+
996
+ /deep/.el-pagination {
997
+ margin-right: 110px;
998
+ }
999
+
1000
+ /deep/.el-pager {
1001
+ background: #EDF0F6;
1002
+ border-radius: 15px;
1003
+ }
1004
+
1005
+ /deep/.el-pagination.is-background .btn-next {
1006
+ width: 30px;
1007
+ height: 30px;
1008
+ background: #EDF0F6;
1009
+ border-radius: 50%;
1010
+ }
1011
+
1012
+ /deep/.el-pagination .btn-next {
1013
+ width: 30px;
1014
+ height: 30px;
1015
+ background: #EDF0F6;
1016
+ border-radius: 50%;
1017
+ padding-left: 0;
1018
+ margin-left: 5px;
1019
+ }
1020
+
1021
+ /deep/.el-pagination .btn-prev {
1022
+ width: 30px;
1023
+ height: 30px;
1024
+ background: #EDF0F6;
1025
+ border-radius: 50%;
1026
+ padding-right: 0;
1027
+ margin-right: 5px;
1028
+ }
1029
+
1030
+ /deep/.el-pagination button {
1031
+ padding: 0;
1032
+ min-width: 30px;
1033
+ }
1034
+
1035
+ /deep/.el-pager li {
1036
+ background: #EDF0F6;
1037
+ height: 30px;
1038
+ min-width: 30px;
1039
+ line-height: 30px;
1040
+ font-size: 12px;
1041
+ color: #717b90;
1042
+ }
1043
+
1044
+ /deep/.el-pager li:first-child {
1045
+ border-bottom-left-radius: 15px !important;
1046
+ border-top-left-radius: 15px !important;
1047
+ }
1048
+
1049
+ /deep/.el-pager li:last-child {
1050
+ border-top-right-radius: 15px !important;
1051
+ border-bottom-right-radius: 15px !important;
1052
+ }
1053
+
1054
+ /deep/.el-pager li.active {
1055
+ width: 30px;
1056
+ height: 30px;
1057
+ min-width: 30px;
1058
+ background: #366AFF;
1059
+ border: 3px solid #A1B9FF;
1060
+ border-radius: 50%;
1061
+ line-height: 24px;
1062
+ color: white;
1063
+ }
1064
+
1065
+ /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
1066
+ background: #366AFF;
1067
+ }
1068
+ }
1069
+
1070
+ .change_scale {
1071
+ width: 100%;
1072
+ height: 50px;
1073
+ position: absolute;
1074
+ top: 50px;
1075
+ left: 0;
1076
+ background: #ffffff;
1077
+ display: flex;
1078
+ align-items: center;
1079
+ padding: 0 10px;
1080
+ box-sizing: border-box;
1081
+
1082
+ section {
1083
+ cursor: pointer;
1084
+ width: 30px;
1085
+ height: 30px;
1086
+ margin-right: 5px;
1087
+ border-radius: 5px;
1088
+ display: flex;
1089
+ align-items: center;
1090
+ justify-content: center;
1091
+
1092
+ i {
1093
+ font-weight: 900;
1094
+ }
1095
+ }
1096
+
1097
+ section:hover {
1098
+ background: rgba(221, 222, 223, 1);
1099
+ }
1100
+ }
1101
+ }
1102
+ </style>
1103
+ <style lang="less">
1104
+ .animation {
1105
+ animation-name: highlight;
1106
+ animation-duration: 4s;
1107
+ }
1108
+
1109
+ @keyframes highlight {
1110
+ 0% {
1111
+ background: rgba(255, 136, 0, 0.3);
1112
+ }
1113
+
1114
+ 25% {
1115
+ background: rgba(255, 136, 0, 0.6);
1116
+ }
1117
+
1118
+ 50% {
1119
+ background: rgba(255, 136, 0, 0.3);
1120
+ }
1121
+
1122
+ 75% {
1123
+ background: rgba(255, 136, 0, 0.6);
1124
+ }
1125
+
1126
+ 100% {
1127
+ background: rgba(255, 136, 0, 0.3);
1128
+ }
1129
1129
  }</style>