app.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // app.js
  2. import CustomHook from 'spa-custom-hooks';
  3. import http from "./utils/http"
  4. let globalData = {
  5. //位置
  6. address: '',
  7. // 是否已拿到token
  8. token: '',
  9. // 用户信息
  10. userInfo: '',
  11. //顶部区域
  12. safeTop: '',
  13. safeBottom: '',
  14. menuH: '',
  15. user: '',
  16. userInfo: '',
  17. config: '',
  18. templateconfig: ''
  19. }
  20. CustomHook.install({
  21. 'Config':{
  22. name: 'Config',
  23. watchKey: 'config',
  24. onUpdate(val) {
  25. return !!val;
  26. }
  27. }
  28. }, globalData || 'globalData')
  29. App({
  30. onLaunch() {
  31. const res = wx.getMenuButtonBoundingClientRect()
  32. this.globalData.safeTop = wx.getStorageSync('safeTop') ? wx.getStorageSync('safeTop') : res.top
  33. this.globalData.menuH = wx.getStorageSync('menuH') ? wx.getStorageSync('menuH') : res.height
  34. if(!wx.getStorageSync('safeTop')){
  35. wx.setStorageSync('safeTop', this.globalData.safeTop)
  36. }
  37. if(!wx.getStorageSync('menuH')){
  38. wx.setStorageSync('menuH', this.globalData.menuH)
  39. }
  40. this.globalData.safeBottom = wx.getStorageSync('safeBottom') ? wx.getStorageSync('safeBottom') : (wx.getSystemInfoSync().safeArea.bottom - wx.getSystemInfoSync().safeArea.height)
  41. if(!wx.getStorageSync('safeBottom')){
  42. wx.setStorageSync('safeBottom', this.globalData.safeBottom)
  43. }
  44. http.post('index/templateconfig').then(res => {
  45. this.globalData.templateconfig = res.data
  46. })
  47. http.post('index/getconfig').then(res => {
  48. this.globalData.config = res.data
  49. })
  50. },
  51. globalData
  52. })