app.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {
  2. ApiModel
  3. } from './utils/api';
  4. App({
  5. onLaunch() {
  6. //自动登录
  7. if (wx.getStorageSync('userMsg').token && ![1007, 1008, 1155].includes(wx.getLaunchOptionsSync().scene)) this.globalData.http.basic({
  8. "classname": "webmanage.site.site",
  9. "method": "querySite_Parameter",
  10. "content": {}
  11. }).then(res => {
  12. console.log("验证登录", res)
  13. if (res.msg == '成功') {
  14. const loginMsg = require("./pages/login/modules/login");
  15. loginMsg.query_userauth();
  16. }
  17. })
  18. },
  19. initSocket() {
  20. let that = this;
  21. this.globalData.SocketTask = wx.connectSocket({
  22. // url: 'wss://meida.cnyunl.com/yos/webSocket/' + wx.getStorageSync('userMsg').token,
  23. url: 'ws://192.168.3.111:8100/yos/webSocket/' + wx.getStorageSync('userMsg').token,
  24. complete: (res) => {
  25. console.log(res)
  26. }
  27. })
  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') {
  35. that.globalData.http.basic({
  36. "classname": "system.payorder.payorder",
  37. "method": "query_userauth",
  38. content: {
  39. nocache: true
  40. }
  41. }).then(res => {
  42. console.log('更新付费信息', res)
  43. wx.setStorageSync('userauth', res.data);
  44. wx.showToast({
  45. title: '应用付费信息已更新',
  46. icon: "none"
  47. })
  48. getCurrentPages().find(v => v.__route__ == 'pages/tabbar/home/index').refreshData();
  49. });
  50. }
  51. })
  52. this.globalData.SocketTask.onError(function (res) {
  53. that.globalData.socketEstablish = false;
  54. })
  55. this.globalData.SocketTask.onClose(function (res) {
  56. that.globalData.socketEstablish = false;
  57. })
  58. },
  59. globalData: {
  60. http: new ApiModel(), //接口文件
  61. queryPer: require("./utils/queryPermissions"), //权限查询
  62. socketEstablish: false, //是否已经建立socket
  63. SocketTask: '', // Socket方法
  64. socket: { // Socket回调
  65. that: null, //保存this
  66. callback: function () {}
  67. },
  68. },
  69. })