HistoryPage.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 v-show="isUrl(scope.row.url)" :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. const sorted = bookManager.getSortedRecent();
  115. const len = (sorted.length < 100 ? sorted.length : 100);
  116. for (let i = 0; i < len; i++) {
  117. const book = sorted[i];
  118. let d = new Date();
  119. d.setTime(book.touchTime);
  120. const t = formatDate(d).split(' ');
  121. let perc = '';
  122. let textLen = '';
  123. const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
  124. if (book.textLength) {
  125. perc = ` [${((p/book.textLength)*100).toFixed(2)}%]`;
  126. textLen = ` ${Math.round(book.textLength/1000)}k`;
  127. }
  128. const fb2 = (book.fb2 ? book.fb2 : {});
  129. let title = fb2.bookTitle;
  130. if (title)
  131. title = `"${title}"`;
  132. else
  133. title = '';
  134. let author = _.compact([
  135. fb2.lastName,
  136. fb2.firstName,
  137. fb2.middleName
  138. ]).join(' ');
  139. author = (author ? author : (fb2.bookTitle ? fb2.bookTitle : book.url));
  140. result.push({
  141. touchDateTime: book.touchTime,
  142. touchDate: t[0],
  143. touchTime: t[1],
  144. desc: {
  145. title: `${title}${perc}${textLen}`,
  146. author,
  147. },
  148. url: book.url,
  149. path: book.path,
  150. key: book.key,
  151. });
  152. }
  153. const search = this.search;
  154. this.tableData = result.filter(item => {
  155. return !search ||
  156. item.touchTime.includes(search) ||
  157. item.touchDate.includes(search) ||
  158. item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
  159. item.desc.author.toLowerCase().includes(search.toLowerCase())
  160. });
  161. }
  162. headerCellStyle(cell) {
  163. let result = {margin: 0, padding: 0};
  164. if (cell.columnIndex > 0) {
  165. result['border-bottom'] = 0;
  166. }
  167. if (cell.rowIndex > 0) {
  168. result.height = '0px';
  169. result['border-right'] = 0;
  170. }
  171. return result;
  172. }
  173. getFileNameFromPath(fb2Path) {
  174. return path.basename(fb2Path).substr(0, 10) + '.fb2';
  175. }
  176. openOriginal(url) {
  177. window.open(url, '_blank');
  178. }
  179. openFb2(path) {
  180. window.open(path, '_blank');
  181. }
  182. async handleDel(key) {
  183. await bookManager.delRecentBook({key});
  184. this.updateTableData();
  185. const newRecent = bookManager.mostRecentBook();
  186. if (this.mostRecentBook != newRecent)
  187. this.$emit('load-book', newRecent);
  188. this.mostRecentBook = newRecent;
  189. if (!this.mostRecentBook)
  190. this.close();
  191. }
  192. loadBook(url) {
  193. this.$emit('load-book', {url});
  194. this.close();
  195. }
  196. isUrl(url) {
  197. return (url.indexOf('file://') != 0);
  198. }
  199. close() {
  200. this.$emit('history-toggle');
  201. }
  202. keyHook(event) {
  203. if (event.type == 'keydown' && event.code == 'Escape') {
  204. this.close();
  205. }
  206. return true;
  207. }
  208. }
  209. //-----------------------------------------------------------------------------
  210. </script>
  211. <style scoped>
  212. .main {
  213. position: absolute;
  214. width: 100%;
  215. height: 100%;
  216. z-index: 50;
  217. display: flex;
  218. flex-direction: column;
  219. align-items: center;
  220. }
  221. .mainWindow {
  222. height: 100%;
  223. display: flex;
  224. }
  225. .desc {
  226. cursor: pointer;
  227. }
  228. </style>