askbot-dragon 1.3.55 → 1.3.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +27 -27
  2. package/babel.config.js +6 -6
  3. package/dragon.iml +7 -7
  4. package/package.json +58 -58
  5. package/public/index.html +58 -58
  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/script.js +36 -36
  14. package/src/assets/less/common.css +6773 -6773
  15. package/src/assets/less/converSationContainer/common.less +191 -191
  16. package/src/assets/less/converSationContainer/converSatonContainer.less +493 -493
  17. package/src/assets/less/iconfont.css +37 -37
  18. package/src/assets/less/ticketMessage.less +211 -211
  19. package/src/components/ActionAlertIframe.vue +112 -112
  20. package/src/components/AiGuide.vue +467 -467
  21. package/src/components/AnswerDocknowledge.vue +417 -367
  22. package/src/components/AnswerVoice.vue +280 -280
  23. package/src/components/AskIFrame.vue +15 -15
  24. package/src/components/ConversationContainer.vue +4075 -4061
  25. package/src/components/FileType.vue +86 -86
  26. package/src/components/Message.vue +27 -27
  27. package/src/components/actionSatisfaction.vue +107 -107
  28. package/src/components/actionSendToBot.vue +62 -62
  29. package/src/components/answerDissatisfaction.vue +62 -62
  30. package/src/components/answerRadio.vue +76 -76
  31. package/src/components/ask-components/DissatisfactionOptions.vue +57 -57
  32. package/src/components/ask-components/Msgloading.vue +37 -37
  33. package/src/components/ask-components/SatisfactionV2.vue +15 -15
  34. package/src/components/askVideo.vue +138 -138
  35. package/src/components/assetDetails.vue +370 -370
  36. package/src/components/assetMessage.vue +228 -228
  37. package/src/components/associationIntention.vue +331 -331
  38. package/src/components/attachmentPreview.vue +90 -90
  39. package/src/components/botActionSatisfactor.vue +68 -68
  40. package/src/components/chatContent.vue +513 -513
  41. package/src/components/feedBack.vue +136 -136
  42. package/src/components/fielListView.vue +349 -349
  43. package/src/components/file/AliyunOssComponents.vue +108 -108
  44. package/src/components/formTemplate.vue +3363 -3363
  45. package/src/components/loadingProcess.vue +164 -164
  46. package/src/components/message/ActionAlertIframe.vue +112 -112
  47. package/src/components/message/ShopMessage.vue +164 -164
  48. package/src/components/message/TextMessage.vue +924 -924
  49. package/src/components/message/TicketMessage.vue +177 -177
  50. package/src/components/message/swiper/index.js +4 -4
  51. package/src/components/message/swiper/ticketSwiper.vue +503 -503
  52. package/src/components/message/swiper/ticketSwiperItem.vue +61 -61
  53. package/src/components/msgLoading.vue +231 -231
  54. package/src/components/myPopup.vue +70 -70
  55. package/src/components/pdfPosition.vue +1009 -378
  56. package/src/components/popup.vue +227 -227
  57. package/src/components/previewDoc.vue +226 -226
  58. package/src/components/previewPdf.vue +221 -220
  59. package/src/components/receiverMessagePlatform.vue +65 -65
  60. package/src/components/recommend.vue +89 -89
  61. package/src/components/selector/hOption.vue +20 -20
  62. package/src/components/selector/hSelector.vue +199 -199
  63. package/src/components/selector/hWrapper.vue +216 -216
  64. package/src/components/senderMessagePlatform.vue +50 -50
  65. package/src/components/source/BotMessage.vue +24 -24
  66. package/src/components/source/CustomMessage.vue +24 -24
  67. package/src/components/test.vue +260 -260
  68. package/src/components/tree.vue +294 -294
  69. package/src/components/utils/AliyunIssUtil.js +72 -72
  70. package/src/components/utils/ckeditor.js +155 -155
  71. package/src/components/utils/ckeditorImageUpload/command.js +109 -109
  72. package/src/components/utils/ckeditorImageUpload/editing.js +11 -11
  73. package/src/components/utils/ckeditorImageUpload/plugin-image.js +11 -11
  74. package/src/components/utils/ckeditorImageUpload/toolbar-ui.js +40 -40
  75. package/src/components/utils/ckeditorfileUpload/common.js +111 -111
  76. package/src/components/utils/ckeditorfileUpload/editing.js +11 -11
  77. package/src/components/utils/ckeditorfileUpload/plugin_file.js +11 -11
  78. package/src/components/utils/ckeditorfileUpload/toolbar_ui.js +34 -34
  79. package/src/components/utils/format_date.js +25 -25
  80. package/src/components/utils/index.js +6 -6
  81. package/src/components/utils/math_utils.js +29 -29
  82. package/src/components/voiceComponent.vue +119 -119
  83. package/src/main.js +60 -60
  84. package/vue.config.js +55 -55
@@ -1,379 +1,1010 @@
1
- <template>
2
- <div class="pdf_view" ref="pdfView" @scroll="pdfScroll">
3
- </div>
4
- </template>
5
-
6
- <script>
7
- import _ from 'lodash'
8
- // import * as pdfjsLib from 'pdfjs-dist'
9
- // pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker';
10
- // import { TextLayerBuilder } from "pdfjs-dist/web/pdf_viewer";
11
- // EventBus pdf_viewer 支持绑定自定义事件,一版不做
12
- // import 'pdfjs-dist/web/pdf_viewer.css'
13
-
14
- const pdfjsLib = window['pdfjs-dist']
15
- if(pdfjsLib) {
16
- pdfjsLib.GlobalWorkerOptions.workerSrc = window['pdfjsWorker']
17
- // 'pdfjs-dist/build/pdf.worker';
18
- }
19
- const { TextLayerBuilder } = window['pdfjsViewer']
20
- export default {
21
- name: 'pdfView',
22
- props:['tagId'],
23
- data() {
24
- return {
25
- url:'',
26
- pages:[],
27
- pageLoadStatus:{
28
- WAIT: 0,
29
- LOADED:1,
30
- },
31
- scale: 1,
32
- rotation:0,
33
- pageSize: {},
34
- PAGE_INTVERVAL: 15,
35
- SLICE_COUNT:5,
36
- contentView:null,
37
- fisrtLoad:true,
38
- TextLayerBuilder:null,
39
- totalPageCount: 0,
40
- identifyTextPostion:{
41
- top: 0,
42
- left: 0 ,
43
- width: 100,
44
- height: 0,
45
- page: 1,
46
- pageHeight:0,
47
- pageWidth:0,
48
- extractInfo:{}
49
- },
50
- pdfUrl:''
51
- }
52
- },
53
- methods:{
54
- async loadPdfData(loadPage) {
55
- // pdfjsLib.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/legacy/build/pdf.worker.entry.js");
56
- // 拿到第一个分片
57
- const { startPage, url } = await this.fetchPdfFragment(loadPage);
58
-
59
- let loadingTask = pdfjsLib.getDocument(url)
60
- loadingTask.promise.then((pdfDoc) => {
61
- // 将已经下载的分片保存到 pages 数组中
62
- for (let i = 0; i < pdfDoc.numPages; i += 1) {
63
- const pageIndex = startPage + i;
64
- const page = this.pages[pageIndex - 1];
65
- if (page.loadStatus !== this.pageLoadStatus.LOADED) {
66
- pdfDoc.getPage(i + 1).then((pdfPage) => {
67
- page.pdfPage = pdfPage;
68
- page.loadStatus = this.pageLoadStatus.LOADED;
69
- // 通知可以进行渲染了
70
- this.startRenderPages(pdfPage, page, pageIndex)
71
- });
72
- }
73
- }
74
- });
75
- },
76
- initPages(totalPage) {
77
- // const pages = [];
78
- this.totalPageCount = totalPage
79
- for (let i = 0; i < totalPage; i += 1) {
80
- this.pages.push({
81
- pageNo: i + 1,
82
- loadStatus: this.pageLoadStatus.WAIT,
83
- pdfPage: null,
84
- dom: null
85
- });
86
- }
87
- },
88
- async fetchPdfFragment(pageIndex) {
89
- // 置换加签后的文件地址。
90
- let obj = {}
91
- await this.$http.post(
92
- '/knowledge-api/temporary-certificate/or-origin?expired=30',
93
- this.pdfUrl + pageIndex + '.pdf',
94
- {
95
- headers: {
96
- "Content-Type": "application/json",
97
- },
98
- }).then(async res =>{
99
- if(res.data) {
100
- // 最后返回一个 包含这4个参数的对象
101
- obj = await {
102
- "startPage": pageIndex, // 分片的开始页码
103
- "endPage": pageIndex + 5, // 分片结束页码
104
- "totalPage": this.totalPageCount, // pdf 总页数
105
- "url": res.data // 分片内容下载地址
106
- }
107
- }
108
- })
109
- return obj
110
- },
111
- startRenderPages(pdfPage, page , pageIndex) {
112
- const viewport = pdfPage.getViewport({
113
- scale: this.scale, // 缩放的比例
114
- rotation: this.rotation, // 旋转的角度
115
- });
116
- // 记录pdf页面高度
117
- const pageSize = {
118
- width: viewport.width,
119
- height: viewport.height,
120
- }
121
- this.pageSize = pageSize
122
- // 创建内容绘制区,并设置大小
123
- this.contentView.style.width = `${ pageSize.width }px`;
124
- this.contentView.style.height = `${( this.totalPageCount * (pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
125
- this.contentView.style.margin = '0 auto 0'
126
- this.contentView.style.position = 'relative'
127
- // contentView.style.overflowY = 'auto'
128
- this.$refs.pdfView.appendChild(this.contentView);
129
- this.renderPages(pageIndex)
130
- },
131
- renderPageContent(page, pageIndex) {
132
- const { pdfPage, pageNo, dom } = page;
133
- // dom 元素已存在,无须重新渲染,直接返回
134
- if (dom && dom.children.length != 0) {
135
- // console.log(dom.children, 'length');
136
- return;
137
- }
138
- const viewport = pdfPage.getViewport({
139
- scale: this.scale,
140
- rotation: this.rotation,
141
- });
142
- // 创建新的canvas
143
- const canvas = document.createElement('canvas');
144
- const context = canvas.getContext('2d');
145
- canvas.height = this.pageSize.height;
146
- canvas.width = this.pageSize.width;
147
- // 创建渲染的dom
148
- const pageDom = document.createElement('div');
149
- pageDom.style.position = 'absolute';
150
- pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
151
- pageDom.style.width = `${this.pageSize.width}px`;
152
- pageDom.style.height = `${this.pageSize.height}px`;
153
- pageDom.appendChild(canvas);
154
- // 渲染内容
155
- // console.log(pdfPage.render({
156
- // canvasContext: context,
157
- // viewport,
158
- // }));
159
- let renderContext = {
160
- canvasContext: context,
161
- viewport:viewport,
162
- }
163
- pdfPage.render(renderContext).promise.then(() =>{
164
- console.log(pdfPage.getTextContent(),'getTextContent');
165
- return pdfPage.getTextContent()
166
- }).then((textContent) =>{
167
- const textLayerDiv = document.createElement('div');
168
- textLayerDiv.setAttribute('class', 'textLayer');
169
- // 将文本图层div添加至每页pdf的div中
170
- // 创建新的TextLayerBuilder实例
171
- // 这里因为版本问题跟pc端有些差异
172
- pageDom.appendChild(textLayerDiv);
173
- let textLayer = new TextLayerBuilder({
174
- textLayerDiv:textLayerDiv,
175
- pageIndex: pdfPage._pageIndex,
176
- viewport: viewport,
177
- });
178
- textLayer.setTextContent(textContent);
179
- textLayer.render()
180
- })
181
- page.dom = pageDom;
182
- if(pageIndex == this.identifyTextPostion.page) {
183
- let div = document.createElement('div')
184
- div.style.position = 'absolute';
185
- let lineHeightScaleWidth = this.pageSize.width / this.identifyTextPostion.pageWidth
186
- let lineHeightScaleHeight = this.pageSize.height / this.identifyTextPostion.pageHeight
187
-
188
- div.style.left = this.identifyTextPostion.left * lineHeightScaleWidth + 'px',
189
- div.style.top = this.identifyTextPostion.top * lineHeightScaleHeight + 'px'
190
- div.style.height = this.identifyTextPostion.height * lineHeightScaleHeight + 'px' ;
191
- div.style.width = this.identifyTextPostion.width * lineHeightScaleWidth + 'px'
192
- div.style.backgroundColor = 'rgb(191, 185, 255, 0.5)'
193
- pageDom.appendChild(div)
194
- }
195
- this.contentView.appendChild(pageDom);
196
- if(this.fisrtLoad) {
197
- setTimeout(() =>{
198
- this.$refs.pdfView.scrollTop = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL))}`
199
- }, 100)
200
- this.fisrtLoad = false
201
- }
202
-
203
- },
204
- // 监听容器的滚动事件,触发 scrollPdf 方法
205
- // 这里加了防抖保证不会一次产生过多请求
206
- scrollPdf: _.debounce(function(e, that) {
207
- const scrollTop = e.target.scrollTop;
208
- const height = e.target.clientHeight;
209
- // 根据内容可视区域中心点计算页码, 没有滚动时,指向第一页
210
- const pageIndex = scrollTop > 0 ?
211
- Math.ceil((scrollTop + (height / 2)) / (that.pageSize.height + that.PAGE_INTVERVAL)) :
212
- 1;
213
- // that.loadBefore(pageIndex);
214
- // that.loadAfter(pageIndex);
215
- this.loadPdfData(pageIndex)
216
- }, 500),
217
- pdfScroll(e) {
218
- // console.log(e);
219
- this.scrollPdf(e,this)
220
- },
221
- // 分片每次只做一次处理,所以不考虑多片情况
222
- loadBefore(pageIndex) {
223
- this.loadPdfData(pageIndex)
224
- // const start = (Math.floor(pageIndex / this.SLICE_COUNT) * this.SLICE_COUNT) - (this.SLICE_COUNT - 1);
225
- // if (start > 0) {
226
- // // const prevPage = this.pages[start - 1] || {};
227
- // this.loadPdfData(start)
228
- // // prevPage.loadStatus === this.pageLoadStatus.WAIT && this.loadPdfData(start);
229
- // }
230
- },
231
- loadAfter(pageIndex) {
232
- this.loadPdfData(pageIndex)
233
- // const start = (Math.floor(pageIndex / this.SLICE_COUNT) * this.SLICE_COUNT) + 1;
234
- // if (start <= this.pages.length) {
235
- // // const nextPage = this.pages[start - 1] || {};
236
- // this.loadPdfData(start)
237
- // // nextPage.loadStatus === this.pageLoadStatus.WAIT && this.loadPdfData(start);
238
- // }
239
- },
240
- // 首先我们获取到需要渲染的范围
241
- // 根据当前的可视范围内的页码,我们前后只保留 8 页
242
- getRenderScope (pageIndex) {
243
- const pagesToRender = [];
244
- let i = pageIndex - 1;
245
- let j = pageIndex + 1;
246
- // pageIndex - 1 表示当前页码数 对应的下标位置
247
- pagesToRender.push(this.pages[pageIndex - 1]);
248
- while (pagesToRender.length < 8 && pagesToRender.length < this.pages.length) {
249
- if (i > 0) {
250
- pagesToRender.push(this.pages[i - 1]);
251
- i -= 1;
252
- }
253
- if (pagesToRender.length >= 8) {
254
- break;
255
- }
256
- if (j <= this.pages.length) {
257
- pagesToRender.push(this.pages[j - 1]);
258
- j += 1;
259
- }
260
- }
261
- return pagesToRender;
262
- },
263
- // 渲染需要展示的页面,不需展示的页码将其清除
264
- renderPages (pageIndex) {
265
- const pagesToRender = this.getRenderScope(pageIndex);
266
- for (const i of this.pages) {
267
- if (pagesToRender.includes(i)) {
268
- i.loadStatus === this.pageLoadStatus.LOADED ?
269
- this.renderPageContent(i, pageIndex) :
270
- this.renderPageLoading(i);
271
- } else {
272
- this.clearPage(i);
273
- }
274
- }
275
- },
276
- // 清除页面 dom
277
- clearPage (page) {
278
- if (page.dom) {
279
- this.contentView.removeChild(page.dom);
280
- page.loadStatus = 0
281
- page.dom = undefined;
282
- }
283
- },
284
- // 页面正在下载时渲染loading视图
285
- renderPageLoading (page) {
286
- const { pageNo, dom } = page;
287
- if (dom && dom.children.length != 0) {
288
- return;
289
- }
290
- const pageDom = document.createElement('div');
291
- pageDom.style.width = `${this.pageSize.width}px`;
292
- pageDom.style.height = `${this.pageSize.height}px`;
293
- pageDom.style.position = 'absolute';
294
- pageDom.style.top = `${
295
- ((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL
296
- }px`;
297
- pageDom.style.backgroundImage = `url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif')`
298
- pageDom.style.backgroundPosition = 'center'
299
- pageDom.style.backgroundRepeat = 'no-repeat'
300
- pageDom.style.backgroundColor = '#FFF'
301
- page.dom = pageDom;
302
- this.contentView.appendChild(pageDom);
303
- }
304
- },
305
- computed:{
306
- perviewUrl() {
307
- return '/web/viewer.html?file=' + '/pdflist/pdf4split-1.pdf'
308
- }
309
- },
310
- watch:{
311
- tagId: {
312
- handler(value) {
313
- if(value) {
314
- // pdf_view 下创建 所有canvs的容器
315
- this.contentView = document.createElement('div')
316
- this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/' + value).then(res =>{
317
- if(res.data.code == 0) {
318
- let pdfResloute = res.data.data
319
- // 根据当前页面宽度设置缩放比例
320
- this.scale = this.$refs.pdfView.clientWidth / pdfResloute.pageWidth
321
- // this.scale = 1
322
- // 从后端获取到当前分片后所有的pdf页码,初始化数组,数组下{} 对应每页pdf文件
323
- this.pdfUrl = pdfResloute.publicPageFileUrl.substring(0, pdfResloute.publicPageFileUrl.lastIndexOf('/') + 1)
324
- this.identifyTextPostion.extractInfo = pdfResloute.extractInfo
325
- this.identifyTextPostion.left = pdfResloute.extractInfo.location[0]
326
- this.identifyTextPostion.top = pdfResloute.extractInfo.location[1]
327
- this.identifyTextPostion.width = pdfResloute.extractInfo.location[2]
328
- this.identifyTextPostion.height = pdfResloute.extractInfo.location[3]
329
- this.identifyTextPostion.page = pdfResloute.page
330
- this.identifyTextPostion.pageHeight = pdfResloute.pageHeight
331
- this.identifyTextPostion.pageWidth = pdfResloute.pageWidth
332
- this.initPages(pdfResloute.total)
333
- // 定位功能,加载对应页码位置
334
- this.loadPdfData(pdfResloute.page)
335
- } else {
336
- let div = document.createElement('div')
337
- div.innerText = '文件加载异常'
338
- this.contentView.appendChild(div)
339
- this.$refs.pdfView.appendChild(this.contentView)
340
- }
341
- })
342
- }
343
- console.log(value);
344
- },
345
- deep:true,
346
- immediate:true
347
- }
348
- },
349
-
350
- mounted() {
351
- // pdf_view 下创建 所有canvs的容器
352
- // this.contentView = document.createElement('div')
353
- // // 从后端获取到当前分片后所有的pdf页码,初始化数组,数组下{} 对应每页pdf文件
354
- // this.initPages(8);
355
- // // 定位功能,加载对应页码位置
356
- // this.loadPdfData(1)
357
- }
358
- }
359
- </script>
360
-
361
- <style lang="less" scoped>
362
- .pdf_view {
363
- width: 100%;
364
- height: 100%;
365
- overflow: auto;
366
- background-color: #f5f7fb;
367
- // > div {
368
- // width: 100%;
369
- // height: 100%;
370
- // overflow: hidden;
371
- // overflow-y: auto;
372
- // position: relative;
373
- // }
374
- > iframe {
375
- width: 100%;
376
- height: 100%;
377
- }
378
- }
1
+ <template>
2
+ <div class="pdf_view" ref="pdfView" @scroll="pdfScroll">
3
+ <div class="btn_footer">
4
+ <div class="prev" @click="prev">上一段</div>
5
+ <div class="next" @click="next">下一段</div>
6
+ </div>
7
+ </div>
8
+ </template>
9
+
10
+ <script>
11
+ import _ from 'lodash'
12
+ // import * as pdfjsLib from 'pdfjs-dist'
13
+ // pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker';
14
+ // import { TextLayerBuilder } from "pdfjs-dist/web/pdf_viewer";
15
+ // EventBus pdf_viewer 支持绑定自定义事件,一版不做
16
+ // import 'pdfjs-dist/web/pdf_viewer.css'
17
+ /* eslint-disable */
18
+ const pdfjsLib = window['pdfjsLib']
19
+ if(pdfjsLib) {
20
+ pdfjsLib.GlobalWorkerOptions.workerSrc = window['pdfjs-dist/build/pdf.worker']
21
+ // 'pdfjs-dist/build/pdf.worker';
22
+ }
23
+ const { TextLayerBuilder } = window['pdfjs-dist/web/pdf_viewer']
24
+ export default {
25
+ name: 'pdfView',
26
+ props:['tagIds'],
27
+ data() {
28
+ return {
29
+ url: '',
30
+ // pdfjsLib: window['pdfjs-dist/build/pdf'],
31
+ // pdfjsLib: pdfjsLib,
32
+ pages: [],
33
+ pageLoadStatus: {
34
+ WAIT: 0,
35
+ LOADED: 1,
36
+ },
37
+ scale: 1,
38
+ rotation: 0,
39
+ pageSize: {},
40
+ PAGE_INTVERVAL: 15,
41
+ SLICE_COUNT: 5,
42
+ contentView: null,
43
+ fisrtLoad: true,
44
+ TextLayerBuilder: null,
45
+ totalPageCount: 0,
46
+ identifyTextPostion: {
47
+ top: 0,
48
+ left: 0,
49
+ width: 100,
50
+ height: 0,
51
+ page: 1,
52
+ pageHeight: 0,
53
+ pageWidth: 0,
54
+ extractInfo: {},
55
+ currentPageAllLine: []
56
+ },
57
+ currentPageAllLine: [],
58
+ pdfUrl: '',
59
+ cachePdf: [],
60
+ newViewer: null,
61
+ currentPage: 0,
62
+ changetoolbar: false,
63
+ allTr:[],
64
+ preViewType: 'pdf'
65
+ }
66
+ },
67
+ // methods:{
68
+ // getpdfResloutePage (pdfResloute) {
69
+ // // 根据当前页面宽度设置缩放比例
70
+ // this.scale = this.$refs.pdfView.clientWidth / pdfResloute.pageWidth
71
+ // // this.scale = 1
72
+ // // 从后端获取到当前分片后所有的pdf页码,初始化数组,数组下{} 对应每页pdf文件
73
+ // this.pdfUrl = pdfResloute.publicPageFileUrl.substring(0, pdfResloute.publicPageFileUrl.lastIndexOf('/') + 1)
74
+ // this.initPages(pdfResloute.total)
75
+ // // 定位功能,加载对应页码位置
76
+ // this.loadPdfData(pdfResloute.page)
77
+ // },
78
+ // setPageAllLine (arr) {
79
+ // this.currentPageAllLine = []
80
+ // arr.forEach((item, index) => {
81
+ // let i = this.currentPageAllLine.findIndex(l => { return l.page && l.page == item.page })
82
+ // if (i != -1) {
83
+ // // this.currentPageAllLine[i].allLines.lines.push(item.extractInfo.lines)
84
+ // this.currentPageAllLine[i].allLines.push({
85
+ // pageCount: index,
86
+ // lines: item.extractInfo.lines
87
+ // })
88
+ // } else {
89
+ // this.currentPageAllLine.push({
90
+ // page: item.page,
91
+ // allLines: [{
92
+ // pageCount: index,
93
+ // lines: item.extractInfo.lines
94
+ // }],
95
+ // })
96
+ // }
97
+ // })
98
+ // },
99
+ // async loadPdfData(loadPage) {
100
+ // // pdfjsLib.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/legacy/build/pdf.worker.entry.js");
101
+ // // 拿到第一个分片
102
+ // const { startPage, url } = await this.fetchPdfFragment(loadPage);
103
+ // console.log(url);
104
+ // let loadingTask = pdfjsLib.getDocument(url)
105
+ // console.log(loadingTask);
106
+ // loadingTask.then((pdfDoc) => {
107
+ // // 将已经下载的分片保存到 pages 数组中
108
+ // for (let i = 0; i < pdfDoc.numPages; i += 1) {
109
+ // const pageIndex = startPage + i;
110
+ // const page = this.pages[pageIndex - 1];
111
+ // if (page.loadStatus !== this.pageLoadStatus.LOADED) {
112
+ // pdfDoc.getPage(i + 1).then((pdfPage) => {
113
+ // page.pdfPage = pdfPage;
114
+ // page.loadStatus = this.pageLoadStatus.LOADED;
115
+ // // 通知可以进行渲染了
116
+ // this.startRenderPages(pdfPage, page, pageIndex)
117
+ // });
118
+ // }
119
+ // }
120
+ // });
121
+ // },
122
+ // initPages(totalPage) {
123
+ // // const pages = [];
124
+ // this.totalPageCount = totalPage
125
+ // for (let i = 0; i < totalPage; i += 1) {
126
+ // this.pages.push({
127
+ // pageNo: i + 1,
128
+ // loadStatus: this.pageLoadStatus.WAIT,
129
+ // pdfPage: null,
130
+ // dom: null
131
+ // });
132
+ // }
133
+ // },
134
+ // async fetchPdfFragment (pageIndex) {
135
+ // // 置换加签后的文件地址。
136
+ // let obj = {}
137
+ // await this.$http.post(
138
+ // '/knowledge-api/temporary-certificate/or-origin?expired=30', this.pdfUrl + pageIndex + '.pdf', {
139
+ // headers:{
140
+ // "Content-Type": "application/json",
141
+ // }
142
+ // }).then(async res => {
143
+ // console.log(res,'resres');
144
+ // if (res.bodyText) {
145
+ // // 最后返回一个 包含这4个参数的对象
146
+ // obj = await {
147
+ // "startPage": pageIndex, // 分片的开始页码
148
+ // "endPage": pageIndex + 5, // 分片结束页码
149
+ // "totalPage": this.totalPageCount, // pdf 总页数
150
+ // "url": res.bodyText // 分片内容下载地址
151
+ // }
152
+ // }
153
+ // })
154
+ // return obj
155
+ // },
156
+ // startRenderPages(pdfPage, page , pageIndex) {
157
+ // const viewport = pdfPage.getViewport({
158
+ // scale: this.scale, // 缩放的比例
159
+ // rotation: this.rotation, // 旋转的角度
160
+ // });
161
+ // // 记录pdf页面高度
162
+ // const pageSize = {
163
+ // width: viewport.width,
164
+ // height: viewport.height,
165
+ // }
166
+ // this.pageSize = pageSize
167
+ // // 创建内容绘制区,并设置大小
168
+ // this.contentView.style.width = `${ pageSize.width }px`;
169
+ // this.contentView.style.height = `${( this.totalPageCount * (pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
170
+ // this.contentView.style.margin = '0 auto 0'
171
+ // this.contentView.style.position = 'relative'
172
+ // // contentView.style.overflowY = 'auto'
173
+ // this.$refs.pdfView.appendChild(this.contentView);
174
+ // this.renderPages(pageIndex)
175
+ // },
176
+ // renderPageContent(page, pageIndex) {
177
+ // const { pdfPage, pageNo, dom } = page;
178
+ // // dom 元素已存在,无须重新渲染,直接返回
179
+ // if (dom && dom.children.length != 0) {
180
+ // // console.log(dom.children, 'length');
181
+ // return;
182
+ // }
183
+ // const viewport = pdfPage.getViewport({
184
+ // scale: this.scale,
185
+ // rotation: this.rotation,
186
+ // });
187
+ // // 创建新的canvas
188
+ // const canvas = document.createElement('canvas');
189
+ // const context = canvas.getContext('2d');
190
+ // canvas.height = this.pageSize.height;
191
+ // canvas.width = this.pageSize.width;
192
+ // // 创建渲染的dom
193
+ // const pageDom = document.createElement('div');
194
+ // pageDom.style.position = 'absolute';
195
+ // pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
196
+ // pageDom.style.width = `${this.pageSize.width}px`;
197
+ // pageDom.style.height = `${this.pageSize.height}px`;
198
+ // pageDom.appendChild(canvas);
199
+ // // 渲染内容
200
+ // // console.log(pdfPage.render({
201
+ // // canvasContext: context,
202
+ // // viewport,
203
+ // // }));
204
+ // let renderContext = {
205
+ // canvasContext: context,
206
+ // viewport:viewport,
207
+ // }
208
+ // pdfPage.render(renderContext).promise.then(() =>{
209
+ // console.log(pdfPage.getTextContent(),'getTextContent');
210
+ // return pdfPage.getTextContent()
211
+ // }).then((textContent) =>{
212
+ // const textLayerDiv = document.createElement('div');
213
+ // textLayerDiv.setAttribute('class', 'textLayer');
214
+ // // 将文本图层div添加至每页pdf的div中
215
+ // // 创建新的TextLayerBuilder实例
216
+ // // 这里因为版本问题跟pc端有些差异
217
+ // pageDom.appendChild(textLayerDiv);
218
+ // let textLayer = new TextLayerBuilder({
219
+ // textLayerDiv:textLayerDiv,
220
+ // pageIndex: pdfPage._pageIndex,
221
+ // viewport: viewport,
222
+ // });
223
+ // textLayer.setTextContent(textContent);
224
+ // textLayer.render()
225
+ // })
226
+ // page.dom = pageDom;
227
+ // if(pageIndex == this.identifyTextPostion.page) {
228
+ // let div = document.createElement('div')
229
+ // div.style.position = 'absolute';
230
+ // let lineHeightScaleWidth = this.pageSize.width / this.identifyTextPostion.pageWidth
231
+ // let lineHeightScaleHeight = this.pageSize.height / this.identifyTextPostion.pageHeight
232
+
233
+ // div.style.left = this.identifyTextPostion.left * lineHeightScaleWidth + 'px',
234
+ // div.style.top = this.identifyTextPostion.top * lineHeightScaleHeight + 'px'
235
+ // div.style.height = this.identifyTextPostion.height * lineHeightScaleHeight + 'px' ;
236
+ // div.style.width = this.identifyTextPostion.width * lineHeightScaleWidth + 'px'
237
+ // div.style.backgroundColor = 'rgb(191, 185, 255, 0.5)'
238
+ // pageDom.appendChild(div)
239
+ // }
240
+ // this.contentView.appendChild(pageDom);
241
+ // if(this.fisrtLoad) {
242
+ // setTimeout(() =>{
243
+ // this.$refs.pdfView.scrollTop = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL))}`
244
+ // }, 100)
245
+ // this.fisrtLoad = false
246
+ // }
247
+
248
+ // },
249
+ // // 监听容器的滚动事件,触发 scrollPdf 方法
250
+ // // 这里加了防抖保证不会一次产生过多请求
251
+ // scrollPdf: _.debounce(function(e, that) {
252
+ // const scrollTop = e.target.scrollTop;
253
+ // const height = e.target.clientHeight;
254
+ // // 根据内容可视区域中心点计算页码, 没有滚动时,指向第一页
255
+ // const pageIndex = scrollTop > 0 ?
256
+ // Math.ceil((scrollTop + (height / 2)) / (that.pageSize.height + that.PAGE_INTVERVAL)) :
257
+ // 1;
258
+ // // that.loadBefore(pageIndex);
259
+ // // that.loadAfter(pageIndex);
260
+ // this.loadPdfData(pageIndex)
261
+ // }, 500),
262
+ // pdfScroll(e) {
263
+ // // console.log(e);
264
+ // this.scrollPdf(e,this)
265
+ // },
266
+ // // 分片每次只做一次处理,所以不考虑多片情况
267
+ // loadBefore(pageIndex) {
268
+ // this.loadPdfData(pageIndex)
269
+ // // const start = (Math.floor(pageIndex / this.SLICE_COUNT) * this.SLICE_COUNT) - (this.SLICE_COUNT - 1);
270
+ // // if (start > 0) {
271
+ // // // const prevPage = this.pages[start - 1] || {};
272
+ // // this.loadPdfData(start)
273
+ // // // prevPage.loadStatus === this.pageLoadStatus.WAIT && this.loadPdfData(start);
274
+ // // }
275
+ // },
276
+ // loadAfter(pageIndex) {
277
+ // this.loadPdfData(pageIndex)
278
+ // // const start = (Math.floor(pageIndex / this.SLICE_COUNT) * this.SLICE_COUNT) + 1;
279
+ // // if (start <= this.pages.length) {
280
+ // // // const nextPage = this.pages[start - 1] || {};
281
+ // // this.loadPdfData(start)
282
+ // // // nextPage.loadStatus === this.pageLoadStatus.WAIT && this.loadPdfData(start);
283
+ // // }
284
+ // },
285
+ // // 首先我们获取到需要渲染的范围
286
+ // // 根据当前的可视范围内的页码,我们前后只保留 8
287
+ // getRenderScope (pageIndex) {
288
+ // const pagesToRender = [];
289
+ // let i = pageIndex - 1;
290
+ // let j = pageIndex + 1;
291
+ // // pageIndex - 1 表示当前页码数 对应的下标位置
292
+ // pagesToRender.push(this.pages[pageIndex - 1]);
293
+ // while (pagesToRender.length < 8 && pagesToRender.length < this.pages.length) {
294
+ // if (i > 0) {
295
+ // pagesToRender.push(this.pages[i - 1]);
296
+ // i -= 1;
297
+ // }
298
+ // if (pagesToRender.length >= 8) {
299
+ // break;
300
+ // }
301
+ // if (j <= this.pages.length) {
302
+ // pagesToRender.push(this.pages[j - 1]);
303
+ // j += 1;
304
+ // }
305
+ // }
306
+ // return pagesToRender;
307
+ // },
308
+ // // 渲染需要展示的页面,不需展示的页码将其清除
309
+ // renderPages (pageIndex) {
310
+ // const pagesToRender = this.getRenderScope(pageIndex);
311
+ // for (const i of this.pages) {
312
+ // if (pagesToRender.includes(i)) {
313
+ // i.loadStatus === this.pageLoadStatus.LOADED ?
314
+ // this.renderPageContent(i, pageIndex) :
315
+ // this.renderPageLoading(i);
316
+ // } else {
317
+ // this.clearPage(i);
318
+ // }
319
+ // }
320
+ // },
321
+ // // 清除页面 dom
322
+ // clearPage (page) {
323
+ // if (page.dom) {
324
+ // this.contentView.removeChild(page.dom);
325
+ // page.loadStatus = 0
326
+ // page.dom = undefined;
327
+ // }
328
+ // },
329
+ // // 页面正在下载时渲染loading视图
330
+ // renderPageLoading (page) {
331
+ // const { pageNo, dom } = page;
332
+ // if (dom && dom.children.length != 0) {
333
+ // return;
334
+ // }
335
+ // const pageDom = document.createElement('div');
336
+ // pageDom.style.width = `${this.pageSize.width}px`;
337
+ // pageDom.style.height = `${this.pageSize.height}px`;
338
+ // pageDom.style.position = 'absolute';
339
+ // pageDom.style.top = `${
340
+ // ((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL
341
+ // }px`;
342
+ // pageDom.style.backgroundImage = `url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif')`
343
+ // pageDom.style.backgroundPosition = 'center'
344
+ // pageDom.style.backgroundRepeat = 'no-repeat'
345
+ // pageDom.style.backgroundColor = '#FFF'
346
+ // page.dom = pageDom;
347
+ // this.contentView.appendChild(pageDom);
348
+ // }
349
+ // },
350
+ methods: {
351
+ getpdfResloutePage (pdfResloute) {
352
+ // 根据当前页面宽度设置缩放比例
353
+ this.scale = this.$refs.pdfView.clientWidth / pdfResloute.pageWidth
354
+ // this.scale = 1
355
+ // 从后端获取到当前分片后所有的pdf页码,初始化数组,数组下{} 对应每页pdf文件
356
+ this.pdfUrl = pdfResloute.publicPageFileUrl.substring(0, pdfResloute.publicPageFileUrl.lastIndexOf('/') + 1)
357
+ this.initPages(pdfResloute.total)
358
+ // 定位功能,加载对应页码位置
359
+ this.loadPdfData(pdfResloute.page)
360
+ },
361
+ async loadPdfData (loadPage) {
362
+ if(this.pages[loadPage - 1] && this.pages[loadPage - 1].dom && this.pages[loadPage - 1].dom.children.length > 0) {
363
+ return
364
+ }
365
+ // pdfjsLib.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/legacy/build/pdf.worker.entry.js");
366
+ // 拿到第一个分片
367
+ const { startPage, url } = await this.fetchPdfFragment(loadPage);
368
+ let loadingTask = pdfjsLib.getDocument(url)
369
+ loadingTask.promise.then((pdfDoc) => {
370
+ // 将已经下载的分片保存到 pages 数组中
371
+ for (let i = 0; i < pdfDoc.numPages; i += 1) {
372
+ const pageIndex = startPage + i;
373
+ const page = this.pages[pageIndex - 1];
374
+ // 不在缓存列表内,重新获取本页pdf
375
+ if (page.loadStatus !== this.pageLoadStatus.LOADED) {
376
+ pdfDoc.getPage(i + 1).then((pdfPage) => {
377
+ page.pdfPage = pdfPage;
378
+ page.loadStatus = this.pageLoadStatus.LOADED;
379
+ // 通知可以进行渲染了
380
+ this.startRenderPages(pdfPage, page, pageIndex)
381
+ });
382
+ } else {
383
+ if (this.changetoolbar) {
384
+ this.$nextTick(() => {
385
+ this.renderHighlights()
386
+ })
387
+ this.changetoolbar = false
388
+ }
389
+ }
390
+ }
391
+ });
392
+ },
393
+ initPages (totalPage) {
394
+ // const pages = [];
395
+ this.totalPageCount = totalPage
396
+ for (let i = 0; i < totalPage; i += 1) {
397
+ this.pages.push({
398
+ pageNo: i + 1,
399
+ loadStatus: this.pageLoadStatus.WAIT,
400
+ pdfPage: null,
401
+ dom: null
402
+ });
403
+ }
404
+ },
405
+ async fetchPdfFragment (pageIndex) {
406
+ // 置换加签后的文件地址。
407
+ let obj = {}
408
+ await this.$http.post(
409
+ '/knowledge-api/temporary-certificate/or-origin?expired=30',
410
+ this.pdfUrl + pageIndex + '.pdf',
411
+ {
412
+ headers: {
413
+ "Content-Type": "application/json",
414
+ },
415
+ }).then(async res => {
416
+ if(res.bodyText) {
417
+ // 最后返回一个 包含这4个参数的对象
418
+ obj = await {
419
+ "startPage": pageIndex, // 分片的开始页码
420
+ "endPage": pageIndex + 5, // 分片结束页码
421
+ "totalPage": this.totalPageCount, // pdf 总页数
422
+ "url": res.bodyText // 分片内容下载地址
423
+ }
424
+ }
425
+ if (res.data) {
426
+ // 最后返回一个 包含这4个参数的对象
427
+ obj = await {
428
+ "startPage": pageIndex, // 分片的开始页码
429
+ "endPage": pageIndex + 5, // 分片结束页码
430
+ "totalPage": this.totalPageCount, // pdf 总页数
431
+ "url": res.data // 分片内容下载地址
432
+ }
433
+ }
434
+ })
435
+ return obj
436
+ },
437
+ startRenderPages (pdfPage, page, pageIndex) {
438
+ const viewport = pdfPage.getViewport({
439
+ scale: this.scale, // 缩放的比例
440
+ rotation: this.rotation, // 旋转的角度
441
+ });
442
+ // 记录pdf页面高度
443
+ const pageSize = {
444
+ width: viewport.width,
445
+ height: viewport.height,
446
+ }
447
+ this.pageSize = pageSize
448
+ // 创建内容绘制区,并设置大小
449
+ this.contentView.style.width = `${pageSize.width}px`;
450
+ this.contentView.style.height = `${(this.totalPageCount * (pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
451
+ this.contentView.style.margin = '0 auto 0'
452
+ this.contentView.style.position = 'relative'
453
+ // contentView.style.overflowY = 'auto'
454
+ this.$refs.pdfView.appendChild(this.contentView);
455
+ this.renderPages(pageIndex)
456
+ },
457
+ renderPageContent (page, pageIndex) {
458
+ const { pdfPage, pageNo, dom } = page;
459
+ // dom 元素已存在,无须重新渲染,直接返回
460
+ console.log(dom, 'dom');
461
+ if (dom && dom.children.length != 0) {
462
+ return;
463
+ }
464
+ const viewport = pdfPage.getViewport({
465
+ scale: this.scale,
466
+ rotation: this.rotation,
467
+ });
468
+ // 创建新的canvas
469
+ const canvas = document.createElement('canvas');
470
+ const context = canvas.getContext('2d');
471
+ canvas.height = this.pageSize.height;
472
+ canvas.width = this.pageSize.width;
473
+ // 创建渲染的dom
474
+ const pageDom = document.createElement('div');
475
+ pageDom.style.position = 'absolute';
476
+ pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL}px`;
477
+ pageDom.style.width = `${this.pageSize.width}px`;
478
+ pageDom.style.height = `${this.pageSize.height}px`;
479
+ pageDom.appendChild(canvas);
480
+ // 渲染内容
481
+ let renderContext = {
482
+ canvasContext: context,
483
+ viewport: viewport,
484
+ }
485
+ pdfPage.render(renderContext).promise.then(() => {
486
+ console.log(pdfPage.getTextContent(), 'getTextContent');
487
+ return pdfPage.getTextContent()
488
+ }).then((textContent) => {
489
+ const textLayerDiv = document.createElement('div');
490
+ textLayerDiv.setAttribute('class', 'textLayer');
491
+ // 将文本图层div添加至每页pdf的div中
492
+ // 创建新的TextLayerBuilder实例
493
+ let textLayer = new TextLayerBuilder({
494
+ textLayerDiv: textLayerDiv,
495
+ pageIndex: pdfPage._pageIndex,
496
+ viewport: viewport,
497
+ });
498
+ let findPage = this.currentPageAllLine.find(l => { return l.page == pageIndex })
499
+ if (findPage) {
500
+ let AllLines = findPage.allLines
501
+ // setTimeout(() => {
502
+ if (AllLines.length > 0) {
503
+ for (let j = 0; j < AllLines.length; j++) {
504
+ let lines = AllLines[j].lines
505
+ let rectdom = document.createElement('div')
506
+ rectdom.setAttribute('react-count', AllLines[j].pageCount);
507
+ rectdom.style.position = 'absolute';
508
+ rectdom.style.top = 0
509
+ rectdom.style.left = 0
510
+ rectdom.classList.add('rectdom')
511
+ for (let index = 0; index < lines.length; index++) {
512
+ if (!/^\s+$/g.test(lines[index].content)) {
513
+ let postionArr = lines[index].location
514
+ let div = document.createElement('div')
515
+ div.style.position = 'absolute';
516
+ div.style.left = postionArr[0] * this.scale + 'px',
517
+ // 后端返回的坐标有基线对齐的问题,top 值是后端算好(基线top - 文字高度),在此加上文字高度的 1/9 (大致比例)为实际展示出文字的top值
518
+ div.style.top = (postionArr[1] + postionArr[3] / 9) * this.scale + 'px'
519
+ div.style.height = postionArr[3] * this.scale + 'px';
520
+ div.style.width = postionArr[2] * this.scale + 'px'
521
+ div.style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
522
+ div.classList.add('lineHeight')
523
+ rectdom.appendChild(div)
524
+ }
525
+ }
526
+ if (rectdom.children.length > 0) {
527
+ pageDom.appendChild(rectdom)
528
+ }
529
+ }
530
+ }
531
+ // }, 0)
532
+ }
533
+ textLayer.setTextContent(textContent);
534
+ textLayer.render()
535
+ // pageDom.appendChild(textLayer.div);
536
+ page.dom = pageDom;
537
+ this.contentView.appendChild(pageDom);
538
+ if (this.changetoolbar) {
539
+ setTimeout(() => {
540
+ console.log('========');
541
+ this.renderHighlights()
542
+ this.changetoolbar = false
543
+ }, 100)
544
+ }
545
+ if (this.fisrtLoad) {
546
+ setTimeout(() => {
547
+ if (this.$refs.pdfView.clientHeight - (this.pageSize.height + this.PAGE_INTVERVAL) > (this.pageSize.height + this.PAGE_INTVERVAL)) {
548
+ let loadNum = Math.ceil(this.$refs.pdfView.clientHeight / (this.pageSize.height + this.PAGE_INTVERVAL))
549
+ for (let n = 0; n < loadNum; n++) {
550
+ this.loadPdfData(pageNo + n)
551
+ }
552
+ }
553
+ if (this.$refs.pdfView.scrollTop == Math.floor((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL))) {
554
+ this.fisrtLoad = false
555
+ } else {
556
+ this.$refs.pdfView.scrollTop = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL))}`
557
+ }
558
+ }, 100)
559
+ }
560
+ })
561
+
562
+ },
563
+ // 监听容器的滚动事件,触发 scrollPdf 方法
564
+ // 这里加了防抖保证不会一次产生过多请求
565
+ debounceScrollPdf: _.debounce(function (e, that) {
566
+ if (this.fisrtLoad) {
567
+ this.fisrtLoad = false
568
+ return
569
+ }
570
+ const scrollTop = e.target.scrollTop;
571
+ const height = e.target.clientHeight;
572
+ // 根据内容可视区域中心点计算页码, 没有滚动时,指向第一页
573
+ const pageIndex = scrollTop > 0 ?
574
+ Math.ceil((scrollTop + (height / 2)) / (that.pageSize.height + that.PAGE_INTVERVAL)) :
575
+ 1;
576
+ // 当前页码在gpt识别列表内
577
+ // let pdfResloute = this.cachePdf[this.currentPage]
578
+ // debugger
579
+ // let pdfResloute = this.cachePdf.find(cache => {
580
+ // return cache.page == pageIndex
581
+ // })
582
+ // if (pdfResloute) {
583
+ // this.identifyTextPostion.extractInfo = pdfResloute.extractInfo
584
+ // this.identifyTextPostion.currentPageAllLine = []
585
+ // this.cachePdf.forEach(item => {
586
+ // if (item.page == pdfResloute.page) {
587
+ // this.identifyTextPostion.currentPageAllLine.push({
588
+ // lines: [...item.extractInfo.lines],
589
+ // page: item.page
590
+ // })
591
+ // }
592
+ // })
593
+ // this.identifyTextPostion.left = pdfResloute.extractInfo.location[0]
594
+ // this.identifyTextPostion.top = pdfResloute.extractInfo.location[1]
595
+ // this.identifyTextPostion.width = pdfResloute.extractInfo.location[2]
596
+ // this.identifyTextPostion.height = pdfResloute.extractInfo.location[3]
597
+ // this.identifyTextPostion.page = pdfResloute.page
598
+ // this.identifyTextPostion.pageHeight = pdfResloute.pageHeight
599
+ // this.identifyTextPostion.pageWidth = pdfResloute.pageWidth
600
+ // }
601
+ that.loadPdfData(pageIndex - 1)
602
+ that.loadPdfData(pageIndex)
603
+ that.loadPdfData(pageIndex + 1)
604
+ // if (height - (that.pageSize.height + that.PAGE_INTVERVAL) > (that.pageSize.height + that.PAGE_INTVERVAL)) {
605
+ // let loadNum = Math.ceil(height / (that.pageSize.height + that.PAGE_INTVERVAL))
606
+ // if (loadNum > 2 && pageIndex > 1) {
607
+ // that.loadPdfData(pageIndex - 1)
608
+ // that.loadPdfData(pageIndex)
609
+ // that.loadPdfData(pageIndex + 1)
610
+ // } else {
611
+ // for (let n = 0; n < loadNum; n++) {
612
+ // that.loadPdfData(pageIndex + n)
613
+ // }
614
+ // }
615
+ // } else {
616
+ // that.loadPdfData(pageIndex)
617
+ // }
618
+ }, 200),
619
+ directScrolling (e, that) {
620
+ if (this.fisrtLoad) {
621
+ this.fisrtLoad = false
622
+ return
623
+ }
624
+ const scrollTop = e.target.scrollTop;
625
+ const height = e.target.clientHeight;
626
+ // 根据内容可视区域中心点计算页码, 没有滚动时,指向第一页
627
+ const pageIndex = scrollTop > 0 ?
628
+ Math.ceil((scrollTop + (height / 2)) / (that.pageSize.height + that.PAGE_INTVERVAL)) :
629
+ 1;
630
+ // // 当前页码在gpt识别列表内
631
+ // let pdfResloute = this.cachePdf[this.currentPage]
632
+ // if (pdfResloute) {
633
+ // this.identifyTextPostion.extractInfo = pdfResloute.extractInfo
634
+ // this.identifyTextPostion.currentPageAllLine = []
635
+ // this.cachePdf.forEach(item => {
636
+ // if (item.page == pdfResloute.page) {
637
+ // this.identifyTextPostion.currentPageAllLine.push({
638
+ // lines: [...item.extractInfo.lines],
639
+ // page: item.page
640
+ // })
641
+ // }
642
+ // })
643
+ // this.identifyTextPostion.left = pdfResloute.extractInfo.location[0]
644
+ // this.identifyTextPostion.top = pdfResloute.extractInfo.location[1]
645
+ // this.identifyTextPostion.width = pdfResloute.extractInfo.location[2]
646
+ // this.identifyTextPostion.height = pdfResloute.extractInfo.location[3]
647
+ // this.identifyTextPostion.page = pdfResloute.page
648
+ // this.identifyTextPostion.pageHeight = pdfResloute.pageHeight
649
+ // this.identifyTextPostion.pageWidth = pdfResloute.pageWidth
650
+ // }
651
+ this.loadPdfData(pageIndex)
652
+ },
653
+ pdfScroll (e) {
654
+ // if (this.changetoolbar) {
655
+ // this.directScrolling(e, this)
656
+ // } else {
657
+ // this.debounceScrollPdf(e, this)
658
+ // }
659
+ if(this.preViewType !== 'pdf') {
660
+ return
661
+ }
662
+ this.debounceScrollPdf(e, this)
663
+ },
664
+ // 分片每次只做一次处理,所以不考虑多片情况
665
+ loadBefore (pageIndex) {
666
+ this.loadPdfData(pageIndex)
667
+ // const start = (Math.floor(pageIndex / this.SLICE_COUNT) * this.SLICE_COUNT) - (this.SLICE_COUNT - 1);
668
+ // if (start > 0) {
669
+ // // const prevPage = this.pages[start - 1] || {};
670
+ // this.loadPdfData(start)
671
+ // // prevPage.loadStatus === this.pageLoadStatus.WAIT && this.loadPdfData(start);
672
+ // }
673
+ },
674
+ loadAfter (pageIndex) {
675
+ this.loadPdfData(pageIndex)
676
+ // const start = (Math.floor(pageIndex / this.SLICE_COUNT) * this.SLICE_COUNT) + 1;
677
+ // if (start <= this.pages.length) {
678
+ // // const nextPage = this.pages[start - 1] || {};
679
+ // this.loadPdfData(start)
680
+ // // nextPage.loadStatus === this.pageLoadStatus.WAIT && this.loadPdfData(start);
681
+ // }
682
+ },
683
+ // 首先我们获取到需要渲染的范围
684
+ // 根据当前的可视范围内的页码,我们前后只保留 8 页
685
+ getRenderScope (pageIndex) {
686
+ const pagesToRender = [];
687
+ let i = pageIndex - 1;
688
+ let j = pageIndex + 1;
689
+ // pageIndex - 1 表示当前页码数 对应的下标位置
690
+ pagesToRender.push(this.pages[pageIndex - 1]);
691
+ while (pagesToRender.length < 10 && pagesToRender.length < this.pages.length) {
692
+ if (i > 0) {
693
+ pagesToRender.push(this.pages[i - 1]);
694
+ i -= 1;
695
+ }
696
+ if (pagesToRender.length >= 10) {
697
+ break;
698
+ }
699
+ if (j <= this.pages.length) {
700
+ pagesToRender.push(this.pages[j - 1]);
701
+ j += 1;
702
+ }
703
+ }
704
+ return pagesToRender;
705
+ },
706
+ // 渲染需要展示的页面,不需展示的页码将其清除
707
+ renderPages (pageIndex) {
708
+ const pagesToRender = this.getRenderScope(pageIndex);
709
+ for (const i of this.pages) {
710
+ if (pagesToRender.includes(i)) {
711
+ i.loadStatus === this.pageLoadStatus.LOADED ?
712
+ this.renderPageContent(i, pageIndex) :
713
+ this.renderPageLoading(i);
714
+ } else {
715
+ this.clearPage(i);
716
+ }
717
+ }
718
+ },
719
+ // 清除页面 dom
720
+ clearPage (page) {
721
+ if (page.dom) {
722
+ this.contentView.removeChild(page.dom);
723
+ page.loadStatus = 0
724
+ page.dom = undefined;
725
+ }
726
+ },
727
+ // 页面正在下载时渲染loading视图
728
+ renderPageLoading (page) {
729
+ const { pageNo, dom } = page;
730
+ if (dom && dom.children.length != 0) {
731
+ return;
732
+ }
733
+ const pageDom = document.createElement('div');
734
+ pageDom.style.width = `${this.pageSize.width}px`;
735
+ pageDom.style.height = `${this.pageSize.height}px`;
736
+ pageDom.style.position = 'absolute';
737
+ pageDom.style.top = `${((pageNo - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + this.PAGE_INTVERVAL
738
+ }px`;
739
+ pageDom.style.backgroundImage = `url('https://guoranopen-zjk.oss-cn-zhangjiakou.aliyuncs.com/cdn-common/images/loading.gif')`
740
+ pageDom.style.backgroundPosition = 'center'
741
+ pageDom.style.backgroundRepeat = 'no-repeat'
742
+ pageDom.style.backgroundColor = '#FFF'
743
+ page.dom = pageDom;
744
+ this.contentView.appendChild(pageDom);
745
+ },
746
+ prev () {
747
+ this.currentPage--
748
+ if (this.currentPage < 0) {
749
+ // this.currentPage = this.tagIds.length - 1
750
+ this.currentPage = 0
751
+ }
752
+ if(this.preViewType == 'pdf') {
753
+ this.scrollToUplaodePage(this.currentPage)
754
+ } else {
755
+ this.scrollToExcalTop(this.currentPage)
756
+ }
757
+ // this.getpdfResloutePage(this.cachePdf[this.currentPage - 1])
758
+ },
759
+ next () {
760
+ this.currentPage++
761
+ if (this.currentPage >= this.tagIds.length) {
762
+ this.currentPage = 0
763
+ }
764
+ if(this.preViewType == 'pdf') {
765
+ this.scrollToUplaodePage(this.currentPage)
766
+ } else {
767
+ this.scrollToExcalTop(this.currentPage)
768
+ }
769
+ },
770
+ currentChange (value) {
771
+ this.currentPage = value - 1
772
+ if(this.preViewType == 'pdf') {
773
+ this.scrollToUplaodePage(this.currentPage)
774
+ } else {
775
+ this.scrollToExcalTop(this.currentPage)
776
+ }
777
+ },
778
+ scrollToUplaodePage (currentPage) {
779
+ this.changetoolbar = true
780
+ if(this.preViewType !== 'pdf') {
781
+ return
782
+ }
783
+ let pdfResloute = this.cachePdf[currentPage]
784
+ this.identifyTextPostion.extractInfo = pdfResloute.extractInfo
785
+ this.identifyTextPostion.left = pdfResloute.extractInfo.location[0]
786
+ this.identifyTextPostion.top = pdfResloute.extractInfo.location[1]
787
+ this.identifyTextPostion.width = pdfResloute.extractInfo.location[2]
788
+ this.identifyTextPostion.height = pdfResloute.extractInfo.location[3]
789
+ this.identifyTextPostion.page = pdfResloute.page
790
+ this.identifyTextPostion.pageHeight = pdfResloute.pageHeight
791
+ this.identifyTextPostion.pageWidth = pdfResloute.pageWidth
792
+ // console.log( Math.floor((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + (this.pageSize.height + this.PAGE_INTVERVAL * 2) ,this.$refs.pdfView.scrollHeight);
793
+ // debugger
794
+ // if(this.$refs.pdfView.scrollTop == Math.floor((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) ||
795
+ // Math.floor((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL)) + (this.pageSize.height + this.PAGE_INTVERVAL) >= this.$refs.pdfView.scrollHeight) {
796
+ // this.renderHighlights()
797
+ // } else {
798
+ // 在当前段落在最后一页pdf时,根据计算的高度并不能触发滚动,在此执行重新渲染方法,非次情况会执行两次,待优化
799
+ this.$nextTick(() => {
800
+ this.renderHighlights()
801
+ })
802
+ this.$refs.pdfView.scrollTop = `${((pdfResloute.page - 1) * (this.pageSize.height + this.PAGE_INTVERVAL))}`
803
+ // }
804
+ },
805
+ scrollToExcalTop(currentPage) {
806
+ for (let index = 0; index < this.allTr.length; index++) {
807
+ if(index == currentPage) {
808
+ this.allTr[index].children.forEach(item =>{
809
+ item.style.background = 'rgba(255, 136, 0, 0.6)'
810
+ })
811
+ this.$refs.pdfView.scrollTop = this.allTr[index].offsetTop
812
+ } else {
813
+ this.allTr[index].children.forEach(item =>{
814
+ item.style.background = 'rgba(54, 106, 255, 0.6)'
815
+ })
816
+ }
817
+ }
818
+ },
819
+ // pdf是否需要重新渲染高亮位置
820
+ renderHighlights () {
821
+ let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
822
+ console.log(lineHeightDom, this.currentPage, 'this.currentPage');
823
+ if (lineHeightDom) {
824
+ lineHeightDom.forEach((d) => {
825
+ for (let i = 0; i < d.children.length; i++) {
826
+ if (d.getAttribute('react-count') == this.currentPage) {
827
+ d.children[i].style.backgroundColor = 'rgba(255, 136, 0, 0.3)'
828
+ } else {
829
+ d.children[i].style.backgroundColor = 'rgba(54, 106, 255, 0.3)'
830
+ }
831
+ }
832
+ })
833
+ }
834
+ },
835
+ displayHiglight (pageIndex) {
836
+ let lineHeightDom = Array.from(document.getElementsByClassName('rectdom'))
837
+ if (lineHeightDom) {
838
+ lineHeightDom.forEach((d) => {
839
+ if (d.getAttribute('page-index') == pageIndex) {
840
+ d.style.display = 'none'
841
+ }
842
+ })
843
+ }
844
+ },
845
+ // 前端暂时缓存多页
846
+ autoLoadMore (pageIndex) {
847
+ let pdfResloute = this.cachePdf.find(cache => {
848
+ return cache.page == pageIndex
849
+ })
850
+ if (pdfResloute) {
851
+ this.getpdfResloutePage(pdfResloute)
852
+ } else {
853
+ this.loadPdfData(pageIndex)
854
+ }
855
+ },
856
+ setPageAllLine (arr) {
857
+ this.currentPageAllLine = []
858
+ arr.forEach((item, index) => {
859
+ let i = this.currentPageAllLine.findIndex(l => { return l.page && l.page == item.page })
860
+ if (i != -1) {
861
+ // this.currentPageAllLine[i].allLines.lines.push(item.extractInfo.lines)
862
+ this.currentPageAllLine[i].allLines.push({
863
+ pageCount: index,
864
+ lines: item.extractInfo.lines
865
+ })
866
+ } else {
867
+ this.currentPageAllLine.push({
868
+ page: item.page,
869
+ allLines: [{
870
+ pageCount: index,
871
+ lines: item.extractInfo.lines
872
+ }],
873
+ })
874
+ }
875
+ })
876
+ }
877
+ },
878
+ computed:{
879
+ perviewUrl() {
880
+ return '/web/viewer.html?file=' + '/pdflist/pdf4split-1.pdf'
881
+ }
882
+ },
883
+ watch:{
884
+ tagIds: {
885
+ handler(value) {
886
+ if(value && value.length) {
887
+ // 在 pdf_view 下创建 所有canvs的容器
888
+ this.contentView = document.createElement('div')
889
+ this.$http.get('/knowledge-api/knowledge/knowledge-part-location-info/list?ids=' + value.join(',')).then(res =>{
890
+ if (res.data.code == 0) {
891
+ // tagIds 会按照gpt识别的生成有序的数组,前端直接按照下标的顺序取就可以了
892
+ // 缓存拿到的所有数据
893
+ this.cachePdf = res.data.data
894
+ let publicPageFileUrl = res.data.data[0].publicPageFileUrl
895
+ this.currentPage = 0
896
+ // console.log(publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')));
897
+ if (publicPageFileUrl.substring(publicPageFileUrl.lastIndexOf('.')) === '.pdf') {
898
+ this.preViewType = 'pdf'
899
+ this.setPageAllLine(this.cachePdf)
900
+ this.getpdfResloutePage(res.data.data[0])
901
+ } else {
902
+ this.preViewType = 'excal'
903
+ this.$http.post(
904
+ '/knowledge-api/temporary-certificate/or-origin?expired=30',
905
+ publicPageFileUrl,
906
+ {
907
+ headers: {
908
+ "Content-Type": "application/json",
909
+ },
910
+ }).then(res => {
911
+ // 使用原声请求方式 axios会带有不需要的请求头
912
+ let xhr = new XMLHttpRequest();
913
+ xhr.open('GET', res.data, true);
914
+ // 定义请求完成的处理函数,请求前也可以增加加载框/禁用下载按钮逻辑
915
+ xhr.onload = ({ currentTarget }) => {
916
+ // 请求完成
917
+ if (currentTarget.status === 200) { // 返回200
918
+ this.contentView.innerHTML = currentTarget.response
919
+ this.contentView.style.padding = '10px'
920
+ this.$refs.pdfView.style.backgroundColor = '#FFFFFF'
921
+ this.$refs.pdfView.appendChild(this.contentView)
922
+ let allTr = Array.from(this.$refs.pdfView.getElementsByTagName('tr'))
923
+ this.allTr = []
924
+ for (let index = 0; index < allTr.length; index++) {
925
+ if(value.includes(allTr[index].getAttribute('tag-id'))) {
926
+ this.allTr.push(allTr[index])
927
+ }
928
+ }
929
+ this.currentChange(1)
930
+
931
+ }
932
+ }
933
+ xhr.send();
934
+ })
935
+ }
936
+
937
+ } else {
938
+ let div = document.createElement('div')
939
+ div.innerText = '文件加载异常'
940
+ this.contentView.appendChild(div)
941
+ this.$refs.pdfView.appendChild(this.contentView)
942
+ }
943
+ })
944
+ }
945
+ console.log(value);
946
+ },
947
+ deep:true,
948
+ immediate:true
949
+ }
950
+ },
951
+
952
+ mounted() {
953
+ // 在 pdf_view 下创建 所有canvs的容器
954
+ // this.contentView = document.createElement('div')
955
+ // // 从后端获取到当前分片后所有的pdf页码,初始化数组,数组下{} 对应每页pdf文件
956
+ // this.initPages(8);
957
+ // // 定位功能,加载对应页码位置
958
+ // this.loadPdfData(1)
959
+ }
960
+ }
961
+ </script>
962
+
963
+ <style lang="less" scoped>
964
+ .pdf_view {
965
+ width: 100%;
966
+ height: 100%;
967
+ overflow: auto;
968
+ background-color: #f5f7fb;
969
+ padding-bottom: 50px;
970
+ position: relative;
971
+ // > div {
972
+ // width: 100%;
973
+ // height: 100%;
974
+ // overflow: hidden;
975
+ // overflow-y: auto;
976
+ // position: relative;
977
+ // }
978
+ > iframe {
979
+ width: 100%;
980
+ height: 100%;
981
+ }
982
+ .btn_footer {
983
+ width: 100%;
984
+ height: 50px;
985
+ display: flex;
986
+ align-items: center;
987
+ justify-content: space-around;
988
+ position: absolute;
989
+ bottom: 50px;
990
+ left: 0;
991
+ .prev, .next {
992
+ width: 35%;
993
+ height: 40px;
994
+ display: flex;
995
+ align-items: center;
996
+ justify-content: center;
997
+ border-radius: 50px;
998
+ cursor: pointer;
999
+ }
1000
+ .prev {
1001
+ background: #F2F5FA;
1002
+ color: #000;
1003
+ }
1004
+ .next {
1005
+ background: #366aff;
1006
+ color: #ffffff;
1007
+ }
1008
+ }
1009
+ }
379
1010
  </style>