app.js 2.3 KB

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