app.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. wx.setStorageSync('appid', 'wx197f219a82a89d7b');
  46. },
  47. initSocket() {
  48. let that = this;
  49. this.globalData.SocketTask = wx.connectSocket({
  50. url: (this.globalData.http.baseUrl + '/yos/webSocket/').replace("https", "wss").replace("http", "ws") + wx.getStorageSync('userMsg').token,
  51. complete: (res) => {
  52. console.log(res)
  53. }
  54. })
  55. this.globalData.SocketTask.onOpen(function (res) {
  56. that.globalData.socketEstablish = true;
  57. })
  58. this.globalData.SocketTask.onMessage(function (res) {
  59. that.globalData.socketCallback(res)
  60. })
  61. this.globalData.SocketTask.onError(function (res) {
  62. that.globalData.socketEstablish = false;
  63. })
  64. this.globalData.SocketTask.onClose(function (res) {
  65. that.globalData.socketEstablish = false;
  66. })
  67. },
  68. /**
  69. * 查询是否为数据代理人
  70. * @param {string} ownertable 数据表名
  71. * @param {number} ownerid 数据id
  72. */
  73. agentOrNot: (ownertable, ownerid) => getApp().globalData.http.basic({
  74. "id": 20230329122604,
  75. "content": {
  76. ownertable,
  77. ownerid
  78. }
  79. }),
  80. globalData: {
  81. http: new ApiModel(), //接口文件
  82. queryPer: require("./utils/queryPermissions"), //权限查询
  83. socketEstablish: false, //是否已经建立socket
  84. SocketTask: '', // Socket方法
  85. socketCallback: null, // Socket回调
  86. handleSelect: null, //处理选择结果 函数
  87. },
  88. })