选中背景色优化

This commit is contained in:
cwchen 2025-11-11 09:43:28 +08:00
parent 4e93be11a2
commit 2417dd974d
1 changed files with 66 additions and 29 deletions

View File

@ -3,7 +3,8 @@
<div class="search-toolbar"> <div class="search-toolbar">
<el-input v-model="keyword" class="search-input" placeholder="输入关键字搜索 PDF" clearable <el-input v-model="keyword" class="search-input" placeholder="输入关键字搜索 PDF" clearable
@keyup.enter.native="handleSearch" @clear="resetSearch"> @keyup.enter.native="handleSearch" @clear="resetSearch">
<el-button slot="append" icon="el-icon-search" @click="handleSearch" :loading="searching" :disabled="searching"> <el-button slot="append" icon="el-icon-search" @click="handleSearch" :loading="searching"
:disabled="searching">
搜索 搜索
</el-button> </el-button>
</el-input> </el-input>
@ -728,7 +729,7 @@ export default {
if (!skipNavigate) { if (!skipNavigate) {
this.navigateToResult(this.currentResultIndex, true) this.navigateToResult(this.currentResultIndex, true)
} else { } else {
this.updateCurrentResultActiveState() this.scheduleActiveHighlightRefresh()
} }
}, },
@ -749,7 +750,7 @@ export default {
} }
this.currentResultIndex = index this.currentResultIndex = index
this.updateCurrentResultActiveState() this.scheduleActiveHighlightRefresh()
const target = this.searchResults[this.currentResultIndex]?.element const target = this.searchResults[this.currentResultIndex]?.element
if (!target) return if (!target) return
@ -842,22 +843,48 @@ export default {
this.searchResults[matchIndex].element = elements[0] || null this.searchResults[matchIndex].element = elements[0] || null
}) })
this.updateCurrentResultActiveState() this.scheduleActiveHighlightRefresh()
}, },
updateCurrentResultActiveState() { updateCurrentResultActiveState() {
const activePageContainers = new Set()
this.searchResults.forEach((item, idx) => { this.searchResults.forEach((item, idx) => {
if (!item) return if (!item) return
const elements = item.elements && item.elements.length ? item.elements : item.element ? [item.element] : [] const elements = item.elements && item.elements.length ? item.elements : item.element ? [item.element] : []
elements.forEach((el) => { elements.forEach((el) => {
if (!el) return if (!el) return
if (idx === this.currentResultIndex) { if (idx === this.currentResultIndex) {
el.classList.add('is-active') el.classList.add('is-active', 'is-current')
const container = el.closest('.pdf-page')
if (container) {
activePageContainers.add(container)
}
} else { } else {
el.classList.remove('is-active') el.classList.remove('is-active', 'is-current')
} }
}) })
}) })
this.pageContainers.forEach((container) => {
if (!container) return
container.classList.remove('has-active-match')
})
activePageContainers.forEach((container) => {
container.classList.add('has-active-match')
})
},
scheduleActiveHighlightRefresh() {
this.$nextTick(() => {
if (typeof window !== 'undefined' && window.requestAnimationFrame) {
window.requestAnimationFrame(() => {
this.updateCurrentResultActiveState()
})
} else {
this.updateCurrentResultActiveState()
}
})
}, },
goToPrevious() { goToPrevious() {
@ -1171,6 +1198,7 @@ export default {
0% { 0% {
transform: rotate(0deg); transform: rotate(0deg);
} }
100% { 100% {
transform: rotate(360deg); transform: rotate(360deg);
} }
@ -1196,9 +1224,18 @@ export default {
border-radius: 2px; border-radius: 2px;
} }
.search-highlight.is-active { ::v-deep .search-highlight.is-active,
background: rgba(32, 109, 255, 0.85); ::v-deep .search-highlight.is-current {
background: #206dff !important;
color: #ffffff; color: #ffffff;
box-shadow: 0 0 0 2px rgba(32, 109, 255, 0.35);
border-radius: 4px;
transition: background 0.2s ease, box-shadow 0.2s ease;
}
.pdf-page.has-active-match {
box-shadow: 0 0 0 3px rgba(32, 109, 255, 0.45), 0 12px 36px rgba(32, 109, 255, 0.18);
transition: box-shadow 0.3s ease;
} }
.state-panel { .state-panel {