app.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. socketEstablish: false, //是否已经建立socket
  48. SocketTask: '', // Socket方法
  49. remindchangepassword_str: "",
  50. refreshData: null, //保存首页更新应用信息函数
  51. evidence
  52. },
  53. })