app.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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': this.globalData.tenant
  18. },
  19. success: res => {
  20. const { errcode, data } = res.data
  21. if (errcode === 0) {
  22. this.globalData.wxInfo = 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. // 微信用户基本信息
  44. userInfo: {},
  45. // 微信用户openid,sessionKey
  46. wxInfo: {},
  47. // 头部高度
  48. height: 0,
  49. // 手机页面高度
  50. windowHeight: 0,
  51. // 请求接口
  52. publicUrl: 'http://192.168.1.19:9901',
  53. // 图片请求接口
  54. fileUrl: "http://broadcast.waityou24.cn",
  55. // 站点标识
  56. tenant: "test"
  57. }
  58. })