Search.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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" style="font-size: 120%">
  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%">{{ item.value }}</div>
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. //-----------------------------------------------------------------------------
  69. import vueComponent from '../vueComponent.js';
  70. //import _ from 'lodash';
  71. const componentOptions = {
  72. components: {
  73. },
  74. watch: {
  75. config() {
  76. this.makeTitle();
  77. },
  78. },
  79. };
  80. class Search {
  81. _options = componentOptions;
  82. collection = '';
  83. projectName = '';
  84. //input field consts
  85. inputMaxLength = 1000;
  86. inputDebounce = 400;
  87. //search fields
  88. author = '';
  89. series = '';
  90. title = '';
  91. genre = '';
  92. lang = '';
  93. limit = 100;
  94. //stuff
  95. queryFound = 0;
  96. totalFound = 0;
  97. limitOptions = [
  98. {label: '10', value: 10},
  99. {label: '20', value: 20},
  100. {label: '50', value: 50},
  101. {label: '100', value: 100},
  102. {label: '1000', value: 1000},
  103. ];
  104. searchResult = {};
  105. tableData = [];
  106. created() {
  107. this.commit = this.$store.commit;
  108. }
  109. mounted() {
  110. this.api = this.$root.api;
  111. this.$refs.authorInput.focus();
  112. this.refresh();//no await
  113. }
  114. get config() {
  115. return this.$store.state.config;
  116. }
  117. makeTitle() {
  118. const collection = this.config.dbConfig.inpxInfo.collection.split('\n');
  119. this.collection = collection[0].trim();
  120. this.projectName = `${this.config.name} v${this.config.version}`;
  121. }
  122. showSearchHelp() {
  123. this.$root.stdDialog.alert(`
  124. <p>
  125. Здесь должна быть подсказка<br>
  126. </p>
  127. `, 'Подсказка', {iconName: 'la la-info-circle'});
  128. }
  129. showCollectionInfo() {
  130. this.$root.stdDialog.alert(`
  131. <p>
  132. Здесь должна быть информация о коллекции<br>
  133. </p>
  134. `, 'Статистика по коллекции', {iconName: 'la la-info-circle'});
  135. }
  136. selectGenre() {
  137. this.$root.stdDialog.alert('Выбор жанра');
  138. }
  139. selectLang() {
  140. this.$root.stdDialog.alert('Выбор языка');
  141. }
  142. async updateTableData() {
  143. let result = [];
  144. let id = 0;
  145. for (const rec of this.searchResult.author) {
  146. result.push({key: id++, value: rec.author});
  147. }
  148. this.tableData = result;
  149. }
  150. async refresh() {
  151. const newQuery = {
  152. author: this.author,
  153. series: this.series,
  154. title: this.title,
  155. genre: this.genre,
  156. lang: this.lang,
  157. limit: this.limit,
  158. };
  159. this.queryExecute = newQuery;
  160. if (this.refreshing)
  161. return;
  162. this.refreshing = true;
  163. try {
  164. while (this.queryExecute) {
  165. const query = this.queryExecute;
  166. this.queryExecute = null;
  167. try {
  168. const result = await this.api.search(query);
  169. this.queryFound = result.author.length;
  170. this.totalFound = result.totalFound;
  171. this.searchResult = result;
  172. this.updateTableData();//no await
  173. } catch (e) {
  174. this.$root.stdDialog.alert(e.message, 'Ошибка');
  175. return;
  176. }
  177. }
  178. } finally {
  179. this.refreshing = false;
  180. }
  181. }
  182. }
  183. export default vueComponent(Search);
  184. //-----------------------------------------------------------------------------
  185. </script>
  186. <style scoped>
  187. .root {
  188. }
  189. .tool-panel {
  190. border-bottom: 1px solid black;
  191. }
  192. .header {
  193. font-size: 150%;
  194. min-height: 30px;
  195. }
  196. .clickable {
  197. color: blue;
  198. cursor: pointer;
  199. }
  200. </style>