LoaderPage.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div ref="main" class="main">
  3. <div class="part">
  4. <span class="greeting bold-font">{{ title }}</span>
  5. <div class="space"></div>
  6. <span class="greeting">Добро пожаловать!</span>
  7. <span class="greeting">Поддерживаются форматы: <b>fb2, html, txt</b> и сжатие: <b>zip, bz2, gz</b></span>
  8. <span v-if="isExternalConverter" class="greeting">...а также форматы: <b>rtf, doc, docx, pdf, epub, mobi</b></span>
  9. </div>
  10. <div class="part center">
  11. <el-input ref="input" placeholder="URL книги" v-model="bookUrl">
  12. <el-button slot="append" icon="el-icon-check" @click="submitUrl"></el-button>
  13. </el-input>
  14. <div class="space"></div>
  15. <input type="file" id="file" ref="file" @change="loadFile" style='display: none;'/>
  16. <el-button size="mini" @click="loadFileClick">
  17. Загрузить файл с диска
  18. </el-button>
  19. <div class="space"></div>
  20. <el-button size="mini" @click="loadBufferClick">
  21. Из буфера обмена
  22. </el-button>
  23. <div class="space"></div>
  24. <span v-if="mode == 'omnireader'" class="bottom-span clickable" @click="openComments">Комментарии</span>
  25. </div>
  26. <div class="part bottom">
  27. <span class="bottom-span clickable" @click="openHelp">Справка</span>
  28. <span class="bottom-span clickable" @click="openDonate">Помочь проекту</span>
  29. <span class="bottom-span">{{ version }}</span>
  30. </div>
  31. <PasteTextPage v-if="pasteTextActive" ref="pasteTextPage" @paste-text-toggle="pasteTextToggle" @load-buffer="loadBuffer"></PasteTextPage>
  32. </div>
  33. </template>
  34. <script>
  35. //-----------------------------------------------------------------------------
  36. import Vue from 'vue';
  37. import Component from 'vue-class-component';
  38. import PasteTextPage from './PasteTextPage/PasteTextPage.vue';
  39. export default @Component({
  40. components: {
  41. PasteTextPage,
  42. },
  43. })
  44. class LoaderPage extends Vue {
  45. bookUrl = null;
  46. loadPercent = 0;
  47. pasteTextActive = false;
  48. created() {
  49. this.commit = this.$store.commit;
  50. }
  51. mounted() {
  52. this.progress = this.$refs.progress;
  53. }
  54. activated() {
  55. this.$refs.input.focus();
  56. }
  57. get title() {
  58. if (this.$store.state.config.mode == 'omnireader')
  59. return 'Omni Reader - браузерная онлайн-читалка.';
  60. return 'Универсальная читалка книг и ресурсов интернета.';
  61. }
  62. get mode() {
  63. return this.$store.state.config.mode;
  64. }
  65. get version() {
  66. return `v${this.$store.state.config.version}`;
  67. }
  68. get isExternalConverter() {
  69. return this.$store.state.config.useExternalBookConverter;
  70. }
  71. submitUrl() {
  72. if (this.bookUrl) {
  73. this.$emit('load-book', {url: this.bookUrl});
  74. this.bookUrl = '';
  75. }
  76. }
  77. loadFileClick() {
  78. this.$refs.file.click();
  79. }
  80. loadFile() {
  81. const file = this.$refs.file.files[0];
  82. this.$refs.file.value = '';
  83. if (file)
  84. this.$emit('load-file', {file});
  85. }
  86. loadBufferClick() {
  87. this.pasteTextToggle();
  88. }
  89. loadBuffer(opts) {
  90. if (opts.buffer.length) {
  91. const file = new File([opts.buffer], 'dummyName-PasteFromClipboard');
  92. this.$emit('load-file', {file});
  93. }
  94. }
  95. pasteTextToggle() {
  96. this.pasteTextActive = !this.pasteTextActive;
  97. }
  98. openHelp() {
  99. this.$emit('help-toggle');
  100. }
  101. openDonate() {
  102. this.$emit('donate-toggle');
  103. }
  104. openComments() {
  105. window.open('http://samlib.ru/comment/b/bookpauk/bookpauk_reader', '_blank');
  106. }
  107. keyHook(event) {
  108. if (this.pasteTextActive) {
  109. return this.$refs.pasteTextPage.keyHook(event);
  110. }
  111. //недостатки сторонних ui
  112. const input = this.$refs.input.$refs.input;
  113. if (document.activeElement === input && event.type == 'keydown' && event.code == 'Enter') {
  114. this.submitUrl();
  115. }
  116. if (event.type == 'keydown' && (event.code == 'F1' || (document.activeElement !== input && event.code == 'KeyH'))) {
  117. this.$emit('help-toggle');
  118. event.preventDefault();
  119. event.stopPropagation();
  120. return true;
  121. }
  122. if (event.type == 'keydown' && (document.activeElement !== input && event.code == 'KeyQ')) {
  123. this.$emit('tool-bar-toggle');
  124. event.preventDefault();
  125. event.stopPropagation();
  126. return true;
  127. }
  128. }
  129. }
  130. //-----------------------------------------------------------------------------
  131. </script>
  132. <style scoped>
  133. .main {
  134. flex: 1;
  135. display: flex;
  136. flex-direction: column;
  137. min-height: 340px;
  138. }
  139. .part {
  140. flex: 1;
  141. display: flex;
  142. flex-direction: column;
  143. justify-content: center;
  144. align-items: center;
  145. }
  146. .greeting {
  147. font-size: 120%;
  148. line-height: 160%;
  149. }
  150. .bold-font {
  151. font-weight: bold;
  152. }
  153. .clickable {
  154. color: blue;
  155. text-decoration: underline;
  156. cursor: pointer;
  157. }
  158. .center {
  159. justify-content: flex-start;
  160. padding: 0 10px 0 10px;
  161. }
  162. .bottom {
  163. justify-content: flex-end;
  164. }
  165. .bottom-span {
  166. font-size: 70%;
  167. margin-bottom: 10px;
  168. }
  169. .el-input {
  170. max-width: 700px;
  171. }
  172. .space {
  173. height: 20px;
  174. }
  175. </style>