HistoryPage.vue 6.9 KB

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