import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin:false,
		userToken:{},
		userInfo:{}
	},
	mutations: {
		doLogin(state, data) {
			state.hasLogin = true;
			state.userToken = data;
			uni.setStorage({
				key: 'userToken',
				data: data
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			state.userToken = {};
			uni.clearStorageSync();
		},
	},
	actions:{
		setLogin({ commit }, token){
			commit('doLogin', token);
		},
	}
})

export default store