From 3564089b7c290e04e27218fa8618583a07629553 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 21 Aug 2022 21:47:31 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Search/Search.vue | 81 ++++++++++++++++++----------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/client/components/Search/Search.vue b/client/components/Search/Search.vue index e19de60..ba3046f 100644 --- a/client/components/Search/Search.vue +++ b/client/components/Search/Search.vue @@ -84,7 +84,7 @@
-
+
Только этот автор @@ -92,15 +92,21 @@
-
-
- -
-
- +
+
+
+ +
+
+ +
- {{ item.name }} + {{ item.name }} +
+ +
+ ({{ item.books.length }})
@@ -276,6 +282,9 @@ class Search { } onScroll() { + if (this.ignoreScrolling) + return; + const curScrollTop = this.$refs.scroller.scrollTop; if (!this.lastScrollTop) this.lastScrollTop = 0; @@ -294,6 +303,12 @@ class Search { this.lastScrollTop = curScrollTop; } + async ignoreScroll(ms) { + this.ignoreScrolling = true; + await utils.sleep(ms); + this.ignoreScrolling = false; + } + scrollToTop() { this.$refs.scroller.scrollTop = 0; const curScrollTop = this.$refs.scroller.scrollTop; @@ -324,17 +339,16 @@ class Search { const author = item.author; if (!this.isExpanded(item)) { - if (expanded.indexOf(author) < 0) { - expanded.push(author); + expanded.push(author); - this.getBooks(item); + this.getBooks(item); - if (expanded.length > 100) { - expanded.shift(); - } - - this.expanded = expanded; + if (expanded.length > 10) { + expanded.shift(); } + + this.expanded = expanded; + this.ignoreScroll(50); } else { const i = expanded.indexOf(author); if (i >= 0) { @@ -345,23 +359,12 @@ class Search { } async loadBooks(authorId) { - let inSearch = true; - (async() => { - await utils.sleep(500); - if (inSearch) - this.loadingMessage = 'Загрузка списка книг...'; - })(); - try { const result = await this.api.getBookList(authorId); - return result; + return result.books; } catch (e) { this.$root.stdDialog.alert(e.message, 'Ошибка'); - return; - } finally { - inSearch = false; - this.loadingMessage = ''; } } @@ -369,7 +372,26 @@ class Search { if (item.books) return; - item.books = await this.loadBooks(item.key); + if (!this.getBooksFlag) + this.getBooksFlag = 0; + + this.getBooksFlag++; + + try { + if (this.getBooksFlag == 1) { + (async() => { + await utils.sleep(500); + if (this.getBooksFlag > 0) + this.loadingMessage = 'Загрузка списка книг...'; + })(); + } + + item.books = await this.loadBooks(item.key); + } finally { + this.getBooksFlag--; + if (this.getBooksFlag == 0) + this.loadingMessage = ''; + } } async updateTableData() { @@ -448,7 +470,6 @@ class Search { this.scrollToTop(); } catch (e) { this.$root.stdDialog.alert(e.message, 'Ошибка'); - return; } finally { inSearch = false; this.loadingMessage = '';