Reader.vue 29 KB

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