app.js 3.6 KB

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