SeriesList.vue 11 KB

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