app.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. safeTop: '',
  11. safeBottom: '',
  12. menuH: '',
  13. // 用户信息
  14. user: '',
  15. userInfo: '',
  16. config: '',
  17. templateconfig: ''
  18. }
  19. CustomHook.install({
  20. 'Address': {
  21. name: 'Address',
  22. watchKey: 'address',
  23. onUpdate(val) {
  24. return !!val;
  25. }
  26. },
  27. 'Config':{
  28. name: 'Config',
  29. watchKey: 'config',
  30. onUpdate(val) {
  31. return !!val;
  32. }
  33. }
  34. }, globalData || 'globalData')
  35. App({
  36. onLaunch() {
  37. const res = wx.getMenuButtonBoundingClientRect()
  38. this.globalData.safeTop = wx.getStorageSync('safeTop') ? wx.getStorageSync('safeTop') : res.top
  39. this.globalData.menuH = wx.getStorageSync('menuH') ? wx.getStorageSync('menuH') : res.height
  40. if(!wx.getStorageSync('safeTop')){
  41. wx.setStorageSync('safeTop', this.globalData.safeTop)
  42. }
  43. if(!wx.getStorageSync('menuH')){
  44. wx.setStorageSync('menuH', this.globalData.menuH)
  45. }
  46. this.globalData.safeBottom = wx.getStorageSync('safeBottom') ? wx.getStorageSync('safeBottom') : (wx.getSystemInfoSync().safeArea.bottom - wx.getSystemInfoSync().safeArea.height)
  47. if(!wx.getStorageSync('safeBottom')){
  48. wx.setStorageSync('safeBottom', this.globalData.safeBottom)
  49. }
  50. http.post('index/getconfig').then(res => {
  51. this.globalData.config = res.data
  52. })
  53. http.post('index/templateconfig').then(res => {
  54. this.globalData.templateconfig = res.data
  55. })
  56. },
  57. onShow(){
  58. let that = this
  59. http.getLocation().then(res => {
  60. that.globalData.address = res
  61. }).catch(e => {
  62. this.globalData.address = e
  63. })
  64. },
  65. globalData
  66. })