TextPage.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div ref="main" class="main">
  3. <pre>{{ this.lastOpenedBook }}</pre>
  4. <pre>{{ meta }}</pre>
  5. <pre>{{ bookPos }}</pre>
  6. <pre>{{ $route.query }}</pre>
  7. </div>
  8. </template>
  9. <script>
  10. //-----------------------------------------------------------------------------
  11. import Vue from 'vue';
  12. import Component from 'vue-class-component';
  13. import _ from 'lodash';
  14. import bookManager from '../share/bookManager';
  15. export default @Component({
  16. watch: {
  17. bookPos: function(newValue) {
  18. this.updateRoute(newValue);
  19. this.commit('reader/setOpenedBook', Object.assign({}, this.lastOpenedBook, {bookPos: newValue}));
  20. this.drawPage();
  21. },
  22. routeParamPos: function(newValue) {
  23. if (newValue !== undefined && newValue != this.bookPos) {
  24. this.bookPos = newValue;
  25. }
  26. },
  27. },
  28. })
  29. class TextPage extends Vue {
  30. meta = null;
  31. fb2 = null;
  32. bookPos = 0;
  33. created() {
  34. this.commit = this.$store.commit;
  35. this.dispatch = this.$store.dispatch;
  36. this.config = this.$store.state.config;
  37. this.reader = this.$store.state.reader;
  38. this.lastOpenTry = '';
  39. }
  40. activated() {
  41. this.$refs.main.focus();
  42. this.book = null;
  43. this.meta = null;
  44. this.fb2 = null;
  45. let last = this.lastOpenedBook;
  46. if (last) {
  47. (async() => {
  48. const isParsed = await bookManager.hasBookParsed(last);
  49. if (!isParsed) {
  50. this.$root.$emit('set-app-title');
  51. if (this.lastOpenTry != last) {
  52. this.$emit('parse-book', last);
  53. this.lastOpenTry = last;
  54. }
  55. return;
  56. }
  57. this.book = await bookManager.getBook(last);
  58. this.meta = bookManager.metaOnly(this.book);
  59. this.fb2 = this.meta.fb2;
  60. this.$root.$emit('set-app-title', _.compact([
  61. this.fb2.lastName,
  62. this.fb2.middleName,
  63. this.fb2.firstName,
  64. '-',
  65. this.fb2.bookTitle
  66. ]).join(' '));
  67. this.bookPos = (this.routeParamPos !== undefined ? this.routeParamPos : last.bookPos || 0);
  68. this.updateRoute(this.bookPos);
  69. this.drawPage();
  70. })();
  71. }
  72. }
  73. get lastOpenedBook() {
  74. return this.$store.getters['reader/lastOpenedBook'];
  75. }
  76. get routeParamPos() {
  77. let result = undefined;
  78. const q = this.$route.query;
  79. if (q['__p']) {
  80. result = q['__p'];
  81. if (Array.isArray(result))
  82. result = result[0];
  83. }
  84. return (result ? parseInt(result, 10) || 0 : result);
  85. }
  86. updateRoute(newPos) {
  87. if (this.book)
  88. this.$router.replace(`/reader?__p=${newPos}&url=${this.lastOpenedBook.url}`);
  89. }
  90. drawPage() {
  91. const last = this.lastOpenedBook;
  92. if (!last)
  93. return;
  94. //пустой канвас
  95. if (!this.book)
  96. return;
  97. }
  98. keyHook(event) {
  99. }
  100. }
  101. //-----------------------------------------------------------------------------
  102. </script>
  103. <style scoped>
  104. .main {
  105. flex: 1;
  106. display: flex;
  107. flex-direction: column;
  108. }
  109. </style>