RecentBooksPage.vue 31 KB

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