优化聊天框输入聚焦逻辑,增强网络错误处理

This commit is contained in:
2026-03-24 16:25:09 +08:00
parent 045391d036
commit 825acbf29c
3 changed files with 48 additions and 13 deletions
+10
View File
@@ -113,6 +113,7 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
const [conversationId, setConversationId] = useState<string | undefined>(undefined);
const abortRef = useRef<AbortController | null>(null);
const bottomRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement | null>(null);
const theme = useTheme();
const canSend = useMemo(() => input.trim().length > 0 && !isStreaming, [input, isStreaming]);
@@ -122,6 +123,14 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
}, [messages, isStreaming]);
useEffect(() => {
if (!open) return;
const timer = window.setTimeout(() => {
inputRef.current?.focus();
}, 0);
return () => window.clearTimeout(timer);
}, [open]);
const handleSend = async () => {
const prompt = input.trim();
if (!prompt || isStreaming) return;
@@ -443,6 +452,7 @@ export const GlobalChatbox: React.FC<Props> = ({ open, onClose }) => {
}}
>
<TextField
inputRef={inputRef}
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyDown={(e) => {