Commit 455aae88 authored by Bill's avatar Bill

接入socket

parent 95e1ccb8
import { Tooltip } from 'antd'; import { Tooltip } from 'antd';
import { BellOutlined, CustomerServiceOutlined } from '@ant-design/icons'; import { BellOutlined, CustomerServiceOutlined } from '@ant-design/icons';
import React from 'react'; import React, { useCallback, useRef, useLayoutEffect } from 'react';
// import { connect, ConnectProps } from 'umi'; // import { connect, ConnectProps } from 'umi';
// import { ConnectState } from '@/models/connect'; // import { ConnectState } from '@/models/connect';
import Avatar from './AvatarDropdown'; import Avatar from './AvatarDropdown';
...@@ -9,6 +9,7 @@ import Location from './Location'; ...@@ -9,6 +9,7 @@ import Location from './Location';
import Roles from './Roles'; import Roles from './Roles';
import styles from '../styles/RightContent.less'; import styles from '../styles/RightContent.less';
import { Link } from 'umi'; import { Link } from 'umi';
import { getAuth } from '@/utils/auth'
// export type SiderTheme = 'light' | 'dark'; // export type SiderTheme = 'light' | 'dark';
// export interface GlobalHeaderRightProps extends Partial<ConnectProps> { // export interface GlobalHeaderRightProps extends Partial<ConnectProps> {
...@@ -25,6 +26,35 @@ const GlobalHeaderRight: React.SFC<{}> = (props) => { ...@@ -25,6 +26,35 @@ const GlobalHeaderRight: React.SFC<{}> = (props) => {
// className = `${styles.right} ${styles.dark}`; // className = `${styles.right} ${styles.dark}`;
// } // }
const userInfo = getAuth()
const ws = useRef<WebSocket | null>(null);
const webSocketInit = useCallback(() => {
console.log(ws.current)
if (!ws.current || ws.current.readyState === 3) {
ws.current = new WebSocket(`ws://10.0.0.25:8100/report/websocket?memberId=${userInfo.memberId}&roleId=${userInfo.memberRoleId}`);
ws.current.onopen = (e) => {
console.log(e)
}
ws.current.onmessage = (e) => {
console.log(e)
};
ws.current.onclose = (e) => {
console.log("关闭连接")
}
ws.current.onerror = (e) => {
console.log("socket 出错")
}
}
}, [ws]);
useLayoutEffect(() => {
webSocketInit();
return () => {
ws.current?.close();
};
}, [ws, webSocketInit]);
return ( return (
<div className={className}> <div className={className}>
<Link to='/' style={{color: 'rgba(0, 0, 0, 0.85)'}}>返回商城</Link> <Link to='/' style={{color: 'rgba(0, 0, 0, 0.85)'}}>返回商城</Link>
......
import React from 'react'; import React, {useState, useEffect} from 'react';
import { history } from 'umi'; import { history } from 'umi';
import { Button, Row, Col, Card, List, Avatar } from 'antd'; import { Card, List, Avatar } from 'antd';
import styles from './index.less' import styles from './index.less'
import { PageHeaderWrapper } from '@ant-design/pro-layout'; import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import StatusTag from '@/components/StatusTag'; import StatusTag from '@/components/StatusTag';
import { PublicApi } from '@/services/api';
import moment from 'moment';
import msg_system from '@/assets/imgs/msg_system.png'
import msg_platform from '@/assets/imgs/msg_platform.png'
const Message: React.FC<{}> = () => { const Message: React.FC<{}> = () => {
const [dataSource, setDataSource] = useState<any>([])
const pagation = {
current: 1,
pageSize: 10,
}
useEffect(() => {
// @ts-ignore
async function init() {
const data = await getList(pagation);
setDataSource(data);
}
init()
}, [])
const data = [ const getList = async (params) => {
{ ///report/message/member/page
id: 1, const res = await PublicApi.getReportMessageMemberPage(params);
icon: '', if(res.code === 1000) {
status: 'success', return res.data
type: '系统消息', }
title: '订单发货', return {
message: '订单发货,请注意查收,清单发货,请注意查收!', totalCount: 0,
time: '2015-15-05', data: []
}, }
{ }
id: 2,
icon: '', const handlePaginationChange = (page, pageSize) => {
status: 'success', getList({page, pageSize})
type: '系统消息', .then((data) => {
title: '订单收货', setDataSource(data);
message: '订单发货,请注意查收,清单发货,请注意查收!', })
time: '2015-15-05', }
},
{
id: 3,
icon: '',
status: 'primary',
type: '系统消息',
title: '系统消息',
message: '账户异常,请注意账户资金安全!',
time: '2015-15-05',
},
{
id: 4,
icon: '',
status: 'primary',
type: '系统消息',
title: '系统消息',
message: '账户支出300元,请注意账户资金安全!',
time: '2015-15-05',
},
];
const renderMessage = (data) => { const renderMessage = (data) => {
...@@ -69,25 +68,23 @@ const Message: React.FC<{}> = () => { ...@@ -69,25 +68,23 @@ const Message: React.FC<{}> = () => {
> >
<List <List
itemLayout="horizontal" itemLayout="horizontal"
dataSource={data} dataSource={dataSource.data}
className={styles.customList} className={styles.customList}
pagination={{ pagination={{
onChange: page => { onChange: handlePaginationChange,
console.log(page);
},
pageSize: 10, pageSize: 10,
size: "small", size: "small",
showQuickJumper: true, showQuickJumper: true,
total: 4, total: dataSource.totalCount,
showTotal: showTotal showTotal: showTotal
}} }}
renderItem={item => ( renderItem={item => (
<List.Item> <List.Item>
<List.Item.Meta <List.Item.Meta
avatar={<Avatar src={item.icon} />} avatar={<Avatar src={msg_system} />}
title={renderMessage(item)} title={renderMessage(item)}
/> />
<div>{item.time}</div> <div>{moment(item.createTime).format('YYYY-MM-DD HH:mm:ss')}</div>
</List.Item> </List.Item>
)} )}
/> />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment