app.js 1.7 KB

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