From fcd3a6eb0750fd53802213f4a16a7d6578162cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=AF=9A?= Date: Thu, 8 Jan 2026 15:23:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20PWA=20=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E9=94=AE=E7=9B=98=E6=94=B6=E8=B5=B7=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E4=B8=8D=E5=9B=9E=E5=BC=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/src/App.vue | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Web/src/App.vue b/Web/src/App.vue index 3600b36..f33095f 100644 --- a/Web/src/App.vue +++ b/Web/src/App.vue @@ -46,19 +46,31 @@ import '@/styles/common.css' const messageStore = useMessageStore() const updateVh = () => { - // 获取真实的视口高度(PWA 模式下准确) const vh = window.innerHeight - // 设置 CSS 变量,让所有组件使用准确的视口高度 document.documentElement.style.setProperty('--vh', `${vh}px`) } +// 修复 PWA 模式下键盘收起页面不回弹的问题 +const handleFocusOut = () => { + if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) { + // 延迟一小段时间执行,确保键盘收起动作已开始 + setTimeout(() => { + // 强制回到顶部 + window.scrollTo(0, 0) + // 同时也触发一次高度更新 + updateVh() + }, 100) + } +} + onMounted(() => { updateVh() window.addEventListener('resize', updateVh) - // 监听 iOS Safari 视口变化 if (window.visualViewport) { window.visualViewport.addEventListener('resize', updateVh) } + // 注册全局失去焦点监听 + document.addEventListener('focusout', handleFocusOut) }) onUnmounted(() => { @@ -66,6 +78,8 @@ onUnmounted(() => { if (window.visualViewport) { window.visualViewport.removeEventListener('resize', updateVh) } + // 销毁监听 + document.removeEventListener('focusout', handleFocusOut) }) const route = useRoute()