diff --git a/frontend-react/src/App.jsx b/frontend-react/src/App.jsx index edeaf58..d2647ca 100644 --- a/frontend-react/src/App.jsx +++ b/frontend-react/src/App.jsx @@ -1,36 +1,58 @@ import React, { useState } from 'react'; -// 引入各区域组件(后续创建) +// 引入各区域组件 import PresetPanel from './components/PresetPanel'; import ChatBox from './components/ChatBox'; import ImageDisplay from './components/ImageDisplay'; import DicePanel from './components/DicePanel'; +import RoleSelector from './components/RoleSelector'; function App() { const [isToolbarExpanded, setIsToolbarExpanded] = useState(false); + const [selectedRole, setSelectedRole] = useState(null); + const [selectedChat, setSelectedChat] = useState(null); const toggleToolbar = () => { setIsToolbarExpanded(!isToolbarExpanded); }; + // 处理角色选择变化 + const handleRoleChange = (role) => { + setSelectedRole(role); + console.log('选择的角色:', role); + // 这里可以添加其他逻辑,比如加载角色的聊天记录等 + }; + + // 处理聊天选择变化 + const handleChatChange = (role, chat) => { + setSelectedChat(chat); + console.log('选择的聊天:', role, chat); + // 这里可以添加其他逻辑,比如加载聊天内容等 + }; + return (
{/* 顶部工具栏 */}
-
AI Chat Studio
+ {/* 工具栏内容区域 */} + {isToolbarExpanded && ( +
+ {/* 角色选择器 */} + +
+ )} + + {/* 工具栏切换按钮 */} - {/* 展开后的内容区域(预留) */} - {isToolbarExpanded && ( -
- {/* 工具栏内容待定 */} -
- )}
{/* 主体内容区域 */} diff --git a/frontend-react/src/components/ChatBox.jsx b/frontend-react/src/components/ChatBox.jsx index 6a3196b..2e71a21 100644 --- a/frontend-react/src/components/ChatBox.jsx +++ b/frontend-react/src/components/ChatBox.jsx @@ -5,16 +5,26 @@ const ChatBox = () => { const [isImageGen, setIsImageGen] = useState(false); const [isDynamicTable, setIsDynamicTable] = useState(false); const [isSettingsExpanded, setIsSettingsExpanded] = useState(false); + const [editingId, setEditingId] = useState(null); + const [editContent, setEditContent] = useState(''); const textareaRef = useRef(null); // 自动调整 Textarea 高度 const adjustHeight = () => { const textarea = textareaRef.current; - if (textarea) { - textarea.style.height = 'auto'; // 重置高度以获取正确的 scrollHeight - // 重新设置高度,限制最大高度由 CSS max-height 控制 - textarea.style.height = textarea.scrollHeight + 'px'; + const wrapper = textarea?.closest('.chat-input-wrapper'); + + if (textarea && wrapper) { + textarea.style.height = '42px'; + wrapper.style.height = 'auto'; + const newHeight = textarea.scrollHeight; + + if (newHeight > 42) { + textarea.style.height = newHeight + 'px'; + } else { + textarea.style.height = '42px'; + } } }; @@ -22,6 +32,34 @@ const ChatBox = () => { adjustHeight(); }; + // 开始编辑消息 + const startEdit = (id, content) => { + setEditingId(id); + setEditContent(content); + }; + + // 保存编辑的消息 + const saveEdit = (id) => { + // 这里可以添加向后端发送请求的代码 + console.log(`保存消息 ${id} 的编辑内容: ${editContent}`); + + // 更新前端显示 + const messageIndex = messages.findIndex(msg => msg.id === id); + if (messageIndex !== -1) { + messages[messageIndex].content = editContent; + } + + // 退出编辑模式 + setEditingId(null); + setEditContent(''); + }; + + // 取消编辑 + const cancelEdit = () => { + setEditingId(null); + setEditContent(''); + }; + // 生成示例数据 const generateMessages = () => { const messages = []; @@ -30,6 +68,7 @@ const ChatBox = () => { messages.push({ id: i, role: isUser ? 'user' : 'ai', + name: isUser ? '我' : 'AI助手', content: isUser ? `这是第 ${i} 条用户消息。这是一段比较长的文本,用来测试气泡的换行效果以及滚动条的表现。` : `这是第 ${i} 条 AI 回复。包含 HTML 标签的内容。如果渲染开关开启,这里应该显示粗体字。如果不开启,应该显示原始标签。` @@ -87,12 +126,62 @@ const ChatBox = () => { {/* 消息列表 */} {messages.map((msg) => (
-
- {isHtmlRender ? ( -
- ) : ( -
{msg.content}
- )} +
+ {/* 消息名称和工具栏在同一行 */} +
+
{msg.name}
+ + {/* 消息工具栏 */} +
+ ID: {msg.id} +
+ + +
+
+
+ + {/* 消息内容 */} +
+
+ {editingId === msg.id ? ( +
+