/** * 聊天输入组件 - 移动端优化 */ 'use client'; import { useState, FormEvent, KeyboardEvent, useRef, useEffect } from 'react'; interface ChatInputProps { onSend: (message: string) => void; isLoading: boolean; onAbort: () => void; } export default function ChatInput({ onSend, isLoading, onAbort }: ChatInputProps) { const [input, setInput] = useState(''); const textareaRef = useRef(null); // 自动调整 textarea 高度 useEffect(() => { if (textareaRef.current) { textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = `${Math.min(textareaRef.current.scrollHeight, 150)}px`; } }, [input]); const handleSubmit = (e: FormEvent) => { e.preventDefault(); if (input.trim() && !isLoading) { onSend(input.trim()); setInput(''); // 重置 textarea 高度 if (textareaRef.current) { textareaRef.current.style.height = 'auto'; } } }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSubmit(e); } }; return (