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