RecentBooksPage.vue 34 KB

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