Добавлена загрузка и распарсивание текущей книги

This commit is contained in:
Book Pauk
2019-01-14 22:11:26 +07:00
parent 475afa553c
commit a81b38cf04
5 changed files with 63 additions and 4 deletions

View File

@@ -43,7 +43,7 @@ class ProgressPage extends Vue {
this.visible = true;
}
async hide() {
hide() {
this.visible = false;
}

View File

@@ -43,7 +43,7 @@
<el-main>
<keep-alive>
<component ref="page" :is="pageActive" @load-book="loadBook"></component>
<component ref="page" :is="pageActive" @load-book="loadBook" @parse-book="parseBook"></component>
</keep-alive>
</el-main>
</el-container>
@@ -157,6 +157,34 @@ class Reader extends Vue {
});
}
parseBook(meta) {
this.progressActive = true;
this.$nextTick(async() => {
if (await bookManager.hasBookParsed(meta)) {
this.progressActive = false;
return;
}
const progress = this.$refs.page;
progress.show();
progress.setState({state: 'parse'});
try {
const isParsed = await bookManager.getBook(meta, (prog) => {
progress.setState({progress: prog});
});
progress.hide(); this.progressActive = false;
if (!isParsed) {
this.loadBook({url: meta.url});
}
} catch (e) {
progress.hide(); this.progressActive = false;
this.$alert(e.message, 'Ошибка', {type: 'error'});
}
});
}
keyHook(event) {
if (this.$root.rootRoute == '/reader') {
if (this.$refs.page && this.$refs.page.keyHook)

View File

@@ -1,7 +1,6 @@
<template>
<div class="main">
<pre>{{ lastOpenedBook }}</pre>
<pre>{{this.$store.state.reader.openedBook}}</pre>
<pre>{{ parsedBook }}</pre>
</div>
</template>
@@ -14,11 +13,30 @@ import bookManager from '../share/bookManager';
export default @Component({
})
class TextPage extends Vue {
parsedBook = null;
created() {
this.commit = this.$store.commit;
this.dispatch = this.$store.dispatch;
this.config = this.$store.state.config;
this.reader = this.$store.state.reader;
this.book = null;
}
activated() {
const last = this.lastOpenedBook;
if (last) {
(async() => {
const isParsed = await bookManager.hasBookParsed(last);
if (!isParsed) {
this.$emit('parse-book', last);
return;
}
const book = await bookManager.getBook(last);
this.book = book.parsed;
})();
}
}
get lastOpenedBook() {

View File

@@ -172,6 +172,8 @@ export default class BookParser {
this.para = para;
callback(100);
await sleep(10);
return {fb2};
}
}

View File

@@ -64,6 +64,17 @@ class BookManager {
return result;
}
hasBookParsed(meta) {
if (!this.books)
return false;
if (!meta.url)
return false;
if (!meta.key)
meta.key = this.keyFromUrl(meta.url);
let book = this.books[meta.key];
return (book && book.parsed);
}
async getBook(meta, callback) {
if (!this.books)
await this.init();