HistoryPage.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div ref="main" class="main">
  3. <Window class="window">
  4. <template slot="header">
  5. Последние 100 открытых книг
  6. </template>
  7. <el-table
  8. :data="tableData"
  9. style="width: 100%"
  10. size="mini"
  11. height="1px"
  12. stripe
  13. border
  14. :default-sort = "{prop: 'touchTime', order: 'descending'}"
  15. :header-cell-style = "headerCellStyle"
  16. >
  17. <el-table-column
  18. prop="touchTime"
  19. min-width="120px"
  20. sortable
  21. >
  22. <template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
  23. Время<br>просмотра
  24. </template>
  25. </el-table-column>
  26. <el-table-column
  27. >
  28. <template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
  29. <el-input
  30. v-model="search"
  31. size="mini"
  32. style="margin: 0; padding: 0; vertical-align: bottom; margin-top: 10px"
  33. placeholder="Найти"/>
  34. </template>
  35. <el-table-column
  36. min-width="300px"
  37. >
  38. <template slot-scope="scope">
  39. <span>{{ scope.row.desc.author }}</span><br>
  40. <span>{{ `"${scope.row.desc.title}"` }}</span>
  41. </template>
  42. </el-table-column>
  43. <el-table-column
  44. >
  45. <template slot-scope="scope">
  46. <el-button
  47. size="mini"
  48. @click="handleDel(scope.$index, scope.row)">Убрать
  49. </el-button>
  50. </template>
  51. </el-table-column>
  52. </el-table-column>
  53. </el-table>
  54. </Window>
  55. </div>
  56. </template>
  57. <script>
  58. //-----------------------------------------------------------------------------
  59. import Vue from 'vue';
  60. import Component from 'vue-class-component';
  61. import _ from 'lodash';
  62. import {formatDate} from '../../../share/utils';
  63. import Window from '../../share/Window.vue';
  64. export default @Component({
  65. components: {
  66. Window,
  67. },
  68. })
  69. class HistoryPage extends Vue {
  70. search = null;
  71. created() {
  72. this.commit = this.$store.commit;
  73. this.reader = this.$store.state.reader;
  74. }
  75. get tableData() {
  76. const state = this.reader;
  77. let result = [];
  78. for (let bookKey in state.openedBook) {
  79. const book = state.openedBook[bookKey];
  80. let touchTime = new Date();
  81. touchTime.setTime(book.touchTime);
  82. result.push({
  83. touchTime: formatDate(touchTime),
  84. desc: {
  85. title: book.fb2.bookTitle,
  86. author: _.compact([
  87. book.fb2.lastName,
  88. book.fb2.firstName,
  89. book.fb2.middleName
  90. ]).join(' '),
  91. }
  92. });
  93. }
  94. const search = this.search;
  95. return result.filter(item => {
  96. return !search ||
  97. item.touchTime.includes(search) ||
  98. item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
  99. item.desc.author.toLowerCase().includes(search.toLowerCase())
  100. });
  101. }
  102. headerCellStyle(cell) {
  103. let result = {margin: 0, padding: 0};
  104. if (cell.columnIndex > 0) {
  105. result['border-bottom'] = 0;
  106. }
  107. if (cell.rowIndex > 0) {
  108. result.height = '0px';
  109. result['border-right'] = 0;
  110. }
  111. return result;
  112. }
  113. keyHook(event) {
  114. if (event.type == 'keydown' && event.code == 'Escape') {
  115. this.$emit('history-toggle');
  116. return true;
  117. }
  118. }
  119. }
  120. //-----------------------------------------------------------------------------
  121. </script>
  122. <style scoped>
  123. .main {
  124. flex: 1;
  125. display: flex;
  126. flex-direction: column;
  127. align-items: center;
  128. }
  129. .window {
  130. min-width: 200px;
  131. max-width: 600px;
  132. }
  133. .header {
  134. margin: 0;
  135. padding: 0;
  136. }
  137. </style>