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

127 lines
3.7 KiB
TypeScript
Raw Normal View History

2023-04-12 10:10:16 +08:00
import { Modal } from 'antd';
2023-04-24 13:43:36 +08:00
import React, { useEffect, useState } from 'react';
2023-04-11 15:29:40 +08:00
import { IChatItem } from '../ChatLogsType';
import { EmojiFormat } from './EmojiFormat';
2023-04-11 15:29:40 +08:00
export const ChatRecord: React.FC<IChatItem> = (props) => {
2023-04-12 10:10:16 +08:00
const [visible, setVisible] = useState(false);
2023-04-13 17:36:49 +08:00
function chatRecordContent(data: any, type: string) {
2023-04-12 10:10:16 +08:00
if (data.type == 'ChatRecordText') {
const content = JSON.parse(data.content);
2023-04-13 17:36:49 +08:00
return (
<div
style={{
maxWidth: type == 'ellipsis' ? 400 : 'inherit',
whiteSpace: type == 'ellipsis' ? 'nowrap' : 'normal',
minWidth: '0',
overflow: type == 'ellipsis' ? 'hidden' : '',
textOverflow: type == 'ellipsis' ? 'ellipsis' : 'inherit',
}}
>
{type == 'ellipsis' ? content.content : <EmojiFormat content={content.content || ''} />}
2023-04-13 17:36:49 +08:00
</div>
);
2023-04-12 10:10:16 +08:00
} else if (data.type == 'ChatRecordImage') {
return <div>[]</div>;
} else if (data.type == 'ChatRecordFile') {
return <div>[]</div>;
} else if (data.type == 'ChatRecordVideo') {
return <div>[]</div>;
} else if (data.type == 'ChatRecordLink') {
return <div>[]</div>;
} else if (data.type == 'ChatRecordLocation') {
return <div>[]</div>;
} else if (data.type == 'ChatRecordMixed') {
return <div>[]</div>;
}
return <div>[]</div>;
}
const [record, setRecord] = useState<any>(null);
useEffect(() => {
try {
const msg = JSON.parse(props.chat?.content as string);
setRecord(msg);
2023-04-24 13:43:36 +08:00
} catch (e) {
/* empty */
}
2023-04-12 10:10:16 +08:00
}, [props.chat]);
2023-04-11 15:29:40 +08:00
function content() {
try {
const msg = JSON.parse(props.chat?.content as string);
2023-04-13 17:36:49 +08:00
// console.log(msg);
2023-04-11 15:29:40 +08:00
return (
2023-04-12 10:10:16 +08:00
<div
style={{
display: 'flex',
color: '#000',
flexDirection: 'column',
minWidth: 260,
cursor: 'pointer',
}}
onClick={() => {
setVisible(true);
}}
2023-04-11 15:29:40 +08:00
>
2023-04-12 10:10:16 +08:00
<div style={{ wordBreak: 'break-all', fontSize: 16 }}>{msg.title}</div>
{msg.item[0] ? (
2023-04-13 17:36:49 +08:00
<div style={{ color: '#999' }}>{chatRecordContent(msg.item[0], 'ellipsis')}</div>
2023-04-12 10:10:16 +08:00
) : null}
{msg.item[1] ? (
2023-04-13 17:36:49 +08:00
<div style={{ color: '#999' }}>{chatRecordContent(msg.item[1], 'ellipsis')}</div>
2023-04-12 10:10:16 +08:00
) : null}
{msg.item[2] ? (
2023-04-13 17:36:49 +08:00
<div style={{ color: '#999' }}>{chatRecordContent(msg.item[2], 'ellipsis')}</div>
2023-04-12 10:10:16 +08:00
) : null}
<div style={{ borderTop: '1px solid #ddd', color: '#999', marginTop: 8, paddingTop: 8 }}>
</div>
</div>
2023-04-11 15:29:40 +08:00
);
} catch (_e) {
return (
<div>
<div style={{ wordBreak: 'break-all', paddingRight: 8 }}>{props.chat?.content}</div>
</div>
);
}
}
return (
<>
2023-04-12 10:10:16 +08:00
<Modal
open={visible}
footer={false}
title={record ? record.title : '无标题'}
onCancel={() => {
setVisible(false);
}}
2023-04-14 17:31:45 +08:00
centered
destroyOnClose
2023-04-12 10:10:16 +08:00
>
2023-04-14 17:31:45 +08:00
<div style={{ maxHeight: '75vh', overflow: 'auto' }}>
2023-04-12 10:10:16 +08:00
{record ? (
<div>
{record.item.map((item: any) => {
return (
<div
style={{ padding: '8px 0', borderBottom: '1px solid #eee' }}
2023-04-12 10:19:03 +08:00
key={`${item.msgtime}_${item.type}_${item.content}`}
2023-04-12 10:10:16 +08:00
>
2023-04-13 17:36:49 +08:00
{chatRecordContent(item, 'no_ellipsis')}
2023-04-12 10:10:16 +08:00
</div>
);
})}
</div>
) : null}
</div>
</Modal>
2023-04-13 17:36:49 +08:00
{content()}
2023-04-11 15:29:40 +08:00
</>
);
};