app.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // app.js
  2. App({
  3. onLaunch() {
  4. // 展示本地存储能力
  5. const logs = wx.getStorageSync('logs') || []
  6. logs.unshift(Date.now())
  7. wx.setStorageSync('logs', logs)
  8. // 登录
  9. wx.login({
  10. success: res => {
  11. const { code: js_code } = res
  12. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  13. wx.request({
  14. url: `${this.globalData.publicUrl}/api/st/system/weixin/appAuth?js_code=` + js_code,
  15. method: "get",
  16. header: {
  17. 'x-tenant': 'test'
  18. },
  19. success: res => {
  20. const { errcode, data } = res.data
  21. if (errcode === 0) {
  22. this.globalData.userInfo = data;
  23. }
  24. },
  25. error: err => {
  26. wx.showToast({
  27. title: err.msg,
  28. icon: 'error'
  29. })
  30. }
  31. })
  32. }
  33. })
  34. //获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度
  35. wx.getSystemInfo({
  36. success: (res) => {
  37. this.globalData.height = res.statusBarHeight
  38. this.globalData.windowHeight = res.windowHeight
  39. }
  40. })
  41. },
  42. globalData: {
  43. userInfo: null,
  44. height: 0,
  45. windowHeight: 0,
  46. publicUrl: 'http://192.168.1.19:9901',
  47. fileUrl: "http://broadcast.waityou24.cn",
  48. openid: null
  49. }
  50. })