TitleList.vue 4.8 KB

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