app.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. wx.removeStorageSync('userMsg')
  12. wx.removeStorageSync('auth')
  13. wx.removeStorageSync('userauth');
  14. wx.setStorageSync('userMsg', JSON.parse(options.query.userMsg));
  15. wx.setStorageSync('auth', JSON.parse(options.query.auth));
  16. wx.setStorageSync('siteP', JSON.parse(options.query.site));
  17. wx.setStorageSync('languagecode', JSON.parse(options.query.languagecode));
  18. //获取用户权限
  19. this.globalData.http.basic({
  20. "classname": "sysmanage.develop.userauth.userauth",
  21. "method": "query_userauth",
  22. content: {
  23. nocache: true
  24. }
  25. }).then(res => {
  26. console.log("跳转进入查询权限", res)
  27. if (res.msg != '成功') return wx.showToast({
  28. title: '权限查询失败,请稍后再试',
  29. icon: "none"
  30. })
  31. wx.setStorageSync('userauth', res.data);
  32. });
  33. try {
  34. if (!wx.getStorageSync('templetList')) getTempletList()
  35. } catch (error) {
  36. getTempletList()
  37. }
  38. function getTempletList() {
  39. this.globalData.http.basic({
  40. "classname": "sysmanage.develop.querytemplet.querytemplet",
  41. "method": "query",
  42. "content": {}
  43. }).then(res => {
  44. console.log("获取列表查询条件", res)
  45. if (res.msg != '成功') return;
  46. let data = res.data.find(v => v.templetname == '站点全部');
  47. if (data) {
  48. res.data = res.data.filter(v => v.templetname != '站点全部')
  49. res.data.unshift(data)
  50. }
  51. wx.setStorageSync('templetList', res.data)
  52. getCurrentPages()[getCurrentPages().length - 1].getList && getCurrentPages()[getCurrentPages().length - 1].getList(true);
  53. })
  54. };
  55. }
  56. wx.setStorageSync('appid', 'wx197f219a82a89d7b');
  57. if (!wx.getStorageSync('languagecode')) wx.setStorageSync('languagecode', 'ZH');
  58. this.globalData.Language.getLanguages(wx.getStorageSync('languagecode'));
  59. },
  60. initSocket() {
  61. let that = this;
  62. this.globalData.SocketTask = wx.connectSocket({
  63. url: (this.globalData.http.baseUrl + '/yos/webSocket/').replace("https", "wss").replace("http", "ws") + wx.getStorageSync('userMsg').token,
  64. complete: (res) => {
  65. console.log(res)
  66. }
  67. })
  68. this.globalData.SocketTask.onOpen(function (res) {
  69. that.globalData.socketEstablish = true;
  70. })
  71. this.globalData.SocketTask.onMessage(function (res) {
  72. that.globalData.socketCallback(res)
  73. })
  74. this.globalData.SocketTask.onError(function (res) {
  75. that.globalData.socketEstablish = false;
  76. })
  77. this.globalData.SocketTask.onClose(function (res) {
  78. that.globalData.socketEstablish = false;
  79. })
  80. },
  81. agentOrNot: (ownertable, ownerid) => getApp().globalData.http.basic({
  82. "id": 20230329122604,
  83. "content": {
  84. ownertable,
  85. ownerid
  86. }
  87. }),
  88. globalData: {
  89. http: new ApiModel(), //接口文件
  90. Language: new Language(), //接口文件
  91. queryPer: require("./utils/queryPermissions"), //权限查询
  92. socketEstablish: false, //是否已经建立socket
  93. SocketTask: '', // Socket方法
  94. socketCallback: null, // Socket回调
  95. handleSelect: null, //处理选择结果 函数
  96. },
  97. })