Доработки для встраивания в сетевую библиотеку проекта Liberama
This commit is contained in:
@@ -430,6 +430,8 @@ class Search {
|
|||||||
searchResult = {};
|
searchResult = {};
|
||||||
tableData = [];
|
tableData = [];
|
||||||
|
|
||||||
|
liberamaReady = false;
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
|
|
||||||
@@ -438,6 +440,17 @@ class Search {
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
(async() => {
|
(async() => {
|
||||||
|
//для встраивания в liberama
|
||||||
|
window.addEventListener('message', (event) => {
|
||||||
|
if (!_.isObject(event.data) || event.data.from != 'ExternalLibs')
|
||||||
|
return;
|
||||||
|
|
||||||
|
//console.log(event);
|
||||||
|
|
||||||
|
this.recvMessage(event.data);
|
||||||
|
});
|
||||||
|
|
||||||
|
//локальный кеш
|
||||||
await authorBooksStorage.init();
|
await authorBooksStorage.init();
|
||||||
|
|
||||||
this.api = this.$root.api;
|
this.api = this.$root.api;
|
||||||
@@ -449,10 +462,12 @@ class Search {
|
|||||||
this.updateSearchFromRouteQuery(this.$route);
|
this.updateSearchFromRouteQuery(this.$route);
|
||||||
|
|
||||||
//чтоб не вызывался лишний refresh
|
//чтоб не вызывался лишний refresh
|
||||||
await utils.sleep(100);
|
await this.$nextTick();
|
||||||
|
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
this.refresh();//no await
|
this.refresh();//no await
|
||||||
|
|
||||||
|
this.sendMessage({type: 'mes', data: 'hello-from-inpx-web'});
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,6 +486,26 @@ class Search {
|
|||||||
this.langDefault = settings.langDefault;
|
this.langDefault = settings.langDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recvMessage(d) {
|
||||||
|
if (d.type == 'mes') {
|
||||||
|
switch(d.data) {
|
||||||
|
case 'ready':
|
||||||
|
this.liberamaReady = true;
|
||||||
|
this.sendMessage({type: 'mes', data: 'ready'});
|
||||||
|
this.sendCurrentUrl();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage(d) {
|
||||||
|
window.parent.postMessage(Object.assign({}, {from: 'inpx-web'}, d), '*');
|
||||||
|
}
|
||||||
|
|
||||||
|
sendCurrentUrl() {
|
||||||
|
this.sendMessage({type: 'urlChange', data: window.location.href});
|
||||||
|
}
|
||||||
|
|
||||||
get config() {
|
get config() {
|
||||||
return this.$store.state.config;
|
return this.$store.state.config;
|
||||||
}
|
}
|
||||||
@@ -536,6 +571,8 @@ class Search {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.$root.setAppTitle(result);
|
this.$root.setAppTitle(result);
|
||||||
|
if (this.liberamaReady)
|
||||||
|
this.sendMessage({type: 'titleChange', data: result});
|
||||||
}
|
}
|
||||||
|
|
||||||
showSearchHelp() {
|
showSearchHelp() {
|
||||||
@@ -806,9 +843,13 @@ class Search {
|
|||||||
this.$root.notify.error('Копирование ссылки не удалось');
|
this.$root.notify.error('Копирование ссылки не удалось');
|
||||||
} else if (action == 'readBook') {
|
} else if (action == 'readBook') {
|
||||||
//читать
|
//читать
|
||||||
|
if (this.liberamaReady) {
|
||||||
|
this.sendMessage({type: 'submitUrl', data: href});
|
||||||
|
} else {
|
||||||
const url = this.config.bookReadLink.replace('${DOWNLOAD_LINK}', href);
|
const url = this.config.bookReadLink.replace('${DOWNLOAD_LINK}', href);
|
||||||
window.open(url, '_blank');
|
window.open(url, '_blank');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
this.$root.stdDialog.alert(e.message, 'Ошибка');
|
this.$root.stdDialog.alert(e.message, 'Ошибка');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -861,6 +902,9 @@ class Search {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateSearchFromRouteQuery(to) {
|
async updateSearchFromRouteQuery(to) {
|
||||||
|
if (this.liberamaReady)
|
||||||
|
this.sendCurrentUrl();
|
||||||
|
|
||||||
if (this.routeUpdating)
|
if (this.routeUpdating)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user