diff --git a/package1/group/groupBuySingle.vue b/package1/group/groupBuySingle.vue index a05759c..0df1d02 100644 --- a/package1/group/groupBuySingle.vue +++ b/package1/group/groupBuySingle.vue @@ -630,7 +630,7 @@ const sysInfo = uni.getSystemInfoSync(); const bottomBarPx = Math.round(80 * sysInfo.windowWidth / 375); const h = sysInfo.windowHeight - this.navBarHeight - bottomBarPx; - return 'display:flex;position:fixed;left:0;top:' + this.navBarHeight + 'px;width:100%;height:' + h + 'px;z-index:50;background:#F5F8F5;padding:0 2.5%;box-sizing:border-box;'; + return 'display:flex;position:fixed;left:0;top:' + this.navBarHeight + 'px;width:95%;margin:0 auto;right:0;height:' + h + 'px;z-index:50;background:#F5F8F5;box-sizing:border-box;'; } else { return 'display:flex;height:72%;margin-top:20rpx;'; } @@ -731,10 +731,18 @@ this.lastScrollTop = e.scrollTop; // 当页面滚动到container应该触顶的位置时,启用吸顶 const stickyThreshold = this.containerOriginalTop - this.navBarHeight; - if (e.scrollTop >= stickyThreshold && stickyThreshold > 0) { + if (stickyThreshold <= 0) return; + if (e.scrollTop >= stickyThreshold) { if (!this.isContainerSticky) { this.isContainerSticky = true; } + // 限制页面滚动不超过吸顶阈值,防止吸顶后页面继续滚动 + if (e.scrollTop > stickyThreshold + 5) { + uni.pageScrollTo({ + scrollTop: stickyThreshold, + duration: 0 + }); + } } else { if (this.isContainerSticky) { this.isContainerSticky = false; @@ -887,32 +895,46 @@ } const selectedCategory = this.menuList[index]; - // 如果是"猜你喜欢"(id为空),滚动到顶部 + // 如果是"推荐"(id为tuijian或空),滚动到顶部 if (!selectedCategory.id && selectedCategory.id !== 0) { this.goodsListScrollTop = 0; this.$nextTick(() => { this.goodsListScrollTop = 0; }); - } else { - - // 通过scroll-into-view滚动到对应分类的第一个商品 + setTimeout(() => { this.isSwitching = false; }, 300); + this.$forceUpdate(); + return; + } + + // 滚动到对应分类的首个商品 + const doScrollToCategory = () => { const targetId = 'category-' + selectedCategory.id; - // 先清空再设置,确保同一个id也能触发滚动 this.scrollIntoViewId = ''; this.$nextTick(() => { this.isAutoScrolling = true; this.scrollIntoViewId = targetId; - // 延迟恢复滚动检测,避免自动滚动触发分类切换 setTimeout(() => { this.isAutoScrolling = false; this.isSwitching = false; }, 500); }); - return; + }; + + // 如果还没吸顶,先滚动页面到吸顶位置,再滚动商品列表 + if (!this.isContainerSticky) { + const stickyThreshold = this.containerOriginalTop - this.navBarHeight; + uni.pageScrollTo({ + scrollTop: stickyThreshold, + duration: 200, + complete: () => { + setTimeout(() => { + doScrollToCategory(); + }, 250); + } + }); + } else { + doScrollToCategory(); } - setTimeout(() => { - this.isSwitching = false; - }, 300); this.$forceUpdate(); }, openOrderWait(item){