|
|
|
@ -99,6 +99,16 @@ Page({ |
|
|
|
showBackToTop: false, |
|
|
|
scrollTop: 0, |
|
|
|
|
|
|
|
// 广告轮播图和功能按钮的显示状态
|
|
|
|
headerElementsHidden: false, |
|
|
|
headerTranslateY: 0, |
|
|
|
headerOpacity: 1, |
|
|
|
|
|
|
|
// 滚动相关
|
|
|
|
lastScrollTop: 0, |
|
|
|
scrollDirection: '', |
|
|
|
scrollThreshold: 20, |
|
|
|
|
|
|
|
// 搜索相关
|
|
|
|
searchKeyword: '', |
|
|
|
selectedRegion: '全国', |
|
|
|
@ -541,7 +551,8 @@ Page({ |
|
|
|
sidebarBtnTop: defaultTop, |
|
|
|
sidebarBtnHidden: false, |
|
|
|
isSearchBarFullyHidden: false, |
|
|
|
lastScrollTop: 0 |
|
|
|
lastScrollTop: 0, |
|
|
|
headerElementsHidden: false |
|
|
|
}); |
|
|
|
this.checkAndRestoreLoginStatus() |
|
|
|
this.loadCategories() |
|
|
|
@ -2342,15 +2353,57 @@ Page({ |
|
|
|
handleScroll: function (scrollTop) { |
|
|
|
const threshold = 50; |
|
|
|
const backToTopThreshold = 300; |
|
|
|
const headerHideThreshold = 20; |
|
|
|
|
|
|
|
const lastScrollTop = this.data.lastScrollTop || 0; |
|
|
|
const isScrollingDown = scrollTop > lastScrollTop; |
|
|
|
const scrollDelta = Math.abs(scrollTop - lastScrollTop); |
|
|
|
|
|
|
|
let needUpdate = false; |
|
|
|
const updates = { |
|
|
|
lastScrollTop: scrollTop |
|
|
|
}; |
|
|
|
|
|
|
|
// 广告轮播图和功能按钮的显示/隐藏逻辑
|
|
|
|
if (scrollDelta > this.data.scrollThreshold) { |
|
|
|
if (isScrollingDown && scrollTop > headerHideThreshold) { |
|
|
|
// 下滑时隐藏广告轮播图和功能按钮
|
|
|
|
updates.headerElementsHidden = true; |
|
|
|
needUpdate = true; |
|
|
|
} else if (!isScrollingDown) { |
|
|
|
// 上滑时显示广告轮播图和功能按钮
|
|
|
|
updates.headerElementsHidden = false; |
|
|
|
needUpdate = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 动态调整top-section-container的高度和商品列表的位置,确保布局正确
|
|
|
|
const query = wx.createSelectorQuery().in(this); |
|
|
|
query.select('.top-section-container').node(); |
|
|
|
query.select('.goods-list').node(); |
|
|
|
query.select('.goods-section').node(); |
|
|
|
query.exec((res) => { |
|
|
|
if (res && res[0] && res[0].node && res[1] && res[1].node && res[2] && res[2].node) { |
|
|
|
const containerNode = res[0].node; |
|
|
|
const goodsNode = res[1].node; |
|
|
|
const goodsSectionNode = res[2].node; |
|
|
|
|
|
|
|
if (this.data.headerElementsHidden) { |
|
|
|
// 隐藏时调整容器高度和商品列表位置,精确计算高度
|
|
|
|
containerNode.style.height = '175rpx'; |
|
|
|
containerNode.style.minHeight = '175rpx'; |
|
|
|
goodsNode.style.paddingTop = '0'; |
|
|
|
goodsSectionNode.style.marginTop = '175rpx'; |
|
|
|
} else { |
|
|
|
// 显示时恢复容器高度和商品列表位置
|
|
|
|
containerNode.style.height = 'auto'; |
|
|
|
containerNode.style.minHeight = '580rpx'; |
|
|
|
goodsNode.style.paddingTop = '0'; |
|
|
|
goodsSectionNode.style.marginTop = '580rpx'; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 搜索框始终固定显示,不做隐藏处理
|
|
|
|
|
|
|
|
// 侧边栏按钮显示逻辑
|
|
|
|
|