app.jsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { Component } from 'react'
  2. import { Provider } from 'react-redux'
  3. import configStore from './store'
  4. import './app.less'
  5. import 'taro-skeleton/dist/index.css'
  6. import Taro from "@tarojs/taro";
  7. import { AtDrawer } from 'taro-ui'
  8. import 'taro-ui/dist/style/components/drawer.scss';
  9. import 'taro-ui/dist/style/components/list.scss';
  10. const store = configStore()
  11. class App extends Component {
  12. componentDidMount () {}
  13. componentDidShow () {
  14. Taro.eventCenter.on('getStorageSync', () => {
  15. this.getStorageSync();
  16. })
  17. this.getStorageSync();
  18. }
  19. getStorageSync(){
  20. let token = Taro.getStorageSync('token');
  21. //建立连接
  22. Taro.connectSocket({
  23. header:{
  24. 'token': token,
  25. },
  26. url: "wss://uat.jishutao.com/webSocketServer",
  27. // 172.16.0.188:8080
  28. // uat.jishutao.com
  29. })
  30. //连接成功
  31. Taro.onSocketOpen(function() {
  32. console.log('连接成功')
  33. // Taro.sendSocketMessage({
  34. // data: 'stock',
  35. // })
  36. })
  37. //接收数据
  38. Taro.onSocketMessage(function(data) {
  39. console.log(data,'接收数据')
  40. Taro.eventCenter.trigger('GoPuncsshIn')
  41. })
  42. //连接失败
  43. Taro.onSocketError(function() {
  44. console.log('websocket连接失败!');
  45. })
  46. //连接关闭
  47. Taro.onSocketClose(function() {
  48. console.log('websocket连接关闭!');
  49. })
  50. }
  51. componentDidHide () {}
  52. componentDidCatchError () {}
  53. // 在 App 类中的 render() 函数没有实际作用
  54. // 请勿修改此函数
  55. render () {
  56. return (
  57. <Provider store={store}>
  58. {this.props.children}
  59. </Provider>
  60. )
  61. }
  62. }
  63. export default App