-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
226 additions
and
29 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/plugins/@gemel/plugin-inquiry-record-detail/src/client/assets/css/chatMessage.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.chatContainer { | ||
width: 520px; | ||
max-height: 520px; | ||
overflow-y: auto; | ||
padding: 12px; | ||
} | ||
|
||
.messageItem { | ||
display: flex; | ||
margin-bottom: 12px; | ||
} | ||
|
||
.messageItemSender { | ||
flex-direction: row-reverse; | ||
} | ||
|
||
.messageContent { | ||
max-width: 300px; | ||
margin: 0 0 0 12px; | ||
padding: 8px 12px; | ||
border-radius: 8px; | ||
word-break: break-all; | ||
line-height: 1.5; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
.messageContentSender { | ||
margin: 0 12px 0 0; | ||
background-color: #e6f7ff; | ||
} | ||
|
||
.avatar { | ||
flex-shrink: 0; | ||
} |
1 change: 1 addition & 0 deletions
1
...gins/@gemel/plugin-inquiry-record-detail/src/client/assets/svg/chatMessages.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions
58
packages/plugins/@gemel/plugin-inquiry-record-detail/src/client/component/ChatMessage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* This file is part of the NocoBase (R) project. | ||
* Copyright (c) 2020-2024 NocoBase Co., Ltd. | ||
* Authors: NocoBase Team. | ||
* | ||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. | ||
* For more information, please refer to: https://www.nocobase.com/agreement. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Avatar } from 'antd'; | ||
import styles from '../assets/css/chatMessage.css'; | ||
import classNames from 'classnames'; | ||
|
||
interface ChatMessage { | ||
speakerRole: 'human' | 'ai'; | ||
content: string; | ||
} | ||
|
||
const ChatMessages: React.FC<{ messages: ChatMessage[] }> = ({ messages }) => { | ||
// 将换行符转换为<br/> | ||
const formatContent = (content: string) => { | ||
if (!content) return null; | ||
return content.split('\n').map((text, index) => ( | ||
<React.Fragment key={index}> | ||
{text} | ||
{index !== content.split('\n').length - 1 && <br />} | ||
</React.Fragment> | ||
)); | ||
}; | ||
|
||
return ( | ||
<div className={styles.chatContainer}> | ||
{messages.map((message, index) => { | ||
const isHuman = message.speakerRole === 'human'; | ||
|
||
return ( | ||
<div key={index} className={classNames(styles.messageItem, isHuman && styles.messageItemSender)}> | ||
<Avatar | ||
className={styles.avatar} | ||
size="small" | ||
style={{ | ||
backgroundColor: isHuman ? '#1890ff' : '#87d068', | ||
}} | ||
> | ||
{isHuman ? 'AI' : 'U'} | ||
</Avatar> | ||
<div className={classNames(styles.messageContent, isHuman && styles.messageContentSender)}> | ||
{formatContent(message.content)} | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ChatMessages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.