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; const {whatsAppStore} = this.context;
whatsAppStore.fetchChatMsgList(whatsAppStore.selectedContact, page, pageSize); 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() { render() {
const {whatsAppStore} = this.context; const {whatsAppStore} = this.context;
const userList = whatsAppStore.userList; const userList = whatsAppStore.userList;
@ -78,16 +117,7 @@ class WhatsApp_session extends Component {
bordered={true} bordered={true}
itemLayout="horizontal" itemLayout="horizontal"
dataSource={chatMsgList} dataSource={chatMsgList}
renderItem={(chatMsg) => ( renderItem={(chatMsg) => this.renderMsgItem(chatMsg)}
<List.Item>
<List.Item.Meta
avatar={<Avatar src={chatMsg.from_avatar} />}
title={chatMsg.from_name}
description={chatMsg.msgtime}
/>
{chatMsg.content.text}
</List.Item>
)}
/> />
<Pagination <Pagination
current={chatMsgPage.currpage} current={chatMsgPage.currpage}

Loading…
Cancel
Save