app.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 + '/yos/webSocket/').replace("https", "wss").replace("http", "ws") + wx.getStorageSync('userMsg').token,
  19. complete: (res) => {
  20. console.log(res)
  21. }
  22. })
  23. this.globalData.SocketTask.onOpen(function (res) {
  24. that.globalData.socketEstablish = true;
  25. })
  26. this.globalData.SocketTask.onMessage(function (res) {
  27. that.globalData.socketCallback(res)
  28. })
  29. this.globalData.SocketTask.onError(function (res) {
  30. that.globalData.socketEstablish = false;
  31. })
  32. this.globalData.SocketTask.onClose(function (res) {
  33. that.globalData.socketEstablish = false;
  34. })
  35. },
  36. globalData: {
  37. http: new ApiModel, //挂载接口文件
  38. queryPer: require("./utils/queryPermissions"), //权限查询
  39. handleSelect: null, //处理选择结果函数
  40. collectCount: "", //购物车商品数量
  41. getCollectCount: null, // 获取购物车数量
  42. socketEstablish: false, //是否已经建立socket
  43. SocketTask: '', // Socket方法
  44. },
  45. })