From c699ebb0bf95772770ff4f64be315cce91d88ffc Mon Sep 17 00:00:00 2001 From: "zhangyumei.0319" Date: Mon, 26 Aug 2024 20:35:50 +0800 Subject: [PATCH] fix: [Chat]Fix special symbols causing conversion errors --- packages/semi-foundation/chat/chat.scss | 5 +++- packages/semi-foundation/chat/variables.scss | 2 ++ packages/semi-ui/chat/_story/constant.js | 8 ++++- .../semi-ui/chat/chatBox/chatBoxContent.tsx | 30 +++++++++++-------- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/packages/semi-foundation/chat/chat.scss b/packages/semi-foundation/chat/chat.scss index 0784ac821c..43cc119bc9 100644 --- a/packages/semi-foundation/chat/chat.scss +++ b/packages/semi-foundation/chat/chat.scss @@ -233,6 +233,7 @@ $module: #{$prefix}-chat; .#{$module}-attachment-file, .#{$module}-attachment-img { margin-top: $spacing-chat_chatBox_content_attachment-marginY; margin-bottom: $spacing-chat_chatBox_content_attachment-marginY; + margin-right: $spacing-chat_chatBox_content_attachment-marginRight; } &-user { @@ -457,6 +458,8 @@ $module: #{$prefix}-chat; flex-wrap: wrap; column-gap: $spacing-chat_attachment-columnGap; row-gap: $spacing-chat_attachment-RowGap; + margin-left: $spacing-chat_attachment-marginX; + margin-right: $spacing-chat_attachment-marginX; &-item { position: relative; @@ -493,7 +496,7 @@ $module: #{$prefix}-chat; } &-file { - display: flex; + display: inline-flex; flex-direction: row; align-items: center; height: $width-chat_attachment_file; diff --git a/packages/semi-foundation/chat/variables.scss b/packages/semi-foundation/chat/variables.scss index 424e8a3865..d40f9e4af3 100644 --- a/packages/semi-foundation/chat/variables.scss +++ b/packages/semi-foundation/chat/variables.scss @@ -67,6 +67,7 @@ $spacing-chat_inputBox_inner-columnGap: 4px; // 输入框容器列间距 $spacing-chat_inputBox-marginY: 4px; $spacing-chat_attachment-columnGap: 10px; // 附件列间距 $spacing-chat_attachment-RowGap: 5px; // 附件行间距 +$spacing-chat_attachment-marginX: 12px; // 附件左右外边距 $spacing-chat_attachment_clear-top: 8px; // 附件清除图标顶部间距 $spacing-chat_attachment_clear-right: 8px; // 附件清除图标右内边距 $spacing-chat_attachment_file-columnGap: 5px; // 文件附件列间距 @@ -74,6 +75,7 @@ $spacing-chat_attachment_file-padding: 5px; // 文件附件内边距 $spacing-chat_chatBox_loading_item-gap: 15px; // 聊天内容加载图标间距 $spacing-chat_divider-marginY: 12px; // 分割线上下外边距 $spacing-chat_chatBox_content_attachment-marginY: 4px; // 聊天框内容文件/图片上下外间距 +$spacing-chat_chatBox_content_attachment-marginRight: 4px; //聊天框内容文件/图片上下右间距 $spacing-chat_chatBox_content_code_topSlot-paddingX: 5px; // 聊天框代码块顶部上下内边距 $spacing-chat_chatBox_content_code_topSlot-paddingY: 8px; // 聊天框代码块顶部左右内边距 $spacing-chat_chatBox_content_code_topSlot_copy-columnGap: 5px; // 聊天框代码块顶部复制按钮列间距: diff --git a/packages/semi-ui/chat/_story/constant.js b/packages/semi-ui/chat/_story/constant.js index b7b25767fd..fd917f4bd6 100644 --- a/packages/semi-ui/chat/_story/constant.js +++ b/packages/semi-ui/chat/_story/constant.js @@ -69,7 +69,13 @@ const infoWithAttachment = [ { type: 'image_url', image_url: { - url: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/edit-bag.jpeg' + url: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/edit-bag.jpeg', + }, + }, + { + type: 'image_url', + image_url: { + url: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/SemiLogo.jpg' }, } ], diff --git a/packages/semi-ui/chat/chatBox/chatBoxContent.tsx b/packages/semi-ui/chat/chatBox/chatBoxContent.tsx index df64f063dc..66038f0188 100644 --- a/packages/semi-ui/chat/chatBox/chatBoxContent.tsx +++ b/packages/semi-ui/chat/chatBox/chatBoxContent.tsx @@ -47,28 +47,34 @@ const ChatBoxContent = (props: ChatBoxContentProps) => { ; } else { - let realContent = ''; + let realContent; if (typeof content === 'string') { - realContent = content; + realContent = ; } else if (Array.isArray(content)) { - realContent = content.map((item)=> { + realContent = content.map((item, index)=> { if (item.type === 'text') { - return item.text; + return ; } else if (item.type === 'image_url') { - return `![image](${item.image_url.url})`; + return ; } else if (item.type === 'file_url') { const { name, size, url, type } = item.file_url; const realType = name.split('.').pop() ?? type?.split('/').pop(); - return ``; + return ; } - return ''; - }).join('\n\n'); + return null; + }); } return (<> - + {realContent} ); } }, [status, content]);