| | |
| | | |
| | | Vue.use(Vuex) |
| | | const userInfo = uni.getStorageSync('userInfo'); |
| | | const token = uni.getStorageSync('token'); |
| | | |
| | | const store = new Vuex.Store({ |
| | | |
| | | state: { |
| | | userInfo: userInfo || null // 用户信息 |
| | | userInfo: userInfo || null, |
| | | token: token || null // token |
| | | }, |
| | | mutations: { |
| | | // 设置用户信息 |
| | | setUserInfo(state, val) { |
| | | state.userInfo = val |
| | | uni.setStorageSync('userInfo', val); |
| | | }, |
| | | setToken(state, val) { |
| | | state.token = val |
| | | uni.setStorageSync('token', val); |
| | | }, |
| | | clearAll(state) { |
| | | state.userInfo = null |
| | | state.token = null |
| | | uni.clearStorageSync() |
| | | } |
| | | }, |
| | | |
| | | actions: { |
| | | // 获取状态高度 |
| | | getHeight(context) { |
| | | let res = uni.getMenuButtonBoundingClientRect() |
| | | let status = uni.getSystemInfoSync() |
| | | var height = res.height |
| | | let statusbarHeight = status.statusBarHeight |
| | | let navHeight = res.height + (res.top - statusbarHeight) * 2; |
| | | context.commit('setHeight', { statusbarHeight, navHeight, height }) |
| | | } |
| | | // getHeight(context) { |
| | | // let res = uni.getMenuButtonBoundingClientRect() |
| | | // let status = uni.getSystemInfoSync() |
| | | // var height = res.height |
| | | // let statusbarHeight = status.statusBarHeight |
| | | // let navHeight = res.height + (res.top - statusbarHeight) * 2; |
| | | // context.commit('setHeight', { statusbarHeight, navHeight, height }) |
| | | // } |
| | | } |
| | | |
| | | }) |