From e447bd26e3bcbdeabc36ed55e9f805c7aa77342c Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Mon, 10 Oct 2022 10:18:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20WhatsApp=20=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/charts/WhatsApp_session.js | 107 +++++++++++++++++++++++++-------- src/stores/Index.js | 2 + src/stores/WhatsApp.js | 63 +++++++++++++++++++ 3 files changed, 148 insertions(+), 24 deletions(-) create mode 100644 src/stores/WhatsApp.js diff --git a/src/charts/WhatsApp_session.js b/src/charts/WhatsApp_session.js index 205c19f..d13b2e8 100644 --- a/src/charts/WhatsApp_session.js +++ b/src/charts/WhatsApp_session.js @@ -1,39 +1,98 @@ -import React, {useContext, useEffect} from 'react'; -import {Row, Col, Button, Divider, Table, Space, Radio, Tooltip} from 'antd'; -import { - ContainerOutlined, - SearchOutlined, -} from '@ant-design/icons'; +import React, {Component} from 'react'; +import {Row, Col, List, Avatar, DatePicker, Pagination} from 'antd'; import {stores_Context} from '../config' -import {Line} from "@ant-design/charts"; import {observer} from 'mobx-react'; -import DatePickerCharts from '../charts/DatePickerCharts' -import {NavLink, useParams} from "react-router-dom"; -import * as comm from "../utils/commons"; -import * as config from "../config"; -import SiteSelect from "../charts/SiteSelect"; -import GroupSelect from "../charts/GroupSelect"; -import {utils, writeFileXLSX} from "xlsx"; +import 'moment/locale/zh-cn'; -const WhatsApp_session = () => { +class WhatsApp_session extends Component { - const {orders_store, date_picker_store, customer_store} = useContext(stores_Context); - const inchina_data = customer_store.inchina_data; + static contextType = stores_Context; + constructor(props) { + super(props); + } - useEffect(() => { - - }, []) + componentDidMount() { + console.info('Wechat_session.componentDidMount'); + const {whatsAppStore} = this.context; + whatsAppStore.fetchWechatUserList(); + } + handleUserClick(user) { + const {whatsAppStore} = this.context; + whatsAppStore.fetchContactList(user); + } + handleContactClick(contact) { + const {whatsAppStore} = this.context; + whatsAppStore.fetchChatMsgList(contact, 0, 20); + } + handlePageChanged(page, pageSize) { + const {whatsAppStore} = this.context; + whatsAppStore.fetchChatMsgList(whatsAppStore.selectedContact, page, pageSize); + } + render() { + const {whatsAppStore} = this.context; + const userList = whatsAppStore.userList; + const contactList = whatsAppStore.contactList; + const chatMsgList = whatsAppStore.chatMsgList; + const chatMsgPage = whatsAppStore.chatMsgPage; return ( -
+ <> - -

WhatsAPP会话

+ + ( + {this.handleUserClick(user)}}> + } + title={user.username} + /> + + )} + /> + + + ( + {this.handleContactClick(contact)}}> + } + title={contact.username} + /> + + )} + /> + + ( + + } + title={chatMsg.from_name} + description={chatMsg.msgtime} + /> + {chatMsg.content.text} + + )} + /> + { this.handlePageChanged(page, pageSize)}} /> + +
-
+ ); + } } export default observer(WhatsApp_session); diff --git a/src/stores/Index.js b/src/stores/Index.js index dd027bb..5054890 100644 --- a/src/stores/Index.js +++ b/src/stores/Index.js @@ -7,6 +7,7 @@ import AuthStore from "./AuthStore"; import ChatSessionStore from "./ChatSessionStore"; import FinancialStore from "./FinancialStore"; import WechatStore from "./Wechat"; +import WhatsAppStore from "./WhatsApp"; class Index { @@ -19,6 +20,7 @@ class Index { this.chat_session_store = new ChatSessionStore(this); this.financial_store = new FinancialStore(this); this.wechatStore = new WechatStore(this); + this.whatsAppStore = new WhatsAppStore(this); makeAutoObservable(this); } diff --git a/src/stores/WhatsApp.js b/src/stores/WhatsApp.js new file mode 100644 index 0000000..320a259 --- /dev/null +++ b/src/stores/WhatsApp.js @@ -0,0 +1,63 @@ +import {makeAutoObservable, runInAction} from "mobx" +import * as config from "../config"; +import * as req from '../utils/request'; + +class WhatsApp { + + constructor(rootStore) { + this.rootStore = rootStore; + makeAutoObservable(this); + } + + fetchWechatUserList() { + + req.fetchJSON(config.HT_HOST + '/weixin/wxwork/get_permit_user_list') + .then(json => { + if (json.errcode === 0) { + runInAction(() => { + this.userList = json.Result.filter(user => { + return user.SMPlatform === 'whatsapp'; + }); + }); + } + }); + } + + fetchContactList(user) { + + req.fetchJSON(config.HT_HOST + '/weixin/wxwork/get_externalcontact_list?userid='+user.userid) + .then(json => { + if (json.errcode === 0) { + runInAction(() => { + this.contactList = json.Result.filter(user => { + return user.SMPlatform === 'whatsapp'; + }); + }); + } + }); + } + + fetchChatMsgList(contact, page, pageSize) { + runInAction(() => { + this.selectedContact = contact; + }); + req.fetchJSON(config.HT_HOST + '/weixin/wxwork/GetChatmsg?external_userid='+this.selectedContact.userid+'&Page_count='+pageSize+'&curr_page='+page) + .then(json => { + if (json.errcode === 0) { + runInAction(() => { + this.chatMsgList = json.chatmsg; + this.chatMsgPage = json.chatpage; + }); + } + }); + } + + userList = [{username: '---', avatar: 'https://joeschmoe.io/api/v1/random'}]; + contactList = [{username: '---', avatar: 'https://joeschmoe.io/api/v1/random'}]; + chatMsgList = [{from_name: '---', from_avatar: 'https://joeschmoe.io/api/v1/random', content: {text: '---'}}]; + chatMsgPage = {currpage: 1, totalpage: 1}; + selectedContact = this.contactList[0]; + +} + +export default WhatsApp; \ No newline at end of file