HistoryPage.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div ref="main" class="main" @click="close">
  3. <div class="clickStop" @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. <a :href="scope.row.url" target="_blank">Оригинал</a><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. let textLen = '';
  106. const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
  107. if (book.textLength) {
  108. perc = ` [${((p/book.textLength)*100).toFixed(2)}%]`;
  109. textLen = ` ${Math.round(book.textLength/1000)}k`;
  110. }
  111. result.push({
  112. touchDateTime: book.touchTime,
  113. touchDate: t[0],
  114. touchTime: t[1],
  115. desc: {
  116. title: `"${book.fb2.bookTitle}"${perc}${textLen}`,
  117. author: _.compact([
  118. book.fb2.lastName,
  119. book.fb2.firstName,
  120. book.fb2.middleName
  121. ]).join(' '),
  122. },
  123. url: book.url,
  124. path: book.path,
  125. key: book.key,
  126. });
  127. }
  128. const search = this.search;
  129. return result.filter(item => {
  130. return !search ||
  131. item.touchTime.includes(search) ||
  132. item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
  133. item.desc.author.toLowerCase().includes(search.toLowerCase())
  134. });
  135. }
  136. headerCellStyle(cell) {
  137. let result = {margin: 0, padding: 0};
  138. if (cell.columnIndex > 0) {
  139. result['border-bottom'] = 0;
  140. }
  141. if (cell.rowIndex > 0) {
  142. result.height = '0px';
  143. result['border-right'] = 0;
  144. }
  145. return result;
  146. }
  147. getFileNameFromPath(fb2Path) {
  148. return path.basename(fb2Path).substr(0, 10) + '.fb2';
  149. }
  150. openOriginal(url) {
  151. window.open(url, '_blank');
  152. }
  153. openFb2(path) {
  154. window.open(path, '_blank');
  155. }
  156. handleDel(key) {
  157. this.commit('reader/delOpenedBook', {key});
  158. }
  159. loadBook(url) {
  160. this.$emit('load-book', {url});
  161. this.close();
  162. }
  163. close() {
  164. this.$emit('history-toggle');
  165. }
  166. keyHook(event) {
  167. if (event.type == 'keydown' && event.code == 'Escape') {
  168. this.close();
  169. }
  170. return true;
  171. }
  172. }
  173. //-----------------------------------------------------------------------------
  174. </script>
  175. <style scoped>
  176. .main {
  177. position: absolute;
  178. width: 100%;
  179. height: 100%;
  180. z-index: 50;
  181. display: flex;
  182. flex-direction: column;
  183. align-items: center;
  184. }
  185. .clickStop {
  186. height: 100%;
  187. display: flex;
  188. }
  189. .header {
  190. margin: 0;
  191. padding: 0;
  192. }
  193. .desc {
  194. cursor: pointer;
  195. }
  196. </style>