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"> @click="goToPrevious">
上一处 上一处
</el-button> </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"> @click="goToNext">
下一处 下一处
</el-button> </el-button>
@ -80,6 +80,10 @@ export default {
} }
return null return null
}, },
isAtLastResult() {
if (!this.searchResults.length) return true
return this.currentResultIndex >= this.searchResults.length - 1
},
}, },
data() { data() {
return { return {
@ -858,14 +862,30 @@ export default {
goToPrevious() { goToPrevious() {
if (!this.searchResults.length) return if (!this.searchResults.length) return
const idx = (this.currentResultIndex - 1 + this.searchResults.length) % this.searchResults.length let targetIndex = this.currentResultIndex
this.navigateToResult(idx) if (targetIndex === -1) {
targetIndex = this.searchResults.length - 1
} else {
targetIndex -= 1
if (targetIndex < 0) {
targetIndex = this.searchResults.length - 1
}
}
this.navigateToResult(targetIndex)
}, },
goToNext() { goToNext() {
if (!this.searchResults.length) return if (!this.searchResults.length) return
const idx = (this.currentResultIndex + 1) % this.searchResults.length let targetIndex = this.currentResultIndex
this.navigateToResult(idx) if (targetIndex === -1) {
targetIndex = 0
} else {
targetIndex += 1
if (targetIndex > this.searchResults.length - 1) {
targetIndex = 0
}
}
this.navigateToResult(targetIndex)
}, },
resetSearch() { resetSearch() {