From ca41fa993dfc73a554fcd3e563a0b39f064b8253 Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Mon, 24 Oct 2022 09:51:27 +0800 Subject: [PATCH] =?UTF-8?q?WhatsApp=20=E5=A2=9E=E5=8A=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E3=80=81=E9=93=BE=E6=8E=A5=E6=B6=88=E6=81=AF=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/charts/WhatsApp_session.js | 50 +++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/charts/WhatsApp_session.js b/src/charts/WhatsApp_session.js index e24d5ea..26dd969 100644 --- a/src/charts/WhatsApp_session.js +++ b/src/charts/WhatsApp_session.js @@ -29,6 +29,45 @@ class WhatsApp_session extends Component { const {whatsAppStore} = this.context; whatsAppStore.fetchChatMsgList(whatsAppStore.selectedContact, page, pageSize); } + + renderMsgItem(chatMsg) { + const msgDate = new Date(chatMsg.msgtime); + const msgDateText = msgDate.toLocaleDateString() + ' ' + msgDate.toLocaleTimeString(); + return ( + + } + title={chatMsg.from_name} + description={msgDateText} + /> + {this.renderMsgContent(chatMsg)} + + ) + } + + renderMsgContent(chatMsg) { + if (chatMsg.msgtype === 'file') { + return ( + {chatMsg.content.filename} + ) + } else if (chatMsg.msgtype === 'image') { + return ( + {chatMsg.msgid} + ) + } else if (chatMsg.msgtype === 'text') { + return ( + <>{chatMsg.content.text} + ) + } else if (chatMsg.msgtype === 'link') { + return ( + {chatMsg.content.title} + ) + } else { + return ( + <>未知消息[{chatMsg.msgtype}] + ) + } + } render() { const {whatsAppStore} = this.context; const userList = whatsAppStore.userList; @@ -78,16 +117,7 @@ class WhatsApp_session extends Component { bordered={true} itemLayout="horizontal" dataSource={chatMsgList} - renderItem={(chatMsg) => ( - - } - title={chatMsg.from_name} - description={chatMsg.msgtime} - /> - {chatMsg.content.text} - - )} + renderItem={(chatMsg) => this.renderMsgItem(chatMsg)} />