import Vue from 'vue'
import Vuex from 'vuex'
import api from '@/common/api.js'
Vue.use(Vuex);
const store = new Vuex.Store({  
    state: {  
        login: true,  
        token: '',  
        avatarUrl: '',  
        userName: '',
		userInfo:null,
		dictObj:null,
		allowLoading:true
    },  
	 getters: {
		userInfo: state => {
			if(state.userInfo==null){
				if(uni.getStorageSync('union_id')){
					getUserInfo(state)
				}
			}
			return state.userInfo
		},
		dictObj:state => {
			return state.dictObj
		},
		allowLoading:state => {
			return state.allowLoading
		},
	},
    mutations: { 
        updateUserInfo(state, provider) {
            state.userInfo = provider.userInfo;  
        },
    }  
})  
async function getUserInfo(state){
	const resdata = await api.getInfo()
	if(resdata.data.code == 200){
		state.userInfo = resdata.data.data;
	}
}
export default store