app.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {
  2. ApiModel
  3. } from './utils/Api';
  4. App({
  5. onLaunch(options) {
  6. //小程序跳转进入
  7. if (options.query.userMsg) {
  8. wx.setStorageSync('userMsg', JSON.parse(options.query.userMsg))
  9. wx.setStorageSync('auth', JSON.parse(options.query.auth))
  10. wx.setStorageSync('siteP', JSON.parse(options.query.site));
  11. //获取用户权限
  12. this.globalData.http.basic({
  13. "classname": "sysmanage.develop.userauth.userauth",
  14. "method": "query_userauth",
  15. content: {
  16. nocache: true
  17. }
  18. }).then(res => {
  19. console.log("跳转进入查询权限", res)
  20. if (res.msg != '成功') return wx.showToast({
  21. title: '权限查询失败,请稍后再试',
  22. icon: "none"
  23. })
  24. wx.setStorageSync('userauth', res.data);
  25. });
  26. }
  27. },
  28. initSocket() {
  29. let that = this;
  30. this.globalData.SocketTask = wx.connectSocket({
  31. url: 'wss://oms.idcgroup.com.cn:8079/yos/webSocket/' + wx.getStorageSync('userMsg').token,
  32. complete: (res) => {
  33. console.log(res)
  34. }
  35. })
  36. this.globalData.SocketTask.onOpen(function (res) {
  37. that.globalData.socketEstablish = true;
  38. })
  39. this.globalData.SocketTask.onMessage(function (res) {
  40. that.globalData.socket.callback(res)
  41. })
  42. this.globalData.SocketTask.onError(function (res) {
  43. that.globalData.socketEstablish = false;
  44. })
  45. this.globalData.SocketTask.onClose(function (res) {
  46. that.globalData.socketEstablish = false;
  47. })
  48. },
  49. globalData: {
  50. http: new ApiModel(), //接口文件
  51. queryPer: require("./utils/queryPermissions"), //权限查询
  52. handleSelect: null, //处理选择结果 函数
  53. socketEstablish: false, //是否已经建立socket
  54. SocketTask: '', // Socket方法
  55. socket: { // Socket回调
  56. that: null, //保存this
  57. callback: function () {}
  58. },
  59. host: "https://oms.idcgroup.com.cn:8079"
  60. }
  61. })