Добавлена кнопка "Показать еще" при отображении большого количества книг

This commit is contained in:
Book Pauk
2022-10-01 13:28:31 +07:00
parent ee53b7bb14
commit 0af22618ce

View File

@@ -153,8 +153,8 @@
</div> </div>
<div v-if="isExpanded(item) && item.books"> <div v-if="isExpanded(item) && item.books">
<div v-for="book in item.books" :key="book._key" class="book-row column"> <div v-for="book in item.books" :key="book.key" class="book-row column">
<div v-if="book._type == 'series'" class="column"> <div v-if="book.type == 'series'" class="column">
<div class="row items-center q-mr-xs no-wrap text-grey-9"> <div class="row items-center q-mr-xs no-wrap text-grey-9">
<div class="row items-center clickable2 q-py-xs no-wrap" @click="expandSeries(book)"> <div class="row items-center clickable2 q-py-xs no-wrap" @click="expandSeries(book)">
<div style="min-width: 30px"> <div style="min-width: 30px">
@@ -173,12 +173,22 @@
</div> </div>
<div v-if="isExpandedSeries(book) && book.books" class="book-row column"> <div v-if="isExpandedSeries(book) && book.books" class="book-row column">
<BookView v-for="subbook in book.books" :key="subbook._key" :book="subbook" :genre-tree="genreTree" @book-event="bookEvent" /> <BookView v-for="subbook in book.books" :key="subbook.key" :book="subbook" :genre-tree="genreTree" @book-event="bookEvent" />
</div> </div>
</div> </div>
<BookView v-else :book="book" :genre-tree="genreTree" @book-event="bookEvent" /> <BookView v-else :book="book" :genre-tree="genreTree" @book-event="bookEvent" />
</div> </div>
</div> </div>
<div v-if="isExpanded(item) && item.showMore" class="row items-center book-row q-mb-sm">
<i class="las la-ellipsis-h text-blue-10" style="font-size: 40px"></i>
<q-btn class="q-ml-md" color="primary" style="width: 200px" dense rounded no-caps @click="showMore(item)">
Показать еще {{ showMoreCount }}
</q-btn>
<q-btn class="q-ml-sm" color="primary" style="width: 200px" dense rounded no-caps @click="showMore(item, true)">
Показать все
</q-btn>
</div>
</div> </div>
<!-- Формирование списка конец ------------------------------------------------------------------> <!-- Формирование списка конец ------------------------------------------------------------------>
@@ -253,6 +263,7 @@ import diffUtils from '../../share/diffUtils';
import _ from 'lodash'; import _ from 'lodash';
const maxItemCount = 500;//выше этого значения показываем "Загрузка" const maxItemCount = 500;//выше этого значения показываем "Загрузка"
const showMoreCount = 200;//значение для "Показать еще"
const componentOptions = { const componentOptions = {
components: { components: {
@@ -360,6 +371,7 @@ class Search {
cachedAuthors = {}; cachedAuthors = {};
hiddenCount = 0; hiddenCount = 0;
showTooltips = true; showTooltips = true;
showMoreCount = showMoreCount;
limitOptions = [ limitOptions = [
{label: '10', value: 10}, {label: '10', value: 10},
@@ -629,10 +641,10 @@ class Search {
if (!this.showCounts || item.count === undefined) if (!this.showCounts || item.count === undefined)
return result; return result;
if (item.books) { if (item.loadedBooks) {
let count = 0; let count = 0;
for (const book of item.books) { for (const book of item.loadedBooks) {
if (book._type == 'series') if (book.type == 'series')
count += book.books.length; count += book.books.length;
else else
count++; count++;
@@ -734,7 +746,7 @@ class Search {
} }
isExpandedSeries(seriesItem) { isExpandedSeries(seriesItem) {
return this.expandedSeries.indexOf(seriesItem._key) >= 0; return this.expandedSeries.indexOf(seriesItem.key) >= 0;
} }
setSetting(name, newValue) { setSetting(name, newValue) {
@@ -818,7 +830,7 @@ class Search {
expandSeries(seriesItem) { expandSeries(seriesItem) {
const expandedSeries = _.cloneDeep(this.expandedSeries); const expandedSeries = _.cloneDeep(this.expandedSeries);
const key = seriesItem._key; const key = seriesItem.key;
if (!this.isExpandedSeries(seriesItem)) { if (!this.isExpandedSeries(seriesItem)) {
expandedSeries.push(key); expandedSeries.push(key);
@@ -954,6 +966,28 @@ class Search {
}); });
} }
showMore(item, all = false) {
if (item.loadedBooks) {
const books = [];
let count = (all ? item.loadedBooks.length : showMoreCount);
for (const book of item.loadedBooks) {
if (book.visible) {
books.push(book);
} else if (count) {
count--;
book.visible = true;
books.push(book);
} else {
break;
}
}
item.showMore = books.length < item.loadedBooks.length;
item.books = books;
}
}
async getBooks(item) { async getBooks(item) {
if (item.books) { if (item.books) {
if (item.count > maxItemCount) { if (item.count > maxItemCount) {
@@ -987,8 +1021,9 @@ class Search {
const prepareBook = (book) => { const prepareBook = (book) => {
return Object.assign( return Object.assign(
{ {
_key: book.id, key: book.id,
_type: 'book', type: 'book',
visible: false,
}, },
book book
); );
@@ -1003,9 +1038,10 @@ class Search {
if (index === undefined) { if (index === undefined) {
index = books.length; index = books.length;
books.push({ books.push({
_key: `${item.author}-${book.series}`, key: `${item.author}-${book.series}`,
_type: 'series', type: 'series',
series: book.series, series: book.series,
visible: false,
books: [], books: [],
}); });
@@ -1021,16 +1057,16 @@ class Search {
//сортировка //сортировка
books.sort((a, b) => { books.sort((a, b) => {
if (a._type == 'series') { if (a.type == 'series') {
return (b._type == 'series' ? a._key.localeCompare(b._key) : -1); return (b.type == 'series' ? a.key.localeCompare(b.key) : -1);
} else { } else {
return (b._type == 'book' ? a.title.localeCompare(b.title) : 1); return (b.type == 'book' ? a.title.localeCompare(b.title) : 1);
} }
}); });
//сортировка внутри серий //сортировка внутри серий
for (const book of books) { for (const book of books) {
if (book._type == 'series') { if (book.type == 'series') {
book.books.sort((a, b) => { book.books.sort((a, b) => {
const dserno = (a.serno || Number.MAX_VALUE) - (b.serno || Number.MAX_VALUE); const dserno = (a.serno || Number.MAX_VALUE) - (b.serno || Number.MAX_VALUE);
const dtitle = a.title.localeCompare(b.title); const dtitle = a.title.localeCompare(b.title);
@@ -1040,11 +1076,13 @@ class Search {
} }
} }
if (books.length == 1 && books[0]._type == 'series' && !this.isExpandedSeries(books[0])) { if (books.length == 1 && books[0].type == 'series' && !this.isExpandedSeries(books[0])) {
this.expandSeries(books[0]); this.expandSeries(books[0]);
} }
item.books = books; item.loadedBooks = books;
this.showMore(item);
await this.$nextTick(); await this.$nextTick();
} finally { } finally {
item.bookLoading = false; item.bookLoading = false;
@@ -1107,8 +1145,10 @@ class Search {
author: rec.author, author: rec.author,
name: rec.author.replace(/,/g, ', '), name: rec.author.replace(/,/g, ', '),
count, count,
book: false, loadedBooks: false,
books: false,
bookLoading: false, bookLoading: false,
showMore: false,
}); });
num++; num++;