From 1bfbb47e9558fd04b4b8357b99ac1fcfd330d88e Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Fri, 18 Oct 2024 10:56:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/page/Meeting/ChatSmallWindow/index.tsx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/page/Meeting/ChatSmallWindow/index.tsx b/src/page/Meeting/ChatSmallWindow/index.tsx index c62f53b..ab7e47d 100644 --- a/src/page/Meeting/ChatSmallWindow/index.tsx +++ b/src/page/Meeting/ChatSmallWindow/index.tsx @@ -8,17 +8,16 @@ const ChatSmallWindow: React.FC = () => { const [isExpand, setIsExpand] = useState(false) 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, chatListIten } = event.data; switch (type) { case 'chatListIten': - setChatLists((newChatList: any) => [chatListIten, ...newChatList]) + setChatLists((newChatList: any) => { + chatListIten.timer = setTimeout(() => { + removeItemByIndex(); + }, 3000); + return [chatListIten, ...newChatList] + }) setTimeout(() => { const chatSmallWindowView = document.getElementById('chatSmallWindowView') as HTMLElement; if (chatSmallWindowView) { @@ -28,11 +27,12 @@ const ChatSmallWindow: React.FC = () => { break; } } - return () => { - clearTimeout(time) - } }, []); - + const removeItemByIndex = () => { + setChatLists((res: any) => { + return res.slice(0, -1) + }) + } return ( <>