SeriesList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div>
  3. <a ref="download" style="display: none;"></a>
  4. <LoadingMessage :message="loadingMessage" z-index="2" />
  5. <LoadingMessage :message="loadingMessage2" z-index="1" />
  6. <!-- Формирование списка ------------------------------------------------------------------------>
  7. <div v-for="item in tableData" :key="item.key" class="column" :class="{'odd-item': item.num % 2}" style="font-size: 120%">
  8. <div class="row items-center q-ml-md q-mr-xs no-wrap">
  9. <div class="row items-center clickable2 q-py-xs no-wrap" @click="expandSeries(item)">
  10. <div style="min-width: 30px">
  11. <div v-if="!isExpandedSeries(item)">
  12. <q-icon name="la la-plus-square" size="28px" />
  13. </div>
  14. <div v-else>
  15. <q-icon name="la la-minus-square" size="28px" />
  16. </div>
  17. </div>
  18. </div>
  19. <div class="clickable2 q-ml-xs q-py-sm text-bold" @click="selectSeries(item.series)">
  20. Серия: {{ item.series }}
  21. </div>
  22. <div class="q-ml-sm text-bold" style="color: #555">
  23. {{ getBookCount(item) }}
  24. </div>
  25. </div>
  26. <div v-if="item.bookLoading" class="book-row row items-center">
  27. <q-icon class="la la-spinner icon-rotate text-blue-8" size="28px" />
  28. <div class="q-ml-xs">
  29. Обработка...
  30. </div>
  31. </div>
  32. <div v-if="isExpandedSeries(item) && item.books">
  33. <div v-if="item.showAllBooks" class="book-row column">
  34. <BookView
  35. v-for="seriesBook in item.allBooks" :key="seriesBook.id"
  36. :book="seriesBook"
  37. mode="series"
  38. :genre-map="genreMap" :show-read-link="showReadLink"
  39. :title-color="isFoundSeriesBook(item, seriesBook) ? 'text-blue-10' : 'text-red'"
  40. @book-event="bookEvent"
  41. />
  42. </div>
  43. <div v-else class="book-row column">
  44. <BookView
  45. v-for="seriesBook in item.books" :key="seriesBook.key"
  46. :book="seriesBook" mode="series" :genre-map="genreMap" :show-read-link="showReadLink" @book-event="bookEvent"
  47. />
  48. </div>
  49. <!--div v-if="!item.showAllBooks && isExpandedSeries(item) && item.books && !item.books.length" class="book-row row items-center">
  50. <q-icon class="la la-meh q-mr-xs" size="24px" />
  51. Возможно у этой серии были найдены книги, помеченные как удаленные, но подходящие по критериям
  52. </div-->
  53. <div
  54. v-if="item.allBooksLoaded && item.allBooksLoaded.length != item.booksLoaded.length"
  55. class="row items-center q-my-sm"
  56. style="margin-left: 100px"
  57. >
  58. <div v-if="item.showAllBooks && item.showMoreAll" class="row items-center q-mr-md">
  59. <i class="las la-ellipsis-h text-red" style="font-size: 40px"></i>
  60. <q-btn class="q-ml-md" color="red" style="width: 200px" dense rounded no-caps @click="showMoreAll(item)">
  61. Показать еще (~{{ showMoreCount }})
  62. </q-btn>
  63. <q-btn class="q-ml-sm" color="red" style="width: 200px" dense rounded no-caps @click="showMoreAll(item, true)">
  64. Показать все ({{ (item.allBooksLoaded && item.allBooksLoaded.length) || '?' }})
  65. </q-btn>
  66. </div>
  67. <div v-if="item.showAllBooks" class="row items-center clickable2 text-blue-10" @click="item.showAllBooks = false">
  68. <q-icon class="la la-long-arrow-alt-up" size="28px" />
  69. Только найденные книги
  70. </div>
  71. <div v-else class="row items-center clickable2 text-red" @click="item.showAllBooks = true">
  72. <q-icon class="la la-long-arrow-alt-down" size="28px" />
  73. Все книги серии
  74. </div>
  75. </div>
  76. </div>
  77. <div v-if="isExpandedSeries(item) && item.showMore" class="row items-center book-row q-mb-sm">
  78. <i class="las la-ellipsis-h text-blue-10" style="font-size: 40px"></i>
  79. <q-btn class="q-ml-md" color="primary" style="width: 200px" dense rounded no-caps @click="showMore(item)">
  80. Показать еще (~{{ showMoreCount }})
  81. </q-btn>
  82. <q-btn class="q-ml-sm" color="primary" style="width: 200px" dense rounded no-caps @click="showMore(item, true)">
  83. Показать все ({{ (item.booksLoaded && item.booksLoaded.length) || '?' }})
  84. </q-btn>
  85. </div>
  86. </div>
  87. <!-- Формирование списка конец ------------------------------------------------------------------>
  88. <div v-if="!refreshing && (!tableData.length || error)" class="row items-center q-ml-md" style="font-size: 120%">
  89. <q-icon class="la la-meh q-mr-xs" size="28px" />
  90. {{ (error ? error : 'Поиск не дал результатов') }}
  91. </div>
  92. </div>
  93. </template>
  94. <script>
  95. //-----------------------------------------------------------------------------
  96. import vueComponent from '../../vueComponent.js';
  97. import { reactive } from 'vue';
  98. import BaseList from '../BaseList';
  99. import * as utils from '../../../share/utils';
  100. import _ from 'lodash';
  101. class SeriesList extends BaseList {
  102. get foundCountMessage() {
  103. return `${this.list.totalFound} сери${utils.wordEnding(this.list.totalFound, 1)}`;
  104. }
  105. isFoundSeriesBook(seriesItem, seriesBook) {
  106. if (!seriesItem.booksSet) {
  107. seriesItem.booksSet = new Set(seriesItem.books.map(b => b.id));
  108. }
  109. return seriesItem.booksSet.has(seriesBook.id);
  110. }
  111. getBookCount(item) {
  112. let result = '';
  113. if (!this.showCounts || item.count === undefined)
  114. return result;
  115. if (item.booksLoaded) {
  116. result = `${item.booksLoaded.length}/${item.count}`;
  117. } else
  118. result = `#/${item.count}`;
  119. return `(${result})`;
  120. }
  121. async getSeriesBooks(seriesItem) {
  122. if (seriesItem.count > this.maxItemCount) {
  123. seriesItem.bookLoading = true;
  124. await this.$nextTick();
  125. }
  126. try {
  127. await super.getSeriesBooks(seriesItem);
  128. if (seriesItem.allBooksLoaded) {
  129. const prepareBook = (book) => {
  130. return Object.assign(
  131. {
  132. key: book.id,
  133. type: 'book',
  134. },
  135. book
  136. );
  137. };
  138. const filtered = this.filterBooks(seriesItem.allBooksLoaded);
  139. const books = [];
  140. for (const book of filtered) {
  141. books.push(prepareBook(book));
  142. }
  143. seriesItem.booksLoaded = books;
  144. this.showMore(seriesItem);
  145. }
  146. } finally {
  147. seriesItem.bookLoading = false;
  148. }
  149. }
  150. async updateTableData() {
  151. let result = [];
  152. const expandedSet = new Set(this.expandedSeries);
  153. const series = this.searchResult.found;
  154. if (!series)
  155. return;
  156. let num = 0;
  157. for (const rec of series) {
  158. const count = (this.showDeleted ? rec.bookCount + rec.bookDelCount : rec.bookCount);
  159. const item = reactive({
  160. key: rec.series,
  161. series: rec.series,
  162. num,
  163. count,
  164. bookLoading: false,
  165. allBooksLoaded: false,
  166. allBooks: false,
  167. showAllBooks: false,
  168. showMoreAll: false,
  169. booksLoaded: false,
  170. books: false,
  171. showMore: false,
  172. });
  173. num++;
  174. if (expandedSet.has(item.series)) {
  175. if (series.length > 1 || item.count > this.maxItemCount)
  176. this.getSeriesBooks(item);//no await
  177. else
  178. await this.getSeriesBooks(item);
  179. }
  180. result.push(item);
  181. }
  182. if (result.length == 1 && !this.isExpandedSeries(result[0])) {
  183. this.expandSeries(result[0]);
  184. }
  185. this.tableData = result;
  186. }
  187. async refresh() {
  188. //параметры запроса
  189. const newQuery = this.getQuery();
  190. if (_.isEqual(newQuery, this.prevQuery))
  191. return;
  192. this.prevQuery = newQuery;
  193. this.queryExecute = newQuery;
  194. if (this.refreshing)
  195. return;
  196. this.error = '';
  197. this.refreshing = true;
  198. (async() => {
  199. await utils.sleep(500);
  200. if (this.refreshing)
  201. this.loadingMessage = 'Поиск серий...';
  202. })();
  203. try {
  204. while (this.queryExecute) {
  205. const query = this.queryExecute;
  206. this.queryExecute = null;
  207. try {
  208. const response = await this.api.search('series', query);
  209. this.list.queryFound = response.found.length;
  210. this.list.totalFound = response.totalFound;
  211. this.list.inpxHash = response.inpxHash;
  212. this.searchResult = response;
  213. await utils.sleep(1);
  214. if (!this.queryExecute) {
  215. await this.updateTableData();
  216. this.scrollToTop();
  217. this.highlightPageScroller(query);
  218. }
  219. } catch (e) {
  220. this.list.queryFound = 0;
  221. this.list.totalFound = 0;
  222. this.searchResult = {found: []};
  223. await this.updateTableData();
  224. //this.$root.stdDialog.alert(e.message, 'Ошибка');
  225. this.error = `Ошибка: ${e.message}`;
  226. }
  227. }
  228. } finally {
  229. this.refreshing = false;
  230. this.loadingMessage = '';
  231. }
  232. }
  233. }
  234. export default vueComponent(SeriesList);
  235. //-----------------------------------------------------------------------------
  236. </script>
  237. <style scoped>
  238. .clickable2 {
  239. cursor: pointer;
  240. }
  241. .odd-item {
  242. background-color: #e8e8e8;
  243. }
  244. .book-row {
  245. margin-left: 50px;
  246. }
  247. </style>