TextPage.vue 3.2 KB

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