app.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.msg != '成功') return wx.showToast({
  34. title: '权限查询失败,请稍后再试',
  35. icon: "none"
  36. })
  37. wx.setStorageSync('userauth', res.data);
  38. });
  39. };
  40. if (!wx.getStorageSync('languagecode')) wx.setStorageSync('languagecode', 'ZH');
  41. this.globalData.Language.getLanguages(wx.getStorageSync('languagecode'));
  42. },
  43. initSocket() {
  44. let that = this;
  45. this.globalData.SocketTask = wx.connectSocket({
  46. url: (this.globalData.http.baseUrl + '/yos/webSocket/').replace("https", "wss").replace("http", "ws") + wx.getStorageSync('userMsg').token,
  47. complete: (res) => {
  48. console.log(res)
  49. }
  50. })
  51. this.globalData.SocketTask.onOpen(function (res) {
  52. that.globalData.socketEstablish = true;
  53. })
  54. this.globalData.SocketTask.onMessage(function (res) {
  55. that.globalData.socket.callback(res)
  56. })
  57. this.globalData.SocketTask.onError(function (res) {
  58. that.globalData.socketEstablish = false;
  59. })
  60. this.globalData.SocketTask.onClose(function (res) {
  61. that.globalData.socketEstablish = false;
  62. })
  63. },
  64. globalData: {
  65. http: new ApiModel, //挂载接口文件
  66. Language: new Language(), //语言包
  67. queryPer: require("./utils/queryPermissions"), //权限查询
  68. handleSelect: null, //处理选择结果 函数
  69. socketEstablish: false, //是否已经建立socket
  70. SocketTask: '', // Socket方法
  71. socketCallback: null, // Socket回调
  72. }
  73. })