Search.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="root column fit">
  3. <div class="tool-panel column bg-green-11">
  4. <div class="header q-mx-md q-mt-sm row justify-between items-center">
  5. <div class="row items-center">
  6. <div class="q-mr-xs">
  7. Коллекция
  8. </div>
  9. <div class="clickable" @click="showCollectionInfo">
  10. {{ collection }}
  11. </div>
  12. </div>
  13. <div class="q-ml-md">
  14. {{ projectName }}
  15. </div>
  16. </div>
  17. <div class="row q-mx-md q-my-sm items-center">
  18. <q-input
  19. ref="authorInput" v-model="author" :maxlength="inputMaxLength" :debounce="inputDebounce"
  20. class="bg-white q-mt-xs" style="width: 300px;" label="Автор" stack-label outlined dense clearable
  21. />
  22. <div class="q-mx-xs" />
  23. <q-input
  24. v-model="series" :maxlength="inputMaxLength" :debounce="inputDebounce"
  25. class="bg-white q-mt-xs" style="width: 200px;" label="Серия" stack-label outlined dense clearable
  26. />
  27. <div class="q-mx-xs" />
  28. <q-input
  29. v-model="title" :maxlength="inputMaxLength" :debounce="inputDebounce"
  30. class="bg-white q-mt-xs" style="width: 200px;" label="Название" stack-label outlined dense clearable
  31. />
  32. <div class="q-mx-xs" />
  33. <q-input
  34. v-model="genre" :maxlength="inputMaxLength" :debounce="inputDebounce"
  35. class="bg-white q-mt-xs" style="width: 200px;" label="Жанр" stack-label outlined dense clearable readonly
  36. @click="selectGenre"
  37. />
  38. <div class="q-mx-xs" />
  39. <q-input
  40. v-model="lang" :maxlength="inputMaxLength" :debounce="inputDebounce"
  41. class="bg-white q-mt-xs" style="width: 80px;" label="Язык" stack-label outlined dense clearable readonly
  42. @click="selectLang"
  43. />
  44. <div class="q-mx-xs" />
  45. <q-btn round dense style="height: 20px" color="info" icon="la la-question" @click="showSearchHelp" />
  46. <div class="q-mx-xs" />
  47. <div class="row items-center q-mt-xs">
  48. Показаны {{ queryFound }} из {{ totalFound }} найденных авторов
  49. </div>
  50. <div class="q-mx-xs" />
  51. <div class="col row justify-end q-mt-xs">
  52. <q-select
  53. v-model="limit" :options="limitOptions" class="bg-white"
  54. dropdown-icon="la la-angle-down la-sm"
  55. outlined dense emit-value map-options
  56. />
  57. </div>
  58. </div>
  59. </div>
  60. <div class="col fit column no-wrap" style="overflow: auto">
  61. <div v-for="item in tableData" :key="item.key" style="border-bottom: 1px solid #aaaaaa">
  62. <div class="q-my-sm q-ml-md" style="font-size: 120%">
  63. {{ item.value }}
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. <script>
  70. //-----------------------------------------------------------------------------
  71. import vueComponent from '../vueComponent.js';
  72. //import _ from 'lodash';
  73. const componentOptions = {
  74. components: {
  75. },
  76. watch: {
  77. config() {
  78. this.makeTitle();
  79. },
  80. },
  81. };
  82. class Search {
  83. _options = componentOptions;
  84. collection = '';
  85. projectName = '';
  86. //input field consts
  87. inputMaxLength = 1000;
  88. inputDebounce = 400;
  89. //search fields
  90. author = '';
  91. series = '';
  92. title = '';
  93. genre = '';
  94. lang = '';
  95. limit = 100;
  96. //stuff
  97. queryFound = 0;
  98. totalFound = 0;
  99. limitOptions = [
  100. {label: '10', value: 10},
  101. {label: '20', value: 20},
  102. {label: '50', value: 50},
  103. {label: '100', value: 100},
  104. {label: '1000', value: 1000},
  105. ];
  106. searchResult = {};
  107. tableData = [];
  108. created() {
  109. this.commit = this.$store.commit;
  110. }
  111. mounted() {
  112. this.api = this.$root.api;
  113. this.$refs.authorInput.focus();
  114. this.refresh();//no await
  115. }
  116. get config() {
  117. return this.$store.state.config;
  118. }
  119. makeTitle() {
  120. const collection = this.config.dbConfig.inpxInfo.collection.split('\n');
  121. this.collection = collection[0].trim();
  122. this.projectName = `${this.config.name} v${this.config.version}`;
  123. }
  124. showSearchHelp() {
  125. this.$root.stdDialog.alert(`
  126. <p>
  127. Здесь должна быть подсказка<br>
  128. </p>
  129. `, 'Подсказка', {iconName: 'la la-info-circle'});
  130. }
  131. showCollectionInfo() {
  132. this.$root.stdDialog.alert(`
  133. <p>
  134. Здесь должна быть информация о коллекции<br>
  135. </p>
  136. `, 'Статистика по коллекции', {iconName: 'la la-info-circle'});
  137. }
  138. selectGenre() {
  139. this.$root.stdDialog.alert('Выбор жанра');
  140. }
  141. selectLang() {
  142. this.$root.stdDialog.alert('Выбор языка');
  143. }
  144. async updateTableData() {
  145. let result = [];
  146. for (const rec of this.searchResult.author) {
  147. result.push({key: rec.id, value: `${rec.id} ${rec.author.replace(/,/g, ', ')}`});
  148. }
  149. this.tableData = result;
  150. }
  151. async refresh() {
  152. const newQuery = {
  153. author: this.author,
  154. series: this.series,
  155. title: this.title,
  156. genre: this.genre,
  157. lang: this.lang,
  158. limit: this.limit,
  159. };
  160. this.queryExecute = newQuery;
  161. if (this.refreshing)
  162. return;
  163. this.refreshing = true;
  164. try {
  165. while (this.queryExecute) {
  166. const query = this.queryExecute;
  167. this.queryExecute = null;
  168. try {
  169. const result = await this.api.search(query);
  170. this.queryFound = result.author.length;
  171. this.totalFound = result.totalFound;
  172. this.searchResult = result;
  173. this.updateTableData();//no await
  174. } catch (e) {
  175. this.$root.stdDialog.alert(e.message, 'Ошибка');
  176. return;
  177. }
  178. }
  179. } finally {
  180. this.refreshing = false;
  181. }
  182. }
  183. }
  184. export default vueComponent(Search);
  185. //-----------------------------------------------------------------------------
  186. </script>
  187. <style scoped>
  188. .root {
  189. }
  190. .tool-panel {
  191. border-bottom: 1px solid black;
  192. }
  193. .header {
  194. font-size: 150%;
  195. min-height: 30px;
  196. }
  197. .clickable {
  198. color: blue;
  199. cursor: pointer;
  200. }
  201. </style>