Files
FastGPT/packages/web/common/system/utils.ts
Compasafe 50481f4ca8 fix: 修改语音组件中判断isPc的逻辑 (#4854)
* fix: 修改语音组件中判断isPc的逻辑

* fix: 修改语音组件中判断isPc的逻辑
2025-05-22 16:29:53 +08:00

48 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import FingerprintJS from '@fingerprintjs/fingerprintjs';
export const getUserFingerprint = async () => {
const fp = await FingerprintJS.load();
const result = await fp.get();
console.log(result.visitorId);
};
export const subRoute = process.env.NEXT_PUBLIC_BASE_URL;
export const getWebReqUrl = (url: string = '') => {
if (!url) return '/';
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL;
if (!baseUrl) return url;
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);
};