Работа над проектом

This commit is contained in:
Book Pauk
2022-08-21 18:08:50 +07:00
parent fc411565b9
commit f3d25039bc
2 changed files with 91 additions and 12 deletions

View File

@@ -82,9 +82,20 @@
<div v-else class="q-my-sm" /> <div v-else class="q-my-sm" />
<!-- Формирование списка ------------------------------------------------------------------------> <!-- Формирование списка ------------------------------------------------------------------------>
<div v-for="item in tableData" :key="item.key" style="border-bottom: 1px solid #aaaaaa"> <div v-for="item in tableData" :key="item.key" :class="{'odd-author': item.num % 2}" style="font-size: 120%">
<div v-if="item.type == 'author'" class="q-my-sm q-ml-md clickable" style="font-size: 120%" @click="authorClick(item.value)"> <div class="row items-center q-ml-md q-my-sm no-wrap">
{{ item.key }} {{ item.name }} <div class="clickable q-mr-sm q-pa-xs">
<div v-if="!isExpanded(item.author)" @click="expandAuthor(item.author, true)">
<q-icon name="la la-plus-square" size="24px" />
</div>
<div v-else @click="expandAuthor(item.author, false)">
<q-icon name="la la-minus-square" size="24px" />
</div>
</div>
<div class="clickable" style="font-weight: bold" @click="authorClick(item.author)">
{{ item.name }}
</div>
</div> </div>
</div> </div>
<!-- Формирование списка конец ------------------------------------------------------------------> <!-- Формирование списка конец ------------------------------------------------------------------>
@@ -104,7 +115,7 @@ import vueComponent from '../vueComponent.js';
import PageScroller from './PageScroller/PageScroller.vue'; import PageScroller from './PageScroller/PageScroller.vue';
import * as utils from '../../share/utils'; import * as utils from '../../share/utils';
//import _ from 'lodash'; import _ from 'lodash';
const componentOptions = { const componentOptions = {
components: { components: {
@@ -132,13 +143,25 @@ const componentOptions = {
page() { page() {
this.refresh(); this.refresh();
}, },
limit() { limit(newValue) {
const newSettings = _.cloneDeep(this.settings);
newSettings.limit = newValue;
this.commit('setSettings', newSettings);
this.updatePageCount(); this.updatePageCount();
this.refresh(); this.refresh();
}, },
totalFound() { totalFound() {
this.updatePageCount(); this.updatePageCount();
} },
expanded: {
deep: true,
handler(newValue) {
const newSettings = _.cloneDeep(this.settings);
newSettings.expanded = _.cloneDeep(newValue);
this.commit('setSettings', newSettings);
},
},
}, },
}; };
class Search { class Search {
@@ -149,6 +172,7 @@ class Search {
loadingMessage = ''; loadingMessage = '';
page = 1; page = 1;
totalPages = 1; totalPages = 1;
expanded = [];
//input field consts //input field consts
inputMaxLength = 1000; inputMaxLength = 1000;
@@ -179,20 +203,35 @@ class Search {
created() { created() {
this.commit = this.$store.commit; this.commit = this.$store.commit;
this.loadSettings();
} }
mounted() { mounted() {
this.api = this.$root.api; this.api = this.$root.api;
this.$refs.authorInput.focus(); if (!this.$root.isMobileDevice)
this.$refs.authorInput.focus();
this.ready = true;
this.refresh();//no await this.refresh();//no await
} }
loadSettings() {
const settings = this.settings;
this.limit = settings.limit;
this.expanded = _.cloneDeep(settings.expanded);
}
get config() { get config() {
return this.$store.state.config; return this.$store.state.config;
} }
get settings() {
return this.$store.state.settings;
}
makeTitle() { makeTitle() {
const collection = this.config.dbConfig.inpxInfo.collection.split('\n'); const collection = this.config.dbConfig.inpxInfo.collection.split('\n');
this.collection = collection[0].trim(); this.collection = collection[0].trim();
@@ -260,21 +299,51 @@ class Search {
this.page = 1; this.page = 1;
} }
authorClick(authorName) { authorClick(author) {
this.author = `=${authorName}`; this.author = `=${author}`;
}
isExpanded(author) {
return this.expanded.indexOf(author) >= 0;
}
expandAuthor(author, expand = true) {
if (expand) {
if (this.expanded.indexOf(author) < 0)
this.expanded.push(author);
} else {
const i = this.expanded.indexOf(author);
if (i >= 0)
this.expanded.splice(i, 1);
}
} }
async updateTableData() { async updateTableData() {
let result = []; let result = [];
for (const rec of this.searchResult.author) { const authors = this.searchResult.author;
result.push({key: rec.id, type: 'author', value: rec.author, name: rec.author.replace(/,/g, ', ')}); if (authors.length == 1) {
this.expandAuthor(authors[0].author);
}
let num = 0;
for (const rec of authors) {
result.push({
key: rec.id,
num,
author: rec.author,
name: rec.author.replace(/,/g, ', '),
});
num++;
} }
this.tableData = result; this.tableData = result;
} }
async refresh() { async refresh() {
if (!this.ready)
return;
const offset = (this.page - 1)*this.limit; const offset = (this.page - 1)*this.limit;
const newQuery = { const newQuery = {
@@ -345,7 +414,10 @@ export default vueComponent(Search);
} }
.clickable { .clickable {
color: blue;
cursor: pointer; cursor: pointer;
} }
.odd-author {
background-color: #e7e7e7;
}
</style> </style>

View File

@@ -1,6 +1,10 @@
// initial state // initial state
const state = { const state = {
config: {}, config: {},
settings: {
limit: 50,
expanded: [],
},
}; };
// getters // getters
@@ -14,6 +18,9 @@ const mutations = {
setConfig(state, value) { setConfig(state, value) {
state.config = value; state.config = value;
}, },
setSettings(state, value) {
state.settings = value;
},
}; };
export default { export default {