app.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {
  2. ApiModel
  3. } from './utils/api';
  4. import {
  5. evidence,
  6. update
  7. } from './utils/pay';
  8. App({
  9. onLaunch() {
  10. //自动登录
  11. if (wx.getStorageSync('userMsg').token && ![1007, 1008, 1155].includes(wx.getLaunchOptionsSync().scene)) this.globalData.http.basic({
  12. "classname": "webmanage.site.site",
  13. "method": "querySite_Parameter",
  14. "content": {}
  15. }).then(res => {
  16. console.log("验证登录", res)
  17. if (res.msg == '成功') {
  18. const loginMsg = require("./pages/login/modules/login");
  19. loginMsg.query_userauth();
  20. }
  21. })
  22. },
  23. initSocket() {
  24. let that = this;
  25. this.globalData.SocketTask = wx.connectSocket({
  26. url: (this.globalData.http.baseUrl + '/yos/webSocket/').replace("https", "wss").replace("http", "ws") + wx.getStorageSync('userMsg').token,
  27. complete: (res) => {
  28. console.log(res)
  29. }
  30. })
  31. this.globalData.SocketTask.onOpen(function (res) {
  32. that.globalData.socketEstablish = true;
  33. })
  34. this.globalData.SocketTask.onMessage(function (res) {
  35. that.globalData.socket.callback(res)
  36. let data = JSON.parse(res.data);
  37. if (data.message.type == 'pay') update();
  38. })
  39. this.globalData.SocketTask.onError(function (res) {
  40. that.globalData.socketEstablish = false;
  41. })
  42. this.globalData.SocketTask.onClose(function (res) {
  43. that.globalData.socketEstablish = false;
  44. })
  45. },
  46. globalData: {
  47. http: new ApiModel(), //接口文件
  48. queryPer: require("./utils/queryPermissions"), //权限查询
  49. socketEstablish: false, //是否已经建立socket
  50. SocketTask: '', // Socket方法
  51. socket: { // Socket回调
  52. that: null, //保存this
  53. callback: function () {}
  54. },
  55. refreshData: null, //保存首页更新应用信息函数
  56. evidence
  57. },
  58. })