Преглед изворни кода

Работа над HistoryPage

Book Pauk пре 6 година
родитељ
комит
641409902e

+ 86 - 11
client/components/Reader/HistoryPage/HistoryPage.vue

@@ -1,13 +1,56 @@
 <template>
 <template>
     <div ref="main" class="main">
     <div ref="main" class="main">
-        <Window>
+        <Window class="window">
             <template slot="header">
             <template slot="header">
-                Прочитаные книги:
+                Последние 100 открытых книг
             </template>
             </template>
 
 
-            <div class="list">
-                Test
-            </div>
+            <el-table
+                :data="tableData"
+                style="width: 100%"
+                size="mini"
+                height="1px"
+                stripe
+                border
+                :default-sort = "{prop: 'touchTime', order: 'descending'}"
+                >
+
+                <el-table-column
+                    prop="touchTime"
+                    min-width="120px"
+                    sortable
+                    >
+                    <template slot="header" slot-scope="scope">
+                        Время<br>просмотра
+                    </template>
+                </el-table-column>
+
+                <el-table-column
+                    min-width="300px"
+                    >
+                    <template slot="header" slot-scope="scope">
+                        <el-input
+                            v-model="search"
+                            size="mini"
+                            placeholder="Найти"/>
+                    </template>
+                    <template slot-scope="scope">
+                        <span>{{ scope.row.desc.author }}</span><br>
+                        <span>{{ `"${scope.row.desc.title}"` }}</span>
+                    </template>                    
+                </el-table-column>
+
+                <el-table-column
+                    >
+                    <template slot-scope="scope">
+                        <el-button
+                            size="mini"
+                            @click="handleDel(scope.$index, scope.row)">Убрать
+                        </el-button>
+                    </template>
+                </el-table-column>
+
+            </el-table>
         </Window>
         </Window>
     </div>
     </div>
 </template>
 </template>
@@ -16,7 +59,8 @@
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 import Vue from 'vue';
 import Vue from 'vue';
 import Component from 'vue-class-component';
 import Component from 'vue-class-component';
-
+import _ from 'lodash';
+import {formatDate} from '../../../share/utils';
 import Window from '../../share/Window.vue';
 import Window from '../../share/Window.vue';
 
 
 export default @Component({
 export default @Component({
@@ -25,11 +69,44 @@ export default @Component({
     },
     },
 })
 })
 class HistoryPage extends Vue {
 class HistoryPage extends Vue {
+    search = null;
+
     created() {
     created() {
         this.commit = this.$store.commit;
         this.commit = this.$store.commit;
         this.reader = this.$store.state.reader;
         this.reader = this.$store.state.reader;
     }
     }
 
 
+    get tableData() {
+        const state = this.reader;
+        let result = [];
+
+        for (let bookKey in state.openedBook) {
+            const book = state.openedBook[bookKey];
+            let touchTime = new Date();
+            touchTime.setTime(book.touchTime);
+
+            result.push({
+                touchTime: formatDate(touchTime),
+                desc: {
+                    title: book.fb2.bookTitle,
+                    author: _.compact([
+                        book.fb2.lastName,
+                        book.fb2.firstName,
+                        book.fb2.middleName
+                    ]).join(' '),
+                }
+            });
+        }
+
+        return result;
+    }
+
+    keyHook(event) {
+        if (event.type == 'keydown' && event.code == 'Escape') {
+            this.$emit('history-toggle');
+            return true;
+        }
+    }
 }
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 </script>
 </script>
@@ -42,11 +119,9 @@ class HistoryPage extends Vue {
     align-items: center;
     align-items: center;
 }
 }
 
 
-.list {
-    flex: 1;
-    background-color: #ffffff;
+.window {
+    min-width: 200px;
+    max-width: 600px;
 }
 }
 
 
-.list-item {
-}
 </style>
 </style>

+ 6 - 1
client/components/Reader/Reader.vue

@@ -46,7 +46,12 @@
 
 
         <el-main>
         <el-main>
             <keep-alive>
             <keep-alive>
-                <component ref="page" :is="pageActive" @load-book="loadBook" @book-pos-changed="bookPosChanged" @tool-bar-toggle="toolBarToggle"></component>
+                <component ref="page" :is="pageActive" 
+                    @load-book="loadBook" 
+                    @book-pos-changed="bookPosChanged" 
+                    @tool-bar-toggle="toolBarToggle"
+                    @history-toggle="historyToggle"
+                ></component>
             </keep-alive>
             </keep-alive>
         </el-main>
         </el-main>
     </el-container>
     </el-container>

+ 6 - 1
client/components/Reader/share/bookManager.js

@@ -121,7 +121,12 @@ class BookManager {
         const parsed = new BookParser();
         const parsed = new BookParser();
 
 
         const parsedMeta = await parsed.parse(data, callback);
         const parsedMeta = await parsed.parse(data, callback);
-        const result = Object.assign({}, meta, parsedMeta, {length: data.length, data, parsed});
+        const result = Object.assign({}, meta, parsedMeta, {
+            length: data.length,
+            textLength: parsed.textLength,
+            data,
+            parsed
+        });
 
 
         return result;
         return result;
     }
     }

+ 2 - 3
client/components/share/Window.vue

@@ -27,9 +27,7 @@ class Window extends Vue {
     flex: 1;
     flex: 1;
     display: flex;
     display: flex;
     flex-direction: column;
     flex-direction: column;
-    min-width: 200px;
-    max-width: 600px;
-    background-color: #f5f7fa;
+    background-color: #e5e7ea;
     margin: 10px;
     margin: 10px;
     border: 1px solid black;
     border: 1px solid black;
     box-shadow: 3px 3px 5px black;
     box-shadow: 3px 3px 5px black;
@@ -43,5 +41,6 @@ class Window extends Vue {
 
 
 .header-text {
 .header-text {
     margin-left: 10px;
     margin-left: 10px;
+    margin-right: 10px;
 }
 }
 </style>
 </style>

+ 8 - 1
client/element.js

@@ -50,6 +50,12 @@ import './theme/main.css';
 import ElInput from 'element-ui/lib/input';
 import ElInput from 'element-ui/lib/input';
 import './theme/input.css';
 import './theme/input.css';
 
 
+import ElTable from 'element-ui/lib/table';
+import './theme/table.css';
+
+import ElTableColumn from 'element-ui/lib/table-column';
+import './theme/table-column.css';
+
 import ElProgress from 'element-ui/lib/progress';
 import ElProgress from 'element-ui/lib/progress';
 import './theme/progress.css';
 import './theme/progress.css';
 
 
@@ -65,7 +71,8 @@ import './theme/message-box.css';
 const components = {
 const components = {
     ElMenu, ElMenuItem, ElButton, ElCheckbox, ElTabs, ElTabPane, ElTooltip,
     ElMenu, ElMenuItem, ElButton, ElCheckbox, ElTabs, ElTabPane, ElTooltip,
     ElContainer, ElAside, ElMain, ElHeader,
     ElContainer, ElAside, ElMain, ElHeader,
-    ElInput, ElProgress
+    ElInput, ElTable, ElTableColumn,
+    ElProgress
 };
 };
 
 
 for (let name in components) {
 for (let name in components) {

+ 12 - 0
client/share/utils.js

@@ -16,4 +16,16 @@ export function hexToString(str) {
         result += String.fromCharCode(parseInt(str.substr(i, 2), 16));
         result += String.fromCharCode(parseInt(str.substr(i, 2), 16));
     }
     }
     return result;
     return result;
+}
+
+export function formatDate(d, format) {
+    if (!format)
+        format = 'normal';
+
+    switch (format) {
+        case 'normal':
+            return `${d.getDate().toString().padStart(2, '0')}.${(d.getMonth() + 1).toString().padStart(2, '0')}.${d.getFullYear()} ` + 
+                `${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}`;
+    }
+    
 }
 }

+ 25 - 1
client/store/modules/reader.js

@@ -25,6 +25,29 @@ const getters = {
 // actions
 // actions
 const actions = {};
 const actions = {};
 
 
+function delBook(state, value) {
+    Vue.delete(state.openedBook, value.key);
+}
+
+function cleanBooks(state) {
+    if (Object.keys(state.openedBook).length > 100) {
+        let min = Date.now();
+        let found = null;
+        for (let bookKey in state.openedBook) {
+            const book = state.openedBook[bookKey];
+            if (book.touchTime < min) {
+                min = book.touchTime;
+                found = book;
+            }
+        }
+
+        if (found) {
+            delBook(found);
+            cleanBooks(state);
+        }
+    }
+}
+
 // mutations
 // mutations
 const mutations = {
 const mutations = {
     setToolBarActive(state, value) {
     setToolBarActive(state, value) {
@@ -32,9 +55,10 @@ const mutations = {
     },
     },
     setOpenedBook(state, value) {
     setOpenedBook(state, value) {
         Vue.set(state.openedBook, value.key, Object.assign({}, value, {touchTime: Date.now()}));
         Vue.set(state.openedBook, value.key, Object.assign({}, value, {touchTime: Date.now()}));
+        cleanBooks(state);
     },
     },
     delOpenedBook(state, value) {
     delOpenedBook(state, value) {
-        Vue.delete(state.openedBook, value.key);
+        delBook(state, value);
     }
     }
 };
 };