WhatsApp 增加图片、链接消息展示

feature/2.0-sales-trade
LiaoYijun 3 years ago
parent f4a2284003
commit ca41fa993d

@ -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 (
<List.Item className='ant-list-item-no-flex'>
<List.Item.Meta
avatar={<Avatar src={chatMsg.from_avatar} />}
title={chatMsg.from_name}
description={msgDateText}
/>
{this.renderMsgContent(chatMsg)}
</List.Item>
)
}
renderMsgContent(chatMsg) {
if (chatMsg.msgtype === 'file') {
return (
<a href={chatMsg.content.fileurl}>{chatMsg.content.filename}</a>
)
} else if (chatMsg.msgtype === 'image') {
return (
<img style={{width: '50%', height: '50%'}} alt={chatMsg.msgid} src={chatMsg.content.imageurl} />
)
} else if (chatMsg.msgtype === 'text') {
return (
<>{chatMsg.content.text}</>
)
} else if (chatMsg.msgtype === 'link') {
return (
<a href={chatMsg.content.link_url}>{chatMsg.content.title}</a>
)
} 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) => (
<List.Item>
<List.Item.Meta
avatar={<Avatar src={chatMsg.from_avatar} />}
title={chatMsg.from_name}
description={chatMsg.msgtime}
/>
{chatMsg.content.text}
</List.Item>
)}
renderItem={(chatMsg) => this.renderMsgItem(chatMsg)}
/>
<Pagination
current={chatMsgPage.currpage}

Loading…
Cancel
Save