From 03535092c0e8b68d18458ce4e5c42e91b7d6f544 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 10 Jun 2022 19:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/conversation/index.jsx | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/pages/customerservice/support/conversation/index.jsx b/src/pages/customerservice/support/conversation/index.jsx index 6d6eb23..30874d9 100644 --- a/src/pages/customerservice/support/conversation/index.jsx +++ b/src/pages/customerservice/support/conversation/index.jsx @@ -231,7 +231,7 @@ const conversation = (props) => { setMsgPage(msgPage+1) } let count = earlierMsg.length - let arr = [...msgList] + let arr = pageNum==1?[] : [...msgList] while(count>0){ arr.unshift(earlierMsg.pop()) count-- @@ -266,14 +266,18 @@ const disconnectedAlert = () =>{ const checkDisconnected = ()=>{ if(window.isCloseChatUIModal!=undefined){ //弹窗没有关闭(弹窗开着或者隐藏,ws不应该断) console.log('websocket断开,重新连接') - if(isModalVisible){ //断连后,用户打开弹窗再发提醒 - setConversationId('') + console.log(window.isModalVisibleForCustomerService) + setConversationId('') + if(window.isModalVisibleForCustomerService){ //断连后,用户打开弹窗再发提醒 disconnectedAlert() } }else{ setConversationId('') setMsgPage(0) - delete window.webSocketForCustomerService //释放websocket对象 + if(window.webSocketForCustomerService!=undefined) delete window.webSocketForCustomerService //释放websocket对象 + if(window.isModalVisibleForCustomerService!=undefined) delete window.isModalVisibleForCustomerService + if(window.isConversationURLChanged!=undefined) delete window.isConversationURLChanged + if(window.msgAlertForCustomerService!=undefined) delete window.msgAlertForCustomerService } } @@ -288,6 +292,7 @@ const getToken = ()=>{ setLoading(true) getMoreMessage(1) }else{ + console.log(window.webSocketForCustomerService) if(window.webSocketForCustomerService!=undefined){ //别的路由切过来,ws没断,重新监听 console.log('ws没断,重新监听') @@ -316,11 +321,16 @@ const monitorWebSocket = (ws)=>{ ws.onmessage = function (res) { if(res.data){ let data = JSON.parse(res.data) - if(window.isConversationURLChanged!= true){ + if(window.isConversationURLChanged){//路由变化 + window.msgAlertForCustomerService = true + showMsg() + }else { + if(window.isBlurForCustomerService){//失焦 + window.msgAlertForCustomerService = true + showMsg() + } setWsMsg(data) } - window.msgAlertForCustomerService = true - showMsg() } }; @@ -359,6 +369,9 @@ useEffect(()=>{ } } }) + if(window.msgAlertForCustomerService){ + msgAlert && msgAlert() //侧边栏提醒 + } },[]) useEffect(()=>{ if(!isCloseWs){ @@ -368,6 +381,7 @@ useEffect(()=>{ } },[isCloseWs]) useEffect(() => { + window.isModalVisibleForCustomerService = isModalVisible if(isModalVisible){ stopMsg() //登录人的信息的关键字 顺序是固定的。 @@ -392,9 +406,6 @@ useEffect(() => { //校验登录 getToken() }else{ - if(window.msgAlertForCustomerService){ - msgAlert && msgAlert() //侧边栏提醒 - } setMsgList([]) } }, [isModalVisible])