app.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // app.js
  2. import login from './utils/login'
  3. const app = getApp()
  4. import * as httpUtil from "./utils/httpUtil";
  5. App({
  6. onLaunch() {
  7. // 展示本地存储能力
  8. const logs = wx.getStorageSync('logs') || []
  9. logs.unshift(Date.now())
  10. wx.setStorageSync('logs', logs)
  11. wx.login({
  12. success: res => {
  13. const app = getApp()
  14. const { code: js_code } = res
  15. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  16. wx.request({
  17. url: `${app.globalData.publicUrl}/api/st/system/weixin/appAuth?js_code=` + js_code,
  18. method: "get",
  19. header: {
  20. 'x-tenant': app.globalData.tenant
  21. },
  22. success: res => {
  23. const { errcode, data } = res.data
  24. if (errcode === 0) {
  25. app.globalData.wxInfo = data;
  26. }
  27. },
  28. error: err => {
  29. wx.showToast({
  30. title: err.msg,
  31. icon: 'error'
  32. })
  33. }
  34. })
  35. }
  36. })
  37. //获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度
  38. wx.getSystemInfo({
  39. success: (res) => {
  40. this.globalData.height = res.statusBarHeight
  41. this.globalData.windowHeight = res.windowHeight
  42. }
  43. })
  44. },
  45. globalData: {
  46. // 微信用户基本信息
  47. userInfo: {},
  48. // 微信用户openid,sessionKey
  49. wxInfo: {},
  50. // 头部高度
  51. height: 0,
  52. // 手机页面高度
  53. windowHeight: 0,
  54. // 请求接口
  55. // publicUrl: 'http://192.168.1.19:9901',
  56. publicUrl: 'https://www.waityou24.cn',
  57. // 图片请求接口
  58. fileUrl: "http://broadcast.waityou24.cn",
  59. // 站点标识
  60. tenant: "test",
  61. },
  62. // 微信openid回调
  63. toLogin: login.toLogin,
  64. ...httpUtil
  65. })