From bcd0becfaa76a99d5cf1e9ddac678c6dd0b4db10 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Jun 2022 17:50:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E8=AF=9Did=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ChatInput/ChatInput.jsx | 2 +- .../support/conversation/index.jsx | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/pages/customerservice/support/conversation/components/ChatInput/ChatInput.jsx b/src/pages/customerservice/support/conversation/components/ChatInput/ChatInput.jsx index 56fa9b6..ce34fc2 100644 --- a/src/pages/customerservice/support/conversation/components/ChatInput/ChatInput.jsx +++ b/src/pages/customerservice/support/conversation/components/ChatInput/ChatInput.jsx @@ -538,7 +538,7 @@ const str_substr = (start, end, str)=> { } }} > - +
{e.preventDefault()}} className={style.input_area} diff --git a/src/pages/customerservice/support/conversation/index.jsx b/src/pages/customerservice/support/conversation/index.jsx index 38316a9..7220479 100644 --- a/src/pages/customerservice/support/conversation/index.jsx +++ b/src/pages/customerservice/support/conversation/index.jsx @@ -12,6 +12,7 @@ import {CUSTOMERSERVICE_WEBSOCKET, CUSTOMERSERVICE_messageAlert} from './constan //网页刷新时,清空sessionStorage window.onbeforeunload = function(){ + sessionStorage.removeItem('CUSTOMERSERVICE_CONVERSATIONID') sessionStorage.removeItem('CUSTOMERSERVICE_isCloseChatUIModal') sessionStorage.removeItem('CUSTOMERSERVICE_msgFlash') } @@ -24,7 +25,6 @@ const conversation = (props) => { const [curuser,setCuruser] = useState({}) const [wsMsg, setWsMsg] = useState({}) const [wsObj, setWsObj] = useState(null) - const [conversationId, setConversationId] = useState('') const [isImgPreviewVisible, setIsImgPreviewVisible] = useState(false) //在线客服/图片预览 const [imageParams, setImageParams] = useState({}) //图片属性 const [show, setShow] = useState(false) @@ -106,14 +106,12 @@ const conversation = (props) => { }); setQueryParams({}) } - const onMsgRender = ()=>{ + const onMsgRender = (data)=>{ let serverAvatar = user - let data = wsMsg if(data && data.clientNo!=undefined){ setServerNo(data.serverNo) //保存客服编码 let type = data.contentType==1?'text':data.contentType==2?'image':data.contentType==3?'file':'text' let content={} - setConversationId(data.conversationId) if(type=='text'){ content = data.contentType==1?entitiestoUtf16(data.message) : data.message }else if(type =='image'){ @@ -242,7 +240,6 @@ const disconnectedAlert = () =>{ const checkDisconnected = ()=>{ if(sessionStorage.getItem('CUSTOMERSERVICE_isCloseChatUIModal')==0){ //弹窗没有关闭(弹窗开着或者隐藏,ws不应该断) console.log('websocket断开,重新连接') - setConversationId('') if(sessionStorage.getItem('CUSTOMERSERVICE_isModalVisible')==1){ //断连后,用户打开弹窗再发提醒 disconnectedAlert() } @@ -290,6 +287,8 @@ const monitorWebSocket = (ws)=>{ ws.onmessage = function (res) { if(res.data){ let data = JSON.parse(res.data) + //切换路由,conversaId会丢失,所以存sessionStorage + sessionStorage.setItem('CUSTOMERSERVICE_CONVERSATIONID',data.conversationId==undefined? 'EMPTY':data.conversationId) if(sessionStorage.getItem('CUSTOMERSERVICE_isConversationURLChanged')==1){//路由变化 sessionStorage.setItem('CUSTOMERSERVICE_msgFlash',1) showMsg() @@ -387,7 +386,7 @@ useEffect(() => { //实时渲染消息 if(sessionStorage.getItem('CUSTOMERSERVICE_isConversationURLChanged') == 0 && wsMsg && wsMsg.clientNo!=undefined){ if(isModalVisible){ //弹窗开着才渲染 - onMsgRender() + onMsgRender(wsMsg) }else{ msgAlert && msgAlert() //只提醒 } @@ -437,12 +436,12 @@ useEffect(() => { kfType={kfType} questionType={questionType} supplierNo={kfType==1?'EMPTY':agentNumber} - conversationId={conversationId} + conversationId={sessionStorage.getItem('CUSTOMERSERVICE_CONVERSATIONID')} roleIds={roleIds} loading={loading} isRateModalVisible={isRateModalVisible} closeWin={()=>{ - if(conversationId!='' && conversationId!=undefined){ + if(sessionStorage.getItem('CUSTOMERSERVICE_CONVERSATIONID')!=null && sessionStorage.getItem('CUSTOMERSERVICE_CONVERSATIONID')!='EMPTY'){ setIsRateModalVisible(true) } setShow(false) @@ -452,7 +451,7 @@ useEffect(() => { closeWin && closeWin() }} closeRateModal={()=>{ - setConversationId('') + sessionStorage.removeItem('CUSTOMERSERVICE_CONVERSATIONID') setIsRateModalVisible(false) }} hideWin={()=>{