Рефакторинг

This commit is contained in:
Book Pauk
2022-07-09 20:50:31 +07:00
parent 53a1d90bd8
commit 30afd2421c

View File

@@ -130,7 +130,7 @@ const componentOptions = {
this.updateBookPosSelection(); this.updateBookPosSelection();
}, },
selectedTab() { selectedTab() {
this.updateBookPosSelection(); this.updateBookPosScrollTop();
}, },
}, },
}; };
@@ -289,7 +289,7 @@ class ContentsPage {
if (!this.isVisible) if (!this.isVisible)
return; return;
await utils.sleep(50); await this.$nextTick();
const bp = this.bookPos; const bp = this.bookPos;
for (let i = 0; i < this.contents.length; i++) { for (let i = 0; i < this.contents.length; i++) {
@@ -298,7 +298,6 @@ class ContentsPage {
if (bp >= item.offset && bp < nextOffset) { if (bp >= item.offset && bp < nextOffset) {
item.isBookPos = true; item.isBookPos = true;
this.updateBookPosScrollTop('contents', item);
} else if (item.isBookPos) { } else if (item.isBookPos) {
item.isBookPos = false; item.isBookPos = false;
} }
@@ -322,11 +321,12 @@ class ContentsPage {
if (bp >= img.offset && bp < nextOffset) { if (bp >= img.offset && bp < nextOffset) {
this.images[i].isBookPos = true; this.images[i].isBookPos = true;
this.updateBookPosScrollTop('images', img);
} else if (img.isBookPos) { } else if (img.isBookPos) {
this.images[i].isBookPos = false; this.images[i].isBookPos = false;
} }
} }
this.updateBookPosScrollTop();
} }
/*getOffsetTop(key) { /*getOffsetTop(key) {
@@ -334,9 +334,32 @@ class ContentsPage {
return (el ? el.offsetTop : 0); return (el ? el.offsetTop : 0);
}*/ }*/
updateBookPosScrollTop(tab, item, subitem, i) { async updateBookPosScrollTop() {
try { try {
if (tab == 'contents' && this.selectedTab == tab) { await this.$nextTick();
if (this.selectedTab == 'contents') {
let item;
let subitem;
let i;
//ищем выделенные item
for(const _item of this.contents) {
if (_item.isBookPos) {
item = _item;
for (let ii = 0; ii < item.list.length; ii++) {
const _subitem = item.list[ii];
if (_subitem.isBookPos) {
subitem = _subitem;
i = ii;
break;
}
}
break;
}
}
//вычисляем и смещаем tabPanel.scrollTop
let el = this.getFirstElem(this.$refs[`mainitem${item.key}`]); let el = this.getFirstElem(this.$refs[`mainitem${item.key}`]);
let elShift = 0; let elShift = 0;
if (subitem && item.expanded) { if (subitem && item.expanded) {
@@ -353,7 +376,18 @@ class ContentsPage {
tabPanel.scrollTop = newScrollTop; tabPanel.scrollTop = newScrollTop;
} }
if (tab == 'images' && this.selectedTab == tab) { if (this.selectedTab == 'images') {
let item;
//ищем выделенные item
for(const _item of this.images) {
if (_item.isBookPos) {
item = _item;
break;
}
}
//вычисляем и смещаем tabPanel.scrollTop
let el = this.getFirstElem(this.$refs[`image${item.key}`]); let el = this.getFirstElem(this.$refs[`image${item.key}`]);
const tabPanel = this.$refs.tabPanelImages; const tabPanel = this.$refs.tabPanelImages;