Работа над проектом

This commit is contained in:
Book Pauk
2022-09-25 17:27:40 +07:00
parent 7e5ea30579
commit e6d0c6e519
7 changed files with 117 additions and 63 deletions

View File

@@ -166,6 +166,16 @@ class Api {
return response;
}
async getBookLink(bookPath) {
const response = await this.request({action: 'get-book-link', bookPath});
if (response.error) {
throw new Error(response.error);
}
return response;
}
async getConfig() {
const response = await this.request({action: 'get-config'});

View File

@@ -89,9 +89,11 @@ class BookView {
}
download() {
this.$emit('bookEvent', {action: 'download', book: this.book});
}
copyLink() {
this.$emit('bookEvent', {action: 'copyLink', book: this.book});
}
}

View File

@@ -148,8 +148,8 @@
</div>
<div v-if="isExpanded(item) && item.books">
<div v-for="book in item.books" :key="book.key" class="book-row column">
<div v-if="book.type == 'series'" class="column">
<div v-for="book in item.books" :key="book._key" class="book-row 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 clickable2 q-py-xs no-wrap" @click="expandSeries(book)">
<div style="min-width: 30px">
@@ -168,7 +168,7 @@
</div>
<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>
<BookView v-else :book="book" :genre-tree="genreTree" @book-event="bookEvent" />
@@ -528,7 +528,7 @@ class Search {
if (item.books) {
let count = 0;
for (const book of item.books) {
if (book.type == 'series')
if (book._type == 'series')
count += book.books.length;
else
count++;
@@ -553,11 +553,31 @@ class Search {
this.search.title = '';
}
async download(book, copy = false) {
try {
const bookPath = `${book.folder}/${book.file}.${book.ext}`;
const response = await this.api.getBookLink(bookPath);
if (!copy) {
//
}
console.log(response);
} catch(e) {
this.$root.stdDialog.alert(e.message, 'Ошибка');
}
}
bookEvent(event) {
switch (event.action) {
case 'titleClick':
this.search.title = `=${event.book.title}`;
break;
case 'download':
this.download(event.book);//no await
break;
case 'copyLink':
this.download(event.book, true);//no await
break;
}
}
@@ -566,7 +586,7 @@ class Search {
}
isExpandedSeries(seriesItem) {
return this.expandedSeries.indexOf(seriesItem.key) >= 0;
return this.expandedSeries.indexOf(seriesItem._key) >= 0;
}
setSetting(name, newValue) {
@@ -650,7 +670,7 @@ class Search {
expandSeries(seriesItem) {
const expandedSeries = _.cloneDeep(this.expandedSeries);
const key = seriesItem.key;
const key = seriesItem._key;
if (!this.isExpandedSeries(seriesItem)) {
expandedSeries.push(key);
@@ -815,18 +835,13 @@ class Search {
const filtered = this.filterBooks(loadedBooks);
const prepareBook = (book) => {
return {
key: book.id,
type: 'book',
title: book.title,
series: book.series,
serno: book.serno,
genre: book.genre,
size: book.size,
ext: book.ext,
src: book,
}
return Object.assign(
{
_key: book.id,
_type: 'book',
},
book
);
};
//объединение по сериям
@@ -838,8 +853,8 @@ class Search {
if (index === undefined) {
index = books.length;
books.push({
key: `${item.author}-${book.series}`,
type: 'series',
_key: `${item.author}-${book.series}`,
_type: 'series',
series: book.series,
books: [],
@@ -856,16 +871,16 @@ class Search {
//сортировка
books.sort((a, b) => {
if (a.type == 'series') {
return (b.type == 'series' ? a.key.localeCompare(b.key) : -1);
if (a._type == 'series') {
return (b._type == 'series' ? a._key.localeCompare(b._key) : -1);
} 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) {
if (book.type == 'series') {
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);
@@ -875,7 +890,7 @@ 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]);
}