app.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. console.log(res);
  12. const { code: js_code } = res
  13. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  14. wx.request({
  15. url: `${this.globalData.publicUrl}/api/st/system/weixin/appAuth?js_code=` + js_code,
  16. method: "get",
  17. header: {
  18. 'x-tenant': 'test'
  19. },
  20. success: res => {
  21. console.log(res)
  22. },
  23. error: err => {
  24. wx.showToast({
  25. title: err.msg,
  26. icon: 'error'
  27. })
  28. }
  29. })
  30. }
  31. })
  32. //获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度
  33. wx.getSystemInfo({
  34. success: (res) => {
  35. this.globalData.height = res.statusBarHeight
  36. this.globalData.windowHeight = res.windowHeight
  37. }
  38. })
  39. },
  40. globalData: {
  41. userInfo: null,
  42. height: 0,
  43. windowHeight: 0,
  44. publicUrl: 'http://192.168.1.19:9901',
  45. fileUrl: "http://broadcast.waityou24.cn"
  46. }
  47. })