app.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. socketEstablish: false, //是否已经建立socket
  32. SocketTask: '', // Socket方法
  33. socket: { // Socket回调
  34. that: null, //保存this
  35. callback: function () {}
  36. },
  37. }
  38. })