app.js 3.2 KB

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