瀏覽代碼

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

Book Pauk 6 年之前
父節點
當前提交
a81b38cf04

+ 1 - 1
client/components/Reader/ProgressPage/ProgressPage.vue

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

+ 29 - 1
client/components/Reader/Reader.vue

@@ -43,7 +43,7 @@
 
 
         <el-main>
         <el-main>
             <keep-alive>
             <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>
             </keep-alive>
         </el-main>
         </el-main>
     </el-container>
     </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) {
     keyHook(event) {
         if (this.$root.rootRoute == '/reader') {
         if (this.$root.rootRoute == '/reader') {
             if (this.$refs.page && this.$refs.page.keyHook)
             if (this.$refs.page && this.$refs.page.keyHook)

+ 20 - 2
client/components/Reader/TextPage/TextPage.vue

@@ -1,7 +1,6 @@
 <template>
 <template>
     <div class="main">
     <div class="main">
-        <pre>{{ lastOpenedBook }}</pre>
-        <pre>{{this.$store.state.reader.openedBook}}</pre>
+        <pre>{{ parsedBook }}</pre>
     </div>
     </div>
 </template>
 </template>
 
 
@@ -14,11 +13,30 @@ import bookManager from '../share/bookManager';
 export default @Component({
 export default @Component({
 })
 })
 class TextPage extends Vue {
 class TextPage extends Vue {
+    parsedBook = null;
+
     created() {
     created() {
         this.commit = this.$store.commit;
         this.commit = this.$store.commit;
         this.dispatch = this.$store.dispatch;
         this.dispatch = this.$store.dispatch;
         this.config = this.$store.state.config;
         this.config = this.$store.state.config;
         this.reader = this.$store.state.reader;
         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() {
     get lastOpenedBook() {

+ 2 - 0
client/components/Reader/share/BookParser.js

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

+ 11 - 0
client/components/Reader/share/bookManager.js

@@ -64,6 +64,17 @@ class BookManager {
         return result;
         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) {
     async getBook(meta, callback) {
         if (!this.books) 
         if (!this.books) 
             await this.init();
             await this.init();