Search.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="root column fit">
  3. <div class="col fit" style="position: relative">
  4. <div v-show="loadingVisible" class="fit row justify-center items-center" style="position: absolute; background-color: rgba(0, 0, 0, 0.2); z-index: 1">
  5. <div class="bg-white row justify-center items-center" style="width: 180px; height: 50px; border-radius: 10px; box-shadow: 2px 2px 10px #333333">
  6. <q-spinner color="primary" size="2em" />
  7. <div class="q-ml-sm">
  8. Поиск авторов...
  9. </div>
  10. </div>
  11. </div>
  12. <div ref="scroller" class="col fit column no-wrap" style="overflow: auto; position: relative" @scroll="onScroll">
  13. <div ref="toolPanel" class="tool-panel column bg-green-11" style="position: sticky; top: 0;">
  14. <div class="header q-mx-md q-mt-sm row justify-between items-center">
  15. <div class="row items-center">
  16. <div class="q-mr-xs">
  17. Коллекция
  18. </div>
  19. <div class="clickable" @click="showCollectionInfo">
  20. {{ collection }}
  21. </div>
  22. </div>
  23. <div class="q-ml-md">
  24. {{ projectName }}
  25. </div>
  26. </div>
  27. <div class="row q-mx-md q-my-sm items-center">
  28. <q-input
  29. ref="authorInput" v-model="author" :maxlength="5000" :debounce="inputDebounce"
  30. class="bg-white q-mt-xs" style="width: 300px;" label="Автор" stack-label outlined dense clearable
  31. />
  32. <div class="q-mx-xs" />
  33. <q-input
  34. v-model="series" :maxlength="inputMaxLength" :debounce="inputDebounce"
  35. class="bg-white q-mt-xs" style="width: 200px;" label="Серия" stack-label outlined dense clearable
  36. />
  37. <div class="q-mx-xs" />
  38. <q-input
  39. v-model="title" :maxlength="inputMaxLength" :debounce="inputDebounce"
  40. class="bg-white q-mt-xs" style="width: 200px;" label="Название" stack-label outlined dense clearable
  41. />
  42. <div class="q-mx-xs" />
  43. <q-input
  44. v-model="genre" :maxlength="inputMaxLength" :debounce="inputDebounce"
  45. class="bg-white q-mt-xs" style="width: 200px;" label="Жанр" stack-label outlined dense clearable readonly
  46. @click="selectGenre"
  47. />
  48. <div class="q-mx-xs" />
  49. <q-input
  50. v-model="lang" :maxlength="inputMaxLength" :debounce="inputDebounce"
  51. class="bg-white q-mt-xs" style="width: 80px;" label="Язык" stack-label outlined dense clearable readonly
  52. @click="selectLang"
  53. />
  54. <div class="q-mx-xs" />
  55. <q-btn round dense style="height: 20px" color="info" icon="la la-question" @click="showSearchHelp" />
  56. <div class="q-mx-xs" />
  57. <div class="row items-center q-mt-xs">
  58. <div v-show="queryFound > 0">
  59. Найдено {{ totalFound }} авторов
  60. </div>
  61. <div v-show="queryFound == 0">
  62. Ничего не найдено
  63. </div>
  64. </div>
  65. <div class="q-mx-xs" />
  66. <div class="col row justify-end q-mt-xs">
  67. <q-select
  68. v-model="limit" :options="limitOptions" class="bg-white"
  69. dropdown-icon="la la-angle-down la-sm"
  70. outlined dense emit-value map-options
  71. />
  72. </div>
  73. </div>
  74. </div>
  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. onScroll() {
  180. const curScrollTop = this.$refs.scroller.scrollTop;
  181. if (!this.lastScrollTop)
  182. this.lastScrollTop = 0;
  183. if (!this.lastScrollTop2)
  184. this.lastScrollTop2 = 0;
  185. if (curScrollTop - this.lastScrollTop > 0) {
  186. this.$refs.toolPanel.style.position = 'relative';
  187. this.$refs.toolPanel.style.top = `${this.lastScrollTop2}px`;
  188. } else if (curScrollTop - this.lastScrollTop < 0) {
  189. this.$refs.toolPanel.style.position = 'sticky';
  190. this.$refs.toolPanel.style.top = 0;
  191. this.lastScrollTop2 = curScrollTop;
  192. }
  193. this.lastScrollTop = curScrollTop;
  194. }
  195. async updateTableData() {
  196. let result = [];
  197. for (const rec of this.searchResult.author) {
  198. result.push({key: rec.id, value: `${rec.id} ${rec.author.replace(/,/g, ', ')}`});
  199. }
  200. this.tableData = result;
  201. }
  202. async refresh() {
  203. const newQuery = {
  204. author: this.author,
  205. series: this.series,
  206. title: this.title,
  207. genre: this.genre,
  208. lang: this.lang,
  209. limit: this.limit,
  210. };
  211. this.queryExecute = newQuery;
  212. if (this.refreshing)
  213. return;
  214. this.refreshing = true;
  215. try {
  216. while (this.queryExecute) {
  217. const query = this.queryExecute;
  218. this.queryExecute = null;
  219. let inSearch = true;
  220. (async() => {
  221. await utils.sleep(500);
  222. if (inSearch)
  223. this.loadingVisible = true;
  224. })();
  225. try {
  226. const result = await this.api.search(query);
  227. this.queryFound = result.author.length;
  228. this.totalFound = result.totalFound;
  229. this.searchResult = result;
  230. await this.updateTableData();
  231. } catch (e) {
  232. this.$root.stdDialog.alert(e.message, 'Ошибка');
  233. return;
  234. } finally {
  235. inSearch = false;
  236. this.loadingVisible = false;
  237. }
  238. }
  239. } finally {
  240. this.refreshing = false;
  241. }
  242. }
  243. }
  244. export default vueComponent(Search);
  245. //-----------------------------------------------------------------------------
  246. </script>
  247. <style scoped>
  248. .root {
  249. }
  250. .tool-panel {
  251. border-bottom: 1px solid black;
  252. }
  253. .header {
  254. font-size: 150%;
  255. min-height: 30px;
  256. }
  257. .clickable {
  258. color: blue;
  259. cursor: pointer;
  260. }
  261. </style>