LoaderPage.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.$alert(e.message, 'Ошибка', {type: 'error'});
  70. }
  71. }
  72. }
  73. loadFle() {
  74. }
  75. openHelp() {
  76. }
  77. openComments() {
  78. window.open('http://samlib.ru/comment/b/bookpauk/bookpauk_reader', '_blank');
  79. }
  80. keyHook(event) {
  81. //недостатки сторонних ui
  82. if (document.activeElement == this.$refs.input.$refs.input && event.type == 'keyup' && event.key == 'Enter')
  83. this.submitUrl();
  84. }
  85. }
  86. //-----------------------------------------------------------------------------
  87. </script>
  88. <style scoped>
  89. .main {
  90. flex: 1;
  91. display: flex;
  92. flex-direction: column;
  93. }
  94. .part {
  95. flex: 1;
  96. display: flex;
  97. flex-direction: column;
  98. justify-content: center;
  99. align-items: center;
  100. }
  101. .greeting {
  102. font-size: 130%;
  103. line-height: 170%;
  104. }
  105. .bold-font {
  106. font-weight: bold;
  107. }
  108. .clickable {
  109. color: blue;
  110. text-decoration: underline;
  111. cursor: pointer;
  112. }
  113. .center {
  114. justify-content: flex-start;
  115. padding: 0 10px 0 10px;
  116. }
  117. .bottom {
  118. justify-content: flex-end;
  119. }
  120. .bottom-span {
  121. font-size: 70%;
  122. margin-bottom: 10px;
  123. }
  124. .el-input {
  125. max-width: 700px;
  126. }
  127. .space {
  128. height: 20px;
  129. }
  130. </style>