TextPage.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <div class="main">
  3. <p v-for="item in items" :key="item.id">
  4. {{ item.text }}
  5. </p>
  6. </div>
  7. </template>
  8. <script>
  9. //-----------------------------------------------------------------------------
  10. import Vue from 'vue';
  11. import Component from 'vue-class-component';
  12. import bookManager from '../share/bookManager';
  13. export default @Component({
  14. })
  15. class TextPage extends Vue {
  16. items = null;
  17. created() {
  18. this.commit = this.$store.commit;
  19. this.dispatch = this.$store.dispatch;
  20. this.config = this.$store.state.config;
  21. this.reader = this.$store.state.reader;
  22. this.book = null;
  23. }
  24. activated() {
  25. const last = this.lastOpenedBook;
  26. if (last) {
  27. (async() => {
  28. const isParsed = await bookManager.hasBookParsed(last);
  29. if (!isParsed) {
  30. this.$emit('parse-book', last);
  31. return;
  32. }
  33. const book = await bookManager.getBook(last);
  34. this.book = book.parsed;
  35. let lines = [];
  36. const len = (this.book.para.length > 50 ? 50 : this.book.para.length);
  37. for (let i = 0; i < len; i++) {
  38. lines.push({key: i, text: this.book.para[i].text});
  39. }
  40. this.items = lines;
  41. })();
  42. }
  43. }
  44. get lastOpenedBook() {
  45. return this.$store.getters['reader/lastOpenedBook'];
  46. }
  47. keyHook(event) {
  48. }
  49. }
  50. //-----------------------------------------------------------------------------
  51. </script>
  52. <style scoped>
  53. .main {
  54. flex: 1;
  55. display: flex;
  56. flex-direction: column;
  57. }
  58. p {
  59. margin: 0;
  60. padding: 0;
  61. text-indent: 3%;
  62. }
  63. </style>