/** * 设备类型 */ export type DeviceType = 'mobile' | 'tablet' | 'desktop'; /** * 平台类型 */ export type DevicePlatform = 'ios' | 'android' | 'windows' | 'macos' | 'linux' | 'unknown'; /** * 设备检测结果 */ export interface DeviceInfo { /** 当前设备类型 */ type: DeviceType; /** 是否为手机 */ isMobile: boolean; /** 是否为平板 */ isTablet: boolean; /** 是否为桌面设备 */ isDesktop: boolean; /** 是否支持触摸输入 */ isTouch: boolean; /** 是否为小屏设备(通常 <= 768px) */ isSmallScreen: boolean; /** 操作系统 / 平台 */ platform: DevicePlatform; } /** * 检测当前运行环境的设备信息 * * 检测顺序: * 1. 使用浏览器现代标准 `navigator.userAgentData`(UA-CH) * 2. 不支持时降级为 User-Agent + 设备特征判断 * * @returns {DeviceInfo} 当前设备信息 * * @example * ```ts * const device = detectDevice() * * if (device.isMobile) { * enableMobileUI() * } * * if (device.isTablet) { * enableTabletLayout() * } * ``` */ export declare function detectDevice(): DeviceInfo;