TitleList.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. <BookView
  9. class="q-ml-md"
  10. title-list
  11. :book="item.book" :genre-map="genreMap" :show-read-link="showReadLink" @book-event="bookEvent"
  12. />
  13. <BookView
  14. v-for="book in item.books" :key="book.id"
  15. :book="book" :genre-map="genreMap"
  16. class="q-ml-md"
  17. title-list
  18. :show-read-link="showReadLink"
  19. @book-event="bookEvent"
  20. />
  21. </div>
  22. <!-- Формирование списка конец ------------------------------------------------------------------>
  23. <div v-if="!refreshing && !tableData.length" class="row items-center q-ml-md" style="font-size: 120%">
  24. <q-icon class="la la-meh q-mr-xs" size="28px" />
  25. Поиск не дал результатов
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. //-----------------------------------------------------------------------------
  31. import vueComponent from '../../vueComponent.js';
  32. import { reactive } from 'vue';
  33. import BaseList from '../BaseList';
  34. import * as utils from '../../../share/utils';
  35. import _ from 'lodash';
  36. class TitleList extends BaseList {
  37. get foundCountMessage() {
  38. return `${this.list.totalFound} уникальн${utils.wordEnding(this.list.totalFound, 6)} назван${utils.wordEnding(this.list.totalFound, 3)}`;
  39. }
  40. async updateTableData() {
  41. let result = [];
  42. const title = this.searchResult.title;
  43. if (!title)
  44. return;
  45. let num = 0;
  46. for (const rec of title) {
  47. const item = reactive({
  48. key: rec.id,
  49. title: rec.title,
  50. num,
  51. book: false,
  52. books: [],
  53. });
  54. if (rec.books) {
  55. const filtered = this.filterBooks(rec.books);
  56. for (let i = 0; i < filtered.length; i++) {
  57. if (i === 0)
  58. item.book = filtered[i];
  59. else
  60. item.books.push(filtered[i]);
  61. }
  62. if (filtered.length) {
  63. num++;
  64. result.push(item);
  65. }
  66. }
  67. }
  68. this.tableData = result;
  69. }
  70. async refresh() {
  71. //параметры запроса
  72. let newQuery = _.cloneDeep(this.search);
  73. newQuery = newQuery.setDefaults(newQuery);
  74. delete newQuery.setDefaults;
  75. newQuery.offset = (newQuery.page - 1)*newQuery.limit;
  76. if (!this.showDeleted)
  77. newQuery.del = 0;
  78. if (_.isEqual(newQuery, this.prevQuery))
  79. return;
  80. this.prevQuery = newQuery;
  81. this.queryExecute = newQuery;
  82. if (this.refreshing)
  83. return;
  84. this.refreshing = true;
  85. (async() => {
  86. await utils.sleep(500);
  87. if (this.refreshing)
  88. this.loadingMessage = 'Поиск книг...';
  89. })();
  90. try {
  91. while (this.queryExecute) {
  92. const query = this.queryExecute;
  93. this.queryExecute = null;
  94. try {
  95. const result = await this.api.titleSearch(query);
  96. this.list.queryFound = result.title.length;
  97. this.list.totalFound = result.totalFound;
  98. this.list.inpxHash = result.inpxHash;
  99. this.searchResult = result;
  100. await utils.sleep(1);
  101. if (!this.queryExecute) {
  102. await this.updateTableData();
  103. this.scrollToTop();
  104. this.highlightPageScroller(query);
  105. }
  106. } catch (e) {
  107. this.$root.stdDialog.alert(e.message, 'Ошибка');
  108. }
  109. }
  110. } finally {
  111. this.refreshing = false;
  112. this.loadingMessage = '';
  113. }
  114. }
  115. }
  116. export default vueComponent(TitleList);
  117. //-----------------------------------------------------------------------------
  118. </script>
  119. <style scoped>
  120. .clickable2 {
  121. cursor: pointer;
  122. }
  123. .odd-item {
  124. background-color: #e8e8e8;
  125. }
  126. </style>