From 58facc62ea0053ca70783f9492be15b04848eefe Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Thu, 17 Oct 2024 12:21:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F10=E7=A7=92=E5=88=A0=E9=99=A4=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E4=B8=80=E9=A1=B9=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/page/Meeting/ChatSmallWindow/index.tsx | 17 ++++++++++++----- src/page/Meeting/index.tsx | 13 +++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/page/Meeting/ChatSmallWindow/index.tsx b/src/page/Meeting/ChatSmallWindow/index.tsx index 6370a9f..3848677 100644 --- a/src/page/Meeting/ChatSmallWindow/index.tsx +++ b/src/page/Meeting/ChatSmallWindow/index.tsx @@ -1,18 +1,22 @@ 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(() => { + let time: NodeJS.Timeout; + time = setInterval(() => { + setChatLists((res: any) => { + return res.length ? res.slice(0, -1) : res + }) + }, 10000) channel.onmessage = function (event) { - const { type, chatList } = event.data; + const { type, chatListIten } = event.data; switch (type) { - case 'chatList': - setChatLists(chatList.reverse()) + case 'chatListIten': + setChatLists((newChatList: any) => [chatListIten, ...newChatList]) setTimeout(() => { const chatSmallWindowView = document.getElementById('chatSmallWindowView') as HTMLElement; if (chatSmallWindowView) { @@ -22,6 +26,9 @@ const ChatSmallWindow: React.FC = () => { break; } } + return () => { + clearTimeout(time) + } }, []); diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index a2d780d..ef8a8b5 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -509,6 +509,10 @@ const Meeting: React.FC = () => { setNoViewChatList(storageNoViewChatList) } setChatList((newChatList: any) => [...newChatList, item]) + channel.postMessage({ + type: 'chatListIten', + chatListIten: item, + }); setStatusList((res: any) => { if (!res.userChatList) { api.open({ @@ -1673,12 +1677,17 @@ const Meeting: React.FC = () => { roomNum: state.channelId, msg: msg, }) - setChatList((newChatList: any) => [...newChatList, { + let item = { uid: userInfo.uid, userName: userInfo.userName, message: msg, timestamp: +new Date() - }]) + } + setChatList((newChatList: any) => [...newChatList, item]) + channel.postMessage({ + type: 'chatListIten', + chatListIten: item, + }); setTextMsg(''); chatScrollBotton() } else {