RecentBooksPage.vue 34 KB

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