Search.vue 26 KB

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