59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
![]() |
import { IChatItem } from '../ChatLogsType';
|
||
|
import styles from './index.module.scss';
|
||
|
|
||
|
export const ChatImage: React.FC<IChatItem> = (props) => {
|
||
|
function content() {
|
||
|
try {
|
||
|
const msg = JSON.parse(props.chat?.content as string);
|
||
|
|
||
|
return (
|
||
|
<div
|
||
|
style={{
|
||
|
display: 'flex',
|
||
|
color: '#000',
|
||
|
width: 180,
|
||
|
height: 150,
|
||
|
justifyContent: 'center',
|
||
|
}}
|
||
|
>
|
||
|
<img
|
||
|
src={`/api/${msg.path}`}
|
||
|
style={{ maxWidth: '100%', maxHeight: '100%', objectFit: 'contain' }}
|
||
|
alt=""
|
||
|
/>
|
||
|
</div>
|
||
|
);
|
||
|
} catch (_e) {
|
||
|
return (
|
||
|
<div>
|
||
|
<div style={{ wordBreak: 'break-all', paddingRight: 8 }}>{props.chat?.content}</div>
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<>
|
||
|
{props.from?.user_id == props.chat?.msg_from ? (
|
||
|
<div className={styles.chatRight}>
|
||
|
<div className={styles.chatContentBox}>
|
||
|
<div className={styles.name}>{props.from?.name}</div>
|
||
|
<div className={styles.content}>{content()}</div>
|
||
|
</div>
|
||
|
<div className={styles.chatAvatar}>{props.from?.name[0]}</div>
|
||
|
</div>
|
||
|
) : (
|
||
|
<div className={styles.chatLeft}>
|
||
|
<div className={styles.chatAvatar}>
|
||
|
<img src={props.to?.cust_info.avatar} alt="" />
|
||
|
</div>
|
||
|
<div className={styles.chatContentBox}>
|
||
|
<div className={styles.name}>{props.to?.cust_info.name}</div>
|
||
|
<div className={styles.content}>{content()}</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
)}
|
||
|
</>
|
||
|
);
|
||
|
};
|