RecentBooksPage.vue 29 KB

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