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] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BE=A7=E8=BE=B9=E6=A0=8F?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E8=BE=B9=E7=95=8C=E6=A3=80=E6=B5=8B=E9=80=BB?= =?UTF-8?q?=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 @@ - +