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
    },  
	 getters: {
		userInfo: state => {
			if(state.userInfo==null){
				if(uni.getStorageSync('union_id')){
					api.getInfo().then(resdata => {
						if(resdata.data.code == 200){
							state.userInfo = resdata.data.data;
						}
						
					});
				}
			}else{
				return state.userInfo
			}
		}
	},
    mutations: {  
        updateUserInfo(state, provider) {  
            state.userInfo = provider.userInfo;  
			console.log(state.userInfo,999)
        },  
        
    }  
})  
export default store