会话id优化

This commit is contained in:
unknown
2022-06-13 17:50:58 +08:00
parent b2bf979cf4
commit bcd0becfaa
2 changed files with 9 additions and 10 deletions

View File

@ -538,7 +538,7 @@ const str_substr = (start, end, str)=> {
} }
}} }}
> >
<ChatToolBar onEmojiSelect={emojiSelectHandle} onImage={onImageHandle} onFile={onFileHandle} onRate={conversationId!='' && conversationId!=undefined ? onRateHandle: null} isRateModalVisible={isRateModalVisible} closeRateModal={closeRateModal}/> <ChatToolBar onEmojiSelect={emojiSelectHandle} onImage={onImageHandle} onFile={onFileHandle} onRate={conversationId==null || conversationId=='EMPTY' ? null: onRateHandle} isRateModalVisible={isRateModalVisible} closeRateModal={closeRateModal}/>
<div <div
onDragOver={(e)=>{e.preventDefault()}} onDragOver={(e)=>{e.preventDefault()}}
className={style.input_area} className={style.input_area}

View File

@ -12,6 +12,7 @@ import {CUSTOMERSERVICE_WEBSOCKET, CUSTOMERSERVICE_messageAlert} from './constan
//网页刷新时清空sessionStorage //网页刷新时清空sessionStorage
window.onbeforeunload = function(){ window.onbeforeunload = function(){
sessionStorage.removeItem('CUSTOMERSERVICE_CONVERSATIONID')
sessionStorage.removeItem('CUSTOMERSERVICE_isCloseChatUIModal') sessionStorage.removeItem('CUSTOMERSERVICE_isCloseChatUIModal')
sessionStorage.removeItem('CUSTOMERSERVICE_msgFlash') sessionStorage.removeItem('CUSTOMERSERVICE_msgFlash')
} }
@ -24,7 +25,6 @@ const conversation = (props) => {
const [curuser,setCuruser] = useState({}) const [curuser,setCuruser] = useState({})
const [wsMsg, setWsMsg] = useState({}) const [wsMsg, setWsMsg] = useState({})
const [wsObj, setWsObj] = useState(null) const [wsObj, setWsObj] = useState(null)
const [conversationId, setConversationId] = useState('')
const [isImgPreviewVisible, setIsImgPreviewVisible] = useState(false) //在线客服/图片预览 const [isImgPreviewVisible, setIsImgPreviewVisible] = useState(false) //在线客服/图片预览
const [imageParams, setImageParams] = useState({}) //图片属性 const [imageParams, setImageParams] = useState({}) //图片属性
const [show, setShow] = useState(false) const [show, setShow] = useState(false)
@ -106,14 +106,12 @@ const conversation = (props) => {
}); });
setQueryParams({}) setQueryParams({})
} }
const onMsgRender = ()=>{ const onMsgRender = (data)=>{
let serverAvatar = user let serverAvatar = user
let data = wsMsg
if(data && data.clientNo!=undefined){ if(data && data.clientNo!=undefined){
setServerNo(data.serverNo) //保存客服编码 setServerNo(data.serverNo) //保存客服编码
let type = data.contentType==1?'text':data.contentType==2?'image':data.contentType==3?'file':'text' let type = data.contentType==1?'text':data.contentType==2?'image':data.contentType==3?'file':'text'
let content={} let content={}
setConversationId(data.conversationId)
if(type=='text'){ if(type=='text'){
content = data.contentType==1?entitiestoUtf16(data.message) : data.message content = data.contentType==1?entitiestoUtf16(data.message) : data.message
}else if(type =='image'){ }else if(type =='image'){
@ -242,7 +240,6 @@ const disconnectedAlert = () =>{
const checkDisconnected = ()=>{ const checkDisconnected = ()=>{
if(sessionStorage.getItem('CUSTOMERSERVICE_isCloseChatUIModal')==0){ //弹窗没有关闭弹窗开着或者隐藏ws不应该断 if(sessionStorage.getItem('CUSTOMERSERVICE_isCloseChatUIModal')==0){ //弹窗没有关闭弹窗开着或者隐藏ws不应该断
console.log('websocket断开重新连接') console.log('websocket断开重新连接')
setConversationId('')
if(sessionStorage.getItem('CUSTOMERSERVICE_isModalVisible')==1){ //断连后,用户打开弹窗再发提醒 if(sessionStorage.getItem('CUSTOMERSERVICE_isModalVisible')==1){ //断连后,用户打开弹窗再发提醒
disconnectedAlert() disconnectedAlert()
} }
@ -290,6 +287,8 @@ const monitorWebSocket = (ws)=>{
ws.onmessage = function (res) { ws.onmessage = function (res) {
if(res.data){ if(res.data){
let data = JSON.parse(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){//路由变化 if(sessionStorage.getItem('CUSTOMERSERVICE_isConversationURLChanged')==1){//路由变化
sessionStorage.setItem('CUSTOMERSERVICE_msgFlash',1) sessionStorage.setItem('CUSTOMERSERVICE_msgFlash',1)
showMsg() showMsg()
@ -387,7 +386,7 @@ useEffect(() => {
//实时渲染消息 //实时渲染消息
if(sessionStorage.getItem('CUSTOMERSERVICE_isConversationURLChanged') == 0 && wsMsg && wsMsg.clientNo!=undefined){ if(sessionStorage.getItem('CUSTOMERSERVICE_isConversationURLChanged') == 0 && wsMsg && wsMsg.clientNo!=undefined){
if(isModalVisible){ //弹窗开着才渲染 if(isModalVisible){ //弹窗开着才渲染
onMsgRender() onMsgRender(wsMsg)
}else{ }else{
msgAlert && msgAlert() //只提醒 msgAlert && msgAlert() //只提醒
} }
@ -437,12 +436,12 @@ useEffect(() => {
kfType={kfType} kfType={kfType}
questionType={questionType} questionType={questionType}
supplierNo={kfType==1?'EMPTY':agentNumber} supplierNo={kfType==1?'EMPTY':agentNumber}
conversationId={conversationId} conversationId={sessionStorage.getItem('CUSTOMERSERVICE_CONVERSATIONID')}
roleIds={roleIds} roleIds={roleIds}
loading={loading} loading={loading}
isRateModalVisible={isRateModalVisible} isRateModalVisible={isRateModalVisible}
closeWin={()=>{ closeWin={()=>{
if(conversationId!='' && conversationId!=undefined){ if(sessionStorage.getItem('CUSTOMERSERVICE_CONVERSATIONID')!=null && sessionStorage.getItem('CUSTOMERSERVICE_CONVERSATIONID')!='EMPTY'){
setIsRateModalVisible(true) setIsRateModalVisible(true)
} }
setShow(false) setShow(false)
@ -452,7 +451,7 @@ useEffect(() => {
closeWin && closeWin() closeWin && closeWin()
}} }}
closeRateModal={()=>{ closeRateModal={()=>{
setConversationId('') sessionStorage.removeItem('CUSTOMERSERVICE_CONVERSATIONID')
setIsRateModalVisible(false) setIsRateModalVisible(false)
}} }}
hideWin={()=>{ hideWin={()=>{