LoaderPage.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div ref="main" class="main">
  3. <div class="part">
  4. <span class="greeting bold-font">{{ title }}</span>
  5. <span class="greeting">Добро пожаловать!</span>
  6. <span class="greeting">Поддерживаются форматы: fb2, fb2.zip, html, txt</span>
  7. </div>
  8. <div class="part center">
  9. <el-input ref="input" placeholder="URL книги" v-model="bookUrl">
  10. <el-button slot="append" icon="el-icon-check" @click="submitUrl"></el-button>
  11. </el-input>
  12. <div class="space"></div>
  13. <el-button size="mini" @click="loadFle">
  14. Загрузить файл с диска
  15. </el-button>
  16. </div>
  17. <div class="part bottom">
  18. <span v-if="config.mode == 'omnireader'" class="bottom-span clickable" @click="openComments">Комментарии</span>
  19. <span class="bottom-span clickable" @click="openHelp">Справка</span>
  20. <span class="bottom-span">{{ version }}</span>
  21. </div>
  22. <ProgressPage ref="progress"></ProgressPage>
  23. </div>
  24. </template>
  25. <script>
  26. //-----------------------------------------------------------------------------
  27. import Vue from 'vue';
  28. import Component from 'vue-class-component';
  29. import ProgressPage from '../ProgressPage/ProgressPage.vue';
  30. import readerApi from '../../../api/reader';
  31. export default @Component({
  32. components: {
  33. ProgressPage
  34. }
  35. })
  36. class LoaderPage extends Vue {
  37. bookUrl = null;
  38. loadPercent = 0;
  39. created() {
  40. this.commit = this.$store.commit;
  41. this.dispatch = this.$store.dispatch;
  42. this.config = this.$store.state.config;
  43. }
  44. mounted() {
  45. this.progress = this.$refs.progress;
  46. }
  47. activated() {
  48. this.$refs.input.focus();
  49. }
  50. get title() {
  51. if (this.config.mode == 'omnireader')
  52. return 'Omni Reader - браузерная онлайн-читалка.';
  53. return 'Универсальная читалка книг и ресурсов интернета.';
  54. }
  55. get version() {
  56. return `v${this.config.version}`;
  57. }
  58. async submitUrl() {
  59. if (this.bookUrl) {
  60. this.progress.show();
  61. this.progress.setState({totalSteps: 4});
  62. try {
  63. const book = await readerApi.loadBook(this.bookUrl, (state) => {
  64. this.progress.setState(state);
  65. });
  66. this.progress.hide();
  67. } catch (e) {
  68. this.progress.hide();
  69. this.$refs.input.blur();
  70. this.$alert(e.message, 'Ошибка', {type: 'error'});
  71. }
  72. }
  73. }
  74. loadFle() {
  75. }
  76. openHelp() {
  77. }
  78. openComments() {
  79. window.open('http://samlib.ru/comment/b/bookpauk/bookpauk_reader', '_blank');
  80. }
  81. keyHook(event) {
  82. //недостатки сторонних ui
  83. if (document.activeElement === this.$refs.input.$refs.input && event.type == 'keyup' && event.key == 'Enter') {
  84. this.submitUrl();
  85. }
  86. }
  87. }
  88. //-----------------------------------------------------------------------------
  89. </script>
  90. <style scoped>
  91. .main {
  92. flex: 1;
  93. display: flex;
  94. flex-direction: column;
  95. }
  96. .part {
  97. flex: 1;
  98. display: flex;
  99. flex-direction: column;
  100. justify-content: center;
  101. align-items: center;
  102. }
  103. .greeting {
  104. font-size: 130%;
  105. line-height: 170%;
  106. }
  107. .bold-font {
  108. font-weight: bold;
  109. }
  110. .clickable {
  111. color: blue;
  112. text-decoration: underline;
  113. cursor: pointer;
  114. }
  115. .center {
  116. justify-content: flex-start;
  117. padding: 0 10px 0 10px;
  118. }
  119. .bottom {
  120. justify-content: flex-end;
  121. }
  122. .bottom-span {
  123. font-size: 70%;
  124. margin-bottom: 10px;
  125. }
  126. .el-input {
  127. max-width: 700px;
  128. }
  129. .space {
  130. height: 20px;
  131. }
  132. </style>