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

This commit is contained in:
Book Pauk
2022-08-21 18:44:06 +07:00
parent f3d25039bc
commit c7073635e3

View File

@@ -82,13 +82,13 @@
<div v-else class="q-my-sm" /> <div v-else class="q-my-sm" />
<!-- Формирование списка ------------------------------------------------------------------------> <!-- Формирование списка ------------------------------------------------------------------------>
<div v-for="item in tableData" :key="item.key" :class="{'odd-author': item.num % 2}" style="font-size: 120%"> <div v-for="item in tableData" :key="item.key" class="column" :class="{'odd-author': item.num % 2}" style="font-size: 120%">
<div class="row items-center q-ml-md q-my-sm no-wrap"> <div class="row items-center q-ml-md q-my-xs no-wrap">
<div class="clickable q-mr-sm q-pa-xs"> <div class="clickable q-mr-sm q-pa-xs">
<div v-if="!isExpanded(item.author)" @click="expandAuthor(item.author, true)"> <div v-if="!isExpanded(item)" @click="expandAuthor(item, true)">
<q-icon name="la la-plus-square" size="24px" /> <q-icon name="la la-plus-square" size="24px" />
</div> </div>
<div v-else @click="expandAuthor(item.author, false)"> <div v-else @click="expandAuthor(item, false)">
<q-icon name="la la-minus-square" size="24px" /> <q-icon name="la la-minus-square" size="24px" />
</div> </div>
</div> </div>
@@ -97,6 +97,10 @@
{{ item.name }} {{ item.name }}
</div> </div>
</div> </div>
<div v-if="isExpanded(item) && item.books">
{{ item.books[0] }}
</div>
</div> </div>
<!-- Формирование списка конец ------------------------------------------------------------------> <!-- Формирование списка конец ------------------------------------------------------------------>
@@ -111,6 +115,7 @@
<script> <script>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
import vueComponent from '../vueComponent.js'; import vueComponent from '../vueComponent.js';
const { reactive } = require('@vue/reactivity');
import PageScroller from './PageScroller/PageScroller.vue'; import PageScroller from './PageScroller/PageScroller.vue';
import * as utils from '../../share/utils'; import * as utils from '../../share/utils';
@@ -154,13 +159,10 @@ const componentOptions = {
totalFound() { totalFound() {
this.updatePageCount(); this.updatePageCount();
}, },
expanded: { expanded(newValue) {
deep: true, const newSettings = _.cloneDeep(this.settings);
handler(newValue) { newSettings.expanded = _.cloneDeep(newValue);
const newSettings = _.cloneDeep(this.settings); this.commit('setSettings', newSettings);
newSettings.expanded = _.cloneDeep(newValue);
this.commit('setSettings', newSettings);
},
}, },
}, },
}; };
@@ -303,38 +305,72 @@ class Search {
this.author = `=${author}`; this.author = `=${author}`;
} }
isExpanded(author) { isExpanded(item) {
return this.expanded.indexOf(author) >= 0; return this.expanded.indexOf(item.author) >= 0;
} }
expandAuthor(author, expand = true) { expandAuthor(item, expand = true) {
const expanded = _.cloneDeep(this.expanded);
const author = item.author;
if (expand) { if (expand) {
if (this.expanded.indexOf(author) < 0) if (expanded.indexOf(author) < 0) {
this.expanded.push(author); expanded.push(author);
this.getBooks(item);
if (expanded.length > 100) {
expanded.shift();
}
this.expanded = expanded;
}
} else { } else {
const i = this.expanded.indexOf(author); const i = expanded.indexOf(author);
if (i >= 0) if (i >= 0) {
this.expanded.splice(i, 1); expanded.splice(i, 1);
this.expanded = expanded;
}
} }
} }
async loadBooks() {
}
async getBooks(item) {
if (item.books)
return;
await utils.sleep(1000);
item.books = [{name: 'book1'}];
}
async updateTableData() { async updateTableData() {
let result = []; let result = [];
const authors = this.searchResult.author; const authors = this.searchResult.author;
if (authors.length == 1) { if (authors.length == 1) {
this.expandAuthor(authors[0].author); this.expandAuthor(authors[0]);
} }
const expandedSet = new Set(this.expanded);
let num = 0; let num = 0;
for (const rec of authors) { for (const rec of authors) {
result.push({ const item = reactive({
key: rec.id, key: rec.id,
num, num,
author: rec.author, author: rec.author,
name: rec.author.replace(/,/g, ', '), name: rec.author.replace(/,/g, ', '),
book: false,
}); });
num++; num++;
if (expandedSet.has(item.author)) {
this.getBooks(item);//no await
}
result.push(item);
} }
this.tableData = result; this.tableData = result;