Search.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. <div v-show="queryFound > 0">
  49. Показаны {{ queryFound }} из {{ totalFound }} найденных авторов
  50. </div>
  51. <div v-show="queryFound == 0">
  52. Ничего не найдено
  53. </div>
  54. </div>
  55. <div class="q-mx-xs" />
  56. <div class="col row justify-end q-mt-xs">
  57. <q-select
  58. v-model="limit" :options="limitOptions" class="bg-white"
  59. dropdown-icon="la la-angle-down la-sm"
  60. outlined dense emit-value map-options
  61. />
  62. </div>
  63. </div>
  64. </div>
  65. <div class="col fit" style="position: relative">
  66. <div v-show="loadingVisible" class="fit row justify-center items-center" style="position: absolute; background-color: rgba(0, 0, 0, 0.2)">
  67. <div class="bg-white row justify-center items-center" style="width: 180px; height: 50px; border-radius: 10px; box-shadow: 2px 2px 10px #333333">
  68. <q-spinner color="primary" size="2em" />
  69. <div class="q-ml-sm">
  70. Поиск авторов...
  71. </div>
  72. </div>
  73. </div>
  74. <div class="col fit column no-wrap" style="overflow: auto">
  75. <div v-for="item in tableData" :key="item.key" style="border-bottom: 1px solid #aaaaaa">
  76. <div class="q-my-sm q-ml-md" style="font-size: 120%">
  77. {{ item.value }}
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. //-----------------------------------------------------------------------------
  86. import vueComponent from '../vueComponent.js';
  87. import * as utils from '../../share/utils';
  88. //import _ from 'lodash';
  89. const componentOptions = {
  90. components: {
  91. },
  92. watch: {
  93. config() {
  94. this.makeTitle();
  95. },
  96. author() {
  97. this.refresh();
  98. },
  99. series() {
  100. this.refresh();
  101. },
  102. title() {
  103. this.refresh();
  104. },
  105. genre() {
  106. this.refresh();
  107. },
  108. lang() {
  109. this.refresh();
  110. },
  111. limit() {
  112. this.refresh();
  113. },
  114. },
  115. };
  116. class Search {
  117. _options = componentOptions;
  118. collection = '';
  119. projectName = '';
  120. loadingVisible = false;
  121. //input field consts
  122. inputMaxLength = 1000;
  123. inputDebounce = 200;
  124. //search fields
  125. author = '';
  126. series = '';
  127. title = '';
  128. genre = '';
  129. lang = '';
  130. limit = 100;
  131. //stuff
  132. queryFound = -1;
  133. totalFound = 0;
  134. limitOptions = [
  135. {label: '10', value: 10},
  136. {label: '20', value: 20},
  137. {label: '50', value: 50},
  138. {label: '100', value: 100},
  139. {label: '1000', value: 1000},
  140. ];
  141. searchResult = {};
  142. tableData = [];
  143. created() {
  144. this.commit = this.$store.commit;
  145. }
  146. mounted() {
  147. this.api = this.$root.api;
  148. this.$refs.authorInput.focus();
  149. this.refresh();//no await
  150. }
  151. get config() {
  152. return this.$store.state.config;
  153. }
  154. makeTitle() {
  155. const collection = this.config.dbConfig.inpxInfo.collection.split('\n');
  156. this.collection = collection[0].trim();
  157. this.projectName = `${this.config.name} v${this.config.version}`;
  158. }
  159. showSearchHelp() {
  160. this.$root.stdDialog.alert(`
  161. <p>
  162. Здесь должна быть подсказка<br>
  163. </p>
  164. `, 'Подсказка', {iconName: 'la la-info-circle'});
  165. }
  166. showCollectionInfo() {
  167. this.$root.stdDialog.alert(`
  168. <p>
  169. Здесь должна быть информация о коллекции<br>
  170. </p>
  171. `, 'Статистика по коллекции', {iconName: 'la la-info-circle'});
  172. }
  173. selectGenre() {
  174. this.$root.stdDialog.alert('Выбор жанра');
  175. }
  176. selectLang() {
  177. this.$root.stdDialog.alert('Выбор языка');
  178. }
  179. async updateTableData() {
  180. let result = [];
  181. for (const rec of this.searchResult.author) {
  182. result.push({key: rec.id, value: `${rec.id} ${rec.author.replace(/,/g, ', ')}`});
  183. }
  184. this.tableData = result;
  185. }
  186. async refresh() {
  187. const newQuery = {
  188. author: this.author,
  189. series: this.series,
  190. title: this.title,
  191. genre: this.genre,
  192. lang: this.lang,
  193. limit: this.limit,
  194. };
  195. this.queryExecute = newQuery;
  196. if (this.refreshing)
  197. return;
  198. this.refreshing = true;
  199. try {
  200. while (this.queryExecute) {
  201. const query = this.queryExecute;
  202. this.queryExecute = null;
  203. let inSearch = true;
  204. (async() => {
  205. await utils.sleep(500);
  206. if (inSearch)
  207. this.loadingVisible = true;
  208. })();
  209. try {
  210. const result = await this.api.search(query);
  211. this.queryFound = result.author.length;
  212. this.totalFound = result.totalFound;
  213. this.searchResult = result;
  214. await this.updateTableData();
  215. } catch (e) {
  216. this.$root.stdDialog.alert(e.message, 'Ошибка');
  217. return;
  218. } finally {
  219. inSearch = false;
  220. this.loadingVisible = false;
  221. }
  222. }
  223. } finally {
  224. this.refreshing = false;
  225. }
  226. }
  227. }
  228. export default vueComponent(Search);
  229. //-----------------------------------------------------------------------------
  230. </script>
  231. <style scoped>
  232. .root {
  233. }
  234. .tool-panel {
  235. border-bottom: 1px solid black;
  236. }
  237. .header {
  238. font-size: 150%;
  239. min-height: 30px;
  240. }
  241. .clickable {
  242. color: blue;
  243. cursor: pointer;
  244. }
  245. </style>