fix: 修改语音组件中判断isPc的逻辑 (#4854)

* fix: 修改语音组件中判断isPc的逻辑

* fix: 修改语音组件中判断isPc的逻辑
This commit is contained in:
Compasafe
2025-05-22 16:29:53 +08:00
committed by GitHub
parent 88bd3aaa9e
commit 50481f4ca8
2 changed files with 31 additions and 1 deletions

View File

@@ -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);
};

View File

@@ -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<VoiceInputComponentRef, VoiceInputProps>(
({ 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);