app.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. complete: (res) => {
  24. console.log(res)
  25. }
  26. })
  27. this.globalData.SocketTask.onOpen(function (res) {
  28. that.globalData.socketEstablish = true;
  29. })
  30. this.globalData.SocketTask.onMessage(function (res) {
  31. that.globalData.socket.callback(res)
  32. })
  33. this.globalData.SocketTask.onError(function (res) {
  34. that.globalData.socketEstablish = false;
  35. })
  36. this.globalData.SocketTask.onClose(function (res) {
  37. that.globalData.socketEstablish = false;
  38. })
  39. },
  40. globalData: {
  41. http: new ApiModel(), //接口文件
  42. queryPer: require("./utils/queryPermissions"), //权限查询
  43. socketEstablish: false, //是否已经建立socket
  44. SocketTask: '', // Socket方法
  45. socket: { // Socket回调
  46. that: null, //保存this
  47. callback: function () {}
  48. },
  49. },
  50. })