app.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {
  2. ApiModel
  3. } from './utils/Api';
  4. App({
  5. onLaunch: function () {
  6. wx.getSystemInfo({
  7. success: e => {
  8. this.globalData.StatusBar = e.statusBarHeight;
  9. let custom = wx.getMenuButtonBoundingClientRect();
  10. this.globalData.Custom = custom;
  11. this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
  12. }
  13. })
  14. },
  15. initSocket() {
  16. let that = this;
  17. this.globalData.SocketTask = wx.connectSocket({
  18. url: this.globalData.http.baseUrl.replace("https", "wss").replace("http", "ws") + '/yos/webSocket/' + wx.getStorageSync('userMsg').token,
  19. complete: (res) => {
  20. console.log(res)
  21. }
  22. })
  23. console.log(this.globalData.http.baseUrl.replace("https", "wss").replace("http", "ws") + '/yos/webSocket/' + wx.getStorageSync('userMsg').token)
  24. this.globalData.SocketTask.onOpen(function (res) {
  25. that.globalData.socketEstablish = true;
  26. })
  27. this.globalData.SocketTask.onMessage(function (res) {
  28. console.log("消息", res)
  29. that.globalData.socketCallback(res)
  30. })
  31. this.globalData.SocketTask.onError(function (res) {
  32. that.globalData.socketEstablish = false;
  33. })
  34. this.globalData.SocketTask.onClose(function (res) {
  35. that.globalData.socketEstablish = false;
  36. })
  37. },
  38. globalData: {
  39. http: new ApiModel, //挂载接口文件
  40. queryPer: require("./utils/queryPermissions"), //权限查询
  41. handleSelect: null, //处理选择结果函数
  42. collectCount: "", //购物车商品数量
  43. getCollectCount: null, // 获取购物车数量
  44. socketEstablish: false, //是否已经建立socket
  45. SocketTask: '', // Socket方法
  46. },
  47. })