HistoryPage.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. >
  16. <el-table-column
  17. prop="touchTime"
  18. min-width="120px"
  19. sortable
  20. >
  21. <template slot="header" slot-scope="scope">
  22. Время<br>просмотра
  23. </template>
  24. </el-table-column>
  25. <el-table-column
  26. min-width="300px"
  27. >
  28. <template slot="header" slot-scope="scope">
  29. <el-input
  30. v-model="search"
  31. size="mini"
  32. placeholder="Найти"/>
  33. </template>
  34. <template slot-scope="scope">
  35. <span>{{ scope.row.desc.author }}</span><br>
  36. <span>{{ `"${scope.row.desc.title}"` }}</span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column
  40. >
  41. <template slot-scope="scope">
  42. <el-button
  43. size="mini"
  44. @click="handleDel(scope.$index, scope.row)">Убрать
  45. </el-button>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. </Window>
  50. </div>
  51. </template>
  52. <script>
  53. //-----------------------------------------------------------------------------
  54. import Vue from 'vue';
  55. import Component from 'vue-class-component';
  56. import _ from 'lodash';
  57. import {formatDate} from '../../../share/utils';
  58. import Window from '../../share/Window.vue';
  59. export default @Component({
  60. components: {
  61. Window,
  62. },
  63. })
  64. class HistoryPage extends Vue {
  65. search = null;
  66. created() {
  67. this.commit = this.$store.commit;
  68. this.reader = this.$store.state.reader;
  69. }
  70. get tableData() {
  71. const state = this.reader;
  72. let result = [];
  73. for (let bookKey in state.openedBook) {
  74. const book = state.openedBook[bookKey];
  75. let touchTime = new Date();
  76. touchTime.setTime(book.touchTime);
  77. result.push({
  78. touchTime: formatDate(touchTime),
  79. desc: {
  80. title: book.fb2.bookTitle,
  81. author: _.compact([
  82. book.fb2.lastName,
  83. book.fb2.firstName,
  84. book.fb2.middleName
  85. ]).join(' '),
  86. }
  87. });
  88. }
  89. return result;
  90. }
  91. keyHook(event) {
  92. if (event.type == 'keydown' && event.code == 'Escape') {
  93. this.$emit('history-toggle');
  94. return true;
  95. }
  96. }
  97. }
  98. //-----------------------------------------------------------------------------
  99. </script>
  100. <style scoped>
  101. .main {
  102. flex: 1;
  103. display: flex;
  104. flex-direction: column;
  105. align-items: center;
  106. }
  107. .window {
  108. min-width: 200px;
  109. max-width: 600px;
  110. }
  111. </style>