🎨 优化正则模块和前端渲染功能

Signed-off-by: Echo <1711788888@qq.com>
This commit is contained in:
2026-03-03 03:40:03 +08:00
parent 3f8220340e
commit cbb4034a91
13 changed files with 613 additions and 95 deletions

View File

@@ -75,6 +75,24 @@ export default function ChatArea({ conversation, character, onConversationUpdate
scrollToBottom()
}, [messages])
// 监听状态栏按钮点击事件
useEffect(() => {
const handleStatusBarAction = (event: CustomEvent) => {
const action = event.detail
if (action && typeof action === 'string' && !sending) {
console.log('[ChatArea] 收到状态栏操作,自动发送消息:', action)
setInputValue(action)
// 延迟发送,确保 inputValue 已更新
setTimeout(() => {
handleSendMessage(action)
}, 100)
}
}
window.addEventListener('sendMessageFromStatusBar', handleStatusBarAction as EventListener)
return () => window.removeEventListener('sendMessageFromStatusBar', handleStatusBarAction as EventListener)
}, [sending])
const loadMessages = async () => {
try {
setLoading(true)
@@ -185,11 +203,10 @@ export default function ChatArea({ conversation, character, onConversationUpdate
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' })
}
const handleSend = async () => {
if (!inputValue.trim() || sending) return
const handleSendMessage = async (message: string) => {
if (!message.trim() || sending) return
const userMessage = inputValue.trim()
setInputValue('')
const userMessage = message.trim()
setSending(true)
const tempUserMessage: Message = {
@@ -277,6 +294,13 @@ export default function ChatArea({ conversation, character, onConversationUpdate
}
}
const handleSend = async () => {
if (!inputValue.trim() || sending) return
const userMessage = inputValue.trim()
setInputValue('')
await handleSendMessage(userMessage)
}
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter' && !e.shiftKey && !sending && inputValue.trim()) {
e.preventDefault()
@@ -644,7 +668,7 @@ export default function ChatArea({ conversation, character, onConversationUpdate
>
<MessageContent
content={msg.content}
role={msg.role}
role={msg.role as 'user' | 'assistant'}
onChoiceSelect={(choice) => {
setInputValue(choice)
textareaRef.current?.focus()