RecentBooksPage.vue 34 KB

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