Работа над BookInfoDialog

This commit is contained in:
Book Pauk
2022-11-06 17:15:45 +07:00
parent 351abe9401
commit d9f1912ea2
7 changed files with 119 additions and 1 deletions

View File

@@ -235,6 +235,10 @@ class Api {
return await this.request(Object.assign({action: 'get-book-link'}, params), 120);
}
async getBookInfo(params) {
return await this.request(Object.assign({action: 'get-book-info'}, params), 120);
}
async getConfig() {
return await this.request({action: 'get-config'});
}

View File

@@ -185,6 +185,10 @@ export default class BaseList {
const url = this.config.bookReadLink.replace('${DOWNLOAD_LINK}', href);
window.open(url, '_blank');
}
} else if (action == 'bookInfo') {
//информация о книге
const response = await this.api.getBookInfo({bookPath, downFileName});
this.$emit('listEvent', {action: 'bookInfo', data: response.bookInfo});
}
} catch(e) {
this.$root.stdDialog.alert(e.message, 'Ошибка');
@@ -208,6 +212,7 @@ export default class BaseList {
case 'download':
case 'copyLink':
case 'readBook':
case 'bookInfo':
this.download(event.book, event.action);//no await
break;
}

View File

@@ -0,0 +1,66 @@
<template>
<Dialog ref="dialog" v-model="dialogVisible">
<template #header>
<div class="row items-center">
<div style="font-size: 110%">
Информация о книге
</div>
</div>
</template>
<div ref="box" class="column q-mt-xs overflow-auto no-wrap" style="width: 200px; padding: 0px 10px 10px 10px;">
</div>
<template #footer>
<q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick">
OK
</q-btn>
</template>
</Dialog>
</template>
<script>
//-----------------------------------------------------------------------------
import vueComponent from '../../vueComponent.js';
import Dialog from '../../share/Dialog.vue';
const componentOptions = {
components: {
Dialog
},
watch: {
modelValue(newValue) {
this.dialogVisible = newValue;
},
dialogVisible(newValue) {
this.$emit('update:modelValue', newValue);
},
}
};
class BookInfoDialog {
_options = componentOptions;
_props = {
modelValue: Boolean,
};
dialogVisible = false;
created() {
this.commit = this.$store.commit;
}
mounted() {
}
okClick() {
this.dialogVisible = false;
}
}
export default vueComponent(BookInfoDialog);
//-----------------------------------------------------------------------------
</script>
<style scoped>
</style>

View File

@@ -55,7 +55,7 @@
{{ bookSize }}, {{ book.ext }}
</div>
<div v-if="showInfo" class="row items-center q-ml-sm clickable" @click="emit('info')">
<div v-if="showInfo" class="row items-center q-ml-sm clickable" @click="emit('bookInfo')">
[ . . . ]
</div>

View File

@@ -250,6 +250,7 @@
<SelectLangDialog v-model="selectLangDialogVisible" v-model:lang="search.lang" :lang-list="langList" :lang-default="langDefault" />
<SelectLibRateDialog v-model="selectLibRateDialogVisible" v-model:librate="search.librate" />
<SelectDateDialog v-model="selectDateDialogVisible" v-model:date="search.date" />
<BookInfoDialog v-model="bookInfoDialogVisible" book-info="bookInfo" />
</div>
</template>
@@ -266,6 +267,7 @@ import SelectGenreDialog from './SelectGenreDialog/SelectGenreDialog.vue';
import SelectLangDialog from './SelectLangDialog/SelectLangDialog.vue';
import SelectLibRateDialog from './SelectLibRateDialog/SelectLibRateDialog.vue';
import SelectDateDialog from './SelectDateDialog/SelectDateDialog.vue';
import BookInfoDialog from './BookInfoDialog/BookInfoDialog.vue';
import authorBooksStorage from './authorBooksStorage';
import DivBtn from '../share/DivBtn.vue';
@@ -292,6 +294,7 @@ const componentOptions = {
SelectLangDialog,
SelectLibRateDialog,
SelectDateDialog,
BookInfoDialog,
Dialog,
DivBtn
},
@@ -404,6 +407,7 @@ class Search {
selectLangDialogVisible = false;
selectLibRateDialogVisible = false;
selectDateDialogVisible = false;
bookInfoDialogVisible = false;
pageCount = 1;
@@ -458,6 +462,8 @@ class Search {
genreTreeInpxHash = '';
showTooltips = true;
bookInfo = {};
limitOptions = [
{label: '10', value: 10},
{label: '20', value: 20},
@@ -879,6 +885,10 @@ class Search {
case 'submitUrl':
this.sendMessage({type: 'submitUrl', data: event.data});
break;
case 'bookInfo':
this.bookInfo = event.data;
this.bookInfoDialogVisible = true;
break;
}
}

View File

@@ -84,6 +84,8 @@ class WebSocketController {
await this.getGenreTree(req, ws); break;
case 'get-book-link':
await this.getBookLink(req, ws); break;
case 'get-book-info':
await this.getBookInfo(req, ws); break;
case 'get-inpx-file':
await this.getInpxFile(req, ws); break;
@@ -173,6 +175,17 @@ class WebSocketController {
this.send(result, req, ws);
}
async getBookInfo(req, ws) {
if (!utils.hasProp(req, 'bookPath'))
throw new Error(`bookPath is empty`);
if (!utils.hasProp(req, 'downFileName'))
throw new Error(`downFileName is empty`);
const result = await this.webWorker.getBookInfo({bookPath: req.bookPath, downFileName: req.downFileName});
this.send(result, req, ws);
}
async getInpxFile(req, ws) {
if (!this.config.allowRemoteLib)
throw new Error('Remote lib access disabled');

View File

@@ -437,6 +437,26 @@ class WebWorker {
}
}
async getBookInfo(params) {
this.checkMyState();
try {
//const db = this.db;
let link = await this.getBookLink(params);
const hash = path.basename(link.link);
/*const bookFile = `${this.config.filesDir}/${hash}`;
const bookInfo = await fb2parser*/
return {hash};
} catch(e) {
log(LM_ERR, `getBookInfo error: ${e.message}`);
if (e.message.indexOf('ENOENT') >= 0)
throw new Error('404 Файл не найден');
throw e;
}
}
/*
async restoreBookFile(publicPath) {
this.checkMyState();