Рефакторинг, небольшие улучшения

This commit is contained in:
Book Pauk
2022-10-24 17:23:13 +07:00
parent b707f8425e
commit 634d646622
2 changed files with 21 additions and 22 deletions

View File

@@ -176,19 +176,22 @@ const componentOptions = {
showDeleted() { showDeleted() {
this.updateTableData(); this.updateTableData();
}, },
ready(newValue) {
if (newValue)
this.refresh();//no await
}
}, },
}; };
class AuthorList extends BaseList { class AuthorList extends BaseList {
_options = componentOptions; _options = componentOptions;
_props = { _props = {
ready: Boolean,
list: Object, list: Object,
search: Object, search: Object,
genreMap: Object, genreMap: Object,
liberamaReady: Boolean, liberamaReady: Boolean,
}; };
ready = false;
loadingMessage = ''; loadingMessage = '';
loadingMessage2 = ''; loadingMessage2 = '';
@@ -214,20 +217,11 @@ class AuthorList extends BaseList {
created() { created() {
this.commit = this.$store.commit; this.commit = this.$store.commit;
this.api = this.$root.api;
this.loadSettings(); this.loadSettings();
} }
mounted() {
(async() => {
//локальный кеш
this.api = this.$root.api;
this.ready = true;
this.refresh();//no await
})();
}
loadSettings() { loadSettings() {
const settings = this.settings; const settings = this.settings;
@@ -821,7 +815,15 @@ class AuthorList extends BaseList {
if (!this.ready) if (!this.ready)
return; return;
//оптимизация //параметры запроса
const newQuery = _.cloneDeep(this.search);
newQuery.offset = (newQuery.page - 1)*newQuery.limit;
if (_.isEqual(newQuery, this.prevQuery))
return;
this.prevQuery = newQuery;
//оптимизация, вместо запроса к серверу, берем из кеша
if (this.abCacheEnabled && this.search.author && this.search.author[0] == '=') { if (this.abCacheEnabled && this.search.author && this.search.author[0] == '=') {
const authorSearch = this.search.author.substring(1); const authorSearch = this.search.author.substring(1);
const author = this.cachedAuthors[authorSearch]; const author = this.cachedAuthors[authorSearch];
@@ -840,12 +842,6 @@ class AuthorList extends BaseList {
} }
} }
//параметры запроса
const offset = (this.search.page - 1)*this.search.limit;
const newQuery = _.cloneDeep(this.search);
newQuery.offset = offset;
this.queryExecute = newQuery; this.queryExecute = newQuery;
if (this.refreshing) if (this.refreshing)

View File

@@ -111,7 +111,7 @@
</div> </div>
<!-- Формирование списка ------------------------------------------------------------------------> <!-- Формирование списка ------------------------------------------------------------------------>
<AuthorList :list="list" :search="search" :genre-map="genreMap" :liberama-ready="liberamaReady" @list-event="listEvent" /> <AuthorList :ready="ready" :list="list" :search="search" :genre-map="genreMap" :liberama-ready="liberamaReady" @list-event="listEvent" />
<!-- Формирование списка конец ------------------------------------------------------------------> <!-- Формирование списка конец ------------------------------------------------------------------>
<div class="row justify-center"> <div class="row justify-center">
@@ -248,6 +248,8 @@ const componentOptions = {
class Search { class Search {
_options = componentOptions; _options = componentOptions;
ready = false;
collection = ''; collection = '';
projectName = ''; projectName = '';
@@ -312,6 +314,7 @@ class Search {
created() { created() {
this.commit = this.$store.commit; this.commit = this.$store.commit;
this.api = this.$root.api;
this.loadSettings(); this.loadSettings();
} }
@@ -331,8 +334,6 @@ class Search {
//локальный кеш //локальный кеш
await authorBooksStorage.init(); await authorBooksStorage.init();
this.api = this.$root.api;
if (!this.$root.isMobileDevice) if (!this.$root.isMobileDevice)
this.$refs.authorInput.focus(); this.$refs.authorInput.focus();
@@ -340,6 +341,8 @@ class Search {
this.updateSearchFromRouteQuery(this.$route); this.updateSearchFromRouteQuery(this.$route);
this.sendMessage({type: 'mes', data: 'hello-from-inpx-web'}); this.sendMessage({type: 'mes', data: 'hello-from-inpx-web'});
this.ready = true;
})(); })();
} }