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

87 lines
2.8 KiB
TypeScript
Raw Normal View History

import { SignalFilled } from '@ant-design/icons';
import { Modal } from 'antd';
import { useEffect, useState } from 'react';
2023-04-13 17:36:49 +08:00
import { IChatItem } from '../ChatLogsType';
import styles from './index.module.scss';
2023-04-13 17:36:49 +08:00
export const ChatVote: React.FC<IChatItem> = (props) => {
const votetype: any = { '101': '发起投票', '102': '参与投票' };
const [open, setOpen] = useState(false);
const [voteitem, setVoteitem] = useState([]);
useEffect(() => {
try {
const msg = JSON.parse(props.chat?.content as string);
setVoteitem(msg?.voteitem);
} catch (e) {}
}, [props.chat]);
2023-04-13 17:36:49 +08:00
function content() {
try {
const msg = JSON.parse(props.chat?.content as string);
return (
<>
<div
style={{ display: 'flex', color: '#000', flexDirection: 'column', cursor: 'pointer' }}
onClick={() => setOpen(true)}
>
<div style={{ wordBreak: 'break-all', fontWeight: 'bold' }}>{msg?.votetitle}</div>
<div style={{ wordBreak: 'break-all' }}>
{Array.isArray(msg?.voteitem)
? [0, 1, 2].map((item) => {
return msg?.voteitem[item] ? (
2023-04-23 10:06:55 +08:00
<div key={msg?.voteitem[item]} className={styles.voteitem}>
2023-04-21 17:36:02 +08:00
{msg?.voteitem[item]}
</div>
) : (
<></>
);
})
: null}
</div>
<div
style={{ borderTop: '1px solid #ddd', color: '#999', marginTop: 8, paddingTop: 8 }}
>
<SignalFilled style={{ color: '#F0B40E' }} /> [
{votetype[msg?.votetype as string]}]
</div>
</div>
<Modal
open={open}
title={msg?.votetitle}
centered
onCancel={() => {
setOpen(false);
}}
footer={false}
>
<div style={{ maxHeight: '75vh', overflow: 'auto' }}>
{Array.isArray(voteitem)
? voteitem.map((item) => {
return (
2023-04-23 10:06:55 +08:00
<div key={`_${item}`} className={styles.voteitem}>
{item}
</div>
);
})
: null}
</div>
</Modal>
</>
);
} catch (e) {}
2023-04-13 17:36:49 +08:00
return (
<div style={{ display: 'flex', color: '#000', flexDirection: 'column' }}>
<div style={{ wordBreak: 'break-all' }}>{props.chat?.content}</div>
2023-04-13 17:36:49 +08:00
<div style={{ borderTop: '1px solid #ddd', color: '#999', marginTop: 8, paddingTop: 8 }}>
<SignalFilled style={{ color: '#F0B40E' }} />
2023-04-13 17:36:49 +08:00
</div>
</div>
);
}
return <>{content()}</>;
};