app.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // app.js
  2. import {
  3. userLogin
  4. } from '~/api/user'
  5. import {
  6. createStoreBindings
  7. } from 'mobx-miniprogram-bindings'
  8. import {
  9. store
  10. } from '~/store/index'
  11. let storeBindings
  12. App({
  13. onLaunch() {
  14. this.checkIsIos()
  15. this.getNavbarInfo()
  16. },
  17. async onShow(options) {
  18. let shareUid = options.query.uid
  19. this.login(shareUid)
  20. },
  21. login(shareUid) {
  22. this.storeBindings = createStoreBindings(this, {
  23. store,
  24. fields: ['numA', ],
  25. actions: ['updateNumA']
  26. })
  27. wx.login({
  28. success: async (res) => {
  29. this.updateNumA(res)
  30. if (res.code) {
  31. // 获取openid
  32. let data = {
  33. code: res.code,
  34. shareUid
  35. }
  36. let userRes = await userLogin(data)
  37. console.log(userRes);
  38. wx.setStorageSync('uid', userRes.data.uid)
  39. wx.setStorageSync('user', userRes.data)
  40. this.globalData.userInfo = userRes.data
  41. if (getApp().callBack) {
  42. getApp().callBack(userRes);
  43. }
  44. }
  45. }
  46. })
  47. },
  48. checkIsIos: function () {
  49. wx.getSystemInfo({
  50. success: (res) => {
  51. if (res.system.search('iOS') != -1) {
  52. this.globalData.isIOS = true
  53. }
  54. }
  55. })
  56. },
  57. getNavbarInfo() {
  58. // 获取系统信息
  59. const systemInfo = wx.getSystemInfoSync();
  60. console.log(systemInfo);
  61. // 胶囊按钮位置信息
  62. const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
  63. // 导航栏高度 = 状态栏高度 + 44
  64. this.globalData.navBarHeight = systemInfo.statusBarHeight + 44;
  65. this.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
  66. this.globalData.menuTop = menuButtonInfo.top;
  67. this.globalData.menuHeight = menuButtonInfo.height;
  68. },
  69. globalData: {
  70. userInfo: null,
  71. isIOS: false, // 判断设备是否为苹果
  72. navBarHeight: 0, // 导航栏高度
  73. menuRight: 0, // 胶囊距右方间距(方保持左、右间距一致)
  74. menuTop: 0, // 胶囊距底部间距(保持底部间距一致)
  75. menuHeight: 0, // 胶囊高度(自定义内容可与胶囊高度保证一致)
  76. }
  77. })