1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { Component } from 'react'
- import { Provider } from 'react-redux'
- import configStore from './store'
- import './app.less'
- import 'taro-skeleton/dist/index.css'
- import Taro from "@tarojs/taro";
- import { AtDrawer } from 'taro-ui'
- import 'taro-ui/dist/style/components/drawer.scss';
- import 'taro-ui/dist/style/components/list.scss';
- const store = configStore()
- class App extends Component {
- componentDidMount () {}
- componentDidShow () {
- Taro.eventCenter.on('getStorageSync', () => {
- this.getStorageSync();
- })
- this.getStorageSync();
- }
- getStorageSync(){
- let token = Taro.getStorageSync('token');
- //建立连接
- Taro.connectSocket({
- header:{
- 'token': token,
- },
- url: "wss://uat.jishutao.com/webSocketServer",
- // 172.16.0.188:8080
- // uat.jishutao.com
- })
- //连接成功
- Taro.onSocketOpen(function() {
- console.log('连接成功')
- // Taro.sendSocketMessage({
- // data: 'stock',
- // })
- })
- //接收数据
- Taro.onSocketMessage(function(data) {
- console.log(data,'接收数据')
- Taro.eventCenter.trigger('GoPuncsshIn')
- })
- //连接失败
- Taro.onSocketError(function() {
- console.log('websocket连接失败!');
- })
- //连接关闭
- Taro.onSocketClose(function() {
- console.log('websocket连接关闭!');
- })
- }
- componentDidHide () {}
- componentDidCatchError () {}
- // 在 App 类中的 render() 函数没有实际作用
- // 请勿修改此函数
- render () {
- return (
- <Provider store={store}>
- {this.props.children}
- </Provider>
- )
- }
- }
- export default App
|