完成请求推送,但组装mes还有问题

This commit is contained in:
2026-05-04 00:33:29 +08:00
parent 7fc9e10c99
commit 2050a30a52
93 changed files with 9499 additions and 2719 deletions

View File

@@ -46,7 +46,8 @@ const ChatBox = () => {
sendMessage,
stopGeneration,
options,
toggleOption
toggleOption,
cycleRenderMode // ✅ 新增:切换渲染模式
} = useChatBoxStore();
// 点击外部关闭选项面板
@@ -202,6 +203,35 @@ const ChatBox = () => {
alert('切换聊天失败: ' + error.message);
}
};
// 新建聊天
const handleCreateNewChat = async () => {
try {
const { currentRole, createChat, setChatBoxRoleAndChat } = useChatBoxStore.getState();
if (!currentRole) {
alert('请先选择一个角色');
return;
}
// 使用当前时间戳作为聊天名称
const chatName = `chat_${Date.now()}`;
// 创建新聊天
await createChat(currentRole, chatName);
// 切换到新创建的聊天
setChatBoxRoleAndChat(currentRole, chatName);
// 关闭选择器
setShowChatSelector(false);
console.log(`已创建并切换到新聊天: ${chatName}`);
} catch (error) {
console.error('创建聊天失败:', error);
alert('创建聊天失败: ' + error.message);
}
};
// 渲染单条消息
const renderMessage = (message) => {
@@ -283,14 +313,30 @@ const ChatBox = () => {
</div>
) : (
<div className="bubble">
{options.htmlRender && !isUser ? (
<div dangerouslySetInnerHTML={{ __html: currentMes }} />
) : options.markdownRender ? (
{options.renderMode === 'html' && !isUser ? (
// ✅ 智能 HTML 渲染:检测是否为纯文本,自动转换换行符
<div dangerouslySetInnerHTML={{
__html: (() => {
// 检测是否包含 HTML 标签
const hasHtmlTags = /<[a-z][\s\S]*>/i.test(currentMes);
if (hasHtmlTags) {
// 如果已有 HTML 标签,直接返回
return currentMes;
}
// 如果是纯文本,将换行符转换为 <br>
return currentMes
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\n/g, '<br>');
})()
}} />
) : options.renderMode === 'markdown' ? (
<MarkdownRenderer content={currentMes} />
) : (
<div className="plain-text">{currentMes}</div>
)}
{hasSwipes && isLatestMessage && !isUser && (
{hasSwipes && !isUser && isLatestMessage && (
<div className="swipe-controls">
<button
className="swipe-button"
@@ -345,24 +391,19 @@ const ChatBox = () => {
</button>
{showOptions && (
<div className="chat-options">
<label className="option-checkbox">
<input
type="checkbox"
checked={options.markdownRender}
onChange={() => toggleOption('markdownRender')}
/>
<span className="checkmark"></span>
<span className="option-label">Markdown渲染</span>
</label>
<label className="option-checkbox">
<input
type="checkbox"
checked={options.htmlRender}
onChange={() => toggleOption('htmlRender')}
/>
<span className="checkmark"></span>
<span className="option-label">HTML渲染</span>
</label>
{/* 渲染模式切换按钮 */}
<div className="option-group-title">显示</div>
<button
className="render-mode-btn"
onClick={() => cycleRenderMode()}
title={`当前: ${options.renderMode === 'none' ? '纯文本' : options.renderMode === 'html' ? 'HTML' : 'Markdown'},点击切换`}
>
{options.renderMode === 'none' ? '📄 纯文本' :
options.renderMode === 'html' ? '🌐 HTML' :
'📝 Markdown'}
</button>
<div className="option-group-title">功能</div>
<label className="option-checkbox">
<input
type="checkbox"
@@ -382,6 +423,17 @@ const ChatBox = () => {
<span className="option-label">动态表格</span>
</label>
{/* 自动掷骰子替换 */}
<label className="option-checkbox">
<input
type="checkbox"
checked={options.autoDiceRoll}
onChange={() => toggleOption('autoDiceRoll')}
/>
<span className="checkmark"></span>
<span className="option-label">🎲 自动掷骰子</span>
</label>
{/* 生图工作流选项 */}
<label className="option-checkbox">
<input
@@ -453,6 +505,16 @@ const ChatBox = () => {
</div>
<div className="chat-selector-body">
{/* 新建聊天按钮 */}
<div className="chat-selector-actions">
<button
className="new-chat-btn"
onClick={handleCreateNewChat}
>
+ 新建聊天
</button>
</div>
{characterChats.length > 0 ? (
<div className="chat-list">
{characterChats.map((chat, index) => (