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