From 5e3fe21c255cbf7066e8e6a087ee16aee82ca9f0 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 25 Sep 2022 13:35:23 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=20lim?= =?UTF-8?q?it=20=D0=B2=20routeQuery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Search/Search.vue | 107 +++++++++++++++------------- 1 file changed, 56 insertions(+), 51 deletions(-) diff --git a/client/components/Search/Search.vue b/client/components/Search/Search.vue index 6164c78..8b3d3eb 100644 --- a/client/components/Search/Search.vue +++ b/client/components/Search/Search.vue @@ -142,7 +142,9 @@
-
Обработка...
+
+ Обработка... +
@@ -327,7 +329,7 @@ class Search { showDeleted = false; abCacheEnabled = true; langDefault = ''; - limit = 50; + limit = 20; //stuff refreshing = false; @@ -565,6 +567,57 @@ class Search { this.commit('setSettings', {[name]: _.cloneDeep(newValue)}); } + setDefaults() { + this.search = Object.assign({}, this.search, { + author: '', + series: '', + title: '', + genre: '', + lang: this.langDefault, + }); + } + + async updateQueryFromRoute(to) { + if (this.routeUpdating) + return; + + const query = to.query; + + this.search = Object.assign({}, this.search, { + author: query.author || '', + series: query.series || '', + title: query.title || '', + genre: query.genre || '', + lang: (query.lang == 'default' ? this.langDefault : query.lang || ''), + page: parseInt(query.page, 10) || 1, + limit: parseInt(query.limit, 10) || 20, + }); + + if (this.search.limit > 1000) + this.search.limit = 1000; + } + + updateRouteQuery() { + this.routeUpdating = true; + try { + const oldQuery = this.$route.query; + const query = _.pickBy(this.search); + + if (this.search.lang == this.langDefault) + query.lang = 'default' + + const diff = diffUtils.getObjDiff(oldQuery, query); + if (!diffUtils.isEmptyObjDiff(diff)) { + this.$router.replace({query}); + } + } finally { + (async() => { + await utils.sleep(100); + this.routeUpdating = false; + })(); + } + } + async expandAuthor(item) { const expanded = _.cloneDeep(this.expanded); const key = item.author; @@ -905,53 +958,6 @@ class Search { this.tableData = result; } - setDefaults() { - this.search = Object.assign({}, this.search, { - author: '', - series: '', - title: '', - genre: '', - lang: this.langDefault, - }); - } - - async updateQueryFromRoute(to) { - if (this.routeUpdating) - return; - - const query = to.query; - - this.search = Object.assign({}, this.search, { - author: query.author || '', - series: query.series || '', - title: query.title || '', - genre: query.genre || '', - lang: (query.lang == 'default' ? this.langDefault : query.lang || ''), - page: parseInt(query.page, 10) || 1, - }); - } - - updateRouteQuery() { - this.routeUpdating = true; - try { - const oldQuery = this.$route.query; - const query = _.pickBy(this.search); - delete query.limit; - if (this.search.lang == this.langDefault) - query.lang = 'default' - - const diff = diffUtils.getObjDiff(oldQuery, query); - if (!diffUtils.isEmptyObjDiff(diff)) { - this.$router.replace({query}); - } - } finally { - (async() => { - await utils.sleep(100); - this.routeUpdating = false; - })(); - } - } - async refresh() { if (!this.ready) return; @@ -978,10 +984,9 @@ class Search { } //параметры запроса - const offset = (this.search.page - 1)*this.limit; + const offset = (this.search.page - 1)*this.search.limit; const newQuery = _.cloneDeep(this.search); - newQuery.limit = this.limit; newQuery.offset = offset; this.queryExecute = newQuery;