app.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. wx.setStorage({ key: "userInfo", data: null })
  24. }
  25. },
  26. error: err => {
  27. wx.showToast({
  28. title: err.msg,
  29. icon: 'error'
  30. })
  31. }
  32. })
  33. }
  34. })
  35. //获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度
  36. wx.getSystemInfo({
  37. success: (res) => {
  38. this.globalData.height = res.statusBarHeight
  39. this.globalData.windowHeight = res.windowHeight
  40. }
  41. })
  42. },
  43. globalData: {
  44. // 微信用户基本信息
  45. userInfo: {},
  46. // 微信用户openid,sessionKey
  47. wxInfo: {},
  48. // 头部高度
  49. height: 0,
  50. // 手机页面高度
  51. windowHeight: 0,
  52. // 请求接口
  53. publicUrl: 'http://192.168.1.19:9901',
  54. // 图片请求接口
  55. fileUrl: "http://broadcast.waityou24.cn",
  56. // 站点标识
  57. tenant: "test"
  58. }
  59. })