Reader.vue 30 KB

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