From 50481f4ca8539d0f514c38957bfae1e168a51ab2 Mon Sep 17 00:00:00 2001 From: Compasafe <903037065@qq.com> Date: Thu, 22 May 2025 16:29:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=B8=AD=E5=88=A4=E6=96=ADisPc=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20(#4854)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修改语音组件中判断isPc的逻辑 * fix: 修改语音组件中判断isPc的逻辑 --- packages/web/common/system/utils.ts | 29 +++++++++++++++++++ .../ChatBox/Input/VoiceInput.tsx | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/web/common/system/utils.ts b/packages/web/common/system/utils.ts index 63fceb55e..ade6b690a 100644 --- a/packages/web/common/system/utils.ts +++ b/packages/web/common/system/utils.ts @@ -16,3 +16,32 @@ export const getWebReqUrl = (url: string = '') => { if (!url.startsWith('/') || url.startsWith(baseUrl)) return url; return `${baseUrl}${url}`; }; + +export const isMobile = () => { + // 服务端渲染时返回 false + if (typeof window === 'undefined') return false; + + // 1. 检查 User-Agent + const userAgent = navigator.userAgent.toLowerCase(); + const mobileKeywords = [ + 'android', + 'iphone', + 'ipod', + 'ipad', + 'windows phone', + 'blackberry', + 'webos', + 'iemobile', + 'opera mini' + ]; + const isMobileUA = mobileKeywords.some((keyword) => userAgent.includes(keyword)); + + // 2. 检查屏幕宽度 + const isMobileWidth = window.innerWidth <= 900; + + // 3. 检查是否支持触摸事件(排除触控屏PC) + const isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0; + + // 综合判断:满足以下任一条件即视为移动端 + return isMobileUA || (isMobileWidth && isTouchDevice); +}; diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/VoiceInput.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/VoiceInput.tsx index 1d851b21f..04fe2e5c5 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/VoiceInput.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/VoiceInput.tsx @@ -16,6 +16,7 @@ import { useSystem } from '@fastgpt/web/hooks/useSystem'; import { useContextSelector } from 'use-context-selector'; import { ChatBoxContext } from '../Provider'; import MyIconButton from '@/pageComponents/account/team/OrgManage/IconButton'; +import { isMobile } from '@fastgpt/web/common/system/utils'; export interface VoiceInputComponentRef { onSpeak: () => void; @@ -213,7 +214,7 @@ const MobileVoiceInput = ({ const VoiceInput = forwardRef( ({ onSendMessage, resetInputVal }, ref) => { const { t } = useTranslation(); - const { isPc } = useSystem(); + const isPc = !isMobile(); const outLinkAuthData = useContextSelector(ChatBoxContext, (v) => v.outLinkAuthData); const appId = useContextSelector(ChatBoxContext, (v) => v.appId);