ExtendedList.vue 4.0 KB

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