Добавил реакцию на роутер
This commit is contained in:
@@ -82,6 +82,21 @@ class Reader extends Vue {
|
|||||||
/*while (this.lastOpenedBook) {
|
/*while (this.lastOpenedBook) {
|
||||||
this.commit('reader/delOpenedBook', this.lastOpenedBook);
|
this.commit('reader/delOpenedBook', this.lastOpenedBook);
|
||||||
}*/
|
}*/
|
||||||
|
if (this.$root.rootRoute == '/reader' && this.routeParamUrl && this.routeParamUrl != this.lastOpenedBook.url) {
|
||||||
|
this.commit('reader/setLoaderActive', true);
|
||||||
|
this.loadBook({url: this.routeParamUrl});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get routeParamUrl() {
|
||||||
|
let result = '';
|
||||||
|
const path = this.$route.fullPath;
|
||||||
|
const i = path.indexOf('url=');
|
||||||
|
if (i >= 0) {
|
||||||
|
result = path.substr(i + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
return decodeURIComponent(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
get loaderActive() {
|
get loaderActive() {
|
||||||
@@ -130,6 +145,11 @@ class Reader extends Vue {
|
|||||||
if (result != 'TextPage') {
|
if (result != 'TextPage') {
|
||||||
this.$root.$emit('set-app-title');
|
this.$root.$emit('set-app-title');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result == 'LoaderPage') {
|
||||||
|
this.$router.replace('/reader');
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<pre>{{ meta }}</pre>
|
<pre>{{ meta }}</pre>
|
||||||
|
<pre>{{ bookPos }}</pre>
|
||||||
|
<pre>{{ $route.query }}</pre>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -13,10 +15,22 @@ import _ from 'lodash';
|
|||||||
import bookManager from '../share/bookManager';
|
import bookManager from '../share/bookManager';
|
||||||
|
|
||||||
export default @Component({
|
export default @Component({
|
||||||
|
watch: {
|
||||||
|
bookPos: function(newValue) {
|
||||||
|
this.updateRoute(newValue);
|
||||||
|
this.drawPage();
|
||||||
|
},
|
||||||
|
routeParamPos: function(newValue) {
|
||||||
|
if (newValue !== undefined && newValue != this.bookPos) {
|
||||||
|
this.bookPos = newValue;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
class TextPage extends Vue {
|
class TextPage extends Vue {
|
||||||
meta = null;
|
meta = null;
|
||||||
fb2 = null;
|
fb2 = null;
|
||||||
|
bookPos = 0;
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
@@ -24,7 +38,7 @@ class TextPage extends Vue {
|
|||||||
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.openFailed = false;
|
this.lastOpenTry = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
activated() {
|
activated() {
|
||||||
@@ -32,15 +46,15 @@ class TextPage extends Vue {
|
|||||||
this.meta = null;
|
this.meta = null;
|
||||||
this.fb2 = null;
|
this.fb2 = null;
|
||||||
|
|
||||||
const last = this.lastOpenedBook;
|
let last = this.lastOpenedBook;
|
||||||
if (last) {
|
if (last) {
|
||||||
(async() => {
|
(async() => {
|
||||||
const isParsed = await bookManager.hasBookParsed(last);
|
const isParsed = await bookManager.hasBookParsed(last);
|
||||||
if (!isParsed) {
|
if (!isParsed) {
|
||||||
this.$root.$emit('set-app-title');
|
this.$root.$emit('set-app-title');
|
||||||
if (!this.openFailed) {
|
if (this.lastOpenTry != last) {
|
||||||
this.$emit('parse-book', last);
|
this.$emit('parse-book', last);
|
||||||
this.openFailed = true;
|
this.lastOpenTry = last;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -55,6 +69,8 @@ class TextPage extends Vue {
|
|||||||
this.fb2.bookTitle
|
this.fb2.bookTitle
|
||||||
]).join(' '));
|
]).join(' '));
|
||||||
|
|
||||||
|
this.bookPos = (this.routeParamPos !== undefined ? this.routeParamPos : last.bookPos || 0);
|
||||||
|
this.updateRoute(this.bookPos);
|
||||||
this.drawPage();
|
this.drawPage();
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
@@ -64,6 +80,23 @@ class TextPage extends Vue {
|
|||||||
return this.$store.getters['reader/lastOpenedBook'];
|
return this.$store.getters['reader/lastOpenedBook'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get routeParamPos() {
|
||||||
|
let result = undefined;
|
||||||
|
const q = this.$route.query;
|
||||||
|
if (q['__p']) {
|
||||||
|
result = q['__p'];
|
||||||
|
if (Array.isArray(result))
|
||||||
|
result = result[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return (result ? parseInt(result, 10) || 0 : result);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateRoute(newPos) {
|
||||||
|
if (this.book)
|
||||||
|
this.$router.replace(`/reader?__p=${newPos}&url=${this.lastOpenedBook.url}`);
|
||||||
|
}
|
||||||
|
|
||||||
drawPage() {
|
drawPage() {
|
||||||
const last = this.lastOpenedBook;
|
const last = this.lastOpenedBook;
|
||||||
if (!last)
|
if (!last)
|
||||||
|
|||||||
Reference in New Issue
Block a user