app.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. if (!wx.getStorageSync('templetList')) this.globalData.http.basic({
  30. "classname": "sysmanage.develop.querytemplet.querytemplet",
  31. "method": "query",
  32. "content": {}
  33. }).then(res => {
  34. console.log("获取列表查询条件", res)
  35. if (res.msg != '成功') return;
  36. let data = res.data.find(v => v.templetname == '站点全部');
  37. if (data) {
  38. res.data = res.data.filter(v => v.templetname != '站点全部')
  39. res.data.unshift(data)
  40. }
  41. wx.setStorageSync('templetList', res.data)
  42. getCurrentPages()[getCurrentPages().length - 1].getList && getCurrentPages()[getCurrentPages().length - 1].getList(true);
  43. })
  44. }
  45. },
  46. initSocket() {
  47. let that = this;
  48. this.globalData.SocketTask = wx.connectSocket({
  49. url: 'wss://oms.idcgroup.com.cn:8079/yos/webSocket/' + wx.getStorageSync('userMsg').token,
  50. complete: (res) => {
  51. console.log(res)
  52. }
  53. })
  54. this.globalData.SocketTask.onOpen(function (res) {
  55. that.globalData.socketEstablish = true;
  56. })
  57. this.globalData.SocketTask.onMessage(function (res) {
  58. that.globalData.socketCallback(res)
  59. })
  60. this.globalData.SocketTask.onError(function (res) {
  61. that.globalData.socketEstablish = false;
  62. })
  63. this.globalData.SocketTask.onClose(function (res) {
  64. that.globalData.socketEstablish = false;
  65. })
  66. },
  67. /**
  68. * 查询是否为数据代理人
  69. * @param {string} ownertable 数据表名
  70. * @param {number} ownerid 数据id
  71. */
  72. agentOrNot: (ownertable, ownerid) => getApp().globalData.http.basic({
  73. "id": 20230329122604,
  74. "content": {
  75. ownertable,
  76. ownerid
  77. }
  78. }),
  79. globalData: {
  80. http: new ApiModel(), //接口文件
  81. queryPer: require("./utils/queryPermissions"), //权限查询
  82. socketEstablish: false, //是否已经建立socket
  83. SocketTask: '', // Socket方法
  84. socketCallback: null, // Socket回调
  85. handleSelect: null, //处理选择结果 函数
  86. },
  87. })