Search.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. <template>
  2. <div class="root column fit" style="position: relative">
  3. <div v-show="loadingMessage" class="fit row justify-center items-center" style="position: absolute; background-color: rgba(0, 0, 0, 0.2); z-index: 2">
  4. <div class="bg-white row justify-center items-center q-px-lg" style="min-width: 180px; height: 50px; border-radius: 10px; box-shadow: 2px 2px 10px #333333">
  5. <q-spinner color="primary" size="2em" />
  6. <div class="q-ml-sm">
  7. {{ loadingMessage }}
  8. </div>
  9. </div>
  10. </div>
  11. <div v-show="loadingMessage2" class="fit row justify-center items-center" style="position: absolute; background-color: rgba(0, 0, 0, 0.2); z-index: 1">
  12. <div class="bg-white row justify-center items-center q-px-lg" style="min-width: 180px; height: 50px; border-radius: 10px; box-shadow: 2px 2px 10px #333333">
  13. <q-spinner color="primary" size="2em" />
  14. <div class="q-ml-sm">
  15. {{ loadingMessage2 }}
  16. </div>
  17. </div>
  18. </div>
  19. <div ref="scroller" class="col fit column no-wrap" style="overflow: auto; position: relative" @scroll="onScroll">
  20. <div ref="toolPanel" class="tool-panel column bg-green-11" style="position: sticky; top: 0; z-index: 10;">
  21. <div class="header q-mx-md q-mb-xs q-mt-sm row items-center">
  22. <div class="row items-center" style="font-size: 150%;">
  23. <div class="q-mr-xs">
  24. Коллекция
  25. </div>
  26. <div class="clickable" @click="showCollectionInfo">
  27. {{ collection }}
  28. </div>
  29. </div>
  30. <DivBtn class="q-mx-md text-white bg-secondary" :size="30" :icon-size="24" :imt="1" icon="la la-cog" round @click="settingsDialogVisible = true">
  31. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  32. Настройки
  33. </q-tooltip>
  34. </DivBtn>
  35. <div class="col"></div>
  36. <div class="q-px-sm q-py-xs bg-green-12" style="border: 1px solid #aaaaaa; border-radius: 6px">
  37. {{ projectName }}
  38. </div>
  39. </div>
  40. <div class="row q-mx-md q-mb-sm items-center">
  41. <q-input
  42. ref="authorInput" v-model="search.author" :maxlength="5000" :debounce="inputDebounce"
  43. class="bg-white q-mt-xs" style="width: 300px;" label="Автор" stack-label outlined dense clearable
  44. />
  45. <div class="q-mx-xs" />
  46. <q-input
  47. v-model="search.series" :maxlength="inputMaxLength" :debounce="inputDebounce"
  48. class="bg-white q-mt-xs" style="width: 200px;" label="Серия" stack-label outlined dense clearable
  49. />
  50. <div class="q-mx-xs" />
  51. <q-input
  52. v-model="search.title" :maxlength="inputMaxLength" :debounce="inputDebounce"
  53. class="bg-white q-mt-xs" style="width: 200px;" label="Название" stack-label outlined dense clearable
  54. />
  55. <div class="q-mx-xs" />
  56. <q-input
  57. v-model="genreNames" :maxlength="inputMaxLength" :debounce="inputDebounce"
  58. class="bg-white q-mt-xs" input-style="cursor: pointer" style="width: 200px;" label="Жанр" stack-label outlined dense clearable readonly
  59. @click="selectGenre"
  60. >
  61. <q-tooltip v-if="genreNames" :delay="500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  62. {{ genreNames }}
  63. </q-tooltip>
  64. </q-input>
  65. <div class="q-mx-xs" />
  66. <q-input
  67. v-model="search.lang" :maxlength="inputMaxLength" :debounce="inputDebounce"
  68. class="bg-white q-mt-xs" input-style="cursor: pointer" style="width: 80px;" label="Язык" stack-label outlined dense clearable readonly
  69. @click="selectLang"
  70. >
  71. <q-tooltip v-if="search.lang" :delay="500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  72. {{ search.lang }}
  73. </q-tooltip>
  74. </q-input>
  75. <div class="q-mx-xs" />
  76. <DivBtn class="text-white q-mt-xs bg-grey-13" :size="30" :icon-size="24" icon="la la-broom" round @click="setDefaults">
  77. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  78. Сбросить поиск
  79. </q-tooltip>
  80. </DivBtn>
  81. <div class="q-mx-xs" />
  82. <DivBtn class="text-white q-mt-xs bg-grey-13" :size="30" :icon-size="24" icon="la la-question" round @click="showSearchHelp">
  83. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%" max-width="400px">
  84. Подсказка
  85. </q-tooltip>
  86. </DivBtn>
  87. <div class="q-mx-xs" />
  88. <div class="row items-center q-mt-xs">
  89. <div v-show="queryFound > 0">
  90. {{ foundAuthorsMessage }}
  91. </div>
  92. <div v-show="queryFound == 0">
  93. Ничего не найдено
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. <div v-show="pageCount > 1" class="row justify-center">
  99. <PageScroller v-model="search.page" :page-count="pageCount" />
  100. </div>
  101. <div v-show="pageCount <= 1" class="q-my-sm" />
  102. <!-- Формирование списка ------------------------------------------------------------------------>
  103. <div v-for="item in tableData" :key="item.key" class="column" :class="{'odd-author': item.num % 2}" style="font-size: 120%">
  104. <div class="row items-center q-ml-md q-mr-xs no-wrap">
  105. <!--div style="min-width: 35px">
  106. <DivBtn v-if="tableData.length > 1" :icon-size="24" icon="la la-check-circle" @click="selectAuthor(item.author)">
  107. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  108. Только этот автор
  109. </q-tooltip>
  110. </DivBtn>
  111. </div-->
  112. <div class="row items-center clickable2 q-py-xs no-wrap" @click="expandAuthor(item)">
  113. <div style="min-width: 30px">
  114. <div v-if="!isExpanded(item)">
  115. <q-icon name="la la-plus-square" size="28px" />
  116. </div>
  117. <div v-else>
  118. <q-icon name="la la-minus-square" size="28px" />
  119. </div>
  120. </div>
  121. </div>
  122. <div class="clickable q-ml-xs q-py-sm" style="font-weight: bold" @click="selectAuthor(item.author)">
  123. {{ item.name }}
  124. </div>
  125. <div class="q-ml-sm" style="font-weight: bold; color: #555">
  126. {{ getBookCount(item) }}
  127. </div>
  128. </div>
  129. <div v-if="isExpanded(item) && item.books">
  130. <div v-for="book in item.books" :key="book.key" class="book-row column">
  131. <div class="q-my-sm" @click="selectTitle(book.title)">
  132. {{ book.title }} {{ book.src.del }}
  133. </div>
  134. <!--div>
  135. {{ item.key }} {{ book.src }}
  136. </div-->
  137. </div>
  138. </div>
  139. </div>
  140. <!-- Формирование списка конец ------------------------------------------------------------------>
  141. <div v-show="pageCount > 1" class="row justify-center">
  142. <PageScroller v-model="search.page" :page-count="pageCount" />
  143. </div>
  144. <div v-show="pageCount <= 1" class="q-my-sm" />
  145. </div>
  146. <Dialog v-model="settingsDialogVisible">
  147. <template #header>
  148. <div class="row items-center" style="font-size: 130%">
  149. <q-icon class="q-mr-sm" name="la la-cog" size="28px"></q-icon>
  150. Настройки
  151. </div>
  152. </template>
  153. <div class="q-mx-md column" style="min-width: 300px; font-size: 120%;">
  154. <div class="row items-center q-ml-sm">
  155. <div class="q-mr-sm">
  156. Результатов на странице
  157. </div>
  158. <q-select
  159. v-model="limit" :options="limitOptions" class="bg-white"
  160. dropdown-icon="la la-angle-down la-sm"
  161. outlined dense emit-value map-options
  162. />
  163. </div>
  164. <q-checkbox v-model="showCounts" size="36px" label="Показывать количество" />
  165. <q-checkbox v-model="showDeleted" size="36px" label="Показывать удаленные" />
  166. <q-checkbox v-model="abCacheEnabled" size="36px" label="Кешировать запросы" />
  167. </div>
  168. <template #footer>
  169. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="settingsDialogVisible = false">
  170. OK
  171. </q-btn>
  172. </template>
  173. </Dialog>
  174. <SelectGenreDialog v-model="selectGenreDialogVisible" v-model:genre="search.genre" :genre-tree="genreTree" />
  175. <SelectLangDialog v-model="selectLangDialogVisible" v-model:lang="search.lang" :lang-list="langList" :lang-default="langDefault" />
  176. </div>
  177. </template>
  178. <script>
  179. //-----------------------------------------------------------------------------
  180. import vueComponent from '../vueComponent.js';
  181. import { reactive } from 'vue';
  182. import PageScroller from './PageScroller/PageScroller.vue';
  183. import SelectGenreDialog from './SelectGenreDialog/SelectGenreDialog.vue';
  184. import SelectLangDialog from './SelectLangDialog/SelectLangDialog.vue';
  185. import authorBooksStorage from './authorBooksStorage';
  186. import DivBtn from '../share/DivBtn.vue';
  187. import Dialog from '../share/Dialog.vue';
  188. import * as utils from '../../share/utils';
  189. import diffUtils from '../../share/diffUtils';
  190. import _ from 'lodash';
  191. const componentOptions = {
  192. components: {
  193. PageScroller,
  194. SelectGenreDialog,
  195. SelectLangDialog,
  196. Dialog,
  197. DivBtn
  198. },
  199. watch: {
  200. config() {
  201. this.makeTitle();
  202. },
  203. settings() {
  204. this.loadSettings();
  205. },
  206. search: {
  207. handler(newValue) {
  208. this.limit = newValue.limit;
  209. this.refresh();
  210. },
  211. deep: true,
  212. },
  213. limit(newValue) {
  214. this.setSetting('limit', newValue);
  215. this.updatePageCount();
  216. },
  217. showCounts(newValue) {
  218. this.setSetting('showCounts', newValue);
  219. },
  220. showDeleted(newValue) {
  221. this.setSetting('showDeleted', newValue);
  222. },
  223. abCacheEnabled(newValue) {
  224. this.setSetting('abCacheEnabled', newValue);
  225. },
  226. totalFound() {
  227. this.updatePageCount();
  228. },
  229. $route(to) {
  230. this.updateQueryFromRoute(to);
  231. },
  232. langDefault() {
  233. this.updateQueryFromRoute(this.$route);
  234. },
  235. },
  236. };
  237. class Search {
  238. _options = componentOptions;
  239. collection = '';
  240. projectName = '';
  241. loadingMessage = '';
  242. loadingMessage2 = '';
  243. settingsDialogVisible = false;
  244. selectGenreDialogVisible = false;
  245. selectLangDialogVisible = false;
  246. pageCount = 1;
  247. //input field consts
  248. inputMaxLength = 1000;
  249. inputDebounce = 200;
  250. //search fields
  251. search = {
  252. author: '',
  253. series: '',
  254. title: '',
  255. genre: '',
  256. lang: '',
  257. page: 1,
  258. limit: 50,
  259. };
  260. //settings
  261. expanded = [];
  262. showCounts = true;
  263. showDeleted = false;
  264. abCacheEnabled = true;
  265. langDefault = '';
  266. limit = 50;
  267. //stuff
  268. queryFound = -1;
  269. totalFound = 0;
  270. bookRowsOnPage = 100;
  271. inpxHash = '';
  272. genreTree = [];
  273. langList = [];
  274. genreTreeInpxHash = '';
  275. limitOptions = [
  276. {label: '10', value: 10},
  277. {label: '20', value: 20},
  278. {label: '50', value: 50},
  279. {label: '100', value: 100},
  280. {label: '200', value: 200},
  281. {label: '500', value: 500},
  282. {label: '1000', value: 1000},
  283. ];
  284. searchResult = {};
  285. tableData = [];
  286. created() {
  287. this.commit = this.$store.commit;
  288. this.loadSettings();
  289. }
  290. mounted() {
  291. (async() => {
  292. await authorBooksStorage.init();
  293. this.api = this.$root.api;
  294. if (!this.$root.isMobileDevice)
  295. this.$refs.authorInput.focus();
  296. this.setDefaults();
  297. this.updateQueryFromRoute(this.$route);
  298. //чтоб не вызывался лишний refresh
  299. await utils.sleep(100);
  300. this.ready = true;
  301. this.refresh();//no await
  302. })();
  303. }
  304. loadSettings() {
  305. const settings = this.settings;
  306. this.search.limit = settings.limit;
  307. this.expanded = _.cloneDeep(settings.expanded);
  308. this.showCounts = settings.showCounts;
  309. this.showDeleted = settings.showDeleted;
  310. this.abCacheEnabled = settings.abCacheEnabled;
  311. this.langDefault = settings.langDefault;
  312. }
  313. get config() {
  314. return this.$store.state.config;
  315. }
  316. get settings() {
  317. return this.$store.state.settings;
  318. }
  319. get genreNames() {
  320. let result = [];
  321. const genre = new Set(this.search.genre.split(','));
  322. for (const section of this.genreTree) {
  323. for (const g of section.value)
  324. if (genre.has(g.value))
  325. result.push(g.name);
  326. }
  327. return result.join(', ');
  328. }
  329. makeTitle() {
  330. const collection = this.config.dbConfig.inpxInfo.collection.split('\n');
  331. this.collection = collection[0].trim();
  332. this.projectName = `${this.config.name} v${this.config.version}`;
  333. }
  334. showSearchHelp() {
  335. this.$root.stdDialog.alert(`
  336. <p>
  337. Здесь должна быть подсказка<br>
  338. </p>
  339. `, 'Подсказка', {iconName: 'la la-info-circle'});
  340. }
  341. showCollectionInfo() {
  342. this.$root.stdDialog.alert(`
  343. <p>
  344. Здесь должна быть информация о коллекции<br>
  345. </p>
  346. `, 'Статистика по коллекции', {iconName: 'la la-info-circle'});
  347. }
  348. selectGenre() {
  349. this.selectGenreDialogVisible = true;
  350. }
  351. selectLang() {
  352. this.selectLangDialogVisible = true;
  353. }
  354. onScroll() {
  355. if (this.ignoreScrolling)
  356. return;
  357. const curScrollTop = this.$refs.scroller.scrollTop;
  358. if (!this.lastScrollTop)
  359. this.lastScrollTop = 0;
  360. if (!this.lastScrollTop2)
  361. this.lastScrollTop2 = 0;
  362. if (curScrollTop - this.lastScrollTop > 0) {
  363. this.$refs.toolPanel.style.position = 'relative';
  364. this.$refs.toolPanel.style.top = `${this.lastScrollTop2}px`;
  365. } else if (curScrollTop - this.lastScrollTop <= 0) {
  366. this.$refs.toolPanel.style.position = 'sticky';
  367. this.$refs.toolPanel.style.top = 0;
  368. this.lastScrollTop2 = curScrollTop;
  369. }
  370. this.lastScrollTop = curScrollTop;
  371. }
  372. async ignoreScroll(ms = 50) {
  373. this.ignoreScrolling = true;
  374. await utils.sleep(ms);
  375. this.ignoreScrolling = false;
  376. }
  377. scrollToTop() {
  378. this.$refs.scroller.scrollTop = 0;
  379. this.lastScrollTop = 0;
  380. }
  381. get foundAuthorsMessage() {
  382. return `Найден${utils.wordEnding(this.totalFound, 2)} ${this.totalFound} автор${utils.wordEnding(this.totalFound)}`;
  383. }
  384. updatePageCount() {
  385. const prevPageCount = this.pageCount;
  386. this.pageCount = Math.ceil(this.totalFound/this.limit);
  387. this.pageCount = (this.pageCount < 1 ? 1 : this.pageCount);
  388. if (this.prevPage && prevPageCount == 1 && this.pageCount > 1 && this.prevPage <= this.pageCount) {
  389. this.search.page = this.prevPage;
  390. }
  391. if (this.search.page > this.pageCount) {
  392. this.prevPage = this.search.page;
  393. this.search.page = 1;
  394. }
  395. }
  396. selectAuthor(author) {
  397. this.search.author = `=${author}`;
  398. this.scrollToTop();
  399. }
  400. selectTitle(title) {
  401. this.search.title = `=${title}`;
  402. }
  403. isExpanded(item) {
  404. return this.expanded.indexOf(item.author) >= 0;
  405. }
  406. setSetting(name, newValue) {
  407. this.commit('setSettings', {[name]: _.cloneDeep(newValue)});
  408. }
  409. expandAuthor(item) {
  410. const expanded = _.cloneDeep(this.expanded);
  411. const author = item.author;
  412. if (!this.isExpanded(item)) {
  413. expanded.push(author);
  414. this.getBooks(item);
  415. if (expanded.length > 10) {
  416. expanded.shift();
  417. }
  418. this.setSetting('expanded', expanded);
  419. this.ignoreScroll();
  420. } else {
  421. const i = expanded.indexOf(author);
  422. if (i >= 0) {
  423. expanded.splice(i, 1);
  424. this.setSetting('expanded', expanded);
  425. }
  426. }
  427. }
  428. getBookCount(item) {
  429. let result = '';
  430. if (!this.showCounts || item.bookCount === undefined)
  431. return result;
  432. if (this.showDeleted) {
  433. result = item.bookCount + item.bookDelCount;
  434. } else {
  435. result = item.bookCount;
  436. }
  437. if (item.books)
  438. result = `${item.books.length}/${result}`;
  439. else
  440. result = `#/${result}`;
  441. return `(${result})`;
  442. }
  443. async loadBooks(authorId) {
  444. try {
  445. let result;
  446. if (this.abCacheEnabled) {
  447. const key = `${authorId}-${this.inpxHash}`;
  448. const data = await authorBooksStorage.getData(key);
  449. if (data) {
  450. result = JSON.parse(data);
  451. } else {
  452. result = await this.api.getBookList(authorId);
  453. await authorBooksStorage.setData(key, JSON.stringify(result));
  454. }
  455. } else {
  456. result = await this.api.getBookList(authorId);
  457. }
  458. return JSON.parse(result.books);
  459. } catch (e) {
  460. this.$root.stdDialog.alert(e.message, 'Ошибка');
  461. }
  462. }
  463. filterBooks(loadedBooks) {
  464. return loadedBooks;
  465. }
  466. async getBooks(item) {
  467. if (item.books)
  468. return;
  469. if (!this.getBooksFlag)
  470. this.getBooksFlag = 0;
  471. this.getBooksFlag++;
  472. try {
  473. if (this.getBooksFlag == 1) {
  474. (async() => {
  475. await utils.sleep(500);
  476. if (this.getBooksFlag > 0)
  477. this.loadingMessage2 = 'Загрузка списка книг...';
  478. })();
  479. }
  480. const loadedBooks = await this.loadBooks(item.key);
  481. const filtered = this.filterBooks(loadedBooks);
  482. filtered.sort((a, b) => a.title.localeCompare(b.title));
  483. const books = [];
  484. for (const book of filtered) {
  485. books.push({key: book.id, title: book.title, src: book});
  486. }
  487. item.books = books;
  488. } finally {
  489. this.getBooksFlag--;
  490. if (this.getBooksFlag == 0)
  491. this.loadingMessage2 = '';
  492. }
  493. }
  494. async updateGenreTreeIfNeeded() {
  495. try {
  496. if (this.genreTreeInpxHash !== this.inpxHash) {
  497. let result;
  498. if (this.abCacheEnabled) {
  499. const key = `genre-tree-${this.inpxHash}`;
  500. const data = await authorBooksStorage.getData(key);
  501. if (data) {
  502. result = JSON.parse(data);
  503. } else {
  504. result = await this.api.getGenreTree();
  505. await authorBooksStorage.setData(key, JSON.stringify(result));
  506. }
  507. } else {
  508. result = await this.api.getGenreTree();
  509. }
  510. this.genreTree = result.genreTree;
  511. this.langList = result.langList;
  512. this.genreTreeInpxHash = result.inpxHash;
  513. }
  514. } catch (e) {
  515. this.$root.stdDialog.alert(e.message, 'Ошибка');
  516. }
  517. }
  518. async updateTableData() {
  519. let result = [];
  520. const expandedSet = new Set(this.expanded);
  521. const authors = this.searchResult.author;
  522. let num = 0;
  523. for (const rec of authors) {
  524. const item = reactive({
  525. key: rec.id,
  526. num,
  527. author: rec.author,
  528. name: rec.author.replace(/,/g, ', '),
  529. bookCount: rec.bookCount,
  530. bookDelCount: rec.bookDelCount,
  531. book: false,
  532. });
  533. num++;
  534. if (expandedSet.has(item.author)) {
  535. this.getBooks(item);//no await
  536. }
  537. result.push(item);
  538. }
  539. if (result.length == 1 && !this.isExpanded(result[0])) {
  540. this.expandAuthor(result[0]);
  541. }
  542. this.tableData = result;
  543. }
  544. setDefaults() {
  545. this.search = Object.assign({}, this.search, {
  546. author: '',
  547. series: '',
  548. title: '',
  549. genre: '',
  550. lang: this.langDefault,
  551. });
  552. }
  553. async updateQueryFromRoute(to) {
  554. if (this.routeUpdating)
  555. return;
  556. const query = to.query;
  557. this.search = Object.assign({}, this.search, {
  558. author: query.author || '',
  559. series: query.series || '',
  560. title: query.title || '',
  561. genre: query.genre || '',
  562. lang: (query.lang == 'default' ? this.langDefault : query.lang || ''),
  563. page: parseInt(query.page, 10) || 1,
  564. });
  565. }
  566. updateRouteQuery() {
  567. this.routeUpdating = true;
  568. try {
  569. const oldQuery = this.$route.query;
  570. const query = _.pickBy(this.search);
  571. delete query.limit;
  572. if (this.search.lang == this.langDefault)
  573. query.lang = 'default'
  574. const diff = diffUtils.getObjDiff(oldQuery, query);
  575. if (!diffUtils.isEmptyObjDiff(diff)) {
  576. this.$router.replace({query});
  577. }
  578. } finally {
  579. (async() => {
  580. await utils.sleep(100);
  581. this.routeUpdating = false;
  582. })();
  583. }
  584. }
  585. async refresh() {
  586. if (!this.ready)
  587. return;
  588. this.updateRouteQuery();
  589. const offset = (this.search.page - 1)*this.limit;
  590. const newQuery = _.cloneDeep(this.search);
  591. newQuery.limit = this.limit;
  592. newQuery.offset = offset;
  593. this.queryExecute = newQuery;
  594. if (this.refreshing)
  595. return;
  596. this.refreshing = true;
  597. try {
  598. while (this.queryExecute) {
  599. const query = this.queryExecute;
  600. this.queryExecute = null;
  601. let inSearch = true;
  602. (async() => {
  603. await utils.sleep(500);
  604. if (inSearch)
  605. this.loadingMessage = 'Поиск авторов...';
  606. })();
  607. try {
  608. const result = await this.api.search(query);
  609. this.queryFound = result.author.length;
  610. this.totalFound = result.totalFound;
  611. this.inpxHash = result.inpxHash;
  612. this.searchResult = result;
  613. await this.updateGenreTreeIfNeeded();
  614. await this.updateTableData();
  615. this.scrollToTop();
  616. } catch (e) {
  617. this.$root.stdDialog.alert(e.message, 'Ошибка');
  618. } finally {
  619. inSearch = false;
  620. this.loadingMessage = '';
  621. }
  622. }
  623. } finally {
  624. this.refreshing = false;
  625. }
  626. }
  627. }
  628. export default vueComponent(Search);
  629. //-----------------------------------------------------------------------------
  630. </script>
  631. <style scoped>
  632. .root {
  633. }
  634. .tool-panel {
  635. border-bottom: 1px solid black;
  636. }
  637. .header {
  638. min-height: 30px;
  639. }
  640. .clickable {
  641. color: blue;
  642. cursor: pointer;
  643. }
  644. .clickable2 {
  645. cursor: pointer;
  646. }
  647. .odd-author {
  648. background-color: #e8e8e8;
  649. }
  650. .book-row {
  651. margin-left: 100px;
  652. }
  653. </style>