pdf 搜索优化

This commit is contained in:
cwchen 2025-11-11 09:17:21 +08:00
parent dcb130c055
commit a8346c2a20
1 changed files with 25 additions and 5 deletions

View File

@ -13,7 +13,7 @@
@click="goToPrevious">
上一处
</el-button>
<el-button class="nav-btn" type="text" icon="el-icon-arrow-down" :disabled="!searchResults.length"
<el-button class="nav-btn" type="text" icon="el-icon-arrow-down" :disabled="!searchResults.length || isAtLastResult"
@click="goToNext">
下一处
</el-button>
@ -80,6 +80,10 @@ export default {
}
return null
},
isAtLastResult() {
if (!this.searchResults.length) return true
return this.currentResultIndex >= this.searchResults.length - 1
},
},
data() {
return {
@ -858,14 +862,30 @@ export default {
goToPrevious() {
if (!this.searchResults.length) return
const idx = (this.currentResultIndex - 1 + this.searchResults.length) % this.searchResults.length
this.navigateToResult(idx)
let targetIndex = this.currentResultIndex
if (targetIndex === -1) {
targetIndex = this.searchResults.length - 1
} else {
targetIndex -= 1
if (targetIndex < 0) {
targetIndex = this.searchResults.length - 1
}
}
this.navigateToResult(targetIndex)
},
goToNext() {
if (!this.searchResults.length) return
const idx = (this.currentResultIndex + 1) % this.searchResults.length
this.navigateToResult(idx)
let targetIndex = this.currentResultIndex
if (targetIndex === -1) {
targetIndex = 0
} else {
targetIndex += 1
if (targetIndex > this.searchResults.length - 1) {
targetIndex = 0
}
}
this.navigateToResult(targetIndex)
},
resetSearch() {