|
|
@ -141,24 +141,37 @@ Page({ |
|
|
const moveY = e.touches[0].clientY; |
|
|
const moveY = e.touches[0].clientY; |
|
|
const diffY = moveY - this.data.startY; |
|
|
const diffY = moveY - this.data.startY; |
|
|
|
|
|
|
|
|
// 如果移动距离超过20px,视为拖动
|
|
|
|
|
|
if (Math.abs(diffY) > 20) { |
|
|
if (Math.abs(diffY) > 20) { |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
isDragging: true |
|
|
isDragging: true |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 更新按钮位置
|
|
|
let newTop = this.data.sidebarBtnTop + diffY * 2; |
|
|
let newTop = this.data.sidebarBtnTop + diffY * 2; // 转换为rpx
|
|
|
|
|
|
|
|
|
|
|
|
// 限制按钮在屏幕范围内
|
|
|
const systemInfo = wx.getSystemInfoSync(); |
|
|
const screenHeight = wx.getSystemInfoSync().screenHeight * 2; // 转换为rpx
|
|
|
const screenHeight = systemInfo.screenHeight; |
|
|
const btnHeight = 180; // 按钮高度,单位rpx
|
|
|
const safeArea = systemInfo.safeArea; |
|
|
const boundary = 300; // 边界值,限制拖动范围
|
|
|
const btnHeight = 90; |
|
|
|
|
|
const margin = 20; |
|
|
|
|
|
const tabBarHeight = 70; |
|
|
|
|
|
|
|
|
if (newTop < boundary) { |
|
|
let minTop, maxTop; |
|
|
newTop = boundary; |
|
|
|
|
|
} else if (newTop > screenHeight - btnHeight - boundary) { |
|
|
if (safeArea) { |
|
|
newTop = screenHeight - btnHeight - boundary; |
|
|
minTop = safeArea.top + margin; |
|
|
|
|
|
maxTop = safeArea.bottom - btnHeight - margin - tabBarHeight; |
|
|
|
|
|
} else { |
|
|
|
|
|
minTop = margin; |
|
|
|
|
|
maxTop = screenHeight - btnHeight - margin - tabBarHeight; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const minTopRpx = minTop * 2; |
|
|
|
|
|
const maxTopRpx = maxTop * 2; |
|
|
|
|
|
|
|
|
|
|
|
if (newTop < minTopRpx) { |
|
|
|
|
|
newTop = minTopRpx; |
|
|
|
|
|
} else if (newTop > maxTopRpx) { |
|
|
|
|
|
newTop = maxTopRpx; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
@ -195,12 +208,18 @@ Page({ |
|
|
console.log('首页初始化') |
|
|
console.log('首页初始化') |
|
|
const savedBtnTop = wx.getStorageSync('sidebarBtnTop'); |
|
|
const savedBtnTop = wx.getStorageSync('sidebarBtnTop'); |
|
|
const savedBtnHidden = wx.getStorageSync('sidebarBtnHidden'); |
|
|
const savedBtnHidden = wx.getStorageSync('sidebarBtnHidden'); |
|
|
if (savedBtnTop !== '') { |
|
|
const systemInfo = wx.getSystemInfoSync(); |
|
|
this.setData({ |
|
|
const screenHeight = systemInfo.screenHeight * 2; |
|
|
sidebarBtnTop: savedBtnTop, |
|
|
|
|
|
sidebarBtnHidden: savedBtnHidden || false |
|
|
let defaultTop = screenHeight / 2; |
|
|
}); |
|
|
if (savedBtnTop !== '' && savedBtnTop !== -100) { |
|
|
|
|
|
defaultTop = savedBtnTop; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
sidebarBtnTop: defaultTop, |
|
|
|
|
|
sidebarBtnHidden: savedBtnHidden || false |
|
|
|
|
|
}); |
|
|
this.checkAndRestoreLoginStatus() |
|
|
this.checkAndRestoreLoginStatus() |
|
|
this.loadGoods() |
|
|
this.loadGoods() |
|
|
}, |
|
|
}, |
|
|
|