fix: gxnlpt 收起分类时自动滚动到该分类标题

收起后内容高度骤减,用户视野可能停留在下方空白区。
现在收起后 smooth scroll 到当前分类 header (留80px顶栏余量)。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liulujian 2026-07-04 23:46:41 +08:00
parent 6967c8adb6
commit a071be1f41

View File

@ -1155,16 +1155,27 @@ export default {
toggleViewMore(category) { toggleViewMore(category) {
const total = category.cardList.length; const total = category.cardList.length;
if (category.visibleCount >= total) { if (category.visibleCount >= total) {
// , //
category.visibleCount = category.previewSize; category.visibleCount = category.previewSize;
this.refreshDisplayList(category);
this.$nextTick(() => {
const el = document.getElementById(category.id);
if (!el) return;
const scrollRoot = this.getScrollRoot();
if (!scrollRoot) return;
const rootRect = scrollRoot.getBoundingClientRect();
const elRect = el.getBoundingClientRect();
const target = scrollRoot.scrollTop + (elRect.top - rootRect.top) - 80;
scrollRoot.scrollTo({ top: Math.max(0, target), behavior: 'smooth' });
});
} else { } else {
// previewSize , total // previewSize , total
category.visibleCount = Math.min( category.visibleCount = Math.min(
category.visibleCount + category.previewSize, category.visibleCount + category.previewSize,
total, total,
); );
this.refreshDisplayList(category);
} }
this.refreshDisplayList(category);
}, },
async loadAllSections() { async loadAllSections() {
this.pageLoading = true; this.pageLoading = true;