diff --git a/client/components/Search/BookView/BookView.vue b/client/components/Search/BookView/BookView.vue index 75a2519..67833b8 100644 --- a/client/components/Search/BookView/BookView.vue +++ b/client/components/Search/BookView/BookView.vue @@ -1,9 +1,27 @@ @@ -21,11 +39,44 @@ class BookView { _options = componentOptions; _props = { book: Object, + genreTree: Array, }; created() { } + get bookSize() { + let size = this.book.size/1024; + let unit = 'KB'; + if (size > 1024) { + size = size/1024; + unit = 'MB'; + } + return `${size.toFixed(0)}${unit}`; + } + + get bookGenre() { + let result = []; + const genre = new Set(this.book.genre.split(',')); + + for (const section of this.genreTree) { + for (const g of section.value) + if (genre.has(g.value)) + result.push(g.name); + } + + return `(${result.join(', ')})`; + } + + selectTitle() { + this.$emit('bookEvent', {action: 'titleClick', book: this.book}); + } + + download() { + } + + copyLink() { + } } export default vueComponent(BookView); @@ -33,4 +84,13 @@ export default vueComponent(BookView); \ No newline at end of file diff --git a/client/components/Search/Search.vue b/client/components/Search/Search.vue index 83fcf33..b0283f5 100644 --- a/client/components/Search/Search.vue +++ b/client/components/Search/Search.vue @@ -131,7 +131,7 @@ -
+
{{ item.name }}
@@ -140,10 +140,15 @@
+
+ Загрузка + +
+
-
+
@@ -161,12 +166,10 @@
- +
-
- -
+
@@ -179,6 +182,7 @@
+
@@ -237,6 +241,8 @@ import diffUtils from '../../share/diffUtils'; import _ from 'lodash'; +const maxItemCount = 500;//выше этого значения показываем "Загрузка" + const componentOptions = { components: { PageScroller, @@ -487,7 +493,7 @@ class Search { } get hiddenResultsMessage() { - return `+${this.hiddenCount} результат${utils.wordEnding(this.hiddenCount)} скрыты`; + return `+${this.hiddenCount} результат${utils.wordEnding(this.hiddenCount)} скрыт${utils.wordEnding(this.hiddenCount, 2)}`; } updatePageCount() { @@ -506,13 +512,37 @@ class Search { } } + getBookCount(item) { + let result = ''; + if (!this.showCounts || item.count === undefined) + return result; + + if (item.books) { + let count = 0; + for (const book of item.books) { + if (book.type == 'series') + count += book.books.length; + else + count++; + } + + result = `${count}/${item.count}`; + } else + result = `#/${item.count}`; + + return `(${result})`; + } + selectAuthor(author) { this.search.author = `=${author}`; + this.search.series = ''; + this.search.title = ''; this.scrollToTop(); } selectSeries(series) { this.search.series = `=${series}`; + this.search.title = ''; } bookEvent(event) { @@ -535,14 +565,14 @@ class Search { this.commit('setSettings', {[name]: _.cloneDeep(newValue)}); } - expandAuthor(item) { + async expandAuthor(item) { const expanded = _.cloneDeep(this.expanded); const key = item.author; if (!this.isExpanded(item)) { expanded.push(key); - this.getBooks(item); + await this.getBooks(item); if (expanded.length > 100) { expanded.shift(); @@ -581,19 +611,6 @@ class Search { } } - getBookCount(item) { - let result = ''; - if (!this.showCounts || item.count === undefined) - return result; - - if (item.books) - result = `${item.books.length}/${item.count}`; - else - result = `#/${item.count}`; - - return `(${result})`; - } - async loadBooks(authorId) { try { let result; @@ -709,13 +726,20 @@ class Search { } async getBooks(item) { - if (item.books) + if (item.books) { + if (item.count > maxItemCount) { + item.bookLoading = true; + await utils.sleep(1);//для перерисовки списка + item.bookLoading = false; + } return; + } if (!this.getBooksFlag) this.getBooksFlag = 0; this.getBooksFlag++; + item.bookLoading = true; try { if (this.getBooksFlag == 1) { @@ -736,6 +760,12 @@ class Search { type: 'book', title: book.title, series: book.series, + serno: book.serno, + genre: book.genre, + size: book.size, + ext: book.ext, + + src: book, } }; @@ -751,6 +781,7 @@ class Search { key: `${item.author}-${book.series}`, type: 'series', series: book.series, + books: [], }); @@ -766,22 +797,32 @@ class Search { //сортировка books.sort((a, b) => { if (a.type == 'series') { - if (b.type == 'series') - return a.key.localeCompare(b.key); - else - return -1; + return (b.type == 'series' ? a.key.localeCompare(b.key) : -1); } else { - if (b.type == 'book') - return a.title.localeCompare(b.title); - else - return 1; + return (b.type == 'book' ? a.title.localeCompare(b.title) : 1); } }); //сортировка внутри серий + for (const book of books) { + if (book.type == 'series') { + book.books.sort((a, b) => { + const dserno = (a.serno || Number.MAX_VALUE) - (b.serno || Number.MAX_VALUE); + const dtitle = a.title.localeCompare(b.title); + const dext = a.ext.localeCompare(b.ext); + return (dserno ? dserno : (dtitle ? dtitle : dext)); + }); + } + } + + if (books.length == 1 && books[0].type == 'series' && !this.isExpandedSeries(books[0])) { + this.expandSeries(books[0]); + } item.books = books; + await this.$nextTick(); } finally { + item.bookLoading = false; this.getBooksFlag--; if (this.getBooksFlag == 0) this.loadingMessage2 = ''; @@ -842,11 +883,12 @@ class Search { name: rec.author.replace(/,/g, ', '), count, book: false, + bookLoading: false, }); num++; if (expandedSet.has(item.author)) { - if (authors.length > 1) + if (authors.length > 1 || item.count > maxItemCount) this.getBooks(item);//no await else await this.getBooks(item); @@ -857,7 +899,7 @@ class Search { if (result.length == 1 && !this.isExpanded(result[0])) { this.expandAuthor(result[0]); - } + } this.tableData = result; } diff --git a/client/components/share/NumInput.vue b/client/components/share/NumInput.vue index c89a9e7..229b0f1 100644 --- a/client/components/share/NumInput.vue +++ b/client/components/share/NumInput.vue @@ -11,8 +11,8 @@