app.js 3.0 KB

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