diff --git a/src/pages/customerservice/support/conversation/components/ChatInput/ChatInput.jsx b/src/pages/customerservice/support/conversation/components/ChatInput/ChatInput.jsx index 8da6935..6a583d3 100644 --- a/src/pages/customerservice/support/conversation/components/ChatInput/ChatInput.jsx +++ b/src/pages/customerservice/support/conversation/components/ChatInput/ChatInput.jsx @@ -209,6 +209,9 @@ const ChatInput = ((props) => { } API.sendToCs(params).then(res => { if (res && res.success) { + if(isSend){ + cancelSend && cancelSend() + } }else{ message.warn(res && res.message) } diff --git a/src/pages/customerservice/support/conversation/index.jsx b/src/pages/customerservice/support/conversation/index.jsx index 8dc51a6..d1ddd5a 100644 --- a/src/pages/customerservice/support/conversation/index.jsx +++ b/src/pages/customerservice/support/conversation/index.jsx @@ -143,7 +143,7 @@ const conversation = (props) => { user: { id: item.senderUid, avatar: item.senderType==1?customerAvatar:serverAvatar, - name: item.senderType==1?staffName:item.customerName, + name: item.senderType==1?staffName:item.customName, }, message: { type: type, content: content }, }) @@ -158,9 +158,11 @@ const conversation = (props) => { arr.unshift(earlierMsg.pop()) count-- } - setMsgList([...arr]) - } - + setMsgList([...arr]) + } + if(sendMsg && sendMsg.length>0) { //连接建立后,sendMsg有值才可以发即时消息(用户不点击发送,打开窗口即发送) + setIsSend(true) + } } else { message.warn(res && res.message) } @@ -210,7 +212,7 @@ const onReset = () => { } //检验连接websocket const checkWebSocket = ()=>{ - if(window.isCloseChatUIModal!=undefined){ //弹窗没有关闭 + if(window.isCloseChatUIModal!=undefined){ //弹窗没有关闭(弹窗开着或者隐藏,ws不应该断) if(window.webSocketForCustomerService==undefined){ console.log('首次创建websocket') //获取当前用户token @@ -220,7 +222,7 @@ const checkWebSocket = ()=>{ if(ws){ //别的路由切过来,ws没断,重新监听 let avatar = client - console.log('别的路由切过来,ws没断,重新监听') + console.log('ws没断,重新监听') setShow(true) monitorWebSocket(ws) setCuruser({ @@ -228,11 +230,14 @@ const checkWebSocket = ()=>{ name: staffName, avatar: avatar, }) + setLoading(true) getMoreMessage(1) }else{ console.log('websocket断开,重新连接') - setConversationId('') - disconnectedAlert() + if(isModalVisible){ //断连后,用户打开弹窗再发提醒 + setConversationId('') + disconnectedAlert() + } } } }else{ @@ -265,13 +270,13 @@ const getToken = ()=>{ name: staffName, avatar: avatar, }) - //window.currentUserForCustomerService = API.check({ clientNo: staffId, supplierNo:kfType==1?'EMPTY':agentNumber }).then(res => { if (res && res.success) { websocketInit(staffId) + setLoading(true) getMoreMessage(1) }else{ closeWin && closeWin() @@ -287,9 +292,6 @@ const monitorWebSocket = (ws)=>{ //记录ws window.webSocketForCustomerService = ws setShow(true) //连接建立后,才可以显示弹窗、收发消息 - if(sendMsg && sendMsg.length>0) { //连接建立后,sendMsg有值才可以发即时消息(用户不点击发送,打开窗口即发送) - setIsSend(true) - } //else{ // //发空消息给websocket // let serverAvatar = user @@ -332,7 +334,6 @@ useEffect(()=>{ if(window.isCloseChatUIModal==undefined){ window.isCloseChatUIModal = isCloseWs //false } - checkWebSocket() } },[isCloseWs]) useEffect(() => { @@ -344,6 +345,7 @@ useEffect(() => { chatUI.style.top = (document.documentElement.clientHeight - hei)*0.5 +"px" record.style.height = listHeight + "px" chatInput.style.height = textHeight + "px" + checkWebSocket() }else{ setMsgList([]) }