CopyTextPage.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. </template>
  8. </Window>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. //-----------------------------------------------------------------------------
  14. import Vue from 'vue';
  15. import Component from 'vue-class-component';
  16. import Window from '../../share/Window.vue';
  17. import {sleep} from '../../../share/utils';
  18. export default @Component({
  19. components: {
  20. Window,
  21. },
  22. })
  23. class CopyTextPage extends Vue {
  24. initStep = null;
  25. initPercentage = 0;
  26. created() {
  27. this.commit = this.$store.commit;
  28. this.reader = this.$store.state.reader;
  29. }
  30. async init(bookPos, parsed) {
  31. if (this.parsed != parsed) {
  32. this.initStep = true;
  33. this.stopInit = false;
  34. let nextPerc = 0;
  35. let text = '';
  36. for (let i = 0; i < parsed.para.length; i++) {
  37. const p = parsed.para[i];
  38. const parts = parsed.splitToStyle(p.text);
  39. if (this.stopInit)
  40. return;
  41. for (const part of parts)
  42. text += part.text;
  43. const perc = Math.round(i/parsed.para.length*100);
  44. if (perc > nextPerc) {
  45. this.initPercentage = perc;
  46. await sleep(1);
  47. nextPerc = perc + 10;
  48. }
  49. }
  50. this.initStep = false;
  51. this.parsed = parsed;
  52. }
  53. }
  54. close() {
  55. this.stopInit = true;
  56. this.$emit('copy-text-toggle');
  57. }
  58. keyHook(event) {
  59. if (event.type == 'keydown' && (event.code == 'Escape')) {
  60. this.close();
  61. }
  62. return true;
  63. }
  64. }
  65. //-----------------------------------------------------------------------------
  66. </script>
  67. <style scoped>
  68. .main {
  69. position: absolute;
  70. width: 100%;
  71. height: 100%;
  72. z-index: 40;
  73. display: flex;
  74. flex-direction: column;
  75. justify-content: center;
  76. align-items: center;
  77. }
  78. .mainWindow {
  79. width: 100%;
  80. max-width: 500px;
  81. height: 125px;
  82. display: flex;
  83. position: relative;
  84. top: -50px;
  85. }
  86. .content {
  87. flex: 1;
  88. display: flex;
  89. justify-content: center;
  90. align-items: center;
  91. padding: 10px;
  92. }
  93. .input {
  94. display: flex;
  95. margin: 0;
  96. padding: 0;
  97. width: 100%;
  98. position: relative;
  99. }
  100. .button-group {
  101. width: 150px;
  102. margin: 0;
  103. padding: 0;
  104. }
  105. .el-button {
  106. padding: 9px 17px 9px 17px;
  107. }
  108. i {
  109. font-size: 20px;
  110. }
  111. </style>