From 9ad46fe088e3b4a0df33ea5920fc72c6f8610b3b Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Tue, 3 Jun 2025 17:26:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=AE=89=E5=85=A8=E5=8C=BA=E5=9F=9F):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=AE=89=E5=85=A8=E5=8C=BA=E5=9F=9F=E8=B7=9D?= =?UTF-8?q?=E7=A6=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 微信小程序需要使用 wx.getWindowInfo() API 获取安全区域距离,其他平台继续使用 uni.getSystemInfoSync() --- src/pages/index/index.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 3757593..e36edcc 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -38,7 +38,25 @@ defineOptions({ }) // 获取屏幕边界到安全区域距离 -const { safeAreaInsets } = uni.getSystemInfoSync() +let safeAreaInsets +// #ifdef MP-WEIXIN +// 微信小程序使用新的API +const systemInfo = wx.getWindowInfo() +safeAreaInsets = systemInfo.safeArea + ? { + top: systemInfo.safeArea.top, + right: systemInfo.windowWidth - systemInfo.safeArea.right, + bottom: systemInfo.windowHeight - systemInfo.safeArea.bottom, + left: systemInfo.safeArea.left, + } + : null +// #endif + +// #ifndef MP-WEIXIN +// 其他平台继续使用uni API +const systemInfo = uni.getSystemInfoSync() +safeAreaInsets = systemInfo.safeAreaInsets +// #endif const author = ref('菲鸽') const description = ref( 'unibest 是一个集成了多种工具和技术的 uniapp 开发模板,由 uniapp + Vue3 + Ts + Vite6 + UnoCss + VSCode 构建,模板具有代码提示、自动格式化、统一配置、代码片段等功能,并内置了许多常用的基本组件和基本功能,让你编写 uniapp 拥有 best 体验。',