| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // app.js
- import CustomHook from 'spa-custom-hooks';
- import http from "./utils/http"
- let globalData = {
- //位置
- address: '',
- // 是否已拿到token
- token: '',
- // 用户信息
- userInfo: '',
- //顶部区域
- safeTop: '',
- safeBottom: '',
- menuH: '',
- user: '',
- userInfo: '',
- config: '',
- templateconfig: ''
- }
- CustomHook.install({
- 'Config':{
- name: 'Config',
- watchKey: 'config',
- onUpdate(val) {
- return !!val;
- }
- }
- }, globalData || 'globalData')
- App({
- onLaunch() {
- const res = wx.getMenuButtonBoundingClientRect()
- this.globalData.safeTop = wx.getStorageSync('safeTop') ? wx.getStorageSync('safeTop') : res.top
- this.globalData.menuH = wx.getStorageSync('menuH') ? wx.getStorageSync('menuH') : res.height
- if(!wx.getStorageSync('safeTop')){
- wx.setStorageSync('safeTop', this.globalData.safeTop)
- }
- if(!wx.getStorageSync('menuH')){
- wx.setStorageSync('menuH', this.globalData.menuH)
- }
- this.globalData.safeBottom = wx.getStorageSync('safeBottom') ? wx.getStorageSync('safeBottom') : (wx.getSystemInfoSync().safeArea.bottom - wx.getSystemInfoSync().safeArea.height)
- if(!wx.getStorageSync('safeBottom')){
- wx.setStorageSync('safeBottom', this.globalData.safeBottom)
- }
- http.post('index/templateconfig').then(res => {
- this.globalData.templateconfig = res.data
- })
- http.post('index/getconfig').then(res => {
- this.globalData.config = res.data
- })
- },
- globalData
- })
|