From bd1e5485d76d23beec10636e19797bd7b09c6bb0 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 13 Nov 2020 18:47:11 +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=20ContentsPage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reader/ContentsPage/ContentsPage.vue | 110 +++++++++++++++++- client/components/Reader/Reader.vue | 8 +- client/components/Reader/share/BookParser.js | 29 ++++- client/quasar.js | 5 +- 4 files changed, 143 insertions(+), 9 deletions(-) diff --git a/client/components/Reader/ContentsPage/ContentsPage.vue b/client/components/Reader/ContentsPage/ContentsPage.vue index a3784b31..1b21d8b5 100644 --- a/client/components/Reader/ContentsPage/ContentsPage.vue +++ b/client/components/Reader/ContentsPage/ContentsPage.vue @@ -1,8 +1,67 @@ @@ -23,11 +82,42 @@ export default @Component({ }, }) class ContentsPage extends Vue { + selectedTab = 'contents'; + contents = []; + created() { } - init() { + init(currentBook, parsed) { this.$refs.window.init(); + + const prepareLabel = (title) => { + let titleParts = title.split('

'); + const textParts = titleParts.filter(v => v).map(v => v.replace(/( |<([^>]+)>)/ig, '')); + return textParts.join('
'); + } + + let i = 0; + const newContents = []; + parsed.contents.forEach((cont) => { + const label = prepareLabel(cont.title); + + let j = 0; + const list = []; + cont.subtitles.forEach((sub) => { + const l = prepareLabel(sub.title); + const p = parsed.para[sub.paraIndex]; + list.push({perc: (p.offset/parsed.textLength*100).toFixed(2), label: l, key: j}); + j++; + }); + + const p = parsed.para[cont.paraIndex]; + newContents.push({perc: (p.offset/parsed.textLength*100).toFixed(0), label, key: i, list}); + + i++; + }); + + this.contents = newContents; } close() { @@ -45,4 +135,22 @@ class ContentsPage extends Vue { diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index 00c6dc81..6a5d1704 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -616,10 +616,14 @@ class Reader extends Vue { contentsPageToggle() { this.contentsPageActive = !this.contentsPageActive; - if (this.contentsPageActive) { + const page = this.$refs.page; + if (this.contentsPageActive && this.activePage == 'TextPage' && page.parsed) { this.closeAllWindows(); - this.$refs.contentsPage.init(); this.contentsPageActive = true; + + this.$nextTick(() => { + this.$refs.contentsPage.init(this.mostRecentBook(), page.parsed); + }); } else { this.contentsPageActive = false; } diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index f7a8a887..8a44a0a9 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -53,9 +53,11 @@ export default class BookParser { let dimPromises = []; //оглавление - this.contents = [];//[{paraIndex: , subtitles: [{paraIndex: }, ... ]}, ... ] - let curTitle = {paraIndex: -1, subtitles: []}; - let curSubtitle = {paraIndex: -1}; + this.contents = [];//[{paraIndex: , title: , subtitles: [{paraIndex: , title: }, ... ]}, ... ] + let curTitle = {paraIndex: -1, title: '', subtitles: []}; + let curSubtitle = {paraIndex: -1, title: ''}; + let inTitle = false; + let inSubtitle = false; let paraIndex = -1; let paraOffset = 0; @@ -124,6 +126,12 @@ export default class BookParser { addIndex: (addIndex ? addIndex : 0), }; + if (inSubtitle) { + curSubtitle.title += '

'; + } else if (inTitle) { + curTitle.title += '

'; + } + para[paraIndex] = p; paraOffset += p.length; }; @@ -163,6 +171,13 @@ export default class BookParser { p.length += len; p.text += text; + + if (inSubtitle) { + curSubtitle.title += text; + } else if (inTitle) { + curTitle.title += text; + } + para[paraIndex] = p; paraOffset += p.length; }; @@ -218,7 +233,8 @@ export default class BookParser { bold = true; center = true; - curTitle = {paraIndex, subtitles: []}; + inTitle = true; + curTitle = {paraIndex, title: '', subtitles: []}; this.contents.push(curTitle); } @@ -247,7 +263,8 @@ export default class BookParser { bold = true; center = true; - curSubtitle = {paraIndex}; + inSubtitle = true; + curSubtitle = {paraIndex, title: ''}; curTitle.subtitles.push(curSubtitle); } @@ -278,6 +295,7 @@ export default class BookParser { isFirstTitlePara = false; bold = false; center = false; + inTitle = false; } if (tag == 'emphasis' || tag == 'strong') { @@ -292,6 +310,7 @@ export default class BookParser { isFirstTitlePara = false; bold = false; center = false; + inSubtitle = false; } if (tag == 'epigraph') { diff --git a/client/quasar.js b/client/quasar.js index 2567ca54..0410d9d1 100644 --- a/client/quasar.js +++ b/client/quasar.js @@ -32,6 +32,8 @@ import {QPopupProxy} from 'quasar/src/components/popup-proxy'; import {QDialog} from 'quasar/src/components/dialog'; import {QChip} from 'quasar/src/components/chip'; import {QTree} from 'quasar/src/components/tree'; +import {QExpansionItem} from 'quasar/src/components/expansion-item'; + const components = { //QLayout, @@ -58,7 +60,8 @@ const components = { QPopupProxy, QDialog, QChip, - QTree + QTree, + QExpansionItem, }; //directives