TextPage.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div ref="main" class="main">
  3. <pre>{{ bookPos }}</pre>
  4. <pre>{{ lastBook }}</pre>
  5. <pre>{{ meta }}</pre>
  6. </div>
  7. </template>
  8. <script>
  9. //-----------------------------------------------------------------------------
  10. import Vue from 'vue';
  11. import Component from 'vue-class-component';
  12. import _ from 'lodash';
  13. import bookManager from '../share/bookManager';
  14. export default @Component({
  15. watch: {
  16. bookPos: function(newValue) {
  17. this.$emit('book-pos-changed', {bookPos: newValue});
  18. this.drawPage();
  19. },
  20. },
  21. })
  22. class TextPage extends Vue {
  23. lastBook = null;
  24. meta = null;
  25. fb2 = null;
  26. bookPos = 0;
  27. created() {
  28. this.commit = this.$store.commit;
  29. this.dispatch = this.$store.dispatch;
  30. this.config = this.$store.state.config;
  31. this.reader = this.$store.state.reader;
  32. }
  33. showBook() {
  34. this.$refs.main.focus();
  35. this.book = null;
  36. this.meta = null;
  37. this.fb2 = null;
  38. this.drawPage();//пока не загрузили, очистим канвас
  39. if (this.lastBook) {
  40. (async() => {
  41. const isParsed = await bookManager.hasBookParsed(this.lastBook);
  42. if (!isParsed) {
  43. return;
  44. }
  45. this.book = await bookManager.getBook(this.lastBook);
  46. this.meta = bookManager.metaOnly(this.book);
  47. this.fb2 = this.meta.fb2;
  48. this.$root.$emit('set-app-title', _.compact([
  49. this.fb2.lastName,
  50. this.fb2.middleName,
  51. this.fb2.firstName,
  52. '-',
  53. this.fb2.bookTitle
  54. ]).join(' '));
  55. this.drawPage();
  56. })();
  57. }
  58. }
  59. drawPage() {
  60. if (!this.lastBook)
  61. return;
  62. //пустой канвас
  63. if (!this.book)
  64. return;
  65. }
  66. keyHook(event) {
  67. }
  68. }
  69. //-----------------------------------------------------------------------------
  70. </script>
  71. <style scoped>
  72. .main {
  73. flex: 1;
  74. display: flex;
  75. flex-direction: column;
  76. }
  77. </style>