app.js 2.6 KB

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