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