app.js 2.5 KB

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