You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
4.9 KiB
React
139 lines
4.9 KiB
React
3 years ago
|
import React, {Component} from 'react';
|
||
3 years ago
|
import {Row, Col, List, Avatar, Space, Pagination} from 'antd';
|
||
3 years ago
|
import {stores_Context} from '../config'
|
||
|
import {observer} from 'mobx-react';
|
||
3 years ago
|
import 'moment/locale/zh-cn';
|
||
3 years ago
|
|
||
3 years ago
|
class Wechat_session extends Component {
|
||
3 years ago
|
|
||
3 years ago
|
static contextType = stores_Context;
|
||
|
constructor(props) {
|
||
|
super(props);
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
componentDidMount() {
|
||
3 years ago
|
console.info('Wechat_session.componentDidMount');
|
||
3 years ago
|
const {wechatStore} = this.context;
|
||
|
wechatStore.fetchWechatUserList();
|
||
|
}
|
||
|
|
||
3 years ago
|
handleUserClick(user) {
|
||
|
const {wechatStore} = this.context;
|
||
|
wechatStore.fetchContactList(user);
|
||
3 years ago
|
}
|
||
3 years ago
|
handleContactClick(contact) {
|
||
|
const {wechatStore} = this.context;
|
||
3 years ago
|
wechatStore.fetchChatMsgList(contact, 0, 20);
|
||
|
}
|
||
|
handlePageChanged(page, pageSize) {
|
||
|
const {wechatStore} = this.context;
|
||
|
wechatStore.fetchChatMsgList(wechatStore.selectedContact, page, pageSize);
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
renderMsgItem(chatMsg) {
|
||
3 years ago
|
const msgDate = new Date(chatMsg.msgtime);
|
||
|
const msgDateText = msgDate.toLocaleDateString() + ' ' + msgDate.toLocaleTimeString();
|
||
3 years ago
|
return (
|
||
|
<List.Item className='ant-list-item-no-flex'>
|
||
|
<List.Item.Meta
|
||
|
avatar={<Avatar src={chatMsg.from_avatar} />}
|
||
|
title={chatMsg.from_name}
|
||
3 years ago
|
description={msgDateText}
|
||
3 years ago
|
/>
|
||
|
{this.renderMsgContent(chatMsg)}
|
||
|
</List.Item>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
renderMsgContent(chatMsg) {
|
||
|
if (chatMsg.msgtype === 'file') {
|
||
|
return (
|
||
3 years ago
|
<a href={chatMsg.content.fileurl}>{chatMsg.content.filename}</a>
|
||
3 years ago
|
)
|
||
|
} else if (chatMsg.msgtype === 'image') {
|
||
3 years ago
|
return (
|
||
3 years ago
|
<img style={{width: '50%', height: '50%'}} alt={chatMsg.msgid} src={chatMsg.content.imageurl} />
|
||
|
)
|
||
|
} else if (chatMsg.msgtype === 'text') {
|
||
|
return (
|
||
|
<>{chatMsg.content.text}</>
|
||
|
)
|
||
3 years ago
|
} else if (chatMsg.msgtype === 'link') {
|
||
|
return (
|
||
|
<a href={chatMsg.content.link_url}>{chatMsg.content.title}</a>
|
||
|
)
|
||
3 years ago
|
} else {
|
||
3 years ago
|
return (
|
||
3 years ago
|
<>未知消息[{chatMsg.msgtype}]</>
|
||
3 years ago
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
render() {
|
||
3 years ago
|
const {wechatStore} = this.context;
|
||
3 years ago
|
const userList = wechatStore.userList;
|
||
3 years ago
|
const contactList = wechatStore.contactList;
|
||
3 years ago
|
const chatMsgList = wechatStore.chatMsgList;
|
||
3 years ago
|
const chatMsgPage = wechatStore.chatMsgPage;
|
||
3 years ago
|
|
||
|
return (
|
||
3 years ago
|
<>
|
||
3 years ago
|
<Row>
|
||
3 years ago
|
<Col span={6}>
|
||
3 years ago
|
<List
|
||
3 years ago
|
style={{maxHeight: 800, minHeight: 800, overflowY: 'auto'}}
|
||
|
bordered={true}
|
||
3 years ago
|
itemLayout="horizontal"
|
||
3 years ago
|
dataSource={userList}
|
||
|
renderItem={(user) => (
|
||
3 years ago
|
<List.Item onClick={() => {this.handleUserClick(user)}}>
|
||
3 years ago
|
<List.Item.Meta
|
||
3 years ago
|
avatar={<Avatar src={user.avatar} />}
|
||
|
title={user.username}
|
||
3 years ago
|
/>
|
||
|
</List.Item>
|
||
|
)}
|
||
|
/>
|
||
|
</Col>
|
||
3 years ago
|
<Col span={6}>
|
||
3 years ago
|
<List
|
||
3 years ago
|
style={{maxHeight: 800, minHeight: 800, overflowY: 'auto'}}
|
||
|
bordered={true}
|
||
3 years ago
|
itemLayout="horizontal"
|
||
|
dataSource={contactList}
|
||
|
renderItem={(contact) => (
|
||
3 years ago
|
<List.Item onClick={() => {this.handleContactClick(contact)}}>
|
||
3 years ago
|
<List.Item.Meta
|
||
|
avatar={<Avatar src={contact.avatar} />}
|
||
|
title={contact.username}
|
||
|
/>
|
||
|
</List.Item>
|
||
|
)}
|
||
|
/>
|
||
|
</Col>
|
||
3 years ago
|
|
||
3 years ago
|
<Col span={12}>
|
||
3 years ago
|
<Space direction="vertical" size="middle" style={{ display: 'flex' }}>
|
||
3 years ago
|
<List
|
||
3 years ago
|
style={{maxHeight: 800, minHeight: 800, overflowY: 'auto'}}
|
||
|
bordered={true}
|
||
3 years ago
|
itemLayout="horizontal"
|
||
|
dataSource={chatMsgList}
|
||
3 years ago
|
renderItem={(chatMsg) => this.renderMsgItem(chatMsg)}
|
||
3 years ago
|
/>
|
||
3 years ago
|
<Pagination
|
||
|
current={chatMsgPage.currpage}
|
||
|
pageSize={20}
|
||
|
total={chatMsgPage.totalpage*20}
|
||
|
onChange={(page, pageSize) => { this.handlePageChanged(page, pageSize)}} />
|
||
3 years ago
|
</Space>
|
||
3 years ago
|
</Col>
|
||
3 years ago
|
|
||
|
</Row>
|
||
3 years ago
|
</>
|
||
3 years ago
|
);
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
}
|
||
|
|
||
3 years ago
|
export default observer(Wechat_session);
|