app.js 2.6 KB

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