From 673f68ea6a8cbeb7a78827f05b008e00e652b224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 27 Dec 2025 10:09:49 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BE=A7=E8=BE=B9?= =?UTF-8?q?=E6=A0=8F=E6=8C=89=E9=92=AE=E8=BE=B9=E7=95=8C=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复安全区域计算,正确处理刘海屏和底部手势区域 - 增加tabBar高度考虑,避免按钮与底部导航栏重合 - 优化默认位置逻辑,隐藏状态时使用屏幕中间位置 --- pages/index/index.js | 51 +++++++++++++++++++++++++++++------------- pages/index/index.wxml | 2 +- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index 8a6c5b0..2baa48b 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -141,24 +141,37 @@ Page({ const moveY = e.touches[0].clientY; const diffY = moveY - this.data.startY; - // 如果移动距离超过20px,视为拖动 if (Math.abs(diffY) > 20) { this.setData({ isDragging: true }); - // 更新按钮位置 - let newTop = this.data.sidebarBtnTop + diffY * 2; // 转换为rpx + let newTop = this.data.sidebarBtnTop + diffY * 2; - // 限制按钮在屏幕范围内 - const screenHeight = wx.getSystemInfoSync().screenHeight * 2; // 转换为rpx - const btnHeight = 180; // 按钮高度,单位rpx - const boundary = 300; // 边界值,限制拖动范围 + const systemInfo = wx.getSystemInfoSync(); + const screenHeight = systemInfo.screenHeight; + const safeArea = systemInfo.safeArea; + const btnHeight = 90; + const margin = 20; + const tabBarHeight = 70; - if (newTop < boundary) { - newTop = boundary; - } else if (newTop > screenHeight - btnHeight - boundary) { - newTop = screenHeight - btnHeight - boundary; + let minTop, maxTop; + + if (safeArea) { + 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({ @@ -195,12 +208,18 @@ Page({ console.log('首页初始化') const savedBtnTop = wx.getStorageSync('sidebarBtnTop'); const savedBtnHidden = wx.getStorageSync('sidebarBtnHidden'); - if (savedBtnTop !== '') { - this.setData({ - sidebarBtnTop: savedBtnTop, - sidebarBtnHidden: savedBtnHidden || false - }); + const systemInfo = wx.getSystemInfoSync(); + const screenHeight = systemInfo.screenHeight * 2; + + let defaultTop = screenHeight / 2; + if (savedBtnTop !== '' && savedBtnTop !== -100) { + defaultTop = savedBtnTop; } + + this.setData({ + sidebarBtnTop: defaultTop, + sidebarBtnHidden: savedBtnHidden || false + }); this.checkAndRestoreLoginStatus() this.loadGoods() }, diff --git a/pages/index/index.wxml b/pages/index/index.wxml index dbc81bb..b99be5d 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -110,7 +110,7 @@ - + From 793637f9e115a0e8267ee111d5c50d57e664b929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 27 Dec 2025 10:21:38 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BE=A7=E8=BE=B9?= =?UTF-8?q?=E6=A0=8F=E6=8C=89=E9=92=AE=E8=BE=B9=E7=95=8C=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用百分比计算边界,兼容所有设备 - 按钮活动范围:屏幕顶部10%到底部75% - 移除复杂的safeArea判断,提高健壮性 --- pages/index/index.js | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index 2baa48b..f9638e8 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -149,29 +149,16 @@ Page({ let newTop = this.data.sidebarBtnTop + diffY * 2; const systemInfo = wx.getSystemInfoSync(); - const screenHeight = systemInfo.screenHeight; - const safeArea = systemInfo.safeArea; + const screenHeight = systemInfo.screenHeight * 2; const btnHeight = 90; - const margin = 20; - const tabBarHeight = 70; - let minTop, maxTop; + const minTop = screenHeight * 0.1; + const maxTop = screenHeight * 0.75; - if (safeArea) { - 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; + if (newTop < minTop) { + newTop = minTop; + } else if (newTop > maxTop) { + newTop = maxTop; } this.setData({ From 09c433ab10a65268c027cffcad013c24032a82a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 27 Dec 2025 10:24:40 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BE=A7=E8=BE=B9?= =?UTF-8?q?=E6=A0=8F=E6=8C=89=E9=92=AE=E9=A1=B6=E9=83=A8=E8=BE=B9=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 顶部限制从10%改为20%屏幕高度 --- pages/index/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index/index.js b/pages/index/index.js index f9638e8..b6eaa56 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -152,7 +152,7 @@ Page({ const screenHeight = systemInfo.screenHeight * 2; const btnHeight = 90; - const minTop = screenHeight * 0.1; + const minTop = screenHeight * 0.2; const maxTop = screenHeight * 0.75; if (newTop < minTop) { From 12db027a80086b91da10cc7f3ca132fc09b633fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 27 Dec 2025 10:28:07 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0iOS=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用safeArea计算iPhone刘海边距 - 保留百分比作为安卓备用方案 --- pages/index/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index b6eaa56..492f69a 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -150,10 +150,18 @@ Page({ const systemInfo = wx.getSystemInfoSync(); const screenHeight = systemInfo.screenHeight * 2; + const safeArea = systemInfo.safeArea; const btnHeight = 90; - const minTop = screenHeight * 0.2; - const maxTop = screenHeight * 0.75; + let minTop, maxTop; + + if (safeArea && safeArea.top > 20) { + minTop = safeArea.top * 2 + 20; + maxTop = safeArea.bottom * 2 - btnHeight - 20; + } else { + minTop = screenHeight * 0.2; + maxTop = screenHeight * 0.6; + } if (newTop < minTop) { newTop = minTop; From c37bb69dc5c399f377dbd9c08dcd70d0406d400f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 27 Dec 2025 10:29:41 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8B=B9=E6=9E=9C?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E4=B8=8A=E6=8C=89=E9=92=AE=E6=B6=88=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 初始化时校验保存的位置是否在有效范围内 - 确保默认位置始终在边界内 (20%~60%) --- pages/index/index.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index 492f69a..9bbcc1f 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -150,18 +150,10 @@ Page({ const systemInfo = wx.getSystemInfoSync(); const screenHeight = systemInfo.screenHeight * 2; - const safeArea = systemInfo.safeArea; const btnHeight = 90; - let minTop, maxTop; - - if (safeArea && safeArea.top > 20) { - minTop = safeArea.top * 2 + 20; - maxTop = safeArea.bottom * 2 - btnHeight - 20; - } else { - minTop = screenHeight * 0.2; - maxTop = screenHeight * 0.6; - } + const minTop = screenHeight * 0.2; + const maxTop = screenHeight * 0.6; if (newTop < minTop) { newTop = minTop; @@ -206,9 +198,13 @@ Page({ const systemInfo = wx.getSystemInfoSync(); const screenHeight = systemInfo.screenHeight * 2; - let defaultTop = screenHeight / 2; + let defaultTop = screenHeight * 0.5; if (savedBtnTop !== '' && savedBtnTop !== -100) { - defaultTop = savedBtnTop; + const minTop = screenHeight * 0.2; + const maxTop = screenHeight * 0.6; + if (savedBtnTop >= minTop && savedBtnTop <= maxTop) { + defaultTop = savedBtnTop; + } } this.setData({ From ec13c6856756a9f09fe97ece9e96a67ba008aacb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 27 Dec 2025 10:33:28 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=8A=A0=E5=BF=AB=E4=BE=A7=E8=BE=B9?= =?UTF-8?q?=E6=A0=8F=E6=8C=89=E9=92=AE=E6=8B=96=E5=8A=A8=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移动系数从2改为3 --- pages/index/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index/index.js b/pages/index/index.js index 9bbcc1f..89479c1 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -146,7 +146,7 @@ Page({ isDragging: true }); - let newTop = this.data.sidebarBtnTop + diffY * 2; + let newTop = this.data.sidebarBtnTop + diffY * 3; const systemInfo = wx.getSystemInfoSync(); const screenHeight = systemInfo.screenHeight * 2; From 115ffb7ec5412228f25196c0779e1b26ba6a860c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 27 Dec 2025 10:40:28 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=97=B6=E6=8C=89=E9=92=AE=E6=B6=88=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - onShow中恢复按钮位置和显示状态 - 确保从其他页面返回时按钮正确显示 --- pages/index/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pages/index/index.js b/pages/index/index.js index 89479c1..b7020b0 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -224,6 +224,26 @@ Page({ const app = getApp(); app.updateCurrentTab('index'); app.globalData.showTabBar = true; + + const savedBtnTop = wx.getStorageSync('sidebarBtnTop'); + const savedBtnHidden = wx.getStorageSync('sidebarBtnHidden'); + const systemInfo = wx.getSystemInfoSync(); + const screenHeight = systemInfo.screenHeight * 2; + + let defaultTop = screenHeight * 0.5; + if (savedBtnTop !== '' && savedBtnTop !== -100) { + const minTop = screenHeight * 0.2; + const maxTop = screenHeight * 0.6; + if (savedBtnTop >= minTop && savedBtnTop <= maxTop) { + defaultTop = savedBtnTop; + } + } + + this.setData({ + sidebarBtnTop: defaultTop, + sidebarBtnHidden: savedBtnHidden || false + }); + this.checkAndRestoreLoginStatus() }, From 3dcbd9638f528cc8ad61076499f54605a96e8c2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 27 Dec 2025 10:42:04 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=88=B0=E6=8B=9B=E5=95=86=E5=85=A5=E9=A9=BB=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=97=B6=E4=BE=A7=E8=BE=B9=E6=A0=8F=E6=8C=89=E9=92=AE=E4=BB=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 跳转前隐藏侧边栏按钮 --- pages/index/index.js | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index b7020b0..b4fc4eb 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -224,26 +224,6 @@ Page({ const app = getApp(); app.updateCurrentTab('index'); app.globalData.showTabBar = true; - - const savedBtnTop = wx.getStorageSync('sidebarBtnTop'); - const savedBtnHidden = wx.getStorageSync('sidebarBtnHidden'); - const systemInfo = wx.getSystemInfoSync(); - const screenHeight = systemInfo.screenHeight * 2; - - let defaultTop = screenHeight * 0.5; - if (savedBtnTop !== '' && savedBtnTop !== -100) { - const minTop = screenHeight * 0.2; - const maxTop = screenHeight * 0.6; - if (savedBtnTop >= minTop && savedBtnTop <= maxTop) { - defaultTop = savedBtnTop; - } - } - - this.setData({ - sidebarBtnTop: defaultTop, - sidebarBtnHidden: savedBtnHidden || false - }); - this.checkAndRestoreLoginStatus() }, @@ -792,6 +772,9 @@ Page({ // 跳转到招商合作页面 navigateToCooperation: function() { + this.setData({ + sidebarBtnHidden: true + }); wx.navigateTo({ url: '/pages/cooperation/index' }) From 05794055502216a0ffdbb08414a771b1fa649ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 27 Dec 2025 10:44:07 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BE=A7=E8=BE=B9?= =?UTF-8?q?=E6=A0=8F=E6=8C=89=E9=92=AE=E5=9C=A8=E9=9D=9E=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BB=8D=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 离开首页时 (onHide) 隐藏侧边栏按钮 - 返回首页时 (onShow) 恢复保存的按钮状态 --- pages/index/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pages/index/index.js b/pages/index/index.js index b4fc4eb..4eeedfa 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -224,9 +224,21 @@ Page({ const app = getApp(); app.updateCurrentTab('index'); app.globalData.showTabBar = true; + + const savedBtnHidden = wx.getStorageSync('sidebarBtnHidden'); + this.setData({ + sidebarBtnHidden: savedBtnHidden || false + }); + this.checkAndRestoreLoginStatus() }, + onHide: function () { + this.setData({ + sidebarBtnHidden: true + }); + }, + onPullDownRefresh: function() { this.onRefresh() },