app.js 2.7 KB

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