123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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 { getWxConfig } from './utils/servers/servers';
- 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', () => {
- let token = Taro.getStorageSync('token');
- if (token) {
- this.getStorageSync();
- }
- })
- let token = Taro.getStorageSync('token');
- if (token) {
- this.getStorageSync();
- }
- this.getWxConfig();
- }
- componentDidHide() {
- Taro.closeSocket();
- }
- getWxConfig() {
- getWxConfig({}).then(v => {
- if (v.error.length === 0) {
- Taro.setStorageSync("wxConfig", v.data || {});
- } else {
- Taro.showToast({
- title: v.error[0].message,
- icon: 'none'
- })
- }
- }).catch((error) => {
- console.log(error)
- })
- }
- getStorageSync() {
- let token = Taro.getStorageSync('token');
- //建立连接
- Taro.connectSocket({
- header: {
- 'token': token,
- },
- url: 'wss://bm.jishutao.com/webSocketServer',
- // url: 'wss://172.16.0.255:8080/webSocketServer'
- // url: 'wss://uat.jishutao.com/webSocketServer'
- })
- //连接成功
- Taro.onSocketOpen(function () {
- console.log('连接成功')
- })
- //接收数据
- Taro.onSocketMessage(function (data) {
- console.log('接收数据', data)
- Taro.eventCenter.trigger('GoPuncsshIn', data)
- })
- //连接失败
- Taro.onSocketError(function () {
- console.log('websocket连接失败!');
- })
- //连接关闭
- Taro.onSocketClose(function () {
- console.log('websocket连接关闭!');
- })
- }
- componentDidCatchError() { }
- // 在 App 类中的 render() 函数没有实际作用
- // 请勿修改此函数
- render() {
- return (
- <Provider store={store}>
- {this.props.children}
- </Provider>
- )
- }
- }
- export default App
|