HistoryPage.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. :row-key = "rowKey"
  18. >
  19. <el-table-column
  20. type="index"
  21. width="35px"
  22. >
  23. </el-table-column>
  24. <el-table-column
  25. prop="touchDateTime"
  26. min-width="90px"
  27. sortable
  28. >
  29. <template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
  30. <span style="font-size: 90%">Время<br>просм.</span>
  31. </template>
  32. <template slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
  33. <div class="desc" @click="loadBook(scope.row.url)">
  34. {{ scope.row.touchDate }}<br>
  35. {{ scope.row.touchTime }}
  36. </div>
  37. </template>
  38. </el-table-column>
  39. <el-table-column
  40. >
  41. <template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
  42. <!--el-input ref="input"
  43. :value="search" @input="search = $event"
  44. size="mini"
  45. style="margin: 0; padding: 0; vertical-align: bottom; margin-top: 10px"
  46. placeholder="Найти"/-->
  47. <div class="el-input el-input--mini">
  48. <input class="el-input__inner"
  49. ref="input"
  50. placeholder="Найти"
  51. style="margin: 0; padding: 0; vertical-align: bottom; margin-top: 20px; padding: 0 10px 0 10px"
  52. :value="search" @input="search = $event.target.value"
  53. />
  54. </div>
  55. </template>
  56. <el-table-column
  57. min-width="300px"
  58. >
  59. <template slot-scope="scope">
  60. <div class="desc" @click="loadBook(scope.row.url)">
  61. <span style="color: green">{{ scope.row.desc.author }}</span><br>
  62. <span>{{ scope.row.desc.title }}</span>
  63. </div>
  64. </template>
  65. </el-table-column>
  66. <el-table-column
  67. min-width="100px"
  68. >
  69. <template slot-scope="scope">
  70. <a v-show="isUrl(scope.row.url)" :href="scope.row.url" target="_blank">Оригинал</a><br>
  71. <a :href="scope.row.path" :download="getFileNameFromPath(scope.row.path)">Скачать FB2</a>
  72. </template>
  73. </el-table-column>
  74. <el-table-column
  75. width="60px"
  76. >
  77. <template slot-scope="scope">
  78. <el-button
  79. size="mini"
  80. style="width: 30px; padding: 7px 0 7px 0; margin-left: 4px"
  81. @click="handleDel(scope.row.key)"><i class="el-icon-close"></i>
  82. </el-button>
  83. </template>
  84. </el-table-column>
  85. </el-table-column>
  86. </el-table>
  87. </Window>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. //-----------------------------------------------------------------------------
  93. import Vue from 'vue';
  94. import Component from 'vue-class-component';
  95. import path from 'path';
  96. import _ from 'lodash';
  97. import {formatDate} from '../../../share/utils';
  98. import Window from '../../share/Window.vue';
  99. import bookManager from '../share/bookManager';
  100. export default @Component({
  101. components: {
  102. Window,
  103. },
  104. watch: {
  105. search: function() {
  106. this.updateTableData();
  107. }
  108. },
  109. })
  110. class HistoryPage extends Vue {
  111. search = null;
  112. tableData = null;
  113. created() {
  114. }
  115. init() {
  116. this.updateTableData();
  117. this.$nextTick(() => {
  118. this.$refs.input.focus();
  119. });
  120. }
  121. rowKey(row) {
  122. return row.key;
  123. }
  124. updateTableData() {
  125. let result = [];
  126. const sorted = bookManager.getSortedRecent();
  127. for (let i = 0; i < sorted.length; i++) {
  128. const book = sorted[i];
  129. if (book.deleted)
  130. continue;
  131. let d = new Date();
  132. d.setTime(book.touchTime);
  133. const t = formatDate(d).split(' ');
  134. let perc = '';
  135. let textLen = '';
  136. const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
  137. if (book.textLength) {
  138. perc = ` [${((p/book.textLength)*100).toFixed(2)}%]`;
  139. textLen = ` ${Math.round(book.textLength/1000)}k`;
  140. }
  141. const fb2 = (book.fb2 ? book.fb2 : {});
  142. let title = fb2.bookTitle;
  143. if (title)
  144. title = `"${title}"`;
  145. else
  146. title = '';
  147. let author = '';
  148. if (fb2.author) {
  149. const authorNames = fb2.author.map(a => _.compact([
  150. a.lastName,
  151. a.firstName,
  152. a.middleName
  153. ]).join(' '));
  154. author = authorNames.join(', ');
  155. } else {
  156. author = _.compact([
  157. fb2.lastName,
  158. fb2.firstName,
  159. fb2.middleName
  160. ]).join(' ');
  161. }
  162. author = (author ? author : (fb2.bookTitle ? fb2.bookTitle : book.url));
  163. result.push({
  164. touchDateTime: book.touchTime,
  165. touchDate: t[0],
  166. touchTime: t[1],
  167. desc: {
  168. title: `${title}${perc}${textLen}`,
  169. author,
  170. },
  171. url: book.url,
  172. path: book.path,
  173. key: book.key,
  174. });
  175. if (result.length >= 100)
  176. break;
  177. }
  178. const search = this.search;
  179. result = result.filter(item => {
  180. return !search ||
  181. item.touchTime.includes(search) ||
  182. item.touchDate.includes(search) ||
  183. item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
  184. item.desc.author.toLowerCase().includes(search.toLowerCase())
  185. });
  186. this.tableData = result;
  187. }
  188. headerCellStyle(cell) {
  189. let result = {margin: 0, padding: 0};
  190. if (cell.columnIndex > 0) {
  191. result['border-bottom'] = 0;
  192. }
  193. if (cell.rowIndex > 0) {
  194. result.height = '0px';
  195. result['border-right'] = 0;
  196. }
  197. return result;
  198. }
  199. getFileNameFromPath(fb2Path) {
  200. return path.basename(fb2Path).substr(0, 10) + '.fb2';
  201. }
  202. openOriginal(url) {
  203. window.open(url, '_blank');
  204. }
  205. openFb2(path) {
  206. window.open(path, '_blank');
  207. }
  208. async handleDel(key) {
  209. await bookManager.delRecentBook({key});
  210. this.updateTableData();
  211. if (!bookManager.mostRecentBook())
  212. this.close();
  213. }
  214. loadBook(url) {
  215. this.$emit('load-book', {url});
  216. this.close();
  217. }
  218. isUrl(url) {
  219. if (url)
  220. return (url.indexOf('file://') != 0);
  221. else
  222. return false;
  223. }
  224. close() {
  225. this.$emit('history-toggle');
  226. }
  227. keyHook(event) {
  228. if (event.type == 'keydown' && event.code == 'Escape') {
  229. this.close();
  230. }
  231. return true;
  232. }
  233. }
  234. //-----------------------------------------------------------------------------
  235. </script>
  236. <style scoped>
  237. .main {
  238. position: absolute;
  239. width: 100%;
  240. height: 100%;
  241. z-index: 50;
  242. display: flex;
  243. flex-direction: column;
  244. align-items: center;
  245. }
  246. .mainWindow {
  247. height: 100%;
  248. display: flex;
  249. }
  250. .desc {
  251. cursor: pointer;
  252. }
  253. </style>