Работа над ContentsPage

This commit is contained in:
Book Pauk
2020-11-13 23:33:36 +07:00
parent 952c337b76
commit b292407ec2
3 changed files with 50 additions and 15 deletions

View File

@@ -59,7 +59,8 @@
</div> </div>
<div class="tab-panel" v-show="selectedTab == 'bookmarks'"> <div class="tab-panel" v-show="selectedTab == 'bookmarks'">
<div> <div class="column justify-center items-center" style="height: 100px">
Раздел находится в разработке
</div> </div>
</div> </div>
@@ -89,9 +90,15 @@ class ContentsPage extends Vue {
created() { created() {
} }
init(currentBook, parsed) { async init(currentBook, parsed) {
this.$refs.window.init(); this.$refs.window.init();
if (this.parsed != parsed) {
this.contents = [];
await this.$nextTick();
this.parsed = parsed;
}
const prepareLabel = (title, bolder = false) => { const prepareLabel = (title, bolder = false) => {
let titleParts = title.split('<p>'); let titleParts = title.split('<p>');
const textParts = titleParts.filter(v => v).map(v => `<div>${v.replace(/(<([^>]+)>)/ig, '')}</div>`); const textParts = titleParts.filter(v => v).map(v => `<div>${v.replace(/(<([^>]+)>)/ig, '')}</div>`);
@@ -100,11 +107,35 @@ class ContentsPage extends Vue {
return textParts.join(''); return textParts.join('');
} }
const insetStyle = inset => `width: ${(inset > 1 ? inset - 1 : 0)*20}px`; const insetStyle = inset => `width: ${inset*20}px`;
const pc = parsed.contents;
const newpc = [];
//преобразуем не первые разделы body в title-subtitle
let curSubtitles = [];
let prevBodyIndex = -1;
for (let i = 0; i < pc.length; i++) {
const cont = pc[i];
if (prevBodyIndex != cont.bodyIndex)
curSubtitles = [];
prevBodyIndex = cont.bodyIndex;
if (cont.bodyIndex > 1) {
if (cont.inset < 1) {
newpc.push(Object.assign({}, cont, {subtitles: curSubtitles}));
} else {
curSubtitles.push(Object.assign({}, cont, {inset: cont.inset - 1}));
}
} else {
newpc.push(cont);
}
}
//формируем newContents
let i = 0; let i = 0;
const newContents = []; const newContents = [];
parsed.contents.forEach((cont) => { newpc.forEach((cont) => {
const label = prepareLabel(cont.title, true); const label = prepareLabel(cont.title, true);
const style = insetStyle(cont.inset); const style = insetStyle(cont.inset);
@@ -127,8 +158,10 @@ class ContentsPage extends Vue {
this.contents = newContents; this.contents = newContents;
} }
setBookPos(newValue) { async setBookPos(newValue) {
this.$emit('book-pos-changed', {bookPos: newValue}); this.$emit('book-pos-changed', {bookPos: newValue});
await this.$nextTick();
this.close();
} }
close() { close() {

View File

@@ -99,7 +99,7 @@
<HelpPage v-if="helpActive" ref="helpPage" @do-action="doAction"></HelpPage> <HelpPage v-if="helpActive" ref="helpPage" @do-action="doAction"></HelpPage>
<ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage> <ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage>
<ServerStorage v-show="hidden" ref="serverStorage"></ServerStorage> <ServerStorage v-show="hidden" ref="serverStorage"></ServerStorage>
<ContentsPage v-show="contentsPageActive" ref="contentsPage" @do-action="doAction" @book-pos-changed="bookPosChanged"></ContentsPage> <ContentsPage v-show="contentsActive" ref="contentsPage" @do-action="doAction" @book-pos-changed="bookPosChanged"></ContentsPage>
<ReaderDialogs ref="dialogs" @donate-toggle="donateToggle" @version-history-toggle="versionHistoryToggle"></ReaderDialogs> <ReaderDialogs ref="dialogs" @donate-toggle="donateToggle" @version-history-toggle="versionHistoryToggle"></ReaderDialogs>
</div> </div>
@@ -209,7 +209,7 @@ class Reader extends Vue {
settingsActive = false; settingsActive = false;
helpActive = false; helpActive = false;
clickMapActive = false; clickMapActive = false;
contentsPageActive = false; contentsActive = false;
bookPos = null; bookPos = null;
allowUrlParamBookPos = false; allowUrlParamBookPos = false;
@@ -500,7 +500,7 @@ class Reader extends Vue {
this.stopScrolling(); this.stopScrolling();
this.stopSearch(); this.stopSearch();
this.helpActive = false; this.helpActive = false;
this.contentsPageActive = false; this.contentsActive = false;
} }
loaderToggle() { loaderToggle() {
@@ -615,17 +615,17 @@ class Reader extends Vue {
} }
contentsPageToggle() { contentsPageToggle() {
this.contentsPageActive = !this.contentsPageActive; this.contentsActive = !this.contentsActive;
const page = this.$refs.page; const page = this.$refs.page;
if (this.contentsPageActive && this.activePage == 'TextPage' && page.parsed) { if (this.contentsActive && this.activePage == 'TextPage' && page.parsed) {
this.closeAllWindows(); this.closeAllWindows();
this.contentsPageActive = true; this.contentsActive = true;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.contentsPage.init(this.mostRecentBook(), page.parsed); this.$refs.contentsPage.init(this.mostRecentBook(), page.parsed);
}); });
} else { } else {
this.contentsPageActive = false; this.contentsActive = false;
} }
} }
@@ -1156,7 +1156,7 @@ class Reader extends Vue {
if (!result && this.copyTextActive) if (!result && this.copyTextActive)
result = this.$refs.copyTextPage.keyHook(event); result = this.$refs.copyTextPage.keyHook(event);
if (!result && this.contentsPageActive) if (!result && this.contentsActive)
result = this.$refs.contentsPage.keyHook(event); result = this.$refs.contentsPage.keyHook(event);
if (!result && this.$refs.page && this.$refs.page.keyHook) if (!result && this.$refs.page && this.$refs.page.keyHook)

View File

@@ -53,12 +53,13 @@ export default class BookParser {
let dimPromises = []; let dimPromises = [];
//оглавление //оглавление
this.contents = [];//[{paraIndex: <number>, title: <string>, subtitles: [{paraIndex: <number>, title: <string>}, ... ]}, ... ] this.contents = [];
let curTitle = {paraIndex: -1, title: '', subtitles: []}; let curTitle = {paraIndex: -1, title: '', subtitles: []};
let curSubtitle = {paraIndex: -1, title: ''}; let curSubtitle = {paraIndex: -1, title: ''};
let inTitle = false; let inTitle = false;
let inSubtitle = false; let inSubtitle = false;
let sectionLevel = 0; let sectionLevel = 0;
let bodyIndex = 0;
let paraIndex = -1; let paraIndex = -1;
let paraOffset = 0; let paraOffset = 0;
@@ -226,6 +227,7 @@ export default class BookParser {
if (!isFirstBody) if (!isFirstBody)
newParagraph(' ', 1); newParagraph(' ', 1);
isFirstBody = false; isFirstBody = false;
bodyIndex++;
} }
if (tag == 'title') { if (tag == 'title') {
@@ -235,7 +237,7 @@ export default class BookParser {
center = true; center = true;
inTitle = true; inTitle = true;
curTitle = {paraIndex, title: '', inset: sectionLevel, subtitles: []}; curTitle = {paraIndex, title: '', inset: sectionLevel, bodyIndex, subtitles: []};
this.contents.push(curTitle); this.contents.push(curTitle);
} }