import React, { useState, useEffect } from 'react'; import { screenAdaptationService } from '../services/screenAdaptationService'; import { getCurrentWindow } from '@tauri-apps/api/window'; interface ScreenAdaptationSettingsProps { onClose?: () => void; } /** * 屏幕适配设置组件 * 允许用户自定义窗口适配参数 */ export const ScreenAdaptationSettings: React.FC = ({ onClose }) => { const [config, setConfig] = useState(screenAdaptationService.getConfig()); const [screenInfo, setScreenInfo] = useState<{ width: number; height: number; type: string; } | null>(null); const [currentSize, setCurrentSize] = useState<{ width: number; height: number; } | null>(null); const [loading, setLoading] = useState(false); useEffect(() => { loadScreenInfo(); loadCurrentSize(); }, []); const loadScreenInfo = async () => { try { const { type } = await screenAdaptationService.getScreenTypeConfig(); // 模拟获取屏幕信息 const info = { width: (globalThis as any).screen?.availWidth || 1920, height: (globalThis as any).screen?.availHeight || 1080, type: type }; setScreenInfo(info); } catch (error) { console.error('获取屏幕信息失败:', error); } }; const loadCurrentSize = async () => { try { const window = getCurrentWindow(); const size = await window.innerSize(); setCurrentSize({ width: size.width, height: size.height }); } catch (error) { console.error('获取当前窗口尺寸失败:', error); } }; const handleConfigChange = (key: string, value: number) => { const newConfig = { ...config, [key]: value }; setConfig(newConfig); screenAdaptationService.updateConfig(newConfig); }; const handleApplyAdaptation = async () => { setLoading(true); try { await screenAdaptationService.applyScreenAdaptation(); await loadCurrentSize(); } catch (error) { console.error('应用屏幕适配失败:', error); } finally { setLoading(false); } }; const handleSmartAdaptation = async () => { setLoading(true); try { await screenAdaptationService.applySmartAdaptation(); setConfig(screenAdaptationService.getConfig()); await loadCurrentSize(); } catch (error) { console.error('智能适配失败:', error); } finally { setLoading(false); } }; const previewSize = screenInfo ? { width: Math.floor(screenInfo.width * config.defaultWidthRatio), height: Math.floor(screenInfo.height * config.defaultHeightRatio) } : null; return (

屏幕适配设置

{onClose && ( )}
{/* 屏幕信息 */} {screenInfo && (

屏幕信息

屏幕尺寸: {screenInfo.width} × {screenInfo.height}
屏幕类型: {screenInfo.type}
{currentSize && (
当前窗口: {currentSize.width} × {currentSize.height}
)} {previewSize && (
预览尺寸: {previewSize.width} × {previewSize.height}
)}
)} {/* 配置选项 */}

窗口尺寸配置

handleConfigChange('defaultWidthRatio', parseFloat(e.target.value))} className="w-full" />
handleConfigChange('defaultHeightRatio', parseFloat(e.target.value))} className="w-full" />
handleConfigChange('minWidth', parseInt(e.target.value))} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500" />
handleConfigChange('minHeight', parseInt(e.target.value))} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500" />
{/* 操作按钮 */}

智能适配:根据屏幕类型自动选择最佳配置

应用设置:使用当前自定义配置

• 设置会在应用重启后保持

); };