2021-10-18 01:05:43 +02:00
|
|
|
<template>
|
|
|
|
<div v-if="show" class="w-screen h-screen fixed top-0 left-0 z-50 bg-primary text-white">
|
|
|
|
<div class="absolute top-4 right-4 z-20">
|
2021-10-23 23:49:34 +02:00
|
|
|
<span class="material-icons cursor-pointer text-4xl" @click="close">close</span>
|
2021-10-18 01:05:43 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="absolute top-4 left-4 font-book">
|
|
|
|
<h1 class="text-2xl mb-1">{{ abTitle }}</h1>
|
|
|
|
<p v-if="abAuthor">by {{ abAuthor }}</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<component v-if="componentName" ref="readerComponent" :is="componentName" :url="ebookUrl" />
|
|
|
|
|
|
|
|
<div class="absolute bottom-2 left-2">{{ ebookType }}</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
2022-04-13 15:26:43 +02:00
|
|
|
return {}
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
show(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
|
|
|
return this.$store.state.showEReader
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$store.commit('setShowEReader', val)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
componentName() {
|
|
|
|
if (this.ebookType === 'epub') return 'readers-epub-reader'
|
|
|
|
else if (this.ebookType === 'mobi') return 'readers-mobi-reader'
|
|
|
|
else if (this.ebookType === 'pdf') return 'readers-pdf-reader'
|
|
|
|
else if (this.ebookType === 'comic') return 'readers-comic-reader'
|
|
|
|
return null
|
|
|
|
},
|
|
|
|
abTitle() {
|
2022-04-13 15:26:43 +02:00
|
|
|
return this.mediaMetadata.title
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
|
|
|
abAuthor() {
|
2022-04-13 15:26:43 +02:00
|
|
|
return this.mediaMetadata.authorName
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
2022-03-14 01:34:31 +01:00
|
|
|
selectedLibraryItem() {
|
2022-04-13 15:26:43 +02:00
|
|
|
return this.$store.state.selectedLibraryItem || {}
|
|
|
|
},
|
|
|
|
media() {
|
|
|
|
return this.selectedLibraryItem.media || {}
|
|
|
|
},
|
|
|
|
mediaMetadata() {
|
|
|
|
return this.media.metadata || {}
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
|
|
|
libraryId() {
|
2022-03-14 01:34:31 +01:00
|
|
|
return this.selectedLibraryItem.libraryId
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
|
|
|
folderId() {
|
2022-03-14 01:34:31 +01:00
|
|
|
return this.selectedLibraryItem.folderId
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
ebookFile() {
|
|
|
|
return this.media.ebookFile
|
|
|
|
},
|
|
|
|
ebookFormat() {
|
|
|
|
if (!this.ebookFile) return null
|
|
|
|
return this.ebookFile.ebookFormat
|
|
|
|
},
|
|
|
|
ebookType() {
|
|
|
|
if (this.isMobi) return 'mobi'
|
|
|
|
else if (this.isEpub) return 'epub'
|
|
|
|
else if (this.isPdf) return 'pdf'
|
|
|
|
else if (this.isComic) return 'comic'
|
|
|
|
return null
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
isEpub() {
|
|
|
|
return this.ebookFormat == 'epub'
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
isMobi() {
|
|
|
|
return this.ebookFormat == 'mobi' || this.ebookFormat == 'azw3'
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
isPdf() {
|
|
|
|
return this.ebookFormat == 'pdf'
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
2022-04-13 15:26:43 +02:00
|
|
|
isComic() {
|
|
|
|
return this.ebookFormat == 'cbz' || this.ebookFormat == 'cbr'
|
|
|
|
},
|
|
|
|
ebookUrl() {
|
|
|
|
if (!this.ebookFile) return null
|
|
|
|
var itemRelPath = this.selectedLibraryItem.relPath
|
|
|
|
if (itemRelPath.startsWith('/')) itemRelPath = itemRelPath.slice(1)
|
|
|
|
var relPath = this.ebookFile.metadata.relPath
|
|
|
|
if (relPath.startsWith('/')) relPath = relPath.slice(1)
|
|
|
|
return `/ebook/${this.libraryId}/${this.folderId}/${itemRelPath}/${relPath}`
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
|
|
|
userToken() {
|
|
|
|
return this.$store.getters['user/getToken']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-10-23 23:49:34 +02:00
|
|
|
hotkey(action) {
|
|
|
|
console.log('Reader hotkey', action)
|
|
|
|
if (!this.$refs.readerComponent) return
|
|
|
|
|
2021-10-24 21:02:49 +02:00
|
|
|
if (action === this.$hotkeys.EReader.NEXT_PAGE) {
|
2021-10-23 23:49:34 +02:00
|
|
|
if (this.$refs.readerComponent.next) this.$refs.readerComponent.next()
|
2021-10-24 21:02:49 +02:00
|
|
|
} else if (action === this.$hotkeys.EReader.PREV_PAGE) {
|
2021-10-23 23:49:34 +02:00
|
|
|
if (this.$refs.readerComponent.prev) this.$refs.readerComponent.prev()
|
2021-10-24 21:02:49 +02:00
|
|
|
} else if (action === this.$hotkeys.EReader.CLOSE) {
|
2021-10-23 23:49:34 +02:00
|
|
|
this.close()
|
2021-10-18 01:05:43 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
registerListeners() {
|
2021-10-23 23:49:34 +02:00
|
|
|
this.$eventBus.$on('reader-hotkey', this.hotkey)
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
|
|
|
unregisterListeners() {
|
2021-10-23 23:49:34 +02:00
|
|
|
this.$eventBus.$off('reader-hotkey', this.hotkey)
|
2021-10-18 01:05:43 +02:00
|
|
|
},
|
|
|
|
init() {
|
|
|
|
this.registerListeners()
|
|
|
|
},
|
|
|
|
close() {
|
2021-10-23 23:49:34 +02:00
|
|
|
this.unregisterListeners()
|
|
|
|
this.show = false
|
2021-10-18 01:05:43 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (this.show) this.init()
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2021-10-23 23:49:34 +02:00
|
|
|
this.unregisterListeners()
|
2021-10-18 01:05:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
/* @import url(@/assets/calibre/basic.css); */
|
|
|
|
.ebook-viewer {
|
|
|
|
height: calc(100% - 96px);
|
|
|
|
}
|
|
|
|
</style>
|