//搜索列表项
<div class="slide-search-item"
v-for="(item, index) in searchList"
:key="index"
v-html="item.excerpt"
@click="displayContent(item.cfi, true)">
</div>
//调用display()
displayContent (target, highlight = false) {
this.display(target, () => {
this.hideTitleAndMenu()
if (highlight) {
this.currentBook.rendition.annotations.highlight(target)
}
})
}
//display()调用refreshLocation()
display (target, cb) {
if (target) {
this.currentBook.rendition.display(target).then(() => {
this.refreshLocation()
if (cb) cb()
})
} else {
this.currentBook.rendition.display().then(() => {
this.refreshLocation()
if (cb) cb()
})
}
}
//refreshLocation()方法
refreshLocation () {
const currentLocation = this.currentBook.rendition.currentLocation()
if (currentLocation && currentLocation.start) {
const startCfi = currentLocation.start.cfi
const progress = this.currentBook.locations.percentageFromCfi(startCfi)
this.setProgress(Math.floor(progress * 100))
this.setSection(currentLocation.start.index)
saveLocation(this.fileName, startCfi)
}
}