app.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {
  2. ApiModel
  3. } from './utils/Api';
  4. App({
  5. onLaunch() {},
  6. initSocket() {
  7. let that = this;
  8. this.globalData.SocketTask = wx.connectSocket({
  9. url: 'wss://meida.cnyunl.com/yos/webSocket/' + wx.getStorageSync('userMsg').token,
  10. complete: (res) => {
  11. console.log(res)
  12. }
  13. })
  14. this.globalData.SocketTask.onOpen(function (res) {
  15. that.globalData.socketEstablish = true;
  16. })
  17. this.globalData.SocketTask.onMessage(function (res) {
  18. that.globalData.socket.callback(res)
  19. })
  20. this.globalData.SocketTask.onError(function (res) {
  21. that.globalData.socketEstablish = false;
  22. })
  23. this.globalData.SocketTask.onClose(function (res) {
  24. that.globalData.socketEstablish = false;
  25. })
  26. },
  27. globalData: {
  28. http: new ApiModel(), //接口文件
  29. queryPer: require("./utils/queryPermissions"), //权限查询
  30. handleSelect: null, //处理选择结果 函数
  31. savePage: null, //保存页面实例
  32. socketEstablish: false, //是否已经建立socket
  33. SocketTask: '', // Socket方法
  34. socket: { // Socket回调
  35. that: null, //保存this
  36. callback: function () {}
  37. },
  38. }
  39. })