From c453250a31df14012b9541165336bd0ce5b92d66 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 May 2022 17:41:08 +0800 Subject: [PATCH] =?UTF-8?q?websocket=20onopen=20=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/conversation/index.jsx | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/pages/customerservice/support/conversation/index.jsx b/src/pages/customerservice/support/conversation/index.jsx index f1f0423..e8bbec7 100644 --- a/src/pages/customerservice/support/conversation/index.jsx +++ b/src/pages/customerservice/support/conversation/index.jsx @@ -93,6 +93,23 @@ const conversation = (props) => { msgAlert && msgAlert() } } + // const sendToCs = (msg)=>{ + // let params = { + // "clientNo": staffId, + // "contentType": 5, + // "custType": kfType == 2? 2 : 1, + // "message": '', + // "questionType": 2, + // "supplierNo": kfType==1?'EMPTY':agentNumber + // } + // API.sendToCs(params).then(res => { + // if (res && !res.data) { + // }else{ + // message.warn(res && res.message) + // } + + // }) + // } const connect = () =>{ let serverAvatar = user const msg = { @@ -118,7 +135,23 @@ const conversation = (props) => { console.log("Connection open ..."); //记录ws setShow(true) //连接建立后,才可以显示弹窗、收发消息 - if(sendMsg && sendMsg.length>0) setIsSend(true) //连接建立后,sendMsg有值才可以发即时消息(用户不点击发送,打开窗口即发送) + if(sendMsg && sendMsg.length>0) { //连接建立后,sendMsg有值才可以发即时消息(用户不点击发送,打开窗口即发送) + setIsSend(true) + }else{ + //发空消息给websocket + let serverAvatar = user + const msg = { + _id: Math.floor(Math.random() * 1000)+new Date(), + date: new Date(), + user: { + id: serverNo, + avatar: serverAvatar, + name: '供应链客服', + }, + message: { type: 'text', content: '您好,欢迎使用供应链客服' }, + } + setMsgList([...msgList, msg]) + } setWsObj(ws) };