app.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 { getWxConfig } from './utils/servers/servers';
  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. //在页面加载完成的生命周期加入这段代码,Taro在componentDidMount生命周期中使用,原生在onLoad中使用
  14. const updateManager = Taro.getUpdateManager()
  15. updateManager.onCheckForUpdate(function (res) {
  16. // 请求完新版本信息的回调
  17. //console.log('请求完新版本信息的回调')
  18. console.log(res.hasUpdate);
  19. })
  20. updateManager.onUpdateReady(function () {
  21. Taro.showModal({
  22. title: '更新提示',
  23. content: '新版本已经准备好,是否重启应用?',
  24. success(res) {
  25. if (res.confirm) {
  26. console.log("go")
  27. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  28. updateManager.applyUpdate()
  29. }
  30. }
  31. })
  32. })
  33. updateManager.onUpdateFailed(function () {
  34. // 新版本下载失败
  35. console.log('新版本下载失败')
  36. // errorReport(ERROREVENTS.VERSION_UPGRADE_FAILED, '新版本下载失败');
  37. })
  38. }
  39. componentDidShow() {
  40. // Taro.eventCenter.on('getStorageSync', () => {
  41. // let token = Taro.getStorageSync('token');
  42. // if (token) {
  43. // this.getStorageSync();
  44. // }
  45. // })
  46. // let token = Taro.getStorageSync('token');
  47. // if (token) {
  48. // this.getStorageSync();
  49. // }
  50. // this.getWxConfig();
  51. }
  52. componentDidHide() {
  53. Taro.closeSocket();
  54. }
  55. // getWxConfig() {
  56. // getWxConfig({}).then(v => {
  57. // if (v.error.length === 0) {
  58. // Taro.setStorageSync("wxConfig", v.data || {});
  59. // } else {
  60. // Taro.showToast({
  61. // title: v.error[0].message,
  62. // icon: 'none'
  63. // })
  64. // }
  65. // }).catch((error) => {
  66. // console.log(error)
  67. // })
  68. // }
  69. getStorageSync() {
  70. let token = Taro.getStorageSync('token');
  71. //建立连接
  72. Taro.connectSocket({
  73. header: {
  74. 'token': token,
  75. },
  76. // 测试
  77. // url: 'wss://bm.jishutao.com/webSocketServer',
  78. // 本地
  79. // url: 'wss://172.16.0.255:8080/webSocketServer'
  80. // 生产
  81. url: 'wss://uat.jishutao.com/webSocketServer'
  82. })
  83. //连接成功
  84. Taro.onSocketOpen(function () {
  85. console.log('连接成功')
  86. })
  87. //接收数据
  88. Taro.onSocketMessage(function (data) {
  89. console.log('接收数据', data)
  90. Taro.eventCenter.trigger('GoPuncsshIn', data)
  91. })
  92. //连接失败
  93. Taro.onSocketError(function () {
  94. console.log('websocket连接失败!');
  95. })
  96. //连接关闭
  97. Taro.onSocketClose(function () {
  98. console.log('websocket连接关闭!');
  99. })
  100. }
  101. componentDidCatchError() { }
  102. // 在 App 类中的 render() 函数没有实际作用
  103. // 请勿修改此函数
  104. render() {
  105. return (
  106. <Provider store={store}>
  107. {this.props.children}
  108. </Provider>
  109. )
  110. }
  111. }
  112. export default App