From f3d25039bc820b3b483b7b21b8d5aee9c3ceb554 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 21 Aug 2022 18:08:50 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Search/Search.vue | 96 +++++++++++++++++++++++++---- client/store/root.js | 7 +++ 2 files changed, 91 insertions(+), 12 deletions(-) diff --git a/client/components/Search/Search.vue b/client/components/Search/Search.vue index 9f1dc95..b0931b7 100644 --- a/client/components/Search/Search.vue +++ b/client/components/Search/Search.vue @@ -82,9 +82,20 @@
-
-
- {{ item.key }} {{ item.name }} +
+
+
+
+ +
+
+ +
+
+ +
+ {{ item.name }} +
@@ -104,7 +115,7 @@ import vueComponent from '../vueComponent.js'; import PageScroller from './PageScroller/PageScroller.vue'; import * as utils from '../../share/utils'; -//import _ from 'lodash'; +import _ from 'lodash'; const componentOptions = { components: { @@ -132,13 +143,25 @@ const componentOptions = { page() { this.refresh(); }, - limit() { + limit(newValue) { + const newSettings = _.cloneDeep(this.settings); + newSettings.limit = newValue; + this.commit('setSettings', newSettings); + this.updatePageCount(); this.refresh(); }, totalFound() { this.updatePageCount(); - } + }, + expanded: { + deep: true, + handler(newValue) { + const newSettings = _.cloneDeep(this.settings); + newSettings.expanded = _.cloneDeep(newValue); + this.commit('setSettings', newSettings); + }, + }, }, }; class Search { @@ -149,6 +172,7 @@ class Search { loadingMessage = ''; page = 1; totalPages = 1; + expanded = []; //input field consts inputMaxLength = 1000; @@ -179,20 +203,35 @@ class Search { created() { this.commit = this.$store.commit; + + this.loadSettings(); } mounted() { this.api = this.$root.api; - this.$refs.authorInput.focus(); + if (!this.$root.isMobileDevice) + this.$refs.authorInput.focus(); + this.ready = true; this.refresh();//no await } + loadSettings() { + const settings = this.settings; + + this.limit = settings.limit; + this.expanded = _.cloneDeep(settings.expanded); + } + get config() { return this.$store.state.config; } + get settings() { + return this.$store.state.settings; + } + makeTitle() { const collection = this.config.dbConfig.inpxInfo.collection.split('\n'); this.collection = collection[0].trim(); @@ -260,21 +299,51 @@ class Search { this.page = 1; } - authorClick(authorName) { - this.author = `=${authorName}`; + authorClick(author) { + 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() { let result = []; - for (const rec of this.searchResult.author) { - result.push({key: rec.id, type: 'author', value: rec.author, name: rec.author.replace(/,/g, ', ')}); + const authors = this.searchResult.author; + 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; } async refresh() { + if (!this.ready) + return; + const offset = (this.page - 1)*this.limit; const newQuery = { @@ -345,7 +414,10 @@ export default vueComponent(Search); } .clickable { - color: blue; cursor: pointer; } + +.odd-author { + background-color: #e7e7e7; +} diff --git a/client/store/root.js b/client/store/root.js index 94ff9a7..367252a 100644 --- a/client/store/root.js +++ b/client/store/root.js @@ -1,6 +1,10 @@ // initial state const state = { config: {}, + settings: { + limit: 50, + expanded: [], + }, }; // getters @@ -14,6 +18,9 @@ const mutations = { setConfig(state, value) { state.config = value; }, + setSettings(state, value) { + state.settings = value; + }, }; export default {