PasteTextPage.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div ref="main" class="main" @click="close">
  3. <div class="mainWindow" @click.stop>
  4. <Window @close="close">
  5. <template slot="header">
  6. Вставьте текст и нажмите
  7. <el-button size="mini" style="font-size: 120%; color: blue" @click="loadBuffer">Загрузить</el-button>
  8. или F2
  9. </template>
  10. <div>
  11. <el-input placeholder="Введите название текста" class="input" v-model="bookTitle"></el-input>
  12. </div>
  13. <hr/>
  14. <textarea ref="textArea" class="text" @paste="calcTitle"></textarea>
  15. </Window>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. //-----------------------------------------------------------------------------
  21. import Vue from 'vue';
  22. import Component from 'vue-class-component';
  23. import Window from '../../../share/Window.vue';
  24. import _ from 'lodash';
  25. import * as utils from '../../../../share/utils';
  26. export default @Component({
  27. components: {
  28. Window,
  29. },
  30. })
  31. class PasteTextPage extends Vue {
  32. bookTitle = '';
  33. created() {
  34. }
  35. mounted() {
  36. this.$refs.textArea.focus();
  37. }
  38. getNonEmptyLine3words(text, count) {
  39. let result = '';
  40. const lines = text.split("\n");
  41. let i = 0;
  42. while (i < lines.length) {
  43. if (lines[i].trim() != '') {
  44. count--;
  45. if (count <= 0) {
  46. result = lines[i];
  47. break;
  48. }
  49. }
  50. i++;
  51. }
  52. result = result.trim().split(' ');
  53. return result.slice(0, 3).join(' ');
  54. }
  55. calcTitle(event) {
  56. if (this.bookTitle == '') {
  57. let text = event.clipboardData.getData('text');
  58. this.bookTitle = `Из буфера обмена ${utils.formatDate(new Date(), 'noDate')}: ` + _.compact([
  59. this.getNonEmptyLine3words(text, 1),
  60. this.getNonEmptyLine3words(text, 2)
  61. ]).join(' - ');
  62. }
  63. }
  64. loadBuffer() {
  65. this.$emit('load-buffer', {buffer: `<cut-title>${this.bookTitle}</cut-title>${this.$refs.textArea.value}`});
  66. this.close();
  67. }
  68. close() {
  69. this.$emit('paste-text-toggle');
  70. }
  71. keyHook(event) {
  72. if (event.type == 'keydown') {
  73. switch (event.code) {
  74. case 'F2':
  75. this.loadBuffer();
  76. break;
  77. case 'Escape':
  78. this.close();
  79. break;
  80. }
  81. }
  82. return true;
  83. }
  84. }
  85. //-----------------------------------------------------------------------------
  86. </script>
  87. <style scoped>
  88. .main {
  89. position: absolute;
  90. width: 100%;
  91. height: 100%;
  92. z-index: 40;
  93. display: flex;
  94. flex-direction: column;
  95. justify-content: center;
  96. align-items: center;
  97. }
  98. .mainWindow {
  99. width: 100%;
  100. height: 100%;
  101. display: flex;
  102. }
  103. .text {
  104. flex: 1;
  105. overflow-wrap: anywhere;
  106. overflow-y: auto;
  107. padding: 0 10px 0 10px;
  108. position: relative;
  109. font-size: 120%;
  110. }
  111. .text:focus {
  112. outline: none;
  113. }
  114. hr {
  115. margin: 0;
  116. padding: 0;
  117. }
  118. </style>