Files
scrm.antd/src/pages/ChatLogs/components/ChatImage.tsx

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-04-12 10:10:16 +08:00
import { Image } from 'antd';
2023-04-24 13:43:36 +08:00
import React, { useState } from 'react';
2023-04-11 15:29:40 +08:00
import { IChatItem } from '../ChatLogsType';
import styles from './index.module.scss';
export const ChatImage: React.FC<IChatItem> = (props) => {
2023-04-12 10:10:16 +08:00
const [visible, setVisible] = useState(false);
2023-04-11 15:29:40 +08:00
function content() {
try {
const msg = JSON.parse(props.chat?.content as string);
return (
<div
2023-04-12 10:10:16 +08:00
className={styles.imgPreview}
2023-04-11 15:29:40 +08:00
style={{
display: 'flex',
color: '#000',
width: 180,
height: 150,
justifyContent: 'center',
}}
>
2023-04-12 10:10:16 +08:00
<Image
preview={{
visible: visible,
2023-04-24 13:43:36 +08:00
onVisibleChange: (value) => {
2023-04-12 10:10:16 +08:00
setVisible(value);
},
}}
2023-04-11 15:29:40 +08:00
src={`/api/${msg.path}`}
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
}}
2023-04-11 15:29:40 +08:00
alt=""
/>
</div>
);
} catch (_e) {
return (
<div>
<div style={{ wordBreak: 'break-all', paddingRight: 8 }}>{props.chat?.content}</div>
</div>
);
}
}
2023-04-13 17:36:49 +08:00
return <>{content()}</>;
2023-04-11 15:29:40 +08:00
};