TextPage.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="main">
  3. <pre>{{ meta }}</pre>
  4. <p v-for="item in items" :key="item.id">
  5. {{ item.text }}
  6. </p>
  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. })
  17. class TextPage extends Vue {
  18. meta = null;
  19. items = null;
  20. created() {
  21. this.commit = this.$store.commit;
  22. this.dispatch = this.$store.dispatch;
  23. this.config = this.$store.state.config;
  24. this.reader = this.$store.state.reader;
  25. this.book = null;
  26. }
  27. activated() {
  28. const last = this.lastOpenedBook;
  29. if (last) {
  30. (async() => {
  31. const isParsed = await bookManager.hasBookParsed(last);
  32. if (!isParsed) {
  33. this.$root.$emit('set-app-title');
  34. this.$emit('parse-book', last);
  35. return;
  36. }
  37. this.book = await bookManager.getBook(last);
  38. this.meta = bookManager.metaOnly(this.book);
  39. const fb2 = this.meta.fb2;
  40. this.$root.$emit('set-app-title', _.compact([
  41. fb2.lastName,
  42. fb2.middleName,
  43. fb2.firstName,
  44. '-',
  45. fb2.bookTitle
  46. ]).join(' '));
  47. //
  48. let lines = [];
  49. let para = this.book.parsed.para;
  50. const len = (para.length > 50 ? 50 : para.length);
  51. for (let i = 0; i < len; i++) {
  52. lines.push({key: i, text: para[i].text});
  53. }
  54. this.items = lines;
  55. //
  56. })();
  57. }
  58. }
  59. get lastOpenedBook() {
  60. return this.$store.getters['reader/lastOpenedBook'];
  61. }
  62. keyHook(event) {
  63. }
  64. }
  65. //-----------------------------------------------------------------------------
  66. </script>
  67. <style scoped>
  68. .main {
  69. flex: 1;
  70. display: flex;
  71. flex-direction: column;
  72. }
  73. p {
  74. margin: 0;
  75. padding: 0;
  76. text-indent: 3%;
  77. }
  78. </style>