app.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.removeStorageSync('templetList');
  12. wx.setStorageSync('userMsg', JSON.parse(options.query.userMsg));
  13. wx.setStorageSync('auth', JSON.parse(options.query.auth));
  14. wx.setStorageSync('siteP', JSON.parse(options.query.site));
  15. wx.setStorageSync('templetList', JSON.parse(options.query.templetList));
  16. console.log("options.query.templetList", options.query.templetList)
  17. //获取用户权限
  18. this.globalData.http.basic({
  19. "classname": "sysmanage.develop.userauth.userauth",
  20. "method": "query_userauth",
  21. content: {
  22. nocache: true
  23. }
  24. }).then(res => {
  25. console.log("跳转进入查询权限", res)
  26. if (res.msg != '成功') return wx.showToast({
  27. title: '权限查询失败,请稍后再试',
  28. icon: "none"
  29. })
  30. wx.setStorageSync('userauth', res.data);
  31. });
  32. }
  33. },
  34. initSocket() {
  35. let that = this;
  36. this.globalData.SocketTask = wx.connectSocket({
  37. url: (this.globalData.http.baseUrl + '/yos/webSocket/').replace("https", "wss").replace("http", "ws") + wx.getStorageSync('userMsg').token,
  38. complete: (res) => {
  39. console.log(res)
  40. }
  41. })
  42. this.globalData.SocketTask.onOpen(function (res) {
  43. that.globalData.socketEstablish = true;
  44. })
  45. this.globalData.SocketTask.onMessage(function (res) {
  46. that.globalData.socketCallback(res)
  47. })
  48. this.globalData.SocketTask.onError(function (res) {
  49. that.globalData.socketEstablish = false;
  50. })
  51. this.globalData.SocketTask.onClose(function (res) {
  52. that.globalData.socketEstablish = false;
  53. })
  54. },
  55. /**
  56. * 查询是否为数据代理人
  57. * @param {string} ownertable 数据表名
  58. * @param {number} ownerid 数据id
  59. */
  60. agentOrNot: (ownertable, ownerid) => getApp().globalData.http.basic({
  61. "id": 20230329122604,
  62. "content": {
  63. ownertable,
  64. ownerid
  65. }
  66. }),
  67. globalData: {
  68. http: new ApiModel(), //接口文件
  69. queryPer: require("./utils/queryPermissions"), //权限查询
  70. socketEstablish: false, //是否已经建立socket
  71. SocketTask: '', // Socket方法
  72. socketCallback: null, // Socket回调
  73. handleSelect: null, //处理选择结果 函数
  74. },
  75. })