HistoryPage.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. import bookManager from '../share/bookManager';
  93. export default @Component({
  94. components: {
  95. Window,
  96. },
  97. watch: {
  98. search: function() {
  99. this.updateTableData();
  100. }
  101. },
  102. })
  103. class HistoryPage extends Vue {
  104. search = null;
  105. tableData = null;
  106. created() {
  107. }
  108. mounted() {
  109. this.updateTableData();
  110. this.mostRecentBook = bookManager.mostRecentBook();
  111. }
  112. updateTableData() {
  113. let result = [];
  114. for (let bookKey in bookManager.recent) {
  115. const book = bookManager.recent[bookKey];
  116. let d = new Date();
  117. d.setTime(book.touchTime);
  118. const t = formatDate(d).split(' ');
  119. let perc = '';
  120. let textLen = '';
  121. const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
  122. if (book.textLength) {
  123. perc = ` [${((p/book.textLength)*100).toFixed(2)}%]`;
  124. textLen = ` ${Math.round(book.textLength/1000)}k`;
  125. }
  126. const fb2 = (book.fb2 ? book.fb2 : {});
  127. result.push({
  128. touchDateTime: book.touchTime,
  129. touchDate: t[0],
  130. touchTime: t[1],
  131. desc: {
  132. title: `"${fb2.bookTitle}"${perc}${textLen}`,
  133. author: _.compact([
  134. fb2.lastName,
  135. fb2.firstName,
  136. fb2.middleName
  137. ]).join(' '),
  138. },
  139. url: book.url,
  140. path: book.path,
  141. key: book.key,
  142. });
  143. }
  144. const search = this.search;
  145. this.tableData = result.filter(item => {
  146. return !search ||
  147. item.touchTime.includes(search) ||
  148. item.touchDate.includes(search) ||
  149. item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
  150. item.desc.author.toLowerCase().includes(search.toLowerCase())
  151. });
  152. }
  153. headerCellStyle(cell) {
  154. let result = {margin: 0, padding: 0};
  155. if (cell.columnIndex > 0) {
  156. result['border-bottom'] = 0;
  157. }
  158. if (cell.rowIndex > 0) {
  159. result.height = '0px';
  160. result['border-right'] = 0;
  161. }
  162. return result;
  163. }
  164. getFileNameFromPath(fb2Path) {
  165. return path.basename(fb2Path).substr(0, 10) + '.fb2';
  166. }
  167. openOriginal(url) {
  168. window.open(url, '_blank');
  169. }
  170. openFb2(path) {
  171. window.open(path, '_blank');
  172. }
  173. async handleDel(key) {
  174. await bookManager.delRecentBook({key});
  175. this.updateTableData();
  176. const newRecent = bookManager.mostRecentBook();
  177. if (this.mostRecentBook != newRecent)
  178. this.$emit('load-book', newRecent);
  179. this.mostRecentBook = newRecent;
  180. if (!this.mostRecentBook)
  181. this.close();
  182. }
  183. loadBook(url) {
  184. if (this.mostRecentBook.url != url)
  185. this.$emit('load-book', {url});
  186. this.close();
  187. }
  188. close() {
  189. this.$emit('history-toggle');
  190. }
  191. keyHook(event) {
  192. if (event.type == 'keydown' && event.code == 'Escape') {
  193. this.close();
  194. }
  195. return true;
  196. }
  197. }
  198. //-----------------------------------------------------------------------------
  199. </script>
  200. <style scoped>
  201. .main {
  202. position: absolute;
  203. width: 100%;
  204. height: 100%;
  205. z-index: 50;
  206. display: flex;
  207. flex-direction: column;
  208. align-items: center;
  209. }
  210. .mainWindow {
  211. height: 100%;
  212. display: flex;
  213. }
  214. .desc {
  215. cursor: pointer;
  216. }
  217. </style>