app.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // app.js
  2. import CustomHook from 'spa-custom-hooks';
  3. import http from "./utils/http"
  4. let globalData = {
  5. //位置
  6. realAddress: '',
  7. address: '',
  8. // 是否已拿到token
  9. token: '',
  10. //顶部区域
  11. safeTop: '',
  12. safeBottom: '',
  13. menuH: '',
  14. // 用户信息
  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. 'Address':{
  29. name:'Address',
  30. watchKey: 'address',
  31. onUpdate(val){
  32. return !!val;
  33. }
  34. },
  35. }, globalData || 'globalData')
  36. App({
  37. onLaunch() {
  38. const res = wx.getMenuButtonBoundingClientRect()
  39. this.globalData.safeTop = wx.getStorageSync('safeTop') ? wx.getStorageSync('safeTop') : res.top
  40. this.globalData.menuH = wx.getStorageSync('menuH') ? wx.getStorageSync('menuH') : res.height
  41. if(!wx.getStorageSync('safeTop')){
  42. wx.setStorageSync('safeTop', this.globalData.safeTop)
  43. }
  44. if(!wx.getStorageSync('menuH')){
  45. wx.setStorageSync('menuH', this.globalData.menuH)
  46. }
  47. this.globalData.safeBottom = wx.getStorageSync('safeBottom') ? wx.getStorageSync('safeBottom') : (wx.getSystemInfoSync().safeArea.bottom - wx.getSystemInfoSync().safeArea.height)
  48. if(!wx.getStorageSync('safeBottom')){
  49. wx.setStorageSync('safeBottom', this.globalData.safeBottom)
  50. }
  51. http.post('index/getconfig').then(res => {
  52. this.globalData.config = res.data
  53. })
  54. http.post('index/templateconfig').then(res => {
  55. this.globalData.templateconfig = res.data
  56. })
  57. },
  58. onShow(){
  59. // 展示本地存储能力
  60. http.getLocation().then(res => {
  61. this.globalData.address = res
  62. this.globalData.realAddress = res
  63. }).catch(e => {
  64. this.globalData.address = e
  65. })
  66. },
  67. globalData
  68. })