From 40f99f0c49eada3e21163a0ebba077487f6aa15d Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Tue, 10 Mar 2026 10:49:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5=E6=94=B9=E9=80=A0?= =?UTF-8?q?=E6=88=90ChatGPT=E9=A3=8E=E6=A0=BC=E5=AF=B9=E8=AF=9D=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=E8=B0=83=E6=95=B4=E5=90=84=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?padding=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tabs/MarkdownTabPage/MarkdownTabPage.tsx | 2 +- src/modules/home/HomePage.tsx | 10 +- src/modules/home/components/ChatContent.tsx | 120 ++++++++++++++++++ src/modules/home/components/ChatLayout.tsx | 11 ++ src/modules/home/components/ChatSidebar.tsx | 53 ++++++++ src/modules/pydemos/PyDemosPage.tsx | 2 +- src/modules/remote/RemotePage.tsx | 7 +- src/modules/search/SearchPage.tsx | 2 +- .../time-tracking/TimeTrackingPage.tsx | 2 +- src/modules/todo/TodoPage.tsx | 6 +- src/pages/NoteBrowser.tsx | 1 - src/stores/chatStore.ts | 98 ++++++++++++++ 12 files changed, 295 insertions(+), 19 deletions(-) create mode 100644 src/modules/home/components/ChatContent.tsx create mode 100644 src/modules/home/components/ChatLayout.tsx create mode 100644 src/modules/home/components/ChatSidebar.tsx create mode 100644 src/stores/chatStore.ts diff --git a/src/components/tabs/MarkdownTabPage/MarkdownTabPage.tsx b/src/components/tabs/MarkdownTabPage/MarkdownTabPage.tsx index 1adfff7..faea37c 100644 --- a/src/components/tabs/MarkdownTabPage/MarkdownTabPage.tsx +++ b/src/components/tabs/MarkdownTabPage/MarkdownTabPage.tsx @@ -29,7 +29,7 @@ export const MarkdownTabPage: React.FC = ({ return (
diff --git a/src/modules/home/HomePage.tsx b/src/modules/home/HomePage.tsx index 93a6f2f..b3dbc32 100644 --- a/src/modules/home/HomePage.tsx +++ b/src/modules/home/HomePage.tsx @@ -1,9 +1,5 @@ +import { ChatLayout } from './components/ChatLayout' + export const HomePage = () => { - return ( -
-

- 开始今天的工作吧! -

-
- ) + return } diff --git a/src/modules/home/components/ChatContent.tsx b/src/modules/home/components/ChatContent.tsx new file mode 100644 index 0000000..1fc98b3 --- /dev/null +++ b/src/modules/home/components/ChatContent.tsx @@ -0,0 +1,120 @@ +import { Send } from 'lucide-react' +import { useChatStore, type ChatMessage } from '@/stores/chatStore' +import { useState, useRef, useEffect } from 'react' + +const MessageItem = ({ message }: { message: ChatMessage }) => { + const isUser = message.role === 'user' + + return ( +
+
+
+ {isUser ? ( + 👤 + ) : ( + 🤖 + )} +
+
+ {message.content} +
+
+
+ ) +} + +export const ChatContent = () => { + const { currentChatId, chats, addMessage, updateChatTitle } = useChatStore() + const [input, setInput] = useState('') + const messagesEndRef = useRef(null) + + const currentChat = chats.find((c) => c.id === currentChatId) + const messages = currentChat?.messages ?? [] + + useEffect(() => { + messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }) + }, [messages.length]) + + const handleSend = () => { + if (!input.trim() || !currentChatId) return + + const userMessage: ChatMessage = { + id: Math.random().toString(36).substring(2, 15), + role: 'user', + content: input.trim(), + timestamp: Date.now(), + } + + addMessage(currentChatId, userMessage) + + if (messages.length === 0) { + const title = input.trim().slice(0, 20) + (input.trim().length > 20 ? '...' : '') + updateChatTitle(currentChatId, title) + } + + setInput('') + } + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault() + handleSend() + } + } + + return ( +
+
+ {messages.length === 0 ? ( +
+

+ 开始今天的工作吧! +

+
+ ) : ( +
+ {messages.map((msg) => ( + + ))} +
+
+ )} +
+ +
+
+
+