app.js 3.7 KB

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