app.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. this.globalData.http.sColors = require("./utils/defaultColors")
  41. _Http.basic({
  42. "classname": "sysmanage.develop.optiontype.optiontype",
  43. "method": "optiontypeselect",
  44. "content": {
  45. "typename": "statuscolors"
  46. }
  47. }).then(res => {
  48. if (res.code != '1') return;
  49. res.data.forEach(v => {
  50. _Http.sColors[v.value] = v.remarks
  51. })
  52. });
  53. } else {
  54. this.globalData.http.sColors = require("./utils/defaultColors")
  55. }
  56. if (!wx.getStorageSync('languagecode')) wx.setStorageSync('languagecode', 'ZH');
  57. this.globalData.Language.getLanguages(wx.getStorageSync('languagecode'));
  58. },
  59. initSocket() {
  60. let that = this;
  61. this.globalData.SocketTask = wx.connectSocket({
  62. url: (this.globalData.http.baseUrl + '/yos/webSocket/').replace("https", "wss").replace("http", "ws") + wx.getStorageSync('userMsg').token,
  63. complete: (res) => {
  64. console.log(res)
  65. }
  66. })
  67. this.globalData.SocketTask.onOpen(function (res) {
  68. that.globalData.socketEstablish = true;
  69. })
  70. this.globalData.SocketTask.onMessage(function (res) {
  71. that.globalData.socket.callback(res)
  72. })
  73. this.globalData.SocketTask.onError(function (res) {
  74. that.globalData.socketEstablish = false;
  75. })
  76. this.globalData.SocketTask.onClose(function (res) {
  77. that.globalData.socketEstablish = false;
  78. })
  79. },
  80. globalData: {
  81. http: new ApiModel, //挂载接口文件
  82. Language: new Language(), //语言包
  83. queryPer: require("./utils/queryPermissions"), //权限查询
  84. handleSelect: null, //处理选择结果 函数
  85. socketEstablish: false, //是否已经建立socket
  86. SocketTask: '', // Socket方法
  87. socketCallback: null, // Socket回调
  88. }
  89. })