feat(uniapp): 按设计稿重构首页并修复点餐分类高亮

重构米糖风格首页与纵向渐变背景;点击分类时锁定 scroll 回写,避免左侧高亮回跳到上一项。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
KroytzandCursor committed 2026-07-24 11:30:34 +08:00
1 parent 4d925fb6ff
commit f7b825ff7b
3 files changed
+533 -228

No files matched your search

+20 -4
View File
@@ -286,6 +286,9 @@ const newValue = ref([])
const shopAd = ref('')
const isCartShow = ref(true)
const popup = ref()
// 点击左侧分类主动滚动时,暂时忽略右侧 scroll 回写,避免高亮回跳到上一项
const menuClickLock = ref(false)
let menuClickLockTimer = null
const measureMenuLayout = () => {
}
@@ -529,19 +532,32 @@ const handleMenuTap = (id) => { //点击菜单项事件
calcSize()
}
menuClickLock.value = true
if (menuClickLockTimer) clearTimeout(menuClickLockTimer)
currentCateId.value = id
nextTick(() => cateScrollTop.value = filteredGoods.value.find(item => item.id == id)?.top || 0)
menuScrollIntoView.value = `menu-${id}`
const targetTop = filteredGoods.value.find(item => item.id == id)?.top || 0
nextTick(() => {
// 同一 scroll-top 重复赋值不会触发滚动,做微小偏移确保生效
cateScrollTop.value = cateScrollTop.value === targetTop ? targetTop + 0.01 : targetTop
})
// scroll-with-animation 期间屏蔽 scroll 回写,动画结束后再放开
menuClickLockTimer = setTimeout(() => {
menuClickLock.value = false
menuClickLockTimer = null
}, 400)
}
const handleGoodsScroll = ({ detail }) => { //商品列表滚动事件
if (menuClickLock.value) return
if (!sizeCalcState.value) {
calcSize()
}
console.log('scrollTop:',detail)
const {
scrollTop
} = detail
let tabs = filteredGoods.value.filter(item => item.top <= scrollTop).reverse()
if (tabs.length > 0) {
// 加一点容差,避免刚好停在分类顶部时因浮点误差高亮到上一项
const tabs = filteredGoods.value.filter(item => item.top <= scrollTop + 2).reverse()
if (tabs.length > 0 && tabs[0].id !== currentCateId.value) {
currentCateId.value = tabs[0].id
}
}