import Vue from 'vue'
|
import Vuex from 'vuex'
|
|
Vue.use(Vuex)
|
|
const navHeight = uni.getStorageSync('navHeight');
|
const statusbarHeight = uni.getStorageSync('statusbarHeight');
|
const userInfo = uni.getStorageSync('userInfo');
|
const shopInfo = uni.getStorageSync('shopInfo');
|
const openid = uni.getStorageSync('openid');
|
const token = uni.getStorageSync('token');
|
const shopToken = uni.getStorageSync('shopToken');
|
|
|
const store = new Vuex.Store({
|
|
state: {
|
imgUrl: 'https://www.duijiaoniwo.com', // 服务器资源前缀
|
navHeight: navHeight || '',
|
statusbarHeight: statusbarHeight || '',
|
userInfo: userInfo || '', // 用户信息
|
shopInfo: shopInfo || '', // 用户信息
|
token: token || '',
|
shopToken: shopToken || '',
|
openid: openid || '',
|
position: null
|
},
|
mutations: {
|
// 设置导航栏高度
|
setHeight(state, val) {
|
state.navHeight = val.navHeight
|
state.statusbarHeight = val.statusbarHeight
|
uni.setStorageSync('navHeight', val.navHeight);
|
uni.setStorageSync('statusbarHeight', val.statusbarHeight);
|
},
|
// 设置token
|
setToken(state, val) {
|
state.token = val
|
uni.setStorageSync('token', val);
|
},
|
setShopToken(state, val) {
|
state.shopToken = val
|
uni.setStorageSync('shopToken', val);
|
},
|
// 设置openid
|
setOpenId(state, openid) {
|
state.openid = openid
|
uni.setStorageSync('openid', openid);
|
},
|
// 设置用户信息
|
setUserInfo(state, val) {
|
state.userInfo = val
|
uni.setStorageSync('userInfo', val);
|
},
|
setShopInfo(state, val) {
|
state.setShopInfo = val
|
uni.setStorageSync('setShopInfo', val);
|
},
|
// 设置当前位置信息
|
setPosition(state, val) {
|
state.position = val
|
},
|
},
|
|
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 })
|
}
|
}
|
|
})
|
|
export default store;
|