LoaderPage.vue 6.3 KB

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