HistoryPage.vue 6.4 KB

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