搜索优化
This commit is contained in:
parent
ca7bc4a1ce
commit
e686a21d18
|
|
@ -39,7 +39,7 @@
|
|||
"jsencrypt": "3.0.0-rc.1",
|
||||
"lodash": "^4.17.21",
|
||||
"nprogress": "0.2.0",
|
||||
"pdfjs-dist": "2.16.105",
|
||||
"pdfjs-dist": "^2.16.105",
|
||||
"quill": "2.0.2",
|
||||
"screenfull": "5.0.2",
|
||||
"sm-crypto": "^0.3.13",
|
||||
|
|
|
|||
|
|
@ -103,9 +103,25 @@ export default {
|
|||
prefetchHandle: null,
|
||||
prefetchScheduled: false,
|
||||
initialPreloadedCount: 0,
|
||||
cMapUrl: '',
|
||||
standardFontDataUrl: '',
|
||||
pdfAssetsBase: '',
|
||||
fontsReady: new Set(),
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
const base = (process.env.BASE_URL || '/').replace(/\/+$/, '/')
|
||||
this.pdfAssetsBase = `${base}pdfjs/`
|
||||
this.cMapUrl = `${this.pdfAssetsBase}cmaps/`
|
||||
this.standardFontDataUrl = `${this.pdfAssetsBase}standard_fonts/`
|
||||
|
||||
pdfjsLib.GlobalCMapOptions = {
|
||||
url: this.cMapUrl,
|
||||
packed: true,
|
||||
}
|
||||
if ('GlobalStandardFontDataUrl' in pdfjsLib) {
|
||||
pdfjsLib.GlobalStandardFontDataUrl = this.standardFontDataUrl
|
||||
}
|
||||
this.pdfUrl = this.$route.query.url || 'http://192.168.0.14:9090/smart-bid/technicalSolutionDatabase/2025/10/30/fe5b46ea37554516a71e7c0c486d3715.pdf'
|
||||
if (this.pdfUrl) {
|
||||
this.loadDocument()
|
||||
|
|
@ -145,6 +161,9 @@ export default {
|
|||
withCredentials: true,
|
||||
httpHeaders: headers,
|
||||
disableWorker: !resolvedWorkerSrc,
|
||||
useWorkerFetch: !!resolvedWorkerSrc,
|
||||
cMapUrl: this.cMapUrl,
|
||||
cMapPacked: true,
|
||||
})
|
||||
this.pdfDoc = await loadingTask.promise
|
||||
console.log('PDF 文档加载成功', this.pdfDoc)
|
||||
|
|
@ -181,6 +200,7 @@ export default {
|
|||
const placeholder = document.createElement('div')
|
||||
placeholder.className = 'pdf-page placeholder'
|
||||
placeholder.style.margin = '0px auto 10px'
|
||||
placeholder.style.position= 'relative';
|
||||
placeholder.dataset.page = pageNumber
|
||||
placeholder.dataset.status = 'placeholder'
|
||||
fragment.appendChild(placeholder)
|
||||
|
|
@ -301,7 +321,6 @@ export default {
|
|||
textLayerDiv.style.height = `${viewport.height}px`
|
||||
textLayerDiv.style.display = visible ? '' : 'none'
|
||||
container.appendChild(textLayerDiv)
|
||||
|
||||
const textLayer = new TextLayerBuilder({
|
||||
textLayerDiv,
|
||||
pageIndex: index,
|
||||
|
|
@ -333,7 +352,7 @@ export default {
|
|||
|
||||
async renderSinglePage(pageNumber) {
|
||||
await this.renderCanvas(pageNumber)
|
||||
await this.renderTextLayer(pageNumber, { visible: true })
|
||||
await this.renderTextLayer(pageNumber, { visible: true, force: true })
|
||||
},
|
||||
|
||||
scheduleRender(pageNumber, { priority = false } = {}) {
|
||||
|
|
@ -620,11 +639,7 @@ export default {
|
|||
if (entry.isIntersecting) {
|
||||
const page = Number(entry.target.dataset.page)
|
||||
if (page) {
|
||||
if (page > this.initialPreloadedCount) {
|
||||
this.renderTextLayer(page, { visible: true })
|
||||
} else if (page !== 1) {
|
||||
this.renderTextLayer(page, { visible: true })
|
||||
}
|
||||
this.renderTextLayer(page, { visible: true, force: true })
|
||||
this.scheduleRender(page, { priority: true })
|
||||
}
|
||||
} else {
|
||||
|
|
@ -737,9 +752,7 @@ export default {
|
|||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: #ffffff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.pdf-page:first-of-type::before,
|
||||
|
|
@ -798,6 +811,7 @@ export default {
|
|||
.pdf-canvas {
|
||||
width: 100%;
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.textLayer {
|
||||
|
|
@ -817,6 +831,20 @@ export default {
|
|||
-webkit-user-select: text;
|
||||
}
|
||||
|
||||
.pdf-page > canvas.pdf-canvas {
|
||||
position: relative;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.pdf-page > .textLayer {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.search-highlight {
|
||||
background: rgba(255, 241, 168, 0.9);
|
||||
padding: 0 2px;
|
||||
|
|
|
|||
Loading…
Reference in New Issue