diff --git a/src/charts/Wechat_session.js b/src/charts/Wechat_session.js index 8ea4e7f..d158e14 100644 --- a/src/charts/Wechat_session.js +++ b/src/charts/Wechat_session.js @@ -29,6 +29,46 @@ class Wechat_session extends Component { const {wechatStore} = this.context; wechatStore.fetchChatMsgList(wechatStore.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 {wechatStore} = this.context; const userList = wechatStore.userList; @@ -71,6 +111,7 @@ class Wechat_session extends Component { )} /> + ( - - } - title={chatMsg.from_name} - description={chatMsg.msgtime} - /> - {chatMsg.content.text} - - )} + renderItem={(chatMsg) => this.renderMsgItem(chatMsg)} />