import styles from '@/page/Meeting/ChatSmallWindow/index.module.scss' import { Input } from 'antd'; import { useEffect, useState } from "react"; import { storage } from '@/utils'; const ChatSmallWindow: React.FC = () => { const [inputValue, setInputValue] = useState('') const [chatLists, setChatLists] = useState([]) const userInfo = JSON.parse(storage.getItem('user') as string) const channel = new BroadcastChannel('meeting_channel'); useEffect(() => { channel.onmessage = function (event) { const { type, chatList } = event.data; switch (type) { case 'chatList': setChatLists(chatList.reverse()) setTimeout(() => { const chatSmallWindowView = document.getElementById('chatSmallWindowView') as HTMLElement; if (chatSmallWindowView) { chatSmallWindowView.scrollTop = chatSmallWindowView.scrollHeight; } }, 100) break; } } }, []); return ( <>
{chatLists.map((item: any) =>
{item.userName} {item.message}
)}
{ setInputValue(e.target.value) }} onPressEnter={() => { if (inputValue) { channel.postMessage({ type: 'chatSmallWindowSendChannelMsg', chatSmallWindowSendChannelMsg: { msg: inputValue, } }); setInputValue('') } }} suffix={ { if (inputValue) { channel.postMessage({ type: 'chatSmallWindowSendChannelMsg', chatSmallWindowSendChannelMsg: { msg: inputValue, } }); setInputValue('') } }} >发送 } />
) } export default ChatSmallWindow