Reader.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. <template>
  2. <el-container>
  3. <el-header v-show="toolBarActive" height='50px'>
  4. <div class="header">
  5. <el-tooltip content="Загрузить книгу" :open-delay="1000" effect="light">
  6. <el-button ref="loader" class="tool-button" :class="buttonActiveClass('loader')" @click="buttonClick('loader')"><i class="el-icon-back"></i></el-button>
  7. </el-tooltip>
  8. <div>
  9. <el-tooltip content="Действие назад" :open-delay="1000" effect="light">
  10. <el-button ref="undoAction" class="tool-button" :class="buttonActiveClass('undoAction')" @click="buttonClick('undoAction')" ><i class="el-icon-arrow-left"></i></el-button>
  11. </el-tooltip>
  12. <el-tooltip content="Действие вперед" :open-delay="1000" effect="light">
  13. <el-button ref="redoAction" class="tool-button" :class="buttonActiveClass('redoAction')" @click="buttonClick('redoAction')" ><i class="el-icon-arrow-right"></i></el-button>
  14. </el-tooltip>
  15. <div class="space"></div>
  16. <el-tooltip content="На весь экран" :open-delay="1000" effect="light">
  17. <el-button ref="fullScreen" class="tool-button" :class="buttonActiveClass('fullScreen')" @click="buttonClick('fullScreen')"><i class="el-icon-rank"></i></el-button>
  18. </el-tooltip>
  19. <el-tooltip content="Плавный скроллинг" :open-delay="1000" effect="light">
  20. <el-button ref="scrolling" class="tool-button" :class="buttonActiveClass('scrolling')" @click="buttonClick('scrolling')"><i class="el-icon-sort"></i></el-button>
  21. </el-tooltip>
  22. <el-tooltip content="Перелистнуть" :open-delay="1000" effect="light">
  23. <el-button ref="setPosition" class="tool-button" :class="buttonActiveClass('setPosition')" @click="buttonClick('setPosition')"><i class="el-icon-d-arrow-right"></i></el-button>
  24. </el-tooltip>
  25. <el-tooltip content="Найти в тексте" :open-delay="1000" effect="light">
  26. <el-button ref="search" class="tool-button" :class="buttonActiveClass('search')" @click="buttonClick('search')"><i class="el-icon-search"></i></el-button>
  27. </el-tooltip>
  28. <el-tooltip content="Скопировать текст со страницы" :open-delay="1000" effect="light">
  29. <el-button ref="copyText" class="tool-button" :class="buttonActiveClass('copyText')" @click="buttonClick('copyText')"><i class="el-icon-edit-outline"></i></el-button>
  30. </el-tooltip>
  31. <el-tooltip content="Принудительно обновить книгу в обход кэша" :open-delay="1000" effect="light">
  32. <el-button ref="refresh" class="tool-button" :class="buttonActiveClass('refresh')" @click="buttonClick('refresh')">
  33. <i class="el-icon-refresh" :class="{clear: !showRefreshIcon}"></i>
  34. </el-button>
  35. </el-tooltip>
  36. <div class="space"></div>
  37. <el-tooltip content="Открыть недавние" :open-delay="1000" effect="light">
  38. <el-button ref="history" class="tool-button" :class="buttonActiveClass('history')" @click="buttonClick('history')"><i class="el-icon-document"></i></el-button>
  39. </el-tooltip>
  40. </div>
  41. <el-tooltip content="Настроить" :open-delay="1000" effect="light">
  42. <el-button ref="settings" class="tool-button" :class="buttonActiveClass('settings')" @click="buttonClick('settings')"><i class="el-icon-setting"></i></el-button>
  43. </el-tooltip>
  44. </div>
  45. </el-header>
  46. <el-main>
  47. <keep-alive>
  48. <component ref="page" :is="activePage"
  49. @load-book="loadBook"
  50. @load-file="loadFile"
  51. @book-pos-changed="bookPosChanged"
  52. @tool-bar-toggle="toolBarToggle"
  53. @full-screen-toogle="fullScreenToggle"
  54. @stop-scrolling="stopScrolling"
  55. @scrolling-toggle="scrollingToggle"
  56. @help-toggle="helpToggle"
  57. ></component>
  58. </keep-alive>
  59. <SetPositionPage v-if="setPositionActive" ref="setPositionPage" @set-position-toggle="setPositionToggle" @book-pos-changed="bookPosChanged"></SetPositionPage>
  60. <SearchPage v-show="searchActive" ref="searchPage"
  61. @search-toggle="searchToggle"
  62. @book-pos-changed="bookPosChanged"
  63. @start-text-search="startTextSearch"
  64. @stop-text-search="stopTextSearch">
  65. </SearchPage>
  66. <CopyTextPage v-if="copyTextActive" ref="copyTextPage" @copy-text-toggle="copyTextToggle"></CopyTextPage>
  67. <HistoryPage v-if="historyActive" ref="historyPage" @load-book="loadBook" @history-toggle="historyToggle"></HistoryPage>
  68. <SettingsPage v-if="settingsActive" ref="settingsPage" @settings-toggle="settingsToggle"></SettingsPage>
  69. <HelpPage v-if="helpActive" ref="helpPage" @help-toggle="helpToggle"></HelpPage>
  70. <ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage>
  71. </el-main>
  72. </el-container>
  73. </template>
  74. <script>
  75. //-----------------------------------------------------------------------------
  76. import Vue from 'vue';
  77. import Component from 'vue-class-component';
  78. import LoaderPage from './LoaderPage/LoaderPage.vue';
  79. import TextPage from './TextPage/TextPage.vue';
  80. import ProgressPage from './ProgressPage/ProgressPage.vue';
  81. import SetPositionPage from './SetPositionPage/SetPositionPage.vue';
  82. import SearchPage from './SearchPage/SearchPage.vue';
  83. import CopyTextPage from './CopyTextPage/CopyTextPage.vue';
  84. import HistoryPage from './HistoryPage/HistoryPage.vue';
  85. import SettingsPage from './SettingsPage/SettingsPage.vue';
  86. import HelpPage from './HelpPage/HelpPage.vue';
  87. import ClickMapPage from './ClickMapPage/ClickMapPage.vue';
  88. import bookManager from './share/bookManager';
  89. import readerApi from '../../api/reader';
  90. import _ from 'lodash';
  91. import {sleep} from '../../share/utils';
  92. export default @Component({
  93. components: {
  94. LoaderPage,
  95. TextPage,
  96. ProgressPage,
  97. SetPositionPage,
  98. SearchPage,
  99. CopyTextPage,
  100. HistoryPage,
  101. SettingsPage,
  102. HelpPage,
  103. ClickMapPage,
  104. },
  105. watch: {
  106. bookPos: function(newValue) {
  107. if (newValue !== undefined && this.activePage == 'TextPage') {
  108. const textPage = this.$refs.page;
  109. if (textPage.bookPos != newValue) {
  110. textPage.bookPos = newValue;
  111. }
  112. this.debouncedSetRecentBook(newValue);
  113. }
  114. },
  115. routeParamPos: function(newValue) {
  116. if (newValue !== undefined && newValue != this.bookPos) {
  117. this.bookPos = newValue;
  118. }
  119. },
  120. routeParamUrl: function(newValue) {
  121. if (newValue !== '' && newValue !== this.mostRecentBook().url) {
  122. this.loadBook({url: newValue, bookPos: this.routeParamPos});
  123. }
  124. },
  125. settings: function(newValue) {
  126. this.allowUrlParamBookPos = newValue.allowUrlParamBookPos;
  127. this.copyFullText = newValue.copyFullText;
  128. this.updateRoute();
  129. },
  130. },
  131. })
  132. class Reader extends Vue {
  133. loaderActive = false;
  134. progressActive = false;
  135. fullScreenActive = false;
  136. scrollingActive = false;
  137. setPositionActive = false;
  138. searchActive = false;
  139. copyTextActive = false;
  140. historyActive = false;
  141. settingsActive = false;
  142. helpActive = false;
  143. clickMapActive = false;
  144. bookPos = null;
  145. allowUrlParamBookPos = false;
  146. showRefreshIcon = true;
  147. mostRecentBookReactive = null;
  148. actionList = [];
  149. actionCur = -1;
  150. created() {
  151. this.loading = true;
  152. this.commit = this.$store.commit;
  153. this.dispatch = this.$store.dispatch;
  154. this.reader = this.$store.state.reader;
  155. this.$root.addKeyHook(this.keyHook);
  156. this.lastActivePage = false;
  157. this.debouncedUpdateRoute = _.debounce(() => {
  158. this.updateRoute();
  159. }, 1000);
  160. this.debouncedSetRecentBook = _.debounce(async(newValue) => {
  161. const recent = this.mostRecentBook();
  162. if (recent && recent.bookPos != newValue) {
  163. await bookManager.setRecentBook(Object.assign({}, recent, {bookPos: newValue, bookPosSeen: this.bookPosSeen}));
  164. if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue))
  165. this.addAction(newValue);
  166. }
  167. }, 500);
  168. document.addEventListener('fullscreenchange', () => {
  169. this.fullScreenActive = (document.fullscreenElement !== null);
  170. });
  171. this.allowUrlParamBookPos = this.settings.allowUrlParamBookPos;
  172. this.copyFullText = this.settings.copyFullText;
  173. }
  174. mounted() {
  175. (async() => {
  176. await bookManager.init();
  177. if (this.$root.rootRoute == '/reader') {
  178. if (this.routeParamUrl) {
  179. this.loadBook({url: this.routeParamUrl, bookPos: this.routeParamPos});
  180. } else if (this.mostRecentBook()) {
  181. this.loadBook({url: this.mostRecentBook().url});
  182. } else {
  183. this.loaderActive = true;
  184. }
  185. }
  186. this.loading = false;
  187. })();
  188. }
  189. get routeParamPos() {
  190. let result = undefined;
  191. const q = this.$route.query;
  192. if (q['__p']) {
  193. result = q['__p'];
  194. if (Array.isArray(result))
  195. result = result[0];
  196. }
  197. return (result ? parseInt(result, 10) || 0 : result);
  198. }
  199. updateRoute(isNewRoute) {
  200. const recent = this.mostRecentBook();
  201. const pos = (recent && recent.bookPos && this.allowUrlParamBookPos ? `__p=${recent.bookPos}&` : '');
  202. const url = (recent ? `url=${recent.url}` : '');
  203. if (isNewRoute)
  204. this.$router.push(`/reader?${pos}${url}`);
  205. else
  206. this.$router.replace(`/reader?${pos}${url}`);
  207. }
  208. get routeParamUrl() {
  209. let result = '';
  210. const path = this.$route.fullPath;
  211. const i = path.indexOf('url=');
  212. if (i >= 0) {
  213. result = path.substr(i + 4);
  214. }
  215. return decodeURIComponent(result);
  216. }
  217. bookPosChanged(event) {
  218. if (event.bookPosSeen !== undefined)
  219. this.bookPosSeen = event.bookPosSeen;
  220. this.bookPos = event.bookPos;
  221. this.debouncedUpdateRoute();
  222. }
  223. get toolBarActive() {
  224. return this.reader.toolBarActive;
  225. }
  226. mostRecentBook() {
  227. const result = bookManager.mostRecentBook();
  228. this.mostRecentBookReactive = result;
  229. return result;
  230. }
  231. get settings() {
  232. return this.$store.state.reader.settings;
  233. }
  234. addAction(pos) {
  235. let a = this.actionList;
  236. if (!a.length || a[a.length - 1] != pos) {
  237. a.push(pos);
  238. if (a.length > 20)
  239. a.shift();
  240. this.actionCur = a.length - 1;
  241. }
  242. }
  243. toolBarToggle() {
  244. this.commit('reader/setToolBarActive', !this.toolBarActive);
  245. this.$root.$emit('resize');
  246. }
  247. fullScreenToggle() {
  248. this.fullScreenActive = !this.fullScreenActive;
  249. if (this.fullScreenActive) {
  250. const element = document.documentElement;
  251. if (element.requestFullscreen) {
  252. element.requestFullscreen();
  253. } else if (element.webkitrequestFullscreen) {
  254. element.webkitRequestFullscreen();
  255. } else if (element.mozRequestFullscreen) {
  256. element.mozRequestFullScreen();
  257. }
  258. } else {
  259. if (document.cancelFullScreen) {
  260. document.cancelFullScreen();
  261. } else if (document.mozCancelFullScreen) {
  262. document.mozCancelFullScreen();
  263. } else if (document.webkitCancelFullScreen) {
  264. document.webkitCancelFullScreen();
  265. }
  266. }
  267. }
  268. closeAllTextPages() {
  269. this.setPositionActive = false;
  270. this.copyTextActive = false;
  271. this.historyActive = false;
  272. this.settingsActive = false;
  273. this.stopScrolling();
  274. this.stopSearch();
  275. this.helpActive = false;
  276. }
  277. loaderToggle() {
  278. this.loaderActive = !this.loaderActive;
  279. if (this.loaderActive) {
  280. this.closeAllTextPages();
  281. }
  282. }
  283. setPositionToggle() {
  284. this.setPositionActive = !this.setPositionActive;
  285. if (this.setPositionActive && this.activePage == 'TextPage' && this.mostRecentBook()) {
  286. this.closeAllTextPages();
  287. this.setPositionActive = true;
  288. this.$nextTick(() => {
  289. this.$refs.setPositionPage.sliderMax = this.mostRecentBook().textLength - 1;
  290. this.$refs.setPositionPage.sliderValue = this.mostRecentBook().bookPos;
  291. });
  292. } else {
  293. this.setPositionActive = false;
  294. }
  295. }
  296. stopScrolling() {
  297. if (this.scrollingActive)
  298. this.scrollingToggle();
  299. }
  300. scrollingToggle() {
  301. this.scrollingActive = !this.scrollingActive;
  302. if (this.activePage == 'TextPage') {
  303. const page = this.$refs.page;
  304. if (this.scrollingActive) {
  305. page.startTextScrolling();
  306. } else {
  307. page.stopTextScrolling();
  308. }
  309. }
  310. }
  311. stopSearch() {
  312. if (this.searchActive)
  313. this.searchToggle();
  314. }
  315. startTextSearch(opts) {
  316. if (this.activePage == 'TextPage')
  317. this.$refs.page.startSearch(opts.needle);
  318. }
  319. stopTextSearch() {
  320. if (this.activePage == 'TextPage')
  321. this.$refs.page.stopSearch();
  322. }
  323. searchToggle() {
  324. this.searchActive = !this.searchActive;
  325. const page = this.$refs.page;
  326. if (this.searchActive && this.activePage == 'TextPage' && page.parsed) {
  327. this.closeAllTextPages();
  328. this.searchActive = true;
  329. this.$nextTick(() => {
  330. this.$refs.searchPage.init(page.parsed);
  331. });
  332. } else {
  333. this.stopTextSearch();
  334. this.searchActive = false;
  335. }
  336. }
  337. copyTextToggle() {
  338. this.copyTextActive = !this.copyTextActive;
  339. const page = this.$refs.page;
  340. if (this.copyTextActive && this.activePage == 'TextPage' && page.parsed) {
  341. this.closeAllTextPages();
  342. this.copyTextActive = true;
  343. this.$nextTick(() => {
  344. this.$refs.copyTextPage.init(this.mostRecentBook().bookPos, page.parsed, this.copyFullText);
  345. });
  346. } else {
  347. this.copyTextActive = false;
  348. }
  349. }
  350. historyToggle() {
  351. this.historyActive = !this.historyActive;
  352. if (this.historyActive) {
  353. this.closeAllTextPages();
  354. this.historyActive = true;
  355. } else {
  356. this.historyActive = false;
  357. }
  358. }
  359. settingsToggle() {
  360. this.settingsActive = !this.settingsActive;
  361. if (this.settingsActive) {
  362. this.closeAllTextPages();
  363. this.settingsActive = true;
  364. } else {
  365. this.settingsActive = false;
  366. }
  367. }
  368. helpToggle() {
  369. this.helpActive = !this.helpActive;
  370. if (this.helpActive) {
  371. this.closeAllTextPages();
  372. this.helpActive = true;
  373. }
  374. }
  375. buttonClick(button) {
  376. switch (button) {
  377. case 'loader':
  378. this.loaderToggle();
  379. break;
  380. case 'undoAction':
  381. if (this.actionCur > 0) {
  382. this.actionCur--;
  383. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  384. }
  385. break;
  386. case 'redoAction':
  387. if (this.actionCur < this.actionList.length - 1) {
  388. this.actionCur++;
  389. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  390. }
  391. break;
  392. case 'fullScreen':
  393. this.fullScreenToggle();
  394. break;
  395. case 'setPosition':
  396. this.setPositionToggle();
  397. break;
  398. case 'scrolling':
  399. this.scrollingToggle();
  400. break;
  401. case 'search':
  402. this.searchToggle();
  403. break;
  404. case 'copyText':
  405. this.copyTextToggle();
  406. break;
  407. case 'history':
  408. this.historyToggle();
  409. break;
  410. case 'refresh':
  411. if (this.mostRecentBook()) {
  412. this.loadBook({url: this.mostRecentBook().url, force: true});
  413. }
  414. break;
  415. case 'settings':
  416. this.settingsToggle();
  417. break;
  418. }
  419. this.$refs[button].$el.blur();
  420. }
  421. buttonActiveClass(button) {
  422. const classActive = { 'tool-button-active': true, 'tool-button-active:hover': true };
  423. const classDisabled = { 'tool-button-disabled': true, 'tool-button-disabled:hover': true };
  424. let classResult = {};
  425. switch (button) {
  426. case 'loader':
  427. case 'fullScreen':
  428. case 'setPosition':
  429. case 'scrolling':
  430. case 'search':
  431. case 'copyText':
  432. case 'history':
  433. case 'settings':
  434. if (this[`${button}Active`])
  435. classResult = classActive;
  436. break;
  437. }
  438. switch (button) {
  439. case 'undoAction':
  440. if (this.actionCur <= 0)
  441. classResult = classDisabled;
  442. break;
  443. case 'redoAction':
  444. if (this.actionCur == this.actionList.length - 1)
  445. classResult = classDisabled;
  446. break;
  447. }
  448. if (this.activePage == 'LoaderPage' || !this.mostRecentBook()) {
  449. switch (button) {
  450. case 'undoAction':
  451. case 'redoAction':
  452. case 'setPosition':
  453. case 'scrolling':
  454. case 'search':
  455. case 'copyText':
  456. classResult = classDisabled;
  457. break;
  458. case 'history':
  459. case 'refresh':
  460. if (!this.mostRecentBook())
  461. classResult = classDisabled;
  462. break;
  463. }
  464. }
  465. return classResult;
  466. }
  467. async showClickMapPage() {
  468. this.clickMapActive = true;
  469. await this.$refs.clickMapPage.slowDisappear();
  470. this.clickMapActive = false;
  471. }
  472. get activePage() {
  473. let result = '';
  474. if (this.progressActive)
  475. result = 'ProgressPage';
  476. else if (this.loaderActive)
  477. result = 'LoaderPage';
  478. else if (this.mostRecentBookReactive)
  479. result = 'TextPage';
  480. if (!result && !this.loading) {
  481. this.loaderActive = true;
  482. result = 'LoaderPage';
  483. }
  484. if (result != 'TextPage') {
  485. this.$root.$emit('set-app-title');
  486. }
  487. if (this.lastActivePage != result && result == 'TextPage') {
  488. //акивируем страницу с текстом
  489. this.$nextTick(async() => {
  490. const last = this.mostRecentBookReactive;
  491. const isParsed = bookManager.hasBookParsed(last);
  492. if (!isParsed) {
  493. this.$root.$emit('set-app-title');
  494. return;
  495. }
  496. this.updateRoute();
  497. const textPage = this.$refs.page;
  498. if (textPage.showBook) {
  499. textPage.lastBook = last;
  500. textPage.bookPos = (last.bookPos !== undefined ? last.bookPos : 0);
  501. textPage.showBook();
  502. }
  503. });
  504. }
  505. this.lastActivePage = result;
  506. return result;
  507. }
  508. loadBook(opts) {
  509. if (!opts) {
  510. this.mostRecentBook();
  511. return;
  512. }
  513. // уже просматривается сейчас
  514. const lastBook = (this.$refs.page ? this.$refs.page.lastBook : null);
  515. if (!opts.force && lastBook && lastBook.url == opts.url && bookManager.hasBookParsed(lastBook)) {
  516. this.loaderActive = false;
  517. return;
  518. }
  519. this.progressActive = true;
  520. this.$nextTick(async() => {
  521. const progress = this.$refs.page;
  522. this.actionList = [];
  523. this.actionCur = -1;
  524. try {
  525. progress.show();
  526. progress.setState({state: 'parse'});
  527. // есть ли среди недавних
  528. const key = bookManager.keyFromUrl(opts.url);
  529. let wasOpened = await bookManager.getRecentBook({key});
  530. wasOpened = (wasOpened ? wasOpened : {});
  531. const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
  532. const bookPosSeen = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPosSeen);
  533. let book = null;
  534. if (!opts.force) {
  535. // пытаемся загрузить и распарсить книгу в менеджере из локального кеша
  536. const bookParsed = await bookManager.getBook({url: opts.url}, (prog) => {
  537. progress.setState({progress: prog});
  538. });
  539. // если есть в локальном кеше
  540. if (bookParsed) {
  541. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, bookManager.metaOnly(bookParsed)));
  542. this.mostRecentBook();
  543. this.addAction(bookPos);
  544. this.loaderActive = false;
  545. progress.hide(); this.progressActive = false;
  546. this.blinkCachedLoadMessage();
  547. await this.showClickMapPage();
  548. return;
  549. }
  550. // иначе идем на сервер
  551. // пытаемся загрузить готовый файл с сервера
  552. if (wasOpened.path) {
  553. try {
  554. const resp = await readerApi.loadCachedBook(wasOpened.path, (state) => {
  555. progress.setState(state);
  556. });
  557. book = Object.assign({}, wasOpened, {data: resp.data});
  558. } catch (e) {
  559. //молчим
  560. }
  561. }
  562. }
  563. progress.setState({totalSteps: 5});
  564. // не удалось, скачиваем книгу полностью с конвертацией
  565. let loadCached = true;
  566. if (!book) {
  567. book = await readerApi.loadBook(opts.url, (state) => {
  568. progress.setState(state);
  569. });
  570. loadCached = false;
  571. }
  572. // добавляем в bookManager
  573. progress.setState({state: 'parse', step: 5});
  574. const addedBook = await bookManager.addBook(book, (prog) => {
  575. progress.setState({progress: prog});
  576. });
  577. // добавляем в историю
  578. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, bookManager.metaOnly(addedBook)));
  579. this.mostRecentBook();
  580. this.addAction(bookPos);
  581. this.updateRoute(true);
  582. this.loaderActive = false;
  583. progress.hide(); this.progressActive = false;
  584. if (loadCached) {
  585. this.blinkCachedLoadMessage();
  586. } else
  587. this.stopBlink = true;
  588. await this.showClickMapPage();
  589. } catch (e) {
  590. progress.hide(); this.progressActive = false;
  591. this.loaderActive = true;
  592. this.$alert(e.message, 'Ошибка', {type: 'error'});
  593. }
  594. });
  595. }
  596. loadFile(opts) {
  597. this.progressActive = true;
  598. this.$nextTick(async() => {
  599. const progress = this.$refs.page;
  600. try {
  601. progress.show();
  602. progress.setState({state: 'upload'});
  603. const url = await readerApi.uploadFile(opts.file, (state) => {
  604. progress.setState(state);
  605. });
  606. progress.hide(); this.progressActive = false;
  607. this.loadBook({url});
  608. } catch (e) {
  609. progress.hide(); this.progressActive = false;
  610. this.loaderActive = true;
  611. this.$alert(e.message, 'Ошибка', {type: 'error'});
  612. }
  613. });
  614. }
  615. blinkCachedLoadMessage() {
  616. this.blinkCount = 30;
  617. if (!this.inBlink) {
  618. this.inBlink = true;
  619. this.stopBlink = false;
  620. this.$nextTick(async() => {
  621. let page = this.$refs.page;
  622. while (this.blinkCount) {
  623. this.showRefreshIcon = !this.showRefreshIcon;
  624. if (page.blinkCachedLoadMessage)
  625. page.blinkCachedLoadMessage(this.showRefreshIcon);
  626. await sleep(500);
  627. if (this.stopBlink)
  628. break;
  629. this.blinkCount--;
  630. page = this.$refs.page;
  631. }
  632. this.showRefreshIcon = true;
  633. this.inBlink = false;
  634. if (page.blinkCachedLoadMessage)
  635. page.blinkCachedLoadMessage('finish');
  636. });
  637. }
  638. }
  639. keyHook(event) {
  640. if (this.$root.rootRoute == '/reader') {
  641. let handled = false;
  642. if (!handled && this.helpActive)
  643. handled = this.$refs.helpPage.keyHook(event);
  644. if (!handled && this.settingsActive)
  645. handled = this.$refs.settingsPage.keyHook(event);
  646. if (!handled && this.historyActive)
  647. handled = this.$refs.historyPage.keyHook(event);
  648. if (!handled && this.setPositionActive)
  649. handled = this.$refs.setPositionPage.keyHook(event);
  650. if (!handled && this.searchActive)
  651. handled = this.$refs.searchPage.keyHook(event);
  652. if (!handled && this.copyTextActive)
  653. handled = this.$refs.copyTextPage.keyHook(event);
  654. if (!handled && this.$refs.page && this.$refs.page.keyHook)
  655. handled = this.$refs.page.keyHook(event);
  656. if (!handled && event.type == 'keydown') {
  657. if (event.code == 'Escape')
  658. this.loaderToggle();
  659. if (this.activePage == 'TextPage') {
  660. switch (event.code) {
  661. case 'KeyP':
  662. this.setPositionToggle();
  663. break;
  664. case 'KeyF':
  665. if (event.ctrlKey) {
  666. this.searchToggle();
  667. event.preventDefault();
  668. event.stopPropagation();
  669. }
  670. break;
  671. case 'KeyC':
  672. if (event.ctrlKey) {
  673. this.copyTextToggle();
  674. event.preventDefault();
  675. event.stopPropagation();
  676. }
  677. break;
  678. case 'KeyZ':
  679. this.scrollingToggle();
  680. break;
  681. case 'KeyH':
  682. this.historyToggle();
  683. break;
  684. case 'KeyS':
  685. this.settingsToggle();
  686. break;
  687. }
  688. }
  689. }
  690. }
  691. }
  692. }
  693. //-----------------------------------------------------------------------------
  694. </script>
  695. <style scoped>
  696. .el-container {
  697. padding: 0;
  698. margin: 0;
  699. height: 100%;
  700. }
  701. .el-header {
  702. padding-left: 5px;
  703. padding-right: 5px;
  704. background-color: #1B695F;
  705. color: #000;
  706. overflow-x: auto;
  707. overflow-y: hidden;
  708. }
  709. .header {
  710. display: flex;
  711. justify-content: space-between;
  712. min-width: 550px;
  713. }
  714. .el-main {
  715. position: relative;
  716. display: flex;
  717. padding: 0;
  718. margin: 0;
  719. background-color: #EBE2C9;
  720. color: #000;
  721. }
  722. .tool-button {
  723. margin: 0 2px 0 2px;
  724. padding: 0;
  725. color: #3E843E;
  726. background-color: #E6EDF4;
  727. margin-top: 5px;
  728. height: 38px;
  729. width: 38px;
  730. border: 0;
  731. box-shadow: 3px 3px 5px black;
  732. }
  733. .tool-button:hover {
  734. background-color: white;
  735. }
  736. .tool-button-active {
  737. box-shadow: 0 0 0;
  738. color: white;
  739. background-color: #8AB45F;
  740. position: relative;
  741. top: 1px;
  742. left: 1px;
  743. }
  744. .tool-button-active:hover {
  745. color: white;
  746. background-color: #81C581;
  747. }
  748. .tool-button-disabled {
  749. color: lightgray;
  750. background-color: gray;
  751. }
  752. .tool-button-disabled:hover {
  753. color: lightgray;
  754. background-color: gray;
  755. }
  756. i {
  757. font-size: 200%;
  758. }
  759. .space {
  760. width: 10px;
  761. display: inline-block;
  762. }
  763. .clear {
  764. color: rgba(0,0,0,0);
  765. }
  766. </style>