HistoryPage.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. Время<br>просм.
  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. @click="handleDel(scope.row.key)">X
  67. </el-button>
  68. </template>
  69. </el-table-column>
  70. </el-table-column>
  71. </el-table>
  72. </Window>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. //-----------------------------------------------------------------------------
  78. import Vue from 'vue';
  79. import Component from 'vue-class-component';
  80. import path from 'path';
  81. import _ from 'lodash';
  82. import {formatDate} from '../../../share/utils';
  83. import Window from '../../share/Window.vue';
  84. export default @Component({
  85. components: {
  86. Window,
  87. },
  88. })
  89. class HistoryPage extends Vue {
  90. search = null;
  91. created() {
  92. this.commit = this.$store.commit;
  93. this.reader = this.$store.state.reader;
  94. }
  95. get tableData() {
  96. const state = this.reader;
  97. let result = [];
  98. for (let bookKey in state.openedBook) {
  99. const book = state.openedBook[bookKey];
  100. let d = new Date();
  101. d.setTime(book.touchTime);
  102. const t = formatDate(d).split(' ');
  103. let perc = '';
  104. const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
  105. if (book.textLength)
  106. perc = ` [${((p/book.textLength)*100).toFixed(2)}%]`;
  107. result.push({
  108. touchDateTime: book.touchTime,
  109. touchDate: t[0],
  110. touchTime: t[1],
  111. desc: {
  112. title: `"${book.fb2.bookTitle}"${perc}`,
  113. author: _.compact([
  114. book.fb2.lastName,
  115. book.fb2.firstName,
  116. book.fb2.middleName
  117. ]).join(' '),
  118. },
  119. url: book.url,
  120. path: book.path,
  121. key: book.key,
  122. });
  123. }
  124. const search = this.search;
  125. return result.filter(item => {
  126. return !search ||
  127. item.touchTime.includes(search) ||
  128. item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
  129. item.desc.author.toLowerCase().includes(search.toLowerCase())
  130. });
  131. }
  132. headerCellStyle(cell) {
  133. let result = {margin: 0, padding: 0};
  134. if (cell.columnIndex > 0) {
  135. result['border-bottom'] = 0;
  136. }
  137. if (cell.rowIndex > 0) {
  138. result.height = '0px';
  139. result['border-right'] = 0;
  140. }
  141. return result;
  142. }
  143. getFileNameFromPath(fb2Path) {
  144. return path.basename(fb2Path).substr(0, 10) + '.fb2';
  145. }
  146. openOriginal(url) {
  147. window.open(url, '_blank');
  148. }
  149. openFb2(path) {
  150. window.open(path, '_blank');
  151. }
  152. handleDel(key) {
  153. this.commit('reader/delOpenedBook', {key});
  154. }
  155. loadBook(url) {
  156. this.$emit('load-book', {url});
  157. this.close();
  158. }
  159. close() {
  160. this.$emit('history-toggle');
  161. }
  162. keyHook(event) {
  163. if (event.type == 'keydown' && event.code == 'Escape') {
  164. this.close();
  165. return true;
  166. }
  167. }
  168. }
  169. //-----------------------------------------------------------------------------
  170. </script>
  171. <style scoped>
  172. .main {
  173. flex: 1;
  174. display: flex;
  175. flex-direction: column;
  176. align-items: center;
  177. }
  178. .header {
  179. margin: 0;
  180. padding: 0;
  181. }
  182. .clickable {
  183. color: blue;
  184. text-decoration: underline;
  185. cursor: pointer;
  186. }
  187. .desc {
  188. cursor: pointer;
  189. }
  190. </style>