Работа над HistoryPage

This commit is contained in:
Book Pauk
2019-01-26 04:25:59 +07:00
parent fc580799ab
commit 01f8bcba6e

View File

@@ -1,6 +1,7 @@
<template> <template>
<div ref="main" class="main"> <div ref="main" class="main" @click="close">
<Window class="window"> <div class="main" @click.stop>
<Window @close="close">
<template slot="header"> <template slot="header">
Последние 100 открытых книг Последние 100 открытых книг
</template> </template>
@@ -12,17 +13,21 @@
height="1px" height="1px"
stripe stripe
border border
:default-sort = "{prop: 'touchTime', order: 'descending'}" :default-sort = "{prop: 'touchDateTime', order: 'descending'}"
:header-cell-style = "headerCellStyle" :header-cell-style = "headerCellStyle"
> >
<el-table-column <el-table-column
prop="touchTime" prop="touchDateTime"
min-width="115px" min-width="90px"
sortable sortable
> >
<template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars --> <template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
Время<br>просмотра Время<br>просм.
</template>
<template slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
{{ scope.row.touchDate }}<br>
{{ scope.row.touchTime }}
</template> </template>
</el-table-column> </el-table-column>
@@ -40,17 +45,29 @@
min-width="300px" min-width="300px"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<div class="desc" @click="loadBook(scope.row.url)">
<span>{{ scope.row.desc.author }}</span><br> <span>{{ scope.row.desc.author }}</span><br>
<span>{{ `"${scope.row.desc.title}"` }}</span> <span>{{ `"${scope.row.desc.title}"` }}</span>
</div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
min-width="100px"
>
<template slot-scope="scope">
<span class="clickable" @click="openOriginal(scope.row.url)">Оригинал</span><br>
<a :href="scope.row.path" :download="getFileNameFromPath(scope.row.path)">Скачать FB2</a>
</template>
</el-table-column>
<el-table-column
width="60px"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
size="mini" size="mini"
@click="handleDel(scope.$index, scope.row)">Убрать @click="handleDel(scope.row.key)">X
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
@@ -60,13 +77,16 @@
</el-table> </el-table>
</Window> </Window>
</div> </div>
</div>
</template> </template>
<script> <script>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
import Vue from 'vue'; import Vue from 'vue';
import Component from 'vue-class-component'; import Component from 'vue-class-component';
import path from 'path';
import _ from 'lodash'; import _ from 'lodash';
import {formatDate} from '../../../share/utils'; import {formatDate} from '../../../share/utils';
import Window from '../../share/Window.vue'; import Window from '../../share/Window.vue';
@@ -89,11 +109,14 @@ class HistoryPage extends Vue {
for (let bookKey in state.openedBook) { for (let bookKey in state.openedBook) {
const book = state.openedBook[bookKey]; const book = state.openedBook[bookKey];
let touchTime = new Date(); let d = new Date();
touchTime.setTime(book.touchTime); d.setTime(book.touchTime);
const t = formatDate(d).split(' ');
result.push({ result.push({
touchTime: formatDate(touchTime), touchDateTime: book.touchTime,
touchDate: t[0],
touchTime: t[1],
desc: { desc: {
title: book.fb2.bookTitle, title: book.fb2.bookTitle,
author: _.compact([ author: _.compact([
@@ -101,7 +124,10 @@ class HistoryPage extends Vue {
book.fb2.firstName, book.fb2.firstName,
book.fb2.middleName book.fb2.middleName
]).join(' '), ]).join(' '),
} },
url: book.url,
path: book.path,
key: book.key,
}); });
} }
@@ -126,9 +152,34 @@ class HistoryPage extends Vue {
return result; return result;
} }
getFileNameFromPath(fb2Path) {
return path.basename(fb2Path).substr(0, 10) + '.fb2';
}
openOriginal(url) {
window.open(url, '_blank');
}
openFb2(path) {
window.open(path, '_blank');
}
handleDel(key) {
this.commit('reader/delOpenedBook', {key});
}
loadBook(url) {
this.$emit('load-book', {url});
this.close();
}
close() {
this.$emit('history-toggle');
}
keyHook(event) { keyHook(event) {
if (event.type == 'keydown' && event.code == 'Escape') { if (event.type == 'keydown' && event.code == 'Escape') {
this.$emit('history-toggle'); this.close();
return true; return true;
} }
} }
@@ -144,13 +195,18 @@ class HistoryPage extends Vue {
align-items: center; align-items: center;
} }
.window {
min-width: 200px;
max-width: 600px;
}
.header { .header {
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.clickable {
color: blue;
text-decoration: underline;
cursor: pointer;
}
.desc {
cursor: pointer;
}
</style> </style>