RecentBooksPage.vue 36 KB

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