From 5a50f7ff0de2d94537dc0dc6b03f9ae230fdd48b Mon Sep 17 00:00:00 2001 From: no99 <17663930442@163.com> Date: Thu, 3 Jul 2025 14:49:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=BB=E5=BC=80homepage=E6=97=B6=E5=8D=B8?= =?UTF-8?q?=E8=BD=BD=E7=A6=81=E6=AD=A2=E6=BB=9A=E5=8A=A8=E7=9A=84=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E5=AE=89=E5=8D=93=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/homePage.vue | 88 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 26 deletions(-) diff --git a/src/views/homePage.vue b/src/views/homePage.vue index 47c9944..04c3a3a 100644 --- a/src/views/homePage.vue +++ b/src/views/homePage.vue @@ -487,33 +487,29 @@ const onBlur = function () { }, 200); }; -window.addEventListener("resize", () => { - // 检测是否为iOS设备 - const isIOS = /iPhone|iPad|iPod|ios/i.test(navigator.userAgent); - console.log("是否为iOS设备:", isIOS); - if (!isIOS) { - console.log("窗口大小变化"); - const homePage = document.querySelector(".homepage"); - homePage.style.height = `${window.innerHeight}px`; - } -}); - -// 禁用全局触摸滚动 -document.addEventListener( - "touchmove", - (e) => { - if (!dataStore.isFeedback) { - // 判断触摸目标是否在可滚动区域内 - const isScrollableArea = e.target.closest(".tab-content"); - - // 如果不在可滚动区域,则阻止滚动 - if (!isScrollableArea) { - e.preventDefault(); - } +// window.addEventListener("resize", () => { +// // 检测是否为iOS设备 +// const isIOS = /iPhone|iPad|iPod|ios/i.test(navigator.userAgent); +// console.log("是否为iOS设备:", isIOS); +// if (!isIOS) { +// console.log("窗口大小变化"); +// const homePage = document.querySelector(".homepage"); +// homePage.style.height = `${window.innerHeight}px`; +// } +// }); + +let touchmoveHandlerRef = null; +const touchmoveHandler = (e) => { + if (!dataStore.isFeedback) { + // 判断触摸目标是否在可滚动区域内 + const isScrollableArea = e.target.closest(".tab-content"); + + // 如果不在可滚动区域,则阻止滚动 + if (!isScrollableArea) { + e.preventDefault(); } - }, - { passive: false } -); + } +}; onMounted(async () => { // const isPhone = @@ -525,6 +521,13 @@ onMounted(async () => { // "localToken", // decodeURIComponent(String(getQueryVariable("token"))) // ); + + // 禁用全局触摸滚动 + touchmoveHandlerRef = touchmoveHandler; + document.addEventListener("touchmove", touchmoveHandlerRef, { + passive: false, + }); + setHeight(document.getElementById("testId")); // 给父组件发送窗口高度 // 获取次数 await chatStore.getUserCount(); @@ -533,12 +536,45 @@ onMounted(async () => { // 监听页面高度 throttledHeightListener(); + const isAndroid = /Android/i.test(navigator.userAgent); + if (isAndroid) { + window.visualViewport.addEventListener("resize", () => { + const keyboardHeight = window.innerHeight - window.visualViewport.height; + console.log("视口大小变化", keyboardHeight); + + // 如果键盘高度大于100px,认为键盘弹出 + if (keyboardHeight > 100) { + const footer = document.querySelector(".el-footer"); + footer.style.paddingBottom = `${keyboardHeight}px`; + + // 滚动到输入框位置 + setTimeout(() => { + const msgInput = document.querySelector(".msg-input"); + if (msgInput) { + msgInput.scrollIntoView({ behavior: "smooth" }); + } + }, 300); + } else { + // 键盘收起 + const footer = document.querySelector(".el-footer"); + footer.style.paddingBottom = "0px"; + } + }); + } + // 添加输入框焦点处理 // handleInputFocus(); // 初始化视口高度变量 // updateAppHeight(); }); + +onUnmounted(() => { + if (touchmoveHandlerRef) { + console.log("卸载touchmoveHandlerRef组件"); + document.removeEventListener("touchmove", touchmoveHandlerRef); + } +});