RecentBooksPage.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. <template>
  2. <Window ref="window" width="600px" @close="close">
  3. <template #header>
  4. <span v-show="!loading">{{ header }}</span>
  5. <span v-if="loading"><q-spinner class="q-mr-sm" color="lime-12" size="20px" :thickness="7" />
  6. Список загружается
  7. </span>
  8. </template>
  9. <template #buttons>
  10. <div
  11. class="row justify-center items-center"
  12. :class="{'header-button': !archive, 'header-button-pressed': archive}"
  13. @mousedown.stop @click="archiveToggle"
  14. >
  15. <q-icon class="q-mr-xs" name="la la-archive" size="20px" />
  16. <span style="font-size: 90%">Архив</span>
  17. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  18. {{ (archive ? 'Скрыть архивные' : 'Показать архивные') }}
  19. </q-tooltip>
  20. </div>
  21. </template>
  22. <a ref="download" style="display: none;" target="_blank"></a>
  23. <div id="vs-container" ref="vsContainer" class="recent-books-scroll col">
  24. <div ref="header" class="scroll-header row bg-blue-2">
  25. <q-btn class="tool-button" round @click="showSameBookClick">
  26. <q-icon name="la la-caret-right" class="icon" :class="{'expanded-icon': showSameBook}" color="green-8" size="24px" />
  27. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  28. Показать/скрыть версии книг
  29. </q-tooltip>
  30. </q-btn>
  31. <q-btn class="tool-button" round @click="scrollToBegin">
  32. <q-icon name="la la-arrow-up" color="green-8" size="24px" />
  33. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  34. В начало списка
  35. </q-tooltip>
  36. </q-btn>
  37. <q-btn class="tool-button" round @click="scrollToEnd">
  38. <q-icon name="la la-arrow-down" color="green-8" size="24px" />
  39. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  40. В конец списка
  41. </q-tooltip>
  42. </q-btn>
  43. <q-btn class="tool-button" round @click="scrollToActiveBook">
  44. <q-icon name="la la-location-arrow" color="green-8" size="24px" />
  45. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  46. На текущую книгу
  47. </q-tooltip>
  48. </q-btn>
  49. <q-input
  50. ref="input"
  51. v-model="search"
  52. class="q-ml-sm q-mt-xs"
  53. outlined dense
  54. style="width: 185px"
  55. bg-color="white"
  56. placeholder="Найти"
  57. @click.stop
  58. >
  59. <template #append>
  60. <q-icon v-if="search !== ''" name="la la-times" class="cursor-pointer" @click.stop="resetSearch" />
  61. </template>
  62. </q-input>
  63. <q-select
  64. ref="sortMethod"
  65. v-model="sortMethod"
  66. class="q-ml-sm q-mt-xs"
  67. :options="sortMethodOptions"
  68. style="width: 180px"
  69. bg-color="white"
  70. dropdown-icon="la la-angle-down la-sm"
  71. outlined dense emit-value map-options display-value-sanitize options-sanitize
  72. options-html display-value-html
  73. @update:model-value="sortMethodSelected"
  74. >
  75. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  76. Метод сортировки
  77. </q-tooltip>
  78. <template #selected-item="scope">
  79. <div style="height: 28px; padding-top: 2px; overflow: hidden" v-html="scope.opt.label" />
  80. </template>
  81. </q-select>
  82. </div>
  83. <q-virtual-scroll
  84. ref="virtualScroll"
  85. v-slot="{ item, index }"
  86. :items="tableData"
  87. scroll-target="#vs-container"
  88. virtual-scroll-item-size="80"
  89. @virtual-scroll="onScroll"
  90. >
  91. <div class="table-row row" :class="{even: index % 2 > 0, 'active-book': item.active, 'active-parent-book': item.activeParent}">
  92. <div v-show="item.inGroup" class="row-part column justify-center items-center" style="width: 40px">
  93. <q-icon name="la la-code-branch" size="24px" style="color: green" />
  94. </div>
  95. <div class="row-part column justify-center items-stretch" style="width: 80px">
  96. <div class="col row justify-center items-center clickable" style="padding: 0 2px 0 2px" @click="loadBook(item, bothBucEnabled && item.needBookUpdate)">
  97. <div v-show="isLoadedCover(item.coverPageUrl)" style="height: 80px" v-html="getCoverHtml(item.coverPageUrl)" />
  98. <q-icon v-show="!isLoadedCover(item.coverPageUrl)" name="la la-book" size="40px" style="color: #dddddd" />
  99. <div v-show="bothBucEnabled && item.needBookUpdate" style="position: absolute; z-index: 10;">
  100. <q-icon name="la la-sync" size="60px" style="color: blue" />
  101. </div>
  102. </div>
  103. <div v-show="!showSameBook && item.group && item.group.length > 0" class="row justify-center" style="font-size: 70%">
  104. {{ (item.group ? item.group.length + 1 : 0) }} верси{{ wordEnding((item.group ? item.group.length + 1 : 0), 1) }}
  105. </div>
  106. </div>
  107. <div class="row-part column items-stretch clickable break-word" @click="loadBook(item)">
  108. <div
  109. class="col" style="border: 1px solid #cccccc; border-bottom: 0; padding: 4px; line-height: 140%;"
  110. :style="{ 'width': (380 - 40*(+item.inGroup)) + 'px' }"
  111. >
  112. <div class="text-green-10" style="font-size: 80%">
  113. {{ item.desc.author }}
  114. </div>
  115. <div style="font-size: 75%">
  116. {{ item.desc.title }}
  117. </div>
  118. <div v-show="bothBucEnabled && item.needBookUpdate" style="font-size: 75%; color: blue">
  119. Размер: {{ item.downloadSize }} &rarr; {{ item.bucSize }}, +{{ item.bucSize - item.downloadSize }}
  120. </div>
  121. </div>
  122. <div class="row" style="font-size: 10px">
  123. <div class="row justify-center items-center row-info-top" style="width: 60px">
  124. {{ item.desc.textLen }}
  125. </div>
  126. <div class="row items-center row-info-top" :style="`width: ${(260 - 40*(+item.inGroup))}px; padding: 1px`">
  127. <div class="read-bar" :style="`width: ${100*item.readPart}%`"></div>
  128. </div>
  129. <div class="row justify-center items-center row-info-top" style="width: 59px">
  130. {{ item.desc.perc }}
  131. </div>
  132. <div class="row-info-top" style="width: 1px">
  133. </div>
  134. </div>
  135. <div class="row" style="font-size: 10px" :style="{ 'width': (380 - 40*(+item.inGroup)) + 'px' }">
  136. <div class="row justify-center items-center row-info-bottom" style="width: 30px">
  137. {{ item.num }}
  138. </div>
  139. <div class="col row">
  140. <div class="row justify-center items-center row-info-bottom time-info" style="width: 50%">
  141. Загружен: {{ item.loadTime }}
  142. </div>
  143. <div class="row justify-center items-center row-info-bottom time-info" style="width: 50%">
  144. Читался: {{ item.touchTime }}
  145. </div>
  146. </div>
  147. <div class="row-info-bottom" style="width: 1px">
  148. </div>
  149. </div>
  150. </div>
  151. <div
  152. class="row-part column"
  153. style="width: 90px;"
  154. >
  155. <div
  156. class="col column justify-center"
  157. style="font-size: 75%; padding-left: 6px; border: 1px solid #cccccc; border-left: 0;"
  158. >
  159. <div style="margin: 25px 0 0 5px">
  160. <a v-show="isUrl(item.url)" :href="item.url" target="_blank">Оригинал</a><br><br>
  161. <a :href="item.path" @click.prevent="downloadBook(item.path, item.fullTitle)">Скачать FB2</a>
  162. </div>
  163. </div>
  164. <div
  165. class="del-button self-end row justify-center items-center clickable"
  166. @click="handleDel(item.key)"
  167. >
  168. <q-icon class="la la-times" size="12px" />
  169. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  170. {{ (archive ? 'Удалить окончательно' : 'Перенести в архив') }}
  171. </q-tooltip>
  172. </div>
  173. <div
  174. v-show="archive"
  175. class="restore-button self-start row justify-center items-center clickable"
  176. @click="handleRestore(item.key)"
  177. >
  178. <q-icon class="la la-arrow-left" size="14px" />
  179. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  180. Восстановить из архива
  181. </q-tooltip>
  182. </div>
  183. <div
  184. v-show="bothBucEnabled && item.showCheckBuc"
  185. class="buc-checkbox self-start"
  186. >
  187. <q-checkbox
  188. v-model="item.checkBuc"
  189. size="xs"
  190. style="position: relative; top: -3px; left: -3px;"
  191. @update:model-value="checkBucChange(item)"
  192. >
  193. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  194. Проверять обновления
  195. </q-tooltip>
  196. </q-checkbox>
  197. </div>
  198. </div>
  199. </div>
  200. </q-virtual-scroll>
  201. </div>
  202. </Window>
  203. </template>
  204. <script>
  205. //-----------------------------------------------------------------------------
  206. import vueComponent from '../../vueComponent.js';
  207. import path from 'path-browserify';
  208. import _ from 'lodash';
  209. import * as utils from '../../../share/utils';
  210. import LockQueue from '../../../share/LockQueue';
  211. import Window from '../../share/Window.vue';
  212. import bookManager from '../share/bookManager';
  213. import readerApi from '../../../api/reader';
  214. import coversStorage from '../share/coversStorage';
  215. const componentOptions = {
  216. components: {
  217. Window,
  218. },
  219. watch: {
  220. search() {
  221. this.updateTableData();
  222. },
  223. sortMethod() {
  224. this.updateTableData();
  225. },
  226. settings() {
  227. this.loadSettings();
  228. },
  229. },
  230. };
  231. class RecentBooksPage {
  232. _options = componentOptions;
  233. loading = false;
  234. search = '';
  235. tableData = [];
  236. sortMethod = '';
  237. showSameBook = false;
  238. bucEnabled = false;
  239. bucSizeDiff = 0;
  240. bucSetOnNew = false;
  241. archive = false;
  242. covers = {};
  243. coversLoadFunc = {};
  244. created() {
  245. this.commit = this.$store.commit;
  246. this.lastScrollTop1 = 0;
  247. this.lastScrollTop2 = 0;
  248. this.lock = new LockQueue(100);
  249. this.loadSettings();
  250. }
  251. init() {
  252. this.$refs.window.init();
  253. this.$nextTick(() => {
  254. //this.$refs.input.focus();//плохо на планшетах
  255. });
  256. this.inited = true;
  257. (async() => {
  258. this.showBar();
  259. await this.updateTableData();
  260. await this.scrollToActiveBook();
  261. //await this.scrollRefresh();
  262. })();
  263. }
  264. loadSettings() {
  265. const settings = this.settings;
  266. this.showSameBook = settings.recentShowSameBook;
  267. this.sortMethod = settings.recentSortMethod || 'loadTimeDesc';
  268. this.bucEnabled = settings.bucEnabled;
  269. this.bucSizeDiff = settings.bucSizeDiff;
  270. this.bucSetOnNew = settings.bucSetOnNew;
  271. }
  272. get settings() {
  273. return this.$store.state.reader.settings;
  274. }
  275. get bothBucEnabled() {
  276. return this.$store.state.config.bucEnabled && this.bucEnabled;
  277. }
  278. async updateTableData() {
  279. if (!this.inited)
  280. return;
  281. await this.lock.get();
  282. try {
  283. let result = [];
  284. const sorted = bookManager.getSortedRecent();
  285. const activeBook = bookManager.mostRecentBook();
  286. //подготовка полей
  287. for (const book of sorted) {
  288. if ((!this.archive && book.deleted) || (this.archive && book.deleted != 1))
  289. continue;
  290. let d = new Date();
  291. d.setTime(book.touchTime);
  292. const touchTime = utils.formatDate(d);
  293. const loadTimeRaw = (book.loadTime ? book.loadTime : 0);//book.addTime);
  294. d.setTime(loadTimeRaw);
  295. const loadTime = utils.formatDate(d);
  296. let readPart = 0;
  297. let perc = '';
  298. let textLen = '';
  299. const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
  300. if (book.textLength) {
  301. readPart = p/book.textLength;
  302. perc = `${(readPart*100).toFixed(2)}%`;
  303. textLen = `${Math.floor(readPart*book.textLength/1000)}/${Math.floor(book.textLength/1000)}`;
  304. }
  305. const bt = utils.getBookTitle(book.fb2);
  306. let title = bt.bookTitle;
  307. title = (title ? `"${title}"`: '');
  308. const author = (bt.author ? bt.author : (bt.bookTitle ? bt.bookTitle : (book.uploadFileName ? book.uploadFileName : book.url))) || '';
  309. result.push({
  310. key: book.key,
  311. url: book.url,
  312. path: book.path,
  313. deleted: book.deleted,
  314. touchTime,
  315. loadTime,
  316. desc: {
  317. author,
  318. title,
  319. perc,
  320. textLen,
  321. },
  322. readPart,
  323. fullTitle: bt.fullTitle,
  324. sameBookKey: book.sameBookKey,
  325. active: (activeBook.key == book.key),
  326. activeParent: false,
  327. inGroup: false,
  328. coverPageUrl: book.coverPageUrl,
  329. showCheckBuc: !this.archive && utils.hasProp(book, 'downloadSize'),
  330. checkBuc: !!book.checkBuc,
  331. needBookUpdate: (!this.archive && book.checkBuc && book.bucSize && utils.hasProp(book, 'downloadSize') && (book.bucSize - book.downloadSize >= this.bucSizeDiff)),
  332. bucSize: book.bucSize,
  333. downloadSize: book.downloadSize,
  334. //для сортировки
  335. loadTimeRaw,
  336. touchTimeRaw: book.touchTime,
  337. });
  338. }
  339. //нумерация
  340. result.sort((a, b) => b.loadTimeRaw - a.loadTimeRaw);
  341. let num = 0;
  342. for (let i = result.length - 1; i >= 0; i--) {
  343. num++;
  344. result[i].num = num;
  345. }
  346. //фильтрация
  347. const search = this.search;
  348. if (search) {
  349. const lowerSearch = search.toLowerCase();
  350. result = result.filter(item => {
  351. return !search ||
  352. item.touchTime.includes(search) ||
  353. item.loadTime.includes(search) ||
  354. item.desc.title.toLowerCase().includes(lowerSearch) ||
  355. item.desc.author.toLowerCase().includes(lowerSearch)
  356. });
  357. }
  358. //сортировка
  359. switch (this.sortMethod) {
  360. case 'loadTimeDesc':
  361. result.sort((a, b) => b.loadTimeRaw - a.loadTimeRaw);
  362. break;
  363. case 'loadTimeAsc':
  364. result.sort((a, b) => a.loadTimeRaw - b.loadTimeRaw);
  365. break;
  366. case 'touchTimeDesc':
  367. result.sort((a, b) => b.touchTimeRaw - a.touchTimeRaw);
  368. break;
  369. case 'touchTimeAsc':
  370. result.sort((a, b) => a.touchTimeRaw - b.touchTimeRaw);
  371. break;
  372. case 'authorDesc':
  373. result.sort((a, b) => b.desc.author.localeCompare(a.desc.author));
  374. break;
  375. case 'authorAsc':
  376. result.sort((a, b) => a.desc.author.localeCompare(b.desc.author));
  377. break;
  378. case 'titleDesc':
  379. result.sort((a, b) => b.desc.title.localeCompare(a.desc.title));
  380. break;
  381. case 'titleAsc':
  382. result.sort((a, b) => a.desc.title.localeCompare(b.desc.title));
  383. break;
  384. }
  385. //группировка
  386. const groups = {};
  387. const parents = {};
  388. let newResult = [];
  389. for (const book of result) {
  390. if (book.sameBookKey !== undefined) {
  391. if (!groups[book.sameBookKey]) {
  392. groups[book.sameBookKey] = [];
  393. parents[book.sameBookKey] = book;
  394. book.group = groups[book.sameBookKey];
  395. newResult.push(book);
  396. } else {
  397. book.inGroup = true;
  398. if (book.active)
  399. parents[book.sameBookKey].activeParent = true;
  400. book.showCheckBuc = false;
  401. book.needBookUpdate = false;
  402. groups[book.sameBookKey].push(book);
  403. }
  404. } else {
  405. newResult.push(book);
  406. }
  407. }
  408. result = newResult;
  409. //showSameBook
  410. if (this.showSameBook) {
  411. newResult = [];
  412. for (const book of result) {
  413. newResult.push(book);
  414. if (book.group) {
  415. for (const sameBook of book.group) {
  416. newResult.push(sameBook);
  417. }
  418. }
  419. }
  420. result = newResult;
  421. }
  422. //другие стадии
  423. //.....
  424. this.tableData = result;
  425. } finally {
  426. this.lock.ret();
  427. }
  428. }
  429. resetSearch() {
  430. this.search = '';
  431. this.$refs.input.focus();
  432. }
  433. wordEnding(num, type = 0) {
  434. const endings = [
  435. ['ов', '', 'а', 'а', 'а', 'ов', 'ов', 'ов', 'ов', 'ов'],
  436. ['й', 'я', 'и', 'и', 'и', 'й', 'й', 'й', 'й', 'й'],
  437. ['о', '', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о']
  438. ];
  439. const deci = num % 100;
  440. if (deci > 10 && deci < 20) {
  441. return endings[type][0];
  442. } else {
  443. return endings[type][num % 10];
  444. }
  445. }
  446. get header() {
  447. const len = (this.tableData ? this.tableData.length : 0);
  448. return `${(this.search ? `Найден${this.wordEnding(len, 2)}` : 'Всего')} ${len} файл${this.wordEnding(len)}${this.archive ? ' в архиве' : ''}`;
  449. }
  450. async downloadBook(fb2path, fullTitle) {
  451. try {
  452. await readerApi.checkCachedBook(fb2path);
  453. const d = this.$refs.download;
  454. d.href = fb2path;
  455. try {
  456. const fn = utils.makeValidFilename(fullTitle);
  457. d.download = fn.substring(0, 100) + '.fb2';
  458. } catch(e) {
  459. d.download = path.basename(fb2path).substr(0, 10) + '.fb2';
  460. }
  461. d.click();
  462. } catch (e) {
  463. let errMes = e.message;
  464. if (errMes.indexOf('404') >= 0)
  465. errMes = 'Файл не найден на сервере (возможно был удален как устаревший)';
  466. this.$root.stdDialog.alert(errMes, 'Ошибка', {color: 'negative'});
  467. }
  468. }
  469. async handleDel(key) {
  470. if (!this.archive) {
  471. await bookManager.delRecentBook({key});
  472. this.$root.notify.info('Перенесено в архив');
  473. } else {
  474. if (await this.$root.stdDialog.confirm('Подтвердите удаление из архива:', ' ')) {
  475. await bookManager.delRecentBook({key}, 2);
  476. this.$root.notify.info('Удалено безвозвратно');
  477. }
  478. }
  479. }
  480. async handleRestore(key) {
  481. await bookManager.restoreRecentBook({key});
  482. this.$root.notify.info('Восстановлено из архива');
  483. }
  484. async loadBook(item, force = false) {
  485. //чтобы не обновлять лишний раз updateTableData
  486. this.inited = false;
  487. if (item.deleted)
  488. await this.handleRestore(item.key);
  489. this.$emit('load-book', {url: item.url, path: item.path, force});
  490. this.close();
  491. }
  492. isUrl(url) {
  493. if (url)
  494. return (url.indexOf('disk://') != 0);
  495. else
  496. return false;
  497. }
  498. showBar() {
  499. this.lastScrollTop1 = this.$refs.vsContainer.scrollTop;
  500. this.$refs.header.style.position = 'sticky';
  501. this.$refs.header.style.top = 0;
  502. }
  503. onScroll() {
  504. const curScrollTop = this.$refs.vsContainer.scrollTop;
  505. if (this.lockScroll) {
  506. this.lastScrollTop1 = curScrollTop;
  507. return;
  508. }
  509. if (curScrollTop - this.lastScrollTop1 > 100) {
  510. this.$refs.header.style.top = `-${this.$refs.header.offsetHeight}px`;
  511. this.$refs.header.style.transition = 'top 0.2s ease 0s';
  512. this.lastScrollTop1 = curScrollTop;
  513. } else if (curScrollTop - this.lastScrollTop2 < 0) {
  514. this.$refs.header.style.position = 'sticky';
  515. this.$refs.header.style.top = 0;
  516. this.lastScrollTop1 = curScrollTop;
  517. }
  518. this.lastScrollTop2 = curScrollTop;
  519. }
  520. showSameBookClick() {
  521. this.showSameBook = !this.showSameBook;
  522. const newSettings = _.cloneDeep(this.settings);
  523. newSettings.recentShowSameBook = this.showSameBook;
  524. this.commit('reader/setSettings', newSettings);
  525. this.updateTableData();
  526. }
  527. sortMethodSelected() {
  528. const newSettings = _.cloneDeep(this.settings);
  529. newSettings.recentSortMethod = this.sortMethod;
  530. this.commit('reader/setSettings', newSettings);
  531. }
  532. async scrollToActiveBook() {
  533. await this.$nextTick();
  534. this.lockScroll = true;
  535. try {
  536. let activeIndex = -1;
  537. let activeParentIndex = -1;
  538. for (let i = 0; i < this.tableData.length; i++) {
  539. const book = this.tableData[i];
  540. if (book.active)
  541. activeIndex = i;
  542. if (book.activeParent)
  543. activeParentIndex = i;
  544. if (activeIndex >= 0 && activeParentIndex >= 0)
  545. break;
  546. }
  547. const index = (activeIndex >= 0 ? activeIndex : activeParentIndex);
  548. if (index >= 0) {
  549. this.$refs.virtualScroll.scrollTo(index, 'center');
  550. }
  551. } finally {
  552. await utils.sleep(100);
  553. this.lockScroll = false;
  554. }
  555. }
  556. async scrollToBegin() {
  557. this.lockScroll = true;
  558. try {
  559. this.$refs.virtualScroll.scrollTo(0, 'center');
  560. } finally {
  561. await utils.sleep(100);
  562. this.lockScroll = false;
  563. }
  564. }
  565. async scrollToEnd() {
  566. this.lockScroll = true;
  567. try {
  568. this.$refs.virtualScroll.scrollTo(this.tableData.length, 'center');
  569. } finally {
  570. await utils.sleep(100);
  571. this.lockScroll = false;
  572. }
  573. }
  574. async scrollRefresh() {
  575. this.lockScroll = true;
  576. await utils.sleep(100);
  577. try {
  578. this.$refs.virtualScroll.refresh();
  579. } finally {
  580. await utils.sleep(100);
  581. this.lockScroll = false;
  582. }
  583. }
  584. get sortMethodOptions() {
  585. return [
  586. {label: '<span style="font-size: 150%">&uarr;</span> Время загрузки', value: 'loadTimeDesc'},
  587. {label: '<span style="font-size: 150%">&darr;</span> Время загрузки', value: 'loadTimeAsc'},
  588. {label: '<span style="font-size: 150%">&uarr;</span> Время чтения', value: 'touchTimeDesc'},
  589. {label: '<span style="font-size: 150%">&darr;</span> Время чтения', value: 'touchTimeAsc'},
  590. {label: '<span style="font-size: 150%">&uarr;</span> Автор', value: 'authorDesc'},
  591. {label: '<span style="font-size: 150%">&darr;</span> Автор', value: 'authorAsc'},
  592. {label: '<span style="font-size: 150%">&uarr;</span> Название', value: 'titleDesc'},
  593. {label: '<span style="font-size: 150%">&darr;</span> Название', value: 'titleAsc'},
  594. ];
  595. }
  596. archiveToggle() {
  597. this.archive = !this.archive;
  598. this.updateTableData();
  599. }
  600. close() {
  601. this.$emit('recent-books-close');
  602. }
  603. keyHook(event) {
  604. if (!this.$root.stdDialog.active && event.type == 'keydown' && event.key == 'Escape') {
  605. this.close();
  606. }
  607. return true;
  608. }
  609. makeCoverHtml(data) {
  610. return `<img src="${data}" style="height: 100%; width: 100%; object-fit: contain" />`;
  611. }
  612. isLoadedCover(coverPageUrl) {
  613. if (!coverPageUrl)
  614. return false;
  615. let loadedCover = this.covers[coverPageUrl];
  616. if (loadedCover == 'error')
  617. return false;
  618. if (!loadedCover) {
  619. (async() => {
  620. if (this.coversLoadFunc[coverPageUrl])
  621. return;
  622. this.coversLoadFunc[coverPageUrl] = (async() => {
  623. //сначала заглянем в storage
  624. let data = await coversStorage.getData(coverPageUrl);
  625. if (data) {
  626. this.covers[coverPageUrl] = this.makeCoverHtml(data);
  627. } else {//иначе идем на сервер
  628. try {
  629. data = await readerApi.getUploadedFileBuf(coverPageUrl);
  630. await coversStorage.setData(coverPageUrl, data);
  631. this.covers[coverPageUrl] = this.makeCoverHtml(data);
  632. } catch (e) {
  633. console.error(e);
  634. this.covers[coverPageUrl] = 'error';
  635. }
  636. }
  637. });
  638. try {
  639. await this.coversLoadFunc[coverPageUrl]();
  640. } finally {
  641. this.coversLoadFunc[coverPageUrl] = null;
  642. }
  643. })();
  644. }
  645. return (loadedCover != undefined);
  646. }
  647. getCoverHtml(coverPageUrl) {
  648. if (coverPageUrl && this.covers[coverPageUrl])
  649. return this.covers[coverPageUrl];
  650. else
  651. return '';
  652. }
  653. async checkBucChange(item) {
  654. const book = await bookManager.getRecentBook(item);
  655. if (book) {
  656. await bookManager.setCheckBuc(book, item.checkBuc);
  657. }
  658. }
  659. }
  660. export default vueComponent(RecentBooksPage);
  661. //-----------------------------------------------------------------------------
  662. </script>
  663. <style scoped>
  664. .recent-books-scroll {
  665. width: 573px;
  666. overflow-y: auto;
  667. overflow-x: hidden;
  668. }
  669. .scroll-header {
  670. height: 50px;
  671. position: sticky;
  672. z-index: 1;
  673. top: 0;
  674. border-bottom: 2px solid #aaaaaa;
  675. padding-left: 5px;
  676. }
  677. .table-row {
  678. min-height: 80px;
  679. }
  680. .row-part {
  681. padding: 4px 0px 4px 0px;
  682. }
  683. .clickable {
  684. cursor: pointer;
  685. }
  686. .break-word {
  687. overflow-wrap: break-word;
  688. word-wrap: break-word;
  689. white-space: normal;
  690. }
  691. .even {
  692. background-color: #f2f2f2;
  693. }
  694. .active-book {
  695. background-color: #b0f0b0 !important;
  696. }
  697. .active-parent-book {
  698. background-color: #ffbbbb !important;
  699. }
  700. .icon {
  701. transition: transform 0.2s;
  702. }
  703. .expanded-icon {
  704. transform: rotate(90deg);
  705. }
  706. .tool-button {
  707. min-width: 30px;
  708. width: 30px;
  709. min-height: 30px;
  710. height: 30px;
  711. margin: 10px 6px 0px 3px;
  712. background-color: white;
  713. }
  714. .row-info-bottom {
  715. line-height: 110%;
  716. border-left: 1px solid #cccccc;
  717. border-bottom: 1px solid #cccccc;
  718. height: 14px;
  719. }
  720. .row-info-top {
  721. line-height: 110%;
  722. border: 1px solid #cccccc;
  723. border-right: 0;
  724. height: 14px;
  725. }
  726. .time-info, .row-info-top {
  727. color: #888888;
  728. }
  729. .read-bar {
  730. height: 6px;
  731. background-color: #b8b8b8;
  732. }
  733. .del-button {
  734. width: 25px;
  735. height: 20px;
  736. position: absolute;
  737. border-left: 1px solid #cccccc;
  738. border-bottom: 1px solid #cccccc;
  739. border-radius: 0 0 0 10px;
  740. margin: 1px;
  741. }
  742. .del-button:hover {
  743. color: white;
  744. background-color: #FF3030;
  745. }
  746. .restore-button {
  747. width: 25px;
  748. height: 20px;
  749. position: absolute;
  750. border-right: 1px solid #cccccc;
  751. border-bottom: 1px solid #cccccc;
  752. border-radius: 0 0 10px 0;
  753. margin: 1px;
  754. }
  755. .restore-button:hover {
  756. color: white;
  757. background-color: #00bb00;
  758. }
  759. .header-button, .header-button-pressed {
  760. width: 80px;
  761. height: 30px;
  762. cursor: pointer;
  763. color: #555555;
  764. }
  765. .header-button:hover {
  766. color: white;
  767. background-color: #39902F;
  768. }
  769. .header-button-pressed {
  770. color: black;
  771. background-color: yellow;
  772. }
  773. .header-button-pressed:hover {
  774. color: black;
  775. }
  776. .buc-checkbox {
  777. position: absolute;
  778. }
  779. </style>