123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <template>
- <Window width="600px" ref="window" @close="close">
- <template slot="header">
- <span v-show="!loading">Последние {{tableData ? tableData.length : 0}} открытых книг</span>
- <span v-show="loading"><i class="el-icon-loading" style="font-size: 25px"></i> <span style="position: relative; top: -4px">Список загружается</span></span>
- </template>
- <el-table
- :data="tableData"
- style="width: 100%"
- size="mini"
- height="1px"
- stripe
- border
- :default-sort = "{prop: 'touchDateTime', order: 'descending'}"
- :header-cell-style = "headerCellStyle"
- :row-key = "rowKey"
- >
- <el-table-column
- type="index"
- width="35px"
- >
- </el-table-column>
- <el-table-column
- prop="touchDateTime"
- min-width="90px"
- sortable
- >
- <template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
- <span style="font-size: 90%">Время<br>просм.</span>
- </template>
- <template slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
- <div class="desc" @click="loadBook(scope.row.url)">
- {{ scope.row.touchDate }}<br>
- {{ scope.row.touchTime }}
- </div>
- </template>
- </el-table-column>
- <el-table-column
- >
- <template slot="header" slot-scope="scope"><!-- eslint-disable-line vue/no-unused-vars -->
- <!--el-input ref="input"
- :value="search" @input="search = $event"
- size="mini"
- style="margin: 0; padding: 0; vertical-align: bottom; margin-top: 10px"
- placeholder="Найти"/-->
- <div class="el-input el-input--mini">
- <input class="el-input__inner"
- ref="input"
- placeholder="Найти"
- style="margin: 0; vertical-align: bottom; margin-top: 20px; padding: 0 10px 0 10px"
- :value="search" @input="search = $event.target.value"
- />
- </div>
- </template>
- <el-table-column
- min-width="300px"
- >
- <template slot-scope="scope">
- <div class="desc" @click="loadBook(scope.row.url)">
- <span style="color: green">{{ scope.row.desc.author }}</span><br>
- <span>{{ scope.row.desc.title }}</span>
- </div>
- </template>
- </el-table-column>
- <el-table-column
- min-width="100px"
- >
- <template slot-scope="scope">
- <a v-show="isUrl(scope.row.url)" :href="scope.row.url" target="_blank">Оригинал</a><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">
- <el-button
- size="mini"
- style="width: 30px; padding: 7px 0 7px 0; margin-left: 4px"
- @click="handleDel(scope.row.key)"><i class="el-icon-close"></i>
- </el-button>
- </template>
- </el-table-column>
- </el-table-column>
- </el-table>
- </Window>
- </template>
- <script>
- //-----------------------------------------------------------------------------
- import Vue from 'vue';
- import Component from 'vue-class-component';
- import path from 'path';
- import _ from 'lodash';
- import * as utils from '../../../share/utils';
- import Window from '../../share/Window.vue';
- import bookManager from '../share/bookManager';
- export default @Component({
- components: {
- Window,
- },
- watch: {
- search: function() {
- this.updateTableData();
- }
- },
- })
- class RecentBooksPage extends Vue {
- loading = false;
- search = null;
- tableData = [];
- created() {
- }
- init() {
- this.$refs.window.init();
- this.$nextTick(() => {
- //this.$refs.input.focus();
- });
- (async() => {//отбражение подгрузки списка
- if (this.initing)
- return;
- this.initing = true;
- await this.updateTableData(3);
- await utils.sleep(200);
- if (bookManager.loaded) {
- await this.updateTableData(10);
- if (bookManager.getSortedRecent().length > 10)
- await utils.sleep(1800);
- } else {
- let i = 0;
- let j = 5;
- while (i < 500 && !bookManager.loaded) {
- if (i % j == 0) {
- bookManager.sortedRecentCached = null;
- await this.updateTableData(100);
- j *= 2;
- }
- await utils.sleep(100);
- i++;
- }
- }
- await this.updateTableData();
- this.initing = false;
- })();
- }
- rowKey(row) {
- return row.key;
- }
- async updateTableData(limit) {
- while (this.updating) await utils.sleep(100);
- this.updating = true;
- let result = [];
- this.loading = !!limit;
- const sorted = bookManager.getSortedRecent();
- for (let i = 0; i < sorted.length; i++) {
- const book = sorted[i];
- if (book.deleted)
- continue;
- if (limit && result.length >= limit)
- break;
- let d = new Date();
- d.setTime(book.touchTime);
- const t = utils.formatDate(d).split(' ');
- let perc = '';
- let textLen = '';
- const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
- if (book.textLength) {
- perc = ` [${((p/book.textLength)*100).toFixed(2)}%]`;
- textLen = ` ${Math.round(book.textLength/1000)}k`;
- }
- const fb2 = (book.fb2 ? book.fb2 : {});
- let title = fb2.bookTitle;
- if (title)
- title = `"${title}"`;
- else
- title = '';
- let author = '';
- if (fb2.author) {
- const authorNames = fb2.author.map(a => _.compact([
- a.lastName,
- a.firstName,
- a.middleName
- ]).join(' '));
- author = authorNames.join(', ');
- } else {
- author = _.compact([
- fb2.lastName,
- fb2.firstName,
- fb2.middleName
- ]).join(' ');
- }
- author = (author ? author : (fb2.bookTitle ? fb2.bookTitle : book.url));
- result.push({
- touchDateTime: book.touchTime,
- touchDate: t[0],
- touchTime: t[1],
- desc: {
- title: `${title}${perc}${textLen}`,
- author,
- },
- url: book.url,
- path: book.path,
- key: book.key,
- });
- if (result.length >= 100)
- break;
- }
- const search = this.search;
- result = result.filter(item => {
- return !search ||
- item.touchTime.includes(search) ||
- item.touchDate.includes(search) ||
- item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
- item.desc.author.toLowerCase().includes(search.toLowerCase())
- });
- /*for (let i = 0; i < result.length; i++) {
- if (!_.isEqual(this.tableData[i], result[i])) {
- this.$set(this.tableData, i, result[i]);
- await utils.sleep(10);
- }
- }
- if (this.tableData.length > result.length)
- this.tableData.splice(result.length);*/
- this.tableData = result;
- this.updating = false;
- }
- headerCellStyle(cell) {
- let result = {margin: 0, padding: 0};
- if (cell.columnIndex > 0) {
- result['border-bottom'] = 0;
- }
- if (cell.rowIndex > 0) {
- result.height = '0px';
- result['border-right'] = 0;
- }
- return result;
- }
- getFileNameFromPath(fb2Path) {
- return path.basename(fb2Path).substr(0, 10) + '.fb2';
- }
- openOriginal(url) {
- window.open(url, '_blank');
- }
- openFb2(path) {
- window.open(path, '_blank');
- }
- async handleDel(key) {
- await bookManager.delRecentBook({key});
- this.updateTableData();
- if (!bookManager.mostRecentBook())
- this.close();
- }
- loadBook(url) {
- this.$emit('load-book', {url});
- this.close();
- }
- isUrl(url) {
- if (url)
- return (url.indexOf('file://') != 0);
- else
- return false;
- }
- close() {
- this.$emit('recent-books-toggle');
- }
- keyHook(event) {
- if (event.type == 'keydown' && event.code == 'Escape') {
- this.close();
- }
- return true;
- }
- }
- //-----------------------------------------------------------------------------
- </script>
- <style scoped>
- .desc {
- cursor: pointer;
- }
- </style>
|