app.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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}/st/api/weixin/appAuth?js_code=` + js_code,
  18. method: "get",
  19. success: res => {
  20. const { errcode, data } = res.data
  21. if (errcode === 0) {
  22. app.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.197:9902',
  53. // publicUrl: 'https://www.waityou24.cn',
  54. // 图片请求接口
  55. fileUrl: "http://broadcast.waityou24.cn",
  56. },
  57. // 微信openid回调
  58. toLogin: login.toLogin,
  59. ...httpUtil
  60. })