HistoryPage.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. Последние 100 открытых книг
  7. </template>
  8. <el-table
  9. :data="tableData"
  10. style="width: 100%"
  11. size="mini"
  12. height="1px"
  13. stripe
  14. border
  15. :default-sort = "{prop: 'touchDateTime', order: 'descending'}"
  16. :header-cell-style = "headerCellStyle"
  17. >
  18. <el-table-column
  19. prop="touchDateTime"
  20. min-width="90px"
  21. sortable
  22. >
  23. <template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
  24. <span style="font-size: 90%">Время<br>просм.</span>
  25. </template>
  26. <template slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
  27. <div class="desc" @click="loadBook(scope.row.url)">
  28. {{ scope.row.touchDate }}<br>
  29. {{ scope.row.touchTime }}
  30. </div>
  31. </template>
  32. </el-table-column>
  33. <el-table-column
  34. >
  35. <template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
  36. <!--el-input ref="input"
  37. :value="search" @input="search = $event"
  38. size="mini"
  39. style="margin: 0; padding: 0; vertical-align: bottom; margin-top: 10px"
  40. placeholder="Найти"/-->
  41. <div class="el-input el-input--mini">
  42. <input class="el-input__inner"
  43. placeholder="Найти"
  44. style="margin: 0; padding: 0; vertical-align: bottom; margin-top: 20px; padding: 0 10px 0 10px"
  45. :value="search" @input="search = $event.target.value"
  46. />
  47. </div>
  48. </template>
  49. <el-table-column
  50. min-width="300px"
  51. >
  52. <template slot-scope="scope">
  53. <div class="desc" @click="loadBook(scope.row.url)">
  54. <span style="color: green">{{ scope.row.desc.author }}</span><br>
  55. <span>{{ scope.row.desc.title }}</span>
  56. </div>
  57. </template>
  58. </el-table-column>
  59. <el-table-column
  60. min-width="100px"
  61. >
  62. <template slot-scope="scope">
  63. <a :href="scope.row.url" target="_blank">Оригинал</a><br>
  64. <a :href="scope.row.path" :download="getFileNameFromPath(scope.row.path)">Скачать FB2</a>
  65. </template>
  66. </el-table-column>
  67. <el-table-column
  68. width="60px"
  69. >
  70. <template slot-scope="scope">
  71. <el-button
  72. size="mini"
  73. style="width: 30px; padding: 7px 0 7px 0; margin-left: 4px"
  74. @click="handleDel(scope.row.key)"><i class="el-icon-close"></i>
  75. </el-button>
  76. </template>
  77. </el-table-column>
  78. </el-table-column>
  79. </el-table>
  80. </Window>
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. //-----------------------------------------------------------------------------
  86. import Vue from 'vue';
  87. import Component from 'vue-class-component';
  88. import path from 'path';
  89. import _ from 'lodash';
  90. import {formatDate} from '../../../share/utils';
  91. import Window from '../../share/Window.vue';
  92. export default @Component({
  93. components: {
  94. Window,
  95. },
  96. })
  97. class HistoryPage extends Vue {
  98. search = null;
  99. created() {
  100. this.commit = this.$store.commit;
  101. this.reader = this.$store.state.reader;
  102. }
  103. get tableData() {
  104. const state = this.reader;
  105. let result = [];
  106. for (let bookKey in state.openedBook) {
  107. const book = state.openedBook[bookKey];
  108. let d = new Date();
  109. d.setTime(book.touchTime);
  110. const t = formatDate(d).split(' ');
  111. let perc = '';
  112. let textLen = '';
  113. const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
  114. if (book.textLength) {
  115. perc = ` [${((p/book.textLength)*100).toFixed(2)}%]`;
  116. textLen = ` ${Math.round(book.textLength/1000)}k`;
  117. }
  118. result.push({
  119. touchDateTime: book.touchTime,
  120. touchDate: t[0],
  121. touchTime: t[1],
  122. desc: {
  123. title: `"${book.fb2.bookTitle}"${perc}${textLen}`,
  124. author: _.compact([
  125. book.fb2.lastName,
  126. book.fb2.firstName,
  127. book.fb2.middleName
  128. ]).join(' '),
  129. },
  130. url: book.url,
  131. path: book.path,
  132. key: book.key,
  133. });
  134. }
  135. const search = this.search;
  136. return result.filter(item => {
  137. return !search ||
  138. item.touchTime.includes(search) ||
  139. item.touchDate.includes(search) ||
  140. item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
  141. item.desc.author.toLowerCase().includes(search.toLowerCase())
  142. });
  143. }
  144. headerCellStyle(cell) {
  145. let result = {margin: 0, padding: 0};
  146. if (cell.columnIndex > 0) {
  147. result['border-bottom'] = 0;
  148. }
  149. if (cell.rowIndex > 0) {
  150. result.height = '0px';
  151. result['border-right'] = 0;
  152. }
  153. return result;
  154. }
  155. getFileNameFromPath(fb2Path) {
  156. return path.basename(fb2Path).substr(0, 10) + '.fb2';
  157. }
  158. openOriginal(url) {
  159. window.open(url, '_blank');
  160. }
  161. openFb2(path) {
  162. window.open(path, '_blank');
  163. }
  164. handleDel(key) {
  165. this.commit('reader/delOpenedBook', {key});
  166. }
  167. loadBook(url) {
  168. this.$emit('load-book', {url});
  169. }
  170. close() {
  171. this.$emit('history-toggle');
  172. }
  173. keyHook(event) {
  174. if (event.type == 'keydown' && event.code == 'Escape') {
  175. this.close();
  176. }
  177. return true;
  178. }
  179. }
  180. //-----------------------------------------------------------------------------
  181. </script>
  182. <style scoped>
  183. .main {
  184. position: absolute;
  185. width: 100%;
  186. height: 100%;
  187. z-index: 50;
  188. display: flex;
  189. flex-direction: column;
  190. align-items: center;
  191. }
  192. .mainWindow {
  193. height: 100%;
  194. display: flex;
  195. }
  196. .desc {
  197. cursor: pointer;
  198. }
  199. </style>